Cobalt6700
Registered
I have started this thread to share my adventure designing and building my own wireless DCC controller - hopefully others find this useful
When I started out converting Locos to RC, I was using Arduinos as the main brain, Veroboard circuits for function controls, a motor controller and Mylocosound cards.
This was not a small amount of effort, the setup for each Loco had to be custom built.
The chip shortage increased the price of the motor controllers I had selected and previously purchased from £30 / board to over £120 / board. This meant converting new Locos was becoming time consuming and expensive - putting this all together in today's money works out costing more than a decent DCC decoder. Plus, I have now found decoders easier to program and maintain.
After doing some research into DCC decoders and the features they offer for the money, I wanted to be able to control these using RC, however the options I had found online all used either a already made controller, or a smartphone app. Reading about configuring these showed them to be quite restrictive for what I wanted to achieve.
I started fiddling with DCC++EX and had the idea of putting this inside a Loco to control a decoder, and thus, the WiDCC board idea was born.
Project goals:
Why use DCC++EX inside of the Loco? Isn’t this a bit ‘sledgehammer to crack a walnut’?
Well, yeah it is a bit really. However, during my research I had tested some of the code I had found online for generating DCC signals with Arduino’s. The DCC waveform is timing sensitive, and whilst the code out there works for the application, once I added my own code to start decoding RC receivers / RF24 modules and writing to servos, that timing went out the window.
The DCC++EX team have done a cracking job with the software, and have re-written existing libraries to work around the tight timing of generating a DCC signal. I did initially muck around with the code and tried to grab only the bits I needed out, however this became a code rabbit hole that I swiftly exited and backfilled.
Using a fully blown DCC++EX instance does require the use of another microcontroller (uC), which adds cost and takes up PCB space. This is something that I wanted to avoid, however it has saved me much time and headache of building my own DCC generating code and getting everything to work with that.
In the end, this has enabled me to run my own code on one uC and send serial commands using the DCC++EX API to the other uC. This means I can run whatever code I want on the main uC, with the DCCEX uC doing just that.
This also gives me access to some of the cool features of DCC++EX, such as writing CV’s. I have not implemented current sense, so it is not able to act as a programming track. This may come in the future, but for now, programming of the decoder is carried out by switching the selector switch from internal DCC to track DCC.
What uC’s does it use?
I originally designed this using ATmega328p’s - the same as an Arduino UNO / NANO. However the lack of serial UARTs and having to use software serial was a bore. I had a go with a NANO Every, based on an ATmega4809, which proved much more capable, plus had a load more Flash and RA, and didn't require external oscillators which saved on PCB space.
The ATmega4809’s seem to work really well and have allowed me to use some really ‘memory hungry’ code whilst prototyping.
Track power and battery power
The board uses two 4A diode bridges to rectify the incoming track voltage. This allows for larger Locos with two power bogies to have their own, diode separated power feeds, preventing bogie to bogie shorts. This happened on one of my early conversions to an Aristocraft FA1 and toasted the internal wiring.
The use of a diode bridge enables the Loco to be fed from DC track power or DCC track power. It also alleviates the issue of connecting a battery the wrong way round should the loco be battery powered. There is an input on the uC that allows the battery voltage to be monitored, and the Loco is shut down once that voltage is reached.
External Cap bank
There is an onboard port for an external Cap bank to provide energy storage for any dead bits of rail. The Cap bank requires its own inrush limiting circuit, however the use of a passive diode and resistor setup has proved adequate. The Cap Bank is not required when battery powered.
Why not have an on-board H-bridge?
I wanted this to be as flexible as possible, and this meant being able to use the right H-bridge for the decoder. Clearly, a little Loco with a basic decoder has a different power requirement to a full sound / smoke / dual motor Loco. My current go-to H-bridge boards are the Cytron MD13s (13A) and the Pololu TB67H420FTG (3.4A).
I have also proved it working with Pololu TB9051FTG (2.6A), L298N (~3A), SN754401(1A), BTS7960 / BTS7970 based boards such as the IBT-2 (quoted at 43A!).
Which RC systems does it work with?
Currently the only tested setups are iBUS from a FlySky based RX (serial protocol) 14 channels over 1 pin and my own design RC RX / TX system using NRF24L01 modules.
With the ability to read serial data, it could work with other serial RX’s, such as those using SBUS, however I do not have the hardware to test this.
It should also be able to read ‘any’ RC RX channels directly onto an input pin, allowing for 6 channels. This is something I had working on a 328P, however not something I have implemented on the 4809. With a bit of interrupt code wrangling, i'm sure this would work, however it is currently outside of my scope.
I have been working in the background on my own RX/TX system. This has been put to one side for the moment as getting the railway working is the current priority, however I will be getting back to it once up and running when I can put it through its paces. More on that later.
How much onboard power does it have?
A lot of my older Loco control boards used off the shelf DC-DC buck converters. These are great, and I still use them in my I2CNet IOC’s as they are cheap and powerful, however they are a fairly large module. For the WiDCC, I chose to have a go at building in a DC-DC buck. Once I found a suitable one, the PCB design was tailored to suit. The buck IC is a Monolithic Power Systems MP2348GTL-Z which can supply 4A @ 5V - plenty for driving Servos. I wanted to be able to drive Servos directly from the board as some decoders only offer 1 or 2 servo outputs, and having more is always better, right?
There is also an on-board 3.3V 300mA regulator, primarily for the NRF24L01 module. The whole board is protected with a 4A fuse.
Does it have any IO?
If not used for servos, the 4 IO ports can be used as either logic level outputs or inputs. They are all PWM capable. I have a plan for a future PCB revision to have the pads for some SMD MOSFETs, allowing these outputs to be higher power if required - currently they can only sink 20mA each.
There are 2 available serial ports, one for the mentioned iBUS input, the other for general purpose. I have used this to drive a Pololu G2 motor board.
SPI is broken out to a 7 pin connector, whilst designed for the NRF24L01 module, this could be used to drive other SPI devices, this has not been tested.
Can I get my hands on one?
At the moment, unfortunately, no. I only really build these for me and a couple of friends. However..
Once I have some hours on these boards in my Locos ( I currently have 3 converted) and I am happy that they do work and don’t explode, I will make the PCB files, parts list and software available for people to build their own. I hope this to be within the net few months.
I will caveat this by saying that I am in no way qualified to design PCB’s or write code, so it is what it is.
I don’t have a plan to make these available for purchase. Whilst I am setup to build a few at a time, going into home production is not something that I want to do. This may change in the future, depending on if anyone actually wants to buy one…
Some pictures of the V1.0 board:
Schematic
PCB design
PCB building
Thanks for reading, hope to update at some point when I have got some use out of them.
When I started out converting Locos to RC, I was using Arduinos as the main brain, Veroboard circuits for function controls, a motor controller and Mylocosound cards.
This was not a small amount of effort, the setup for each Loco had to be custom built.
The chip shortage increased the price of the motor controllers I had selected and previously purchased from £30 / board to over £120 / board. This meant converting new Locos was becoming time consuming and expensive - putting this all together in today's money works out costing more than a decent DCC decoder. Plus, I have now found decoders easier to program and maintain.
After doing some research into DCC decoders and the features they offer for the money, I wanted to be able to control these using RC, however the options I had found online all used either a already made controller, or a smartphone app. Reading about configuring these showed them to be quite restrictive for what I wanted to achieve.
I started fiddling with DCC++EX and had the idea of putting this inside a Loco to control a decoder, and thus, the WiDCC board idea was born.
Project goals:
- Drive a DCC decoder from inside a loco using track or battery power
- Have two track power inputs with their own diode bridge - to prevent ‘front to back’ shorts on larger locos
- Have a connection for an external capacitor bank to deal with momentary power loss (dirty track, frog)
- Work with a number of external H-Bridges
- Use a RC TX and RX or my own NRF24L01 based TX and RX setup to control a Loco
- Have enough onboard power to drive 4 Servos
- Be able to work with a track voltage of 24VDC or 24V DCC
Why use DCC++EX inside of the Loco? Isn’t this a bit ‘sledgehammer to crack a walnut’?
Well, yeah it is a bit really. However, during my research I had tested some of the code I had found online for generating DCC signals with Arduino’s. The DCC waveform is timing sensitive, and whilst the code out there works for the application, once I added my own code to start decoding RC receivers / RF24 modules and writing to servos, that timing went out the window.
The DCC++EX team have done a cracking job with the software, and have re-written existing libraries to work around the tight timing of generating a DCC signal. I did initially muck around with the code and tried to grab only the bits I needed out, however this became a code rabbit hole that I swiftly exited and backfilled.
Using a fully blown DCC++EX instance does require the use of another microcontroller (uC), which adds cost and takes up PCB space. This is something that I wanted to avoid, however it has saved me much time and headache of building my own DCC generating code and getting everything to work with that.
In the end, this has enabled me to run my own code on one uC and send serial commands using the DCC++EX API to the other uC. This means I can run whatever code I want on the main uC, with the DCCEX uC doing just that.
This also gives me access to some of the cool features of DCC++EX, such as writing CV’s. I have not implemented current sense, so it is not able to act as a programming track. This may come in the future, but for now, programming of the decoder is carried out by switching the selector switch from internal DCC to track DCC.
What uC’s does it use?
I originally designed this using ATmega328p’s - the same as an Arduino UNO / NANO. However the lack of serial UARTs and having to use software serial was a bore. I had a go with a NANO Every, based on an ATmega4809, which proved much more capable, plus had a load more Flash and RA, and didn't require external oscillators which saved on PCB space.
The ATmega4809’s seem to work really well and have allowed me to use some really ‘memory hungry’ code whilst prototyping.
Track power and battery power
The board uses two 4A diode bridges to rectify the incoming track voltage. This allows for larger Locos with two power bogies to have their own, diode separated power feeds, preventing bogie to bogie shorts. This happened on one of my early conversions to an Aristocraft FA1 and toasted the internal wiring.
The use of a diode bridge enables the Loco to be fed from DC track power or DCC track power. It also alleviates the issue of connecting a battery the wrong way round should the loco be battery powered. There is an input on the uC that allows the battery voltage to be monitored, and the Loco is shut down once that voltage is reached.
External Cap bank
There is an onboard port for an external Cap bank to provide energy storage for any dead bits of rail. The Cap bank requires its own inrush limiting circuit, however the use of a passive diode and resistor setup has proved adequate. The Cap Bank is not required when battery powered.
Why not have an on-board H-bridge?
I wanted this to be as flexible as possible, and this meant being able to use the right H-bridge for the decoder. Clearly, a little Loco with a basic decoder has a different power requirement to a full sound / smoke / dual motor Loco. My current go-to H-bridge boards are the Cytron MD13s (13A) and the Pololu TB67H420FTG (3.4A).
I have also proved it working with Pololu TB9051FTG (2.6A), L298N (~3A), SN754401(1A), BTS7960 / BTS7970 based boards such as the IBT-2 (quoted at 43A!).
Which RC systems does it work with?
Currently the only tested setups are iBUS from a FlySky based RX (serial protocol) 14 channels over 1 pin and my own design RC RX / TX system using NRF24L01 modules.
With the ability to read serial data, it could work with other serial RX’s, such as those using SBUS, however I do not have the hardware to test this.
It should also be able to read ‘any’ RC RX channels directly onto an input pin, allowing for 6 channels. This is something I had working on a 328P, however not something I have implemented on the 4809. With a bit of interrupt code wrangling, i'm sure this would work, however it is currently outside of my scope.
I have been working in the background on my own RX/TX system. This has been put to one side for the moment as getting the railway working is the current priority, however I will be getting back to it once up and running when I can put it through its paces. More on that later.
How much onboard power does it have?
A lot of my older Loco control boards used off the shelf DC-DC buck converters. These are great, and I still use them in my I2CNet IOC’s as they are cheap and powerful, however they are a fairly large module. For the WiDCC, I chose to have a go at building in a DC-DC buck. Once I found a suitable one, the PCB design was tailored to suit. The buck IC is a Monolithic Power Systems MP2348GTL-Z which can supply 4A @ 5V - plenty for driving Servos. I wanted to be able to drive Servos directly from the board as some decoders only offer 1 or 2 servo outputs, and having more is always better, right?
There is also an on-board 3.3V 300mA regulator, primarily for the NRF24L01 module. The whole board is protected with a 4A fuse.
Does it have any IO?
If not used for servos, the 4 IO ports can be used as either logic level outputs or inputs. They are all PWM capable. I have a plan for a future PCB revision to have the pads for some SMD MOSFETs, allowing these outputs to be higher power if required - currently they can only sink 20mA each.
There are 2 available serial ports, one for the mentioned iBUS input, the other for general purpose. I have used this to drive a Pololu G2 motor board.
SPI is broken out to a 7 pin connector, whilst designed for the NRF24L01 module, this could be used to drive other SPI devices, this has not been tested.
Can I get my hands on one?
At the moment, unfortunately, no. I only really build these for me and a couple of friends. However..
Once I have some hours on these boards in my Locos ( I currently have 3 converted) and I am happy that they do work and don’t explode, I will make the PCB files, parts list and software available for people to build their own. I hope this to be within the net few months.
I will caveat this by saying that I am in no way qualified to design PCB’s or write code, so it is what it is.
I don’t have a plan to make these available for purchase. Whilst I am setup to build a few at a time, going into home production is not something that I want to do. This may change in the future, depending on if anyone actually wants to buy one…
Some pictures of the V1.0 board:
Schematic
PCB design
PCB building
Thanks for reading, hope to update at some point when I have got some use out of them.