nigelwright7557 Posted November 15, 2020 Share Posted November 15, 2020 I am working on a DCC shuttle controller. I managed to find a simple description of how a basic DCC command works. From that I can control speed and time from potentiometers into a microcontroller. I am using a cheap PIC microcontroller running at 8MHz. I use two breaks in the track to stop the train at either end and a relay to restore power when direction is changed. The software is the main thing to be right as the timing pulses are exactly 58uS and 100uS. I just do it port bit banged rather than use PWM. I might change it to PWM if its not accurate enough. Waiting for a DCC loco at the moment. Software is written but not tested in real life yet. Link to post Share on other sites More sharing options...
Crosland Posted November 15, 2020 Share Posted November 15, 2020 1 hour ago, nigelwright7557 said: I am using a cheap PIC microcontroller running at 8MHz. I use two breaks in the track to stop the train at either end and a relay to restore power when direction is changed. The software is the main thing to be right as the timing pulses are exactly 58uS and 100uS. I just do it port bit banged rather than use PWM. I might change it to PWM if its not accurate enough. Its very easy in a PIC although I would want to use a faster one. Timing for zeros is considerable more lax, due to the option of "zero stretching" for driving unchipped locos. For ones, the spec allows for +/- 3us at the command station Just set up a timer for 58us interrupt and bit bang the DCC in the interrupt service routine. Use two periods (116 us) for each zero bit. To minimise the jitter you can calculate the output to be asserted at the very start of the next ISR. That gives you much more deterministic timing. PWM is a bit more complex as you have to re-load the period each time the bit stream changes from 1 to 0 and vice-versa. you have to get it just right so the new period is loaded correctly. You can also control the ADC with a state machine in the same ISR. You can end up with more processing being done in the ISR than main() (talking C here), which is generally frowned upon, but it works very well for this application. 1 Link to post Share on other sites More sharing options...
nigelwright7557 Posted November 15, 2020 Author Share Posted November 15, 2020 (edited) I wrote the code for preamble, sendzero and sendbyte. Sendbyte doesnt call sendzero or sendone as I did it discretely so the bit times could be finely adjusted. Thanks for the tip on zero stretching. After returning form the above functions it can be stretched a little. Some time is spent reading ADC's for timer setting and speed setting so I just leave output at 12 volts for a little while. White waiting for turnaround timer to timeout I send DCC codes again so the loco doesnt time out and go into DC mode. I was in two minds about addressing, whether to use "broadcast" address 0 to send speed and direction or actually send out data with all addresses. In the end I settled on sending out all addresses with speed/direction. Edited November 15, 2020 by nigelwright7557 Link to post Share on other sites More sharing options...
Pete the Elaner Posted November 16, 2020 Share Posted November 16, 2020 Are there any decoders which can do this? Hornby's Sapphire could. It required settings some (8 I think) CVs for 2 movements & 2 pauses, then a further one to switch the shuttle on. I did this on a friend's layout & we left it running while we had dinner. It would have worked fine if we had considered it was running up & down a gradient. It went a little further on the downhill each time so ran into the buffers on the downhill leg. Oops! It took a little setting up so maybe it could be combined with ABC braking for more controllability. Link to post Share on other sites More sharing options...
Ron Ron Ron Posted November 16, 2020 Share Posted November 16, 2020 1 hour ago, Pete the Elaner said: Are there any decoders which can do this? .... DCC Concepts Zen Black. Possibly Lenz ABC with BM modules? There appear to be a number of ready made DCC shuttle modules available. . 1 Link to post Share on other sites More sharing options...
Nigelcliffe Posted November 16, 2020 Share Posted November 16, 2020 2 hours ago, Pete the Elaner said: Are there any decoders which can do this? Lenz decoders (for at least a decade, probably more), either a simple "end to end" shuttle. Or a more complex "end to end, with intermediate stops". Requires appropriate brake modules, just the five-diode (BM1) for the simpler type, or a mixture of brake modules for the more complex options. Works with any make of command station. - Nigel Link to post Share on other sites More sharing options...
RMweb Premium Steven B Posted November 16, 2020 RMweb Premium Share Posted November 16, 2020 The DSS1 Locoshuttle allows for automated shuttle control when running on a Loconet based system. There's also a couple of basic scripts provided with JMRI which can be expanded upon. It'll be interesting to see how this develops. @nigelwright7557 how are you planning on assigning a loco to the module? A DCC command or hardcoded? Or will you use the global broadcast address of zero and rely on electrically isolating the track from the rest of your layout. Steven B. Link to post Share on other sites More sharing options...
nigelwright7557 Posted November 16, 2020 Author Share Posted November 16, 2020 (edited) I am currently sending out speed and direction with addresses from 1-99. I am having trouble getting my loco running at the moment despite DCC commands looking spot on on the scope. I am just driving the track with 12 volts and zero volts, does it need to be phase reversed or just switched between zero and 12 volts ? I had a look at a decode circuit and theirs needs the phase in one direction to read the DCC command through an opto coupler. Reworked my pcb tonight to do phase reversals and not single ended driving of the track. I had 3 other pcb's in the system for update so sent them all plus DCC pcb at same time for manufacture. Edited November 16, 2020 by nigelwright7557 Link to post Share on other sites More sharing options...
Crosland Posted November 17, 2020 Share Posted November 17, 2020 18 hours ago, nigelwright7557 said: II am having trouble getting my loco running at the moment despite DCC commands looking spot on on the scope. I am just driving the track with 12 volts and zero volts, does it need to be phase reversed or just switched between zero and 12 volts ? DCC is differential and each rail switches alternately between 0 and +ve supply. SO when one is 12V the other is zero, and vice-versa. You need a H-bridge output stage to drive the two rails. Link to post Share on other sites More sharing options...
nigelwright7557 Posted November 17, 2020 Author Share Posted November 17, 2020 7 hours ago, Crosland said: DCC is differential and each rail switches alternately between 0 and +ve supply. SO when one is 12V the other is zero, and vice-versa. You need a H-bridge output stage to drive the two rails. Thanks. I managed to find a motor driver h bridge driver which will give a couple of amps. Just waiting for parts and a new pcb. Link to post Share on other sites More sharing options...
nigelwright7557 Posted November 24, 2020 Author Share Posted November 24, 2020 My new pcb with motor H driver in and built up. Took some time to get 1 and 0 timings as close as I could get them. I can now get loco to move forward and backwards. I can also alter its speed. Struggling setting CV1 despite sending out codes DCC spec says. Code has to be sent twice to set a CV which I do. Link to post Share on other sites More sharing options...
DenbyModeller Posted December 18, 2021 Share Posted December 18, 2021 Just found this thread, I've set up my layout with DCC Concepts Zen Black Shuttle units and it's been working perfectly. Link to post Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now