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

16146 views
30 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    November 2016
  • 196 posts
DIY decoder
Posted by khier on Tuesday, May 29, 2018 8:22 AM

Hi,

 

Did anyone try to build  own decoder? It would be interested to know how it looks like.

 

Regards

 

Walid

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Tuesday, May 29, 2018 11:44 AM

recent threads got me thinking about the this.  can you build one small enough?

greg - Philadelphia & Reading / Reading

  • 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

  • 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 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
    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: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
    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
    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
    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
    November 2005
  • From: St. Paul
  • 823 posts
Posted by garya on Tuesday, May 29, 2018 4:06 PM

Gary

  • 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
    July 2009
  • From: lavale, md
  • 4,678 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
    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
    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
    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
    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 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
    July 2009
  • From: lavale, md
  • 4,678 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 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
    December 2004
  • From: Bedford, MA, USA
  • 21,481 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
    July 2007
  • From: Yorkton, Sk, Cnd
  • 441 posts
Posted by wvg_ca on Wednesday, May 30, 2018 2:22 PM

close, :)

  • 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
    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
    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 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
    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
    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
    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 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

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!