Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

DIY decoder

15577 views
30 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Thursday, May 31, 2018 5:07 PM

 That's exactly what I was talking about saving - all the headaches. It's going to be a lot more than 50 lines of code to implement all 4 programming methods - though you really only need to implement one. No one does Register mode any more, you can leave that one completely out. Pick one, implement that. All systems support at least 2 of the other 3, most still support the ancient register mode just in case you have some very old decoders, but of all the ones you might NOT find on a modern system, that would be the one.

Consisting - well, I guess this is where Digitrax's way is better. The decoder gets no changes when I consist, I just need to know the address. And it's not likely a function decoder for controller the lights of a passenger car would be consisted with anything anyway

 You were talking about making a function decoder for a apssenger car - and you're the one programming it, so you know the address.

  I still don;t understand why it would matter what system you are using. I have multiple methods of programming decoders and I can assure you that each and every decoder does not have some code in it to tell if it is getting programming commands from Digitrax or NCE or MRC or Roco or some DIY DCC system. Unless you mean support for the 4 methods, but the only thing that might not give you the option of any of them would be a homemade DCC system. Most any commercial system does at least 3 out of the 4. And it's not like you're giving this to other people who might have no clue - if you are building it then you know what program mode(s) you included in the code.

 If you don;t allow programming and hard code the address - just keep a list, or use JMRI to keep it for you. So the next one you program, you give a different address. I keep coming back to the whole idea of, once set up and running, how often do you actually change anything? Especially the address - if you've addressed the loco to the cab number, why would you ever change it, other than removing the decoder and putting it in a different loco? No, this is not good for making these by the dozens and selling or giving them to people, especially if trying to create a marketable product, you need to follow ALL NMRA specifications. But for experimenting with for yourself? At least START simple and then add in CV programming or whatever other features you want. Decoding the packets and making calls to functions based on the packet type or command is kind of the easy part. Acting on that data, or pulling the data from the command is where it starts to get complex. For all the things you aren't implementing initially - just make the function a trivial one that does nothing. Your program will be a whole lot of do nothing trivial functions plus a few that actually do something. Then as you want to add another feature, fill out the code for that function.

                                    --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    November 2016
  • 196 posts
Posted by khier on Thursday, May 31, 2018 10:50 AM

rrinker

 What would you need to change if moving to a different DCC system?


It matters as long as the CV have to be manipulated.

rrinker

 How often do you actually reprogram the regualr decoders you have now, once you get a given loco set up and working the way you want?


And how would you retrieve the address? Assuming you bought a new locomotive, how to guarantee you will not give it the same address of an existing one?

rrinker

 It's just less convenient to change on the fly


VERY inconvenient

rrinker

, but once it's all set up the way you want, how much changing will you do



Activate/deactivate consist, for example.

 

And what on earth would I save by skipping the programming mode? 30, 40, or even 50 lines of code? The headache is not to type the lines as I said earlier, but to dig into the confusing NMRA standards and extract the data.

Regards

Walid

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Thursday, May 31, 2018 7:16 AM

 It wouldn;t matter what system you used it on. The fexied address would be the fixed address. The packet for F2 On is the same on any DCC system. What would you need to change if moving to a different DCC system? How often do you actually reprogram the regualr decoders you have now, once you get a given loco set up and working the way you want? Hard coding the config in your firmware instead of using DCC programming doesn;t restrict you to one DCC system or brand. It's just less convenient to change on the fly, but once it's all set up the way you want, how much changing will you do?

                                  --Randy


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    November 2016
  • 196 posts
Posted by khier on Thursday, May 31, 2018 3:35 AM

rrinker
 

If doing it for your own use and not as a product to sell to others - you can.......



This is what I thought at the beginning. However, it would be tedious to use things without the ability to retrieve/manipulate CV values. What happens if my z21 for any reason died and I had to use different/older equipment? Besides, I was not sure which protocol my command station uses. What makes things worse, z21 has three programming menus. They do not clearly speicify POM/Programming track, or otherwise. I could not believe my eyes when I discovered for example that it sometimes uses byte 2 for light control if no speed command were sent, but switch to the F0 to control light after sending speed information. Therefore, I have to be as universal as I can (well, not exactly universal, I dropped the paging mode completely), even for my own use.  

Walid

  • Member since
    July 2007
  • From: Yorkton, Sk, Cnd
  • 441 posts
Posted by wvg_ca on Wednesday, May 30, 2018 11:41 PM

mine is basically a copy of the MERG version 12, code is on thier page ..pcb decoder

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Wednesday, May 30, 2018 8:41 PM

The same code will run on any compatible Atmel microcontroller. Including nice small surface mount ones. You don't need to use a full Arduino, although a Pro Mini or Nano is small enough to fit in a hood diesel in HO, but maybe not that AND all the parts to drive the motor. Even then, most of the size of the device is in things that aren;t needed, the second voltage regulator, all those pins in large .100 spacing, a reset pushbutton, a USB jack... 

                                   --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    March 2018
  • 688 posts
Posted by BNSF UP and others modeler on Wednesday, May 30, 2018 6:03 PM

Yes, the first link leads you to instructions for a decoder that is to big for smaller scales. Not real helpful unless there is another article on how to make a smaller one.

I'm beginning to realize that Windows 10 and sound decoders have a lot in common. There are so many things you have to change in order to get them to work the way you want.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Wednesday, May 30, 2018 5:14 PM

gregc

 

 
garya

 

if you look thru these links, you'll find a zip file containing NmraDcc.cpp/h which presumably receive and decode DCC packets

 

 DOH. Here I am trying to figure out a way to self-calibrate an IR sensor to adjust to varying light (because I have every intention of having both day and night operations) and right there Geoff has the EASY answer - a DIFFERENTIAL IR detector. Rather than detecting absolute levels to indicate the beam is blocked or not, it compares two sensors - on exposed to ambient and one that gets blocked by the train. Simple!

                                              --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Wednesday, May 30, 2018 5:10 PM

khier

Randy,

 

Main problem was/is to understand the NMRA documents. I could achieve some progress, but the backward compatibility (who needs 14, or even 28 speed steps??), especially the programming (of the decoder), are really stupid. There four ways to manipulate the CVs and do the programming. Perhaps there are even more.  I am at the stage to build circuits and perform testing (well, each time I thought I am done I found other things to do). My idea is to start with a function only decoder, essentially for interior lighting, and move to motor decoder later.

Regards

Walid

 

If doing it for your own use and not as a product to sell to others - you can leave out what you want, and you can hard code (well, use #DEFINE in your code) the CV values and just change the settings in the micro's programming environment and flash new code to it. All you really need is to decipher the control packets and completely ignore programming of CVs. Especially for an accessory decoder - all iut needs to do is see packets addressed to whatever address you assign it (no need t implement all program modes - just implement one if you want to program it via DCC, or hard code it in the program if not) and then look for function state messages, and then only for the functions you plan to use - say F1-F4, and ignore all the others.

                                            --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    July 2007
  • From: Yorkton, Sk, Cnd
  • 441 posts
Posted by wvg_ca on Wednesday, May 30, 2018 2:22 PM

close, :)

  • Member since
    December 2004
  • From: Bedford, MA, USA
  • 21,342 posts
Posted by MisterBeasley on Wednesday, May 30, 2018 2:01 PM

Sure, but I realized I'd have to use one of those old wide-body BB Athearns to put it in...

It takes an iron man to play with a toy iron horse. 

  • Member since
    November 2016
  • 196 posts
Posted by khier on Wednesday, May 30, 2018 8:01 AM

gregc
 
garya

 

if you look thru these links, you'll find a zip file containing NmraDcc.cpp/h which presumably receive and decode DCC packets



Thanks, I will have a look.

  • Member since
    July 2009
  • From: lavale, md
  • 4,642 posts
Posted by gregc on Wednesday, May 30, 2018 7:48 AM

garya

if you look thru these links, you'll find a zip file containing NmraDcc.cpp/h which presumably receive and decode DCC packets

greg - Philadelphia & Reading / Reading

  • Member since
    November 2016
  • 196 posts
Posted by khier on Wednesday, May 30, 2018 7:43 AM

Randy,

 

Main problem was/is to understand the NMRA documents. I could achieve some progress, but the backward compatibility (who needs 14, or even 28 speed steps??), especially the programming (of the decoder), are really stupid. There four ways to manipulate the CVs and do the programming. Perhaps there are even more.  I am at the stage to build circuits and perform testing (well, each time I thought I am done I found other things to do). My idea is to start with a function only decoder, essentially for interior lighting, and move to motor decoder later.

Regards

Walid

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Wednesday, May 30, 2018 7:10 AM

 There is no official NMRA software. Just people who write software that decodes the NMRA packet standards. It can be convoluted in places because they tacked stuff in later as they added features, but mostly it's all just bit pattern matching to determine the next step in decoding a given packet - in the standards I'm referring to sections where it says for example if bits 7 and 8 are set then it's X type of packet and it directions you to the next section for the meaning of the other bits, or if bit 7 is 1 and bit 8 is 0, then look to a different section for what the rest of the packet is.

 And you don't try to do it all in one decoder - if you are building a mobile decoder you can completely ignore all stationary decoder packets and vice versa. 

 While a decent and potentially fun project if that's your thing, I doubt you could ever save money over commercial decoders. Even if you value your time at 0.

 As for replacing an existing one - if you can determine which micro is used, I'm sure you could. Need to do a little circuit tracing to determine which pin gets the DCC signal to decooder, which are hooked to the function outputs, and which are hooked to the H bridge for motor drive, but that's shouldn;t be too difficult. I wouldn't doubt that some decoders which are not field updatable use mask rom versions of the micros, so you may need to find a pin compatible programmable one for a replacement rather than a direct replacement. If would be very unlikely that the manufacturer would leave the micro unlocked so that you could read the source code, and by letter of the DMCA that would be illegal anyway.

                              --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    November 2016
  • 196 posts
Posted by khier on Wednesday, May 30, 2018 2:51 AM

rrinker

 NMRA DCC decoder firmware is available for PIC and Atmel processors at least, as open source software. You just have to write the part that does somethign when the device sees packets addressed to it.

                                      --Randy




Do you mean an official NMRA version? If yes, where can I get it? 

Walid

  • Member since
    April 2003
  • 305,205 posts
Posted by Anonymous on Tuesday, May 29, 2018 9:09 PM

BNSF UP and others modeler

Oh goody, this has been a long time question for me. I have done some looking, and my results are as following: either the decoder project did not have very clear instructions and info about it, or it was to big to actually fit in a locomotive, like the first link in the earlier post. Haven't really found anyone who made a budget friendly sound decoder yet either. Anybody know if there are instructions for those out there?

 

The problem with sound decoders is.. the sound.  You have to pay someone (or go yourself) to go out and record the (insert what you want), or license the files from someone else.

  • Member since
    March 2018
  • 688 posts
Posted by BNSF UP and others modeler on Tuesday, May 29, 2018 8:25 PM

Oh goody, this has been a long time question for me. I have done some looking, and my results are as following: either the decoder project did not have very clear instructions and info about it, or it was to big to actually fit in a locomotive, like the first link in the earlier post. Haven't really found anyone who made a budget friendly sound decoder yet either. Anybody know if there are instructions for those out there?

I'm beginning to realize that Windows 10 and sound decoders have a lot in common. There are so many things you have to change in order to get them to work the way you want.

  • Member since
    July 2009
  • From: lavale, md
  • 4,642 posts
Posted by gregc on Tuesday, May 29, 2018 7:55 PM

i wonder about simply reprogramming an existing decoder, since i'm curious about changing the behaviour (momentum, speed curve, BEMF).

if the chip is locked and unable to be reprogrammed, i wonder if it could be replaced and in circuit programming (ICP) leads added

greg - Philadelphia & Reading / Reading

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Tuesday, May 29, 2018 6:25 PM

 Several, if you google diy dcc decoder. Don't know if anyoone's tried sound - that's orders of magnitude more complex that a motor only decoder, just because you have to ALSO code the sound playback, and you need a powerful enough microcontroller (that's the problem with early Digitrax sound decoders and why they slow down when playing sounds if BEMF is turned on - the micro is not powerful enough to handle reproducing sounds AND calculating BEMF in real time.). All of the popular sound decoders use custom or semi-custom chips, probably FPGAs.

 A motoor decoder is fairly simple, there is a bridge rectifier, a voltage regular to get the 5 or 3.3v for the micro, an transistor array for function drives, and an H bridge for motor drive. It's mostly software. A few passives for filtering and so forth. To get it small enough requires skill with surface mount components. I doubt many is any motor only decoders are more than a 2 layer board.

 NMRA DCC decoder firmware is available for PIC and Atmel processors at least, as open source software. You just have to write the part that does somethign when the device sees packets addressed to it.

                                      --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    November 2005
  • From: St. Paul
  • 821 posts
Posted by garya on Tuesday, May 29, 2018 4:06 PM

Gary

  • Member since
    November 2016
  • 196 posts
Posted by khier on Tuesday, May 29, 2018 3:49 PM

Bayfield Transfer Railway

Possible probably, but I can't imagine it being cost effective unless you like doing that sort of thing for its own sake.

 

 

Well, consider lighting cars interior. A train contains 8 - 10 cars x 20$ each, you end with 160-200$/ train. If you cut the costs by 50 or 60% you can save cash.

Regards

 

 

  

  • Member since
    July 2007
  • From: Yorkton, Sk, Cnd
  • 441 posts
Posted by wvg_ca on Tuesday, May 29, 2018 1:36 PM

used freely available public domain code, pcb in eagle, cost was $10 each in lots of 10 [pre assembled]

  • Member since
    April 2012
  • From: Huron, SD
  • 1,016 posts
Posted by Bayfield Transfer Railway on Tuesday, May 29, 2018 1:09 PM

Possible probably, but I can't imagine it being cost effective unless you like doing that sort of thing for its own sake.

 

Disclaimer:  This post may contain humor, sarcasm, and/or flatulence.

Michael Mornard

Bringing the North Woods to South Dakota!

  • Member since
    November 2016
  • 196 posts
Posted by khier on Tuesday, May 29, 2018 12:43 PM

wvg_ca

pretty straight forward  ..

did one for HO a few years ago, no sound, but with BEMF and keep alive connections



Interesting... more details, please.

  • Member since
    July 2007
  • From: Yorkton, Sk, Cnd
  • 441 posts
Posted by wvg_ca on Tuesday, May 29, 2018 12:37 PM

pretty straight forward  ..

did one for HO a few years ago, no sound, but with BEMF and keep alive connections

  • Member since
    November 2016
  • 196 posts
Posted by khier on Tuesday, May 29, 2018 12:32 PM

SouthPenn

The interesting thing about building your own, it can be a custom sized to fit a particular engine.

 

Yes.

SouthPenn

Sounds like a nightmare though.



Maybe I am stupid, but when it comes to NMRA documents, yes, it is like a nightmare.

  • Member since
    March 2015
  • 1,358 posts
Posted by SouthPenn on Tuesday, May 29, 2018 12:08 PM

The interesting thing about building your own, it can be a custom sized to fit a particular engine. Some parts in the front, some in the back connected by wires.

Sounds like a nightmare though.

South Penn
  • Member since
    November 2016
  • 196 posts
Posted by khier on Tuesday, May 29, 2018 11:58 AM

gregc

 can you build one small enough?




The question is, can i build one in the first place?

As for the size, it depends how small it should be. I guess the size of a cab unit, drop in decoder is feasible. However, to be compatible with everything from legacy equipment to the latest standards and DC, is a bit pain in the neck to extract the information from NMRA documents.

Therefore I was asking is someone ever did Big Smile

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!