NMRA DCC controller

I want to discuss the problem of writing a program to generate serial NMRA DCC code whilst managing the content of each of the 24 cells of the 3 word instruction. The DCC output has to be continuous whilst refiguring the 24 data bits to write to all the trains decoder. I am at the moment constructing one looped command reading the logic states from 24 on off switches, but would like the configuration function to be managed (simultaneously) by the processor.
Can this be done by the mega with the Arduino IDE compiler or is the compiler and/or the Atmel2560 not suitable for parallel processing?

Have You looked up tje NMRA standard and how it is composed?

1 Like

I would start by reading the NMRA DCC manual. Can it be down with an Arduino probably yes. You need to know the physical layer being used and anything applicable regarding the data such as baud, clock, etc.

This can definitely be done. There are already solutions for this , eg DCC++.
Decoding can also be done by an Arduino, e.g. with the NmraDcc Library

But I don't understand your description of the DCC protocol. Have you read the NMRA papers?

1 Like

Most Arduinos (with the possible exception of the discontinued Yun) don't multi-task. This is a good thing because debugging such code isn't something you would want to inflict on newcomers to coding.

Even the slowest Arduino is pretty fast though. Especially when you're looking at model train controllers. I think I've seen references to DCC here in the past, so I expect it can be done.

There are multi core devices that can be programmed using the Arduino IDE such as the ESP32. If the standard Arduinos aren't fast enough, consider the Teensy range or Adafruit's feathers.

1 Like

I have read and understood NMRA information: basic command structure (3 words) and the extended NMRA coding (4 words) I have looked at and noted the jitter free output at the point before it goes into the half bridge "booster" and i have also taken serial logic analyser shots where i found that the working system I am looking at is the extended format. so = address word, extended address word (because the controller supports points, decouplers, signal lights etcetera), data(instruction word and column parity check bits.
I have been trying , tentatively, to create these words as a serial stream but am finding that at the 50 microsecond and 100 microsecond level any "micros" instructions were having the scanning time of the sketch added. In tis way making the 1's and zero,s too long. I tried doing without the delays but the times were then to short. The selection of o's and i's being governed by microswitches on a breadboard. I see that somebody has suggested using the Arduino IDE with other chips but I am wondering weither I am going to come across these timing issues with a different processor.

I have put in an extended reply to railroader but you raised the term physical layer. I am wondering if this is controlled by a behind the scenes operation controlled by the compiler thro' the Arduino IDE. I understand that the terms baud and clock would be replaced by the timing of logic 1 which is 54 microseconds high then 54 microseconds low. Similarly with logic 0 this is 100+ microseconds high followed by 100+ microseconds low. It seems to me that the decoder then discriminates between these to recreate the 0/1 logic data stream datastream and that any jitter outside these renders the data unreadable. This is why, unless I get these timings right the decoders won't be able do decode them.

I understand that Library programs are used as is and cannot be listed to analyse when I get problems. I may be wrong but downloaded an LCD program which had instructions how to use it but no program list.

Any library that you use with Arduino is supplied as source code - you're free to analyze/edit it as much as you like.

1 Like

Thanks for your input I am coming to the conclusion that I would have to have major software writing skills to deal with this problem with an IDE much closer to the the machine code which compilers generate.

DCC++ Basestation is a sketch completely written in C++ for the Arduino IDE and runs on Arduino Uno. The code is available in its entirety on GitHub. It creates a perfect DCC signal. I often use it to test my decoders.

You can use it as it is, or to analyse it to create your own DCC Sketch.


You must use the timer HW of the Arduino to create the correct DCC timing. This is how DCC++ works too.

1 Like

Thanks for the response to my question about DCC on model railways.
What you suggested is at a much higher level of writing than I could expect to attain or feel able to dismantle to get the bits I want.
I am hoping that I could get information about how to program a pin on a UNO or Mega to drive a motor half bridge connected to my railway. I understand that the serial stream consists of a preamble , 2 address words , a data word and a bit parity word with associated start and stop bits. If you can point me in the direction of some written information about Arduino IDE acceptable commands with examples perhaps I can work from that.
Someone suggested that the program lists for Library programs can be down loaded. I downloaded an LCD library program, which I was able to demonstrate to myself but don’t know how or where you get the program list. Perhaps with this I could program a graphics LCD display by developing it to get more data onto a graphics information annunciator.

What is wrong with using DCC++? It creates the DCC signal you want.

1 Like

My understanding of DCC++ is that the track is connected to a base unit (UNO + motor drive shield) which is connected to a lap top via a USB port. To operate the system some method of describing the track layout is operated to create a control board on screen. A loco is then put on the track somewhere and its position put on the control board. The loco is then driven using the lap top keyboard round a “journey” going through points which are set in its favour thro the tracks via the base unit whilst moving the indicator on the control board. All this is meanwhile being recorded in the lap top. At journeys end the loco can be lifted off the track and put at the start point and the start command given from the lap top and a faithful reproduction of the journey will be seen to happen along with the dynamic representation on the lap top control board.

What are the other trains doing while this is going on?

My traffic management system controls four locos in two Zones using a track block system of 19 sensors to inform the processor where each identified loco is. They do have set routes but these can be overridden by the press of a keypad on the control desk. An LED in the top corner of the key is lit for branch or extinguished for main. The turn in points have a first come first served protocol as does the diamond crossing on the inner double loop. An empty block ahead protocol stops following trains from going into the train in front.

Speed controls are DC voltages sent to another processor for DCC encoding and driving the track.

What I would like to do is have my Zone managing chips instruct a DCC encoder and track driver digitally.

How do I reverse DCC++ into the Zonal management chips or overlay the traffic management on the DCC++ package?

The DCC++ is a type of legacy system whereas I want to create an automated future system with override capability.

You don't need to use the laptop part. The part that runs on UNO is a basic base station that can be controlled via the serial line. These low level commands are documented and with these commands the creation of DCC packets is controlled.
You can programm your automated system in such a way, that it creates the serial command for the DCC++ basestation. And DCC++ basestation creates the DCC signal accordingly.

These DCC++ Commands are low level, but not 'lowest' level. You should have an understanding how locos and accessories are adressed and which DCC-commands are possible. But you don't need to know the exact bit structure of the DCC packets.

1 Like

Search for "iTrain". It's made by a Dutch guy and it administrates all my 35 trains running on 750 feet of tracks. That system needs devices indicating the presence of a train. I use some 150 such devices....

1 Like

am trying to install the DCC++ software for nmra control but when i try to compile DCCpp_Uno error messages concerning the absence of some of the .h inclusions comes up. I have looked in the library and, for example, I try to download accessories I get an error saying it doesn't have a Mega or Uno (depending on which I select in Tools) capability. I managed to get the SerialCommands inclusion but have no way of knowing if what I have downloaded is correct. I started from DCC++ _Uno I think.

I understood that if you downloaded the base program the inclusions would come with it.

Try and post the compiler error report.

What did you download? There are many files in the ino-directory. You can download the complete basestation zip-file here