Jump to content
 

Latest project a DCC shuttle controller.


Recommended Posts

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.

 

 

 

 

 

 

100_0362.JPG

Link to post
Share on other sites

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.

  • Like 1
Link to post
Share on other sites

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 by nigelwright7557
Link to post
Share on other sites

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

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

  • RMweb Premium

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

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 by nigelwright7557
Link to post
Share on other sites

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

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

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

  • 1 year later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...