Electrical signal from DCC decoder to engine motor

Robert Owen Jun 7, 2020

  1. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    I am writing software to build a DCC system and am tired of putting track together and balancing an N scale engine on it for 15 mins of testing. As a consequence I want to build an engine motor simulator or circuit board, that includes a decoder, that will light up a different LED depending on whether the train is going forward or reverse. Using this I can test my DCC software without assembling track. My question is what is the shape of the electrical power waveform from the decoder to the engine motor? Is it DC or PWM? I assume it is DC so that, by reversing polarity, the engine will change direction. If it is PWM I am not sure how the direction of the engine is reversed, unless the PWM signal goes from, say, 0V to 12V for forward and 0v to -12V for reverse.
    Any information will be appreciated.
     
  2. Quax

    Quax TrainBoard Member

    27
    5
    8
    I was in the same situation but to reduce the number of side projects, I simply bought a decoder tester (the ESU one) which (in combination with a DCC loco decoder) does exactly what you are looking for. Of course, if you like this to be your project, then go for it!
    I think that the motor control of most decoders uses PWM (please correct me if I'm wrong).
     
    Last edited: Jun 7, 2020
  3. rray

    rray Staff Member

    8,310
    9,456
    133
    +1 Decoder Tester:
    ESU Decoder Tester.jpg
     
    saucon likes this.
  4. wvgca

    wvgca TrainBoard Member

    499
    305
    21
    a decoder uses PWM to control the motor speed ... but a decoder tester would be the easiest way to accomplish what you want ..
    based on the MERG specs for decoders...
     
  5. Quax

    Quax TrainBoard Member

    27
    5
    8
    I have made a developer's box including the DCC base station components (Arduino board + motor shield), a RailCom display, ESU decoder tester + DCC decoder for my project. Without having a real layout, this was really helpful.

    image.png
     
  6. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    @Robert Owen What kind of software are you writing?

    If you want to build your own decoder with test lights, there is this:

    https://model-railroad-hobbyist.com/node/19070

    Using the decoder tester is a great idea, but you also have to buy a decoder. This is much less expensive.

    I pointed you to the first of several articles in a series on this. This one shows the original version with the LEDs and a video that shows you exactly what it does. Later articles show the new boards you can have made very inexpensively and more options. These can act as a mobile or stationary decoder. So you can simulate a loco or an accessory. It doesn't have a motor on it, but you could easily add a resistor for load to a pin and then even have it do the current pulse if you want to read and write CVs on the service track.

    I have a setup similar the Quax for our development work on DCC++ EX, but I also have these Geoff Bunza boards because they do just about anything. They can even be a DCC signal decoder with a different firmware upload and display the packets sent to the track on a computer connected via its usb port and the FTDI board you use to program the Arduino.
     
    Last edited: Jun 8, 2020
  7. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    Thanks for the replies. There is more information around than I thought. If the engine runs on PWM, to go into reverse the polarity of the power to the motor must reverse. PWM will only gcontrol speed.
     
  8. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    Decoders usually use some form of H-Bridge, just like the motorboard on DCC++ EX does, to handle PWM speed and direction information. In the case of the Arduino and Motor Board, the H-Bridge is used to generate a bipolar square wave and create the 1s and 0s of the DCC signal. The loco decoder takes the un-rectified signal and decodes it. In another circuit path, it rectifies the signal into DC and passes it to its own H-Bridge where the decoding circuit portion turns on the right H-Bridge current path. That could be 4 discreet transistors with their diodes or an IC. A signal biases one pair of the bridge transistors connected to one lead of the motor for forward or to the other pair connected to the other motor lead for negative. You may already be familiar with how a H-Bridge circuit works, but if not, studying that is your answer. There are some open source decoder circuits out there. The link I showed you is one of those. Look at Geoff's full schematic that shows all of the options on it if you want to control a motor. He uses a Texas Instruments SN754410NE 1 Amp Quad Half H driver ($2.50). Here is a link to the second part of that article where he designed a circuit board you can download the CAD file for and upload to a board manufacturer in about 5 minutes and get these boards for a couple of bucks for 3 from Oshpark or your favorite board fabricator. Once you have the parts, it only takes 20 mins or so to solder one of these up, if that.

    https://model-railroad-hobbyist.com/node/24316

    In it's full "loco decoder simulator" mode (my term since that is not its original purpose) You solder all the parts on. You need the opto-isolator circuit to get the DCC signal and send it to a pin on the microcontroller so the firmware can decode it. You need the rectifier circuit to power the whole thing and to provide DC voltage for the motor (though you could externally power this if you don't want to tap it off the track and thus save parts and soldering) and you need the motor bridge circuit to control a motor. So just add a few diodes and their current limiting resistors and a motor, upload the right one of Geoff's Arduino sketches, and viola, you have a $15 to $20 version of what you would need a decoder tester ($47) and a decoder ($20-$80?) for. So while the decoder tester is great if you are using it to test decoders, if you are using it as a decoder or train "simulator", that's a bit expensive and ties up a decoder. Then again, you have minimal soldering/wiring with the testor/decoder solution and you have that decoders commands. You would have to modify commands in the sketch to put CVs in there if you wanted to emulate a particular command set from a particular decoder.
     
    Last edited: Jun 8, 2020
  9. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    Thanks flightrisk, very helpful answer. Living in a small apartment I do not have the space to keep track around, so an engine simulator is the best option while I write code.
     
  10. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    Well tell us what you are writing! :)
     
  11. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    DCC++ still requires intervention by a human to manage the layout. I am building a layout in which Arduino controls 5 trains without my intervention. On the attached diagram, two trains will travel the main line (in black), in opposite directions, at random times. Arduino needs to keep track of the location of each train and decide how it will stop them crashing. Delaying one train while the other passes where there are parallel tracks.

    In addition to this is a section of track, in red, that will contain two engines that will constantly shuttle rolling stock from one side of the main line to the other (from side A to side B). Also, at the top of the hill is a section of track, C, that hold rolling stock from A and B. These movements will be random. The red track crosses the mainline, so Arduino needs to keep track of the engines at A and B (and C), to stop them crashing into a train traveling the main line.

    The tricky part is using enough sensors so that Arduino knows where each train is and in which direction it is traveling.

    The layout will be modeled on a mining community in the Canadian Rocky Mountains. The scenery is not important to me, Arduino sketches are what interest me.

    That is the plan. Let me know if you need more detail.
     

    Attached Files:

  12. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    I also should add that when the goods train arrives at the incline on the left, the single engine shown in the diagram will leave the siding and push the goods train up the incline. When the goods train reaches the top, the single engine will return to the siding at the bottom. Arduino needs to control this without causing an accident.
     
  13. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    Thanks for sharing that Robert. I like your graphics. Looks like something you may be documenting at some point for others to follow. Very cool.

    You may already be aware of this, but the original DCC++ does do automation. Check Gregg's development build. In particular the "eggtimer" and "autopiliot" code. Here in GitHub: https://github.com/DCC-EX/BaseStation-Classic/tree/development/DCCpp

    "An embedded AutoPilot routine that randomly selects a train to run through the entire layout, after which it is brought back into its original siding and the the patterns repeats with another randomly-selected train. This is the AutoPilot routine showed on the DCC++ YouTube channel. It does not require any computer, nor DCC++ Controller to be running (DCC++ Controller contains a much more complicated 3-train Auto Pilot mode, also as shown on the DCC++ YouTube channel)."

    I've not played with his controller software built using the "Processing" language in Java, but as mentioned above, that has some things built in as well to use a controller to do this instead of the base station to handle the automation.

    Video here:


    and here, I believe, is the one that uses the DCC++ Controller software:


    If you want to take a look at the controller with an example layout, that is here: https://github.com/DccPlusPlus/Controller/tree/sample-layout
     
  14. Robert Owen

    Robert Owen TrainBoard Member

    51
    5
    6
    Thanks Flightrisk.

    I want all 5 of my trains to run simultaneously. A bit of a challenge, although detecting position will be the hard one, or at least to do it cost effectively. I will let you know what happens.
     
    FlightRisk likes this.

Share This Page