Model RR - A DCC decoder - How to?
Prashant Bhandary email (remove spam text)
This is addressed to all PIC gurus on the list. The application is, you
guessed it, a DCC decoder which fits inside a tiny train. I am looking
It is a packet based digital standard to drive toy trains. The signal swings
between +/- 12V(or so). The signal is connected to the rails and also provides
the power. The decoder reads the signal, decodes it and changes speed,
direction, lights, etc. accordingly. Each decoder has its own address allowing
each locomotive to be individually controlled by a single signal. Assorted
accessories like turnouts, signals, etc. may be driven off the same signal.
The PIC 16C84 is probably the only candidate in the PIC family or probably
any other family(?) for the following reasons.
1. Size. You can't use a DIP and an 18 pin SOIC is as small as you can get.
It is hard to squeeze in one or more support chips.
2. Data EEPROM. Settings need to be stored on power down. There isn't enough
space for a cell. This probably eliminates every other PIC.
3. ISP. A home-built might just be a little dearer than an off-the-shelf.
Besides the fun of developing something yourself, the other factor is that
you can 'upgrade' the software if necessary. This eliminates all EPROM/OTP
varieties as the OTP is unsuitable and the EPROM versions come only in DIP
or PLCC(?) and are too big.
A 1 is a high followed by a low between 52 and 64 us. A 0 is a high followed
by a low between 90 and 10000 us. As the polarity is not fixed, the high and
low may be reversed. i.e. a 1 may be a low followed by a high between 52 and
All commands are sent as packets. A packet consists of atleast 10 1 bits, a
0 start bit, an 8 bit address, a 0 data start bit, one or more 8 bit data bytes
separated by 0 bits, a XOR 8 bit for error correction and a 1 packet end bit.
The idle condition is all 0s(?).
If the packet address matches the decoder address, the decoder acts on it. The
speed/direction packet is the most basic. More complex packets exist for other
functions like controlling lights, sound, accelaration/deaccelaration or even
reprogramming the decoder address. Packets are periodically retransmitted.
Gory details can be found at http://www.tttrains.com/nmradcc/s91.html, s92.html,
rp911.html, rp921.html, rp922.html, rp924.html.
The main packet is for control of motor speed and direction. The motor has
14 speeds. This is done by PWM. Other packets may be progressively implemented.
Wish I knew. Can it be done at all? My usual ploy for reading bitstreams is to
have a periodic interrupt to sample the input. I do RS 232 using this method
with an interrupt rate of 104 us for 1200 baud input. To sample a 52us signal,
say 2 times, would give about 25 steps @ 4MHz or 60 steps @ 10MHz. The first is
just too difficult for me and the second is daunting. A counter/capture would
have been great but 16C84 cousins have already been ruled out. A Port B
interrupt may be a problem due to noise(?). One way around this could be a
40 us interrupt that enables the Port B interrupt. The Port B interrupt
disables itself and sets
off the time again. This will give the main loop quiet periods to get on
with life in general. There remains the option of a loop timed just
right which also does PWM. How difficult would this be? Are there any other
options I haven't considered? Don't tell me a device to run toy trains is too
much for a PIC or any general purpose micro to handle :-)
The damn things are cheap(AU$50?) and getting cheaper :-) So why build it?
it is there. Because you can change the software to keep it up to date with new
packets. Because you can implement special requirements. Because using PICs
Decoders for driving accessories don't have size restrictions and may have more
options for implementation.
The other missing bit is the control station. This could be a PC driving a PIC.
This, again, is a lesser problem and is solvable. It is also the most expensive
part of a DCC setup and is more easily justified on economic grounds.
P.S. Looks like Digikey sells single 10 MHz SMT PIC 16C84s. Anybody know of a
source in my neck o' the woods(Australia)? The supplier here wants a minimum
order of 126 pieces and this part is not popular enough for a bulk buy. Any
| | Prashant Bhandary
| +---+ | Spatial Information Systems Section
| | | | Roads and Traffic Authority
| | | | Rosebery NSW 2018, AUSTRALIA
| | | | Tel: +61-2-662 5299
| | +----+ | Fax: +61-2-662 5348
| | | | Email: rta.nsw.gov.auprashb
| +--------+ |
| Still a newbie | "2b|!2b" - William Shakespeare
seeking: microchip ints interrupt
See also: www.piclist.com/techref/index.htm?key=model+dcc+decoder
You must be a member of the
piclist mailing list
(not only a www.piclist.com member) to post to the