Reviving DCC command Station
After several years of pause, I’ve decided to update my LocoNetControlStation project, both hardware and software side.
Hardware changes in new version:
-
Fit the Command station into a DIN rail enclosure.
-
Update DCC circuitry to modern ICs (instead of old L298N) to ease reading of current.
-
Use official ESP32-DevKitC board instead of Lolin32 Lite to avoid problems with availability and quality.
-
Modularize the design to allow adding new features without PCB redesign, for exmaple LCC or RailCom
-
Use USB-PD to power the board, use switching regulator instead of LM7805.
-
Add a small OLED display for status and diagnostics.
-
Limit current of LocoNet RailSync to better follow specs (to simplify things, it’s limited to 30mA, roughly 10 times less then the documentation mentions).
| The PCB design will be released to public when finished, but I would consider it as an educational project for other people, rather than useful for recreating. I adapted it for my capabilities and needs, e.g. used components that I had in stock, will use full-color PCB because it’s cheaper with JLCPCB coupons, so it might not be the optimal to replicate 1-to-1. Same applies to firmware. |
Software changes:
-
Actualize toolchains, update ESP32 SDK, libraries. The project was last actively worked on in 2021, so everything is rather encient. I was surprised that it still compiles, though.
-
Regularly send (refresh) function states to locomotives (old code only sends loco speed/direction packets, this was an issue I noticed while running on dirty tracks).
-
Display diagnostic info on OLED display (it shows number of WiThrottle/LbServer clients, track power state, number of running trains and some other)
-
Fast clock support on LocoNet, WiThrottle (and, in future, DCC)
-
Better processing of LocoNet turnout commands (also fixed some bugs with LocoNet slot ownership and dispatching)
-
WiThrottle has support for "steal" messages.
Upgrading code to ESP-IDF v5 proved to be a major challenge. New timer API caused the DCC bit timings to break, as the jitter in timer callbacks was too large in the new API for some reason. I was able to somewhat combat this by switching to RMT peripheral, but it’s also suffering from problems due to delays between RMT transmissions. In new SDK RMT peripheral has completely new API which doesn’t allow continous streaming. So, a legacy RMT driver was used for uninterrupted streaming. Because it’s completely removed in ESP-IDF 6, I decided to copy it from SDK 5 and store it as a library in repository (project still uses SDK 5 though). The implementation has limitations on DCC packet size, it’s limited to allocated RMT memory. ESP32 has 64 symbols (=DCC bits) per block, of which it it has 8, so it’s not a problem for original ESP32, but can be a major limitation for newer ESP32s.
Another major task was refreshing of function packets on DCC track. This required inventing some kind of a priority queue backed by table of alocated locomotives so that each locomotive regularly produces a speed/dir DCC packet or a function packet (3 groups of functions are cycled through, totalling 12 functions). Other, non-locomotive packets go through the queue directly and get picked up by DCC pulse generator according to their priority. For now priority system is rather simple, stop and emergency stop packets have higher priority than normal packets.
A lot of other work was done, I’ve spent a month in total on the software, I think. There are still some major improvements possible, like handling of various messages via a application-wide message bus and processing physical LocoNet packets in a separate task (to not block other tasks that initiate communication).
PS. While I was updating the PCB, easyEDA released a version 3 and the release process disappointed me a lot. Not only was the new version lacking features from EasyEDA v2 for no reason, it’s a major incompatible release, its v3 file format is incompatible with v2 software, so everyone needs to upgrade the projects, and the process is irreversible. Previous version was pulled from the website and is not available in browser, so users are forced to use the new one even if the new feature set is limiting for them. In addition, To add to the insult, support is ignoring feedback and giving responses like "The v3 effect has already been changed and will not be retracted based on a minority of opinions."
All in all, very frustrating experience. I will consider KiCAD in future.