Searching \ for 'Model RR - A DCC decoder - How to?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/index.htm?key=model+dcc+decoder
Search entire site for: 'Model RR - A DCC decoder - How to?'.

Truncated match.
PICList Thread
'Model RR - A DCC decoder - How to?'
1996\05\01@005008 by Prashant Bhandary

flavicon
picon face
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
for suggestions/ideas/advice.

What's DCC
----------
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.
Neat, huh?

Which CPU?
----------
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.

DCC specs
---------
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
64us.

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.

Decoder requirements
--------------------
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.

How?
----
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 :-)

Misc
----
The damn things are cheap(AU$50?) and getting cheaper :-) So why build it?
Because
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
is fun.

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.

Regards

Prashant

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
suggestions, Don?
+----------------+  -------------------------------------------------
|                |    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: spam_OUTprashbTakeThisOuTspamrta.nsw.gov.au
|   +--------+   |
| Still a newbie |    "2b|!2b" - William Shakespeare
+----------------+  -------------------------------------------------

1996\05\01@093850 by Norm Cramer

flavicon
face
At 02:49 PM 5/1/96 +1000, you wrote:
>

[snip]

>How?
>----

Based on my command station work with DCC and PICs, I think it can be done
quite simply.  The timing is from the zero crossings.  Use the DCC signal
and set up the PIC to interrupt on port B change.  Use the timer to time the
time between interrupts.  Check the time and see if it is a one or a zero.
The code to decode the packet is pretty straight forward.  I wrote a tool in
C to test my command station implimentation.  I uses times from the MPSIM
trace file and determines if the timing is correct for the DCC signal.  It
is just a development tool but I am willing to send it to you "as is" to
show how I detected packets.  There are probably some improvements needed
but it is basically a decoder (Note that the time limits used are for the
command station, not the decoder since it is testing the command station).
I think you could do this with a 4MHz 16C84.

>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.

Agreed.
>A counter/capture would
>have been great but 16C84 cousins have already been ruled out.

Agreed!!!

>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.

I think this is the most likely solution.  I am not sure that noise is a
problem.  Some test would tell but this is the first approach I would take.
Another solution to the noise would be to "filter" the DCC signal with
software.  i.e. ignore polarity shifts that are smaller than the DCC 1's
time.  I still think with a +- 12VDC (or more I use +-18VDC) signal, that
noise on the zero crossing should be rare.  The protocol recommends
repeating packets as frequently as possible so it may not be a problem at all.

>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 complexity of the timed loop and syncing with the command station
(streached zeros, timing tolerances etc) could be hard.

>Misc
>----
>The damn things are cheap(AU$50?) and getting cheaper :-) So why build it?
>Because
>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
>is fun.

All very good reasons.

>
>Decoders for driving accessories don't have size restrictions and may have more
>options for implementation.

This may be the first thing to build, then use what you learn to build the
loco decoder.  BTW I bought a decoder for $29.95 (US) to test my command
station.  It may be a little large to put into an N scale loco though.

>
>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.
>

I am working this part of the problem and have a workable solution. (As I
described via direct e-mail to you).

Regards,

Norm

1996\05\01@184559 by Don McKenzie

flavicon
face
On Wed, 1 May 1996, Prashant Bhandary wrote:

> 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
> for suggestions/ideas/advice.
> Regards
>
> Prashant
>lots of snips--------------------------
> 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
> suggestions, Don?

Bob Nicol of Microzed in Armidale has a bigger stock of PIC parts than I
do, although SMT may also be a problem for him. I have never stocked them
for similar reasons. If that other mob has a stock of 4Mhz versions or
you have some, you could try pushing the chip speed a little.

With DIP parts, I have the 84/04 running off an 8Mhz crystal. Take your
pick out of the box. Any piece will work. When I told Gary Barnes of
Perth WA about this he sent me a little prototype board he had made up.

It has one of those 4 pin canned oscillators (ttl characteristics) and
will run any 84/04/P at 12 Mhz!!!

If you sent a man to the moon with it, watch out for legal stuff because
of manufacturers specs., but for 'you and I' projects, who cares!, as
long as it works 100%.

As I am sure you will be up against no stock in Australia. Do what I do,
go through digikey if you really need small quantities in a hurry at a
reasonable price.

Hope this is of some help. Don...

Don McKenzie .....donmckKILLspamspam@spam@labyrinth.net.au
DonTronics Tullamarine, Australia
http://www.labyrinth.net.au/~donmck

PIC Basic Compiler available now. PIC Programmers starting at $15US
PicoSaurus, the 40 pin ETI PIC Basic with 8K EEPROM Free Windows Dev Sys

1996\05\02@032454 by Prashant Bhandary

flavicon
picon face
At 08:36 AM 1/05/96 -0500, you wrote:
>
>>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.
>
>I think this is the most likely solution.  I am not sure that noise is a
>problem.  Some test would tell but this is the first approach I would take.
>Another solution to the noise would be to "filter" the DCC signal with
>software.  i.e. ignore polarity shifts that are smaller than the DCC 1's
>time.  I still think with a +- 12VDC (or more I use +-18VDC) signal, that
>noise on the zero crossing should be rare.  The protocol recommends
>repeating packets as frequently as possible so it may not be a problem at all.

The noise causing packets to be lost is not the problem. It may cause the
interrupt to be called too frequently to allow the main loop to run at all.
Filtering it out will still deprive the main loop its chance to run. The
main worry is it may interfere with the PWM. Noise would be due to dirty
track resulting in the signal dropping back to 0 intermittently. Pure +ve
to -ve transitions are hard to differentiate from drop to 0 without some
external components. So, whenever the train hits a dirty patch on the track,
it will mess up the PWM and falter. Hence my suggestion to block out
transitions for 40 us after a valid state change.

One possible way of differentiating between + to - transition and drops to
zero would be to use two inputs and do differential sensing in software.

The right place to do the PWM is another problem. PWM in the ISR can make
the ISR too long(?). Doing it in the main loop using the timer as a running
counter is an option.

Regards

Prashant
+----------------+  -------------------------------------------------
|                |    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: prashbspamKILLspamrta.nsw.gov.au
|   +--------+   |
| Still a newbie |    "2b|!2b" - William Shakespeare
+----------------+  -------------------------------------------------

1996\05\02@091003 by Norm Cramer

flavicon
face
At 05:24 PM 5/2/96 +1000, you wrote:

[snip]

>The
>main worry is it may interfere with the PWM. Noise would be due to dirty
>track resulting in the signal dropping back to 0 intermittently. Pure +ve
>to -ve transitions are hard to differentiate from drop to 0 without some
>external components. So, whenever the train hits a dirty patch on the track,
>it will mess up the PWM and falter. Hence my suggestion to block out
>transitions for 40 us after a valid state change.
>

Oops, haden't thought about the dirty track problem.  I like the
differential sensing approach and a block out for 40 usec should provide
"main loop" processing time.  At what rate do you want to do the PWM to the
motor?  If it is low enough, this approach should work.

>One possible way of differentiating between + to - transition and drops to
>zero would be to use two inputs and do differential sensing in software.
>
>The right place to do the PWM is another problem. PWM in the ISR can make
>the ISR too long(?). Doing it in the main loop using the timer as a running
>counter is an option.

What I have done in the command station to get it to fit into the 16c84 is
add a second timer in software that counts in 58usec intervals.  It's not
accuracte enough for PWM but works great for key debounce and autorepeate.
Depending on the PWM period, you may be able to just increment a counter
every time the timer isr happens. (Note 58usec is the 1's time) The command
station uses tmr0 to generate the DCC signal.


Another question to address is how to convert the PIC output level to a
voltage to run the motor in such a small space?  This doesn't need to be
solved yet but any ideas from the group would be usefull for planning.

How small does the decoder have to be?  The one I am using is about 1" x
3/4" and fits OK in an HO scale locomotive (HO SCALE is 87:1) but won't fit
in N scale (160:1).

Regards,

Norm

1996\05\02@124714 by Martin J. Maney

flavicon
face
On Thu, 2 May 1996, Prashant Bhandary wrote:

> track resulting in the signal dropping back to 0 intermittently. Pure +ve
> to -ve transitions are hard to differentiate from drop to 0 without some
> external components. So, whenever the train hits a dirty patch on the track,

If you can spare RA4 and one other I/O pin I think you could do this with
nothing but a couple of resistors and diodes (at least some of which you
would need to get the +-V into the PIC anyway).  RA4 because it has a
Schmitt trigger, and if the thresholds are stable enough and you fiddle
with the biasing that could possibly be enough all by itself.  But for
the cost of one more pin and a resistor you can add some
software-controlled hysteresis to what RA4 already provides.  This was my
first thought, since the input thresholds for the Schmitt input at RA4
are only rather loosely spec'd.  Looking at it again (in the table in
11.3 of the spec sheet), it's not even clear which side of the curve
those numbers are supposed to represent.

1996\05\06@042152 by Prashant Bhandary

flavicon
picon face
At 08:05 AM 2/05/96 -0500, you wrote:
>Another question to address is how to convert the PIC output level to a
>voltage to run the motor in such a small space?  This doesn't need to be
>solved yet but any ideas from the group would be usefull for planning.
>
That shouldn't be difficult. I have envisaged two approaches. Use an H bridge
chip. One candidate which is available locally in one-ofs is UDN2916EB. This is
a 24 pin gull wing SMT. It has a lot more than I want - it is a dual H bridge
and has some current PWM circuitry. I would like to find a smaller single H
bridge.
The other alternative is to use 4 PIC outputs to drive a bridge. This will need
4 transistors+4resistors+4 diodes/1 bridge rectifier. This may even be smaller
and definitely cheaper than the single chip solution. Ordinary SMT components
are available at surplus stores at throwaway prices.

What are you using in your command station?

>How small does the decoder have to be?  The one I am using is about 1" x
>3/4" and fits OK in an HO scale locomotive (HO SCALE is 87:1) but won't fit
>in N scale (160:1).
>

I don't know the exact dimensions but I am looking at building it first in HO
and then move to N. Some commercial decoders for N are in two parts to make
installation easier. The N scale loco I have got seems to have enough space for
a decoder about 3/4" x 3/4" x 1/4".

Regards

Prashant
+----------------+  -------------------------------------------------
|                |    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: .....prashbKILLspamspam.....rta.nsw.gov.au
|   +--------+   |
| Still a newbie |    "2b|!2b" - William Shakespeare
+----------------+  -------------------------------------------------

1996\05\06@092805 by Norm Cramer

flavicon
face
At 06:21 PM 5/6/96 +1000, you wrote:
>
>What are you using in your command station?
>

The command station is currently using a power op-amp made by SGS Thomson,
part L165.  It is only rated at 3A.  I will be switching to a full H bridge
using discreet n-chan mosfets and a fet-driver to get more current.  The
power op-amp might be a good approach for the decoder.  The disadvantage for
a command station is it needs a bipolar supply.  The decoder inherently has
a bipolar supply from the rails.  The only package information I have is a
TO-220 style case.  There may be a surface mount power op-amp out there
somewhere.  It's easy to get the op-amp to do bipolar but a little harder to
do PWM.  I haven't thought about how to make it do PWM, but it shouldn't be
too hard.


Regards,

Norm

1996\05\06@220712 by Prashant Bhandary

flavicon
picon face
At 08:24 AM 6/05/96 -0500, you wrote:
>The command station is currently using a power op-amp made by SGS Thomson,
>part L165.  It is only rated at 3A.  I will be switching to a full H bridge
>using discreet n-chan mosfets and a fet-driver to get more current.  The
>power op-amp might be a good approach for the decoder.  The disadvantage for
>a command station is it needs a bipolar supply.  The decoder inherently has
>a bipolar supply from the rails.  The only package information I have is a
>TO-220 style case.  There may be a surface mount power op-amp out there
>somewhere.  It's easy to get the op-amp to do bipolar but a little harder to
>do PWM.  I haven't thought about how to make it do PWM, but it shouldn't be
>too hard.

As you mentioned, power op amps need a bipolar supply which is a pain. Besides,
you aren't using the linear part. Single chip H bridges are easily available
which
make using discrete solutions unecessary. I don't know about the cost factor
though.
For example, the SGS Thomson L298 should give you enough juice. I don't remember
the rating but should be around 4A. It costs about AU$25. I remember seeing it
being used in a DCC station circuit and can dig it out for you if you like. For
low power applications I use a L293 rated at 600ma/1A. You get two in a 16/20
pin
DIP. I've used it to drive a stepper off a PC parallel port.

Regards

Prashant
+----------------+  -------------------------------------------------
|                |    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: EraseMEprashbspam_OUTspamTakeThisOuTrta.nsw.gov.au
|   +--------+   |
| Still a newbie |    "2b|!2b" - William Shakespeare
+----------------+  -------------------------------------------------

More... (looser matching)
- Last day of these posts
- In 1996 , 1997 only
- Today
- New search...