Interfacing with a DCC decoder

Good afternoon all,

I'm wondering if it's possible to interface with a DCC decoder easily?

The problem is the way these decoders work - they use low-side (NPN) switching, with a common positive and separate negative "outputs". Is there a way for a PICAXE to detect that one of these lines has been activated, and if not is there external circuitry which could convert this to the required logic signal?

Cheers
 

hippy

Technical Support
Staff member
I believe it should be fairly easy to interface with what comes out of a DCC decoder but I don't have any experience of DCC. It seems it is even possible to use a PICAXE to act as a DCC decoder. There are prior posts on the forum about DCC and westaust55 is perhaps a 'resident expert' on that having undertaken a number of DCC related projects.

It might be worth trying a forum search, perhaps via Google with "site:www.picaxeforum.co.uk" added to get round the "DCC" being a short word. Here's one thread which may be a good place to start -

http://www.picaxeforum.co.uk/showthread.php?26683-Anyone-tried-dcc-coding-decoding-with-picaxe
 
Last edited by a moderator:

AllyCat

Senior Member
Hi,

I believe this is one of Westaust55's specialist areas and he has done it with a combination of a small amount of additional hardware and "Overclocking" an X2 at 80 MHz. I think it's fully documented somewhere on the forum but (as usual) the search engine is rather poor. Perhaps try Googling "DCC and PICaxe".

Cheers, Alan.
 
Thanks for the replies guys,

I've already had a look, and it appears that most threads on the subject are about using PICAXEs as complete replacements for DCC decoders, which unfortunately isn't what I'm after.

I would like to keep the decoders in the locomotives, as some locos will have sophisticated sound decoders. The PICAXE would be a drop-in "addon" board to control the lighting functions, expand on the basic "on-off with occasional features" functionality of the DCC decoder being used, and would allow me to fit different models of decoders without altering the wiring of the loco.

Cheers
 
I'm not an expert on DCC but does this thread discuss what you want?
thanks for the reply,

I'm afraid not - it's a very interesting project (I may or may not be filing it away for future reference.......), but unfortunately not quite what I'm after here.

my problem really boils down to this:

PICAXE inputs obviously use a logic (5V) input, but DCC decoders have their switching on the low side, ie with a common positive. Is it possible to detect when the line has been activated, for example by measuring current drain (or lack thereof)?
 

hippy

Technical Support
Staff member
If the DCC Decoder has an open-collector output, as you seem to describe it, it should be fairly easy to interface to a PICAXE ...

Code:
V+ ---.             .--------.---- 5V
      |            .|.       |
      |            | |       |
  .---^---.        |_|   .---^----.
  |       |         |    |        |
  |  DCC  |---|<|---^--->| PICAXE |
  |       |              |        |
  `---.---'  Diode       `---.----'
      |                      |
0V ---^----------------------^---- 0V
You wouldn't even need an external resistor if using an input with an internal pull-up.

Added: This should also work even if the outputs are V+/0V rather than open-collector.

Alternatively an opto-coupler can be used which is what many might recommend ...

Code:
V+ ---.--------.       .----------.---- 5V
      |       .|.     .|.         |
      |       |_|     |_|         |
      |        |       |__        |
  .---^---.   _|_     _|  |   .---^----.
  |       |   \ /...|/    |   |        |
  |  DCC  |   -.-   |\_   `-->| PICAXE |
  |       |----'       |      |        |
  `---.---'            |      `---.----'
      |                |          |
0V ---^----------------^----------^---- 0V
 
Last edited:
If the DCC Decoder has an open-collector output, as you seem to describe it, it should be fairly easy to interface to a PICAXE ...

Code:
V+ ---.             .--------.---- 5V
      |            .|.       |
      |            | |       |
  .---^---.        |_|   .---^----.
  |       |         |    |        |
  |  DCC  |---|<|---^--->| PICAXE |
  |       |              |        |
  `---.---'              `---.----'
      |                      |
0V ---^----------------------^---- 0V
You wouldn't even need an external resistor if using an input with an internal pull-up.

Alternatively an opto-coupler can be used which is what many might recommend ...

Code:
V+ ---.--------.       .----------.---- 5V
      |       .|.     .|.         |
      |       |_|     |_|         |
      |        |       |__        |
  .---^---.   _|_     _|  |   .---^----.
  |       |   \ /...|/    |   |        |
  |  DCC  |   -.-   |\_   `-->| PICAXE |
  |       |----'       |      |        |
  `---.---'            |      `---.----'
      |                |          |
0V ---^----------------^----------^---- 0V
Ah, ASCII art... ;-)

I completely forgot about optocoupling... d'oh... that seems like the obvious solution!! Where's my breadboard...

Cheers for help Hippy, I'll post back here as and when I get a chance at home to try the solution out. For now, I need to get my grubby paws on some OCs...
 

westaust55

Moderator
To the best of my knowledge, all DCC decoder function outputs are open collector switching the wire/pin down to 0 volts.
Likewise all DCC decoders with function outputs provide a 12 Vdc wire/pin intended to supply power for the loads switched by the function outputs.
Typically that 12 Vdc will have a capacity of at least 200 mA.
Using a 100 mA 5 Vdc regulator powered from the decoder 12 Vdc wire/pin would permit you to power the PICAXE chip if desired.

The circuit for a direct connection as proposed by hippy will definitely work.
I would go so far as to suggest that the diode can also be deleted.


Albeit not your current requirement, you may find reading my thread on creating a PICAXE based accessory decoder of interest:
http://www.picaxeforum.co.uk/showthread.php?27439-PICAXE-based-DCC-Accessory-Decoder
 
I'm planning on powering the PICAXE directly from the DCC supply using fast-recovery diodes in a full-bridge rectifier configuration (and linear regulator, obviously), which allows me to order umpteen small PCBs all with the same design to fit into any loco, as well as coaches :)
 

westaust55

Moderator
Even function only decoders such as the TCS FL2 and FL4 already incorporate the diode bridge for providing a DCC supply.
They will even have an onboard voltage regulator for the onboard PIC micro controller.
Most commercial decoders that&#8217;s i am aware of use a PIC microcontrollers thought the DIY field often use Arduino based controllers.
 
So for coaches with a decoder, I could just use the 12-16V DC rail from the decoder, leaving the rectifier on my PCB unoccupied, and for coaches with no decoder use the rectifier?

Basically, I'm planning on transmitting function status between coaches using infrared - means I only need one decoder per train
 

hippy

Technical Support
Staff member
To the best of my knowledge, all DCC decoder function outputs are open collector switching the wire/pin down to 0 volts.

The circuit for a direct connection as proposed by hippy will definitely work.
I would go so far as to suggest that the diode can also be deleted.
You are right; that's not needed for a genuinely open-collector output.

In fact the diode solution turns a high/low, V+/0V, signal into what is effectively an open collector output which can be read by a PICAXE with a pull-up.
 
You are right; that's not needed for a genuinely open-collector output.

In fact the diode solution turns a high/low, V+/0V, signal into what is effectively an open collector output which can be read by a PICAXE with a pull-up.
Gotcha - so a bit like an i2c bus, with a 1k pull up, and clever(ish) programming to recognise that the input is inverted? Would definitely save space over using optocouplers... Since my design is all about minimal space, even with the chip on one side of the board, and passives on the other &#55357;&#56834;
 

westaust55

Moderator
So for coaches with a decoder, I could just use the 12-16V DC rail from the decoder, leaving the rectifier on my PCB unoccupied, and for coaches with no decoder use the rectifier?
Correct.

If you wish to have a constant current flicker free lighting circuit to avoid those brief times when wheel to rail contact is lost then have a look at my attached circuit. Does involve a couple of small SMD IC's.
With 6600 uF of capacitance and up to 8 hi-intensity LED's operating at approx 2.1 mA the circuit will maintain the constant current for approx 3 seconds.
.View attachment DCC Carriage Lighting Schematic.pdf

I tried super capacitors (from a reputable electronics store) and besides maintaining the LEDs for far longer than necessary (45 mins!) the failure rate of the supercaps was horrific.

Basically, I'm planning on transmitting function status between coaches using infrared - means I only need one decoder per train
That would work but the extra components for the IR LED and detector adds to complexity.
What others have done (I have a decoder in each carriage), assuming they stay in fixed rakes, is to run a couple of fine wires between the carriages - they will look like the brake lines.
There are some very small (miniature) 2-pin and 4-pin plugs and sockets available out there - E-bay and elsewhere which can be used to allow disconnect of carriages should the need arise.

But thinking further:
I guess that is where the PICAXE chip are coming into play - for the IR comms and lighting control on the "other" carriages. :)
 
Correct.

If you wish to have a constant current flicker free lighting circuit to avoid those brief times when wheel to rail contact is lost then have a look at my attached circuit. Does involve a couple of small SMD IC's.
With 6600 uF of capacitance and up to 8 hi-intensity LED's operating at approx 2.1 mA the circuit will maintain the constant current for approx 3 seconds.
.View attachment 22170

I tried super capacitors (from a reputable electronics store) and besides maintaining the LEDs for far longer than necessary (45 mins!) the failure rate of the supercaps was horrific.


That would work but the extra components for the IR LED and detector adds to complexity.
What others have done (I have a decoder in each carriage), assuming they stay in fixed rakes, is to run a couple of fine wires between the carriages - they will look like the brake lines.
There are some very small (miniature) 2-pin and 4-pin plugs and sockets available out there - E-bay and elsewhere which can be used to allow disconnect of carriages should the need arise.
I've been hunting, but I'll keep looking :)

Cheers for the help guys!
 

hippy

Technical Support
Staff member
Gotcha - so a bit like an i2c bus, with a 1k pull up, and clever(ish) programming to recognise that the input is inverted?
Pretty much, but the coding isn't very difficult ...

Code:
Symbol INPUT_PIN    = pinC.1
Symbol INPUT_ACTIVE = 0

Do
  If INPUT_PIN =  INPUT_ACTIVE Then ...
  If INPUT_PIN <> INPUT_ACTIVE Then ...
Loop
Just change "INPUT_ACTIVE=0" to "=1" if required.
 
Pretty much, but the coding isn't very difficult ...

Code:
Symbol INPUT_PIN    = pinC.1
Symbol INPUT_ACTIVE = 0

Do
  If INPUT_PIN =  INPUT_ACTIVE Then ...
  If INPUT_PIN <> INPUT_ACTIVE Then ...
Loop
Just change "INPUT_ACTIVE=0" to "=1" if required.
Aye, I was joking - the only difficulty is rembering that the input is inverted :)
 
Last edited:

westaust55

Moderator
And a further alternative for coding if there is a preference to generate code where action is on a "1" level is to use the XOR math function.

This example assumes you have two inputs on pins C3 and C.4 and some related outputs on B.0 and B.1.

Code:
; pin C.3 = control signal 0
; pin C.4 = control signal 1

DO

  b0 = pinsC
  b0= b0 XOR %00011000 / 8 ; the /8 is not necessary if you are happy to check bits 3 and 4 directly

  If bit0 = 1 then ; check control signal 0
    high b.0
  else 
    low b.0
  endif
  If bit1 = 1 then ; check control signal 1
    high b.1
  else 
    low b.1
  endif
  pause 1000
LOOP
 
Top