PICAXE based DCC Accessory Decoder

westaust55

Moderator
To meet my own needs and in response to a number of past threads inquiring about PICAXE based DCC decoders for model railways, I present my own PICAXE based DCC Accessory Decoder.
Developed initial on a breadboard and I have subsequently constructed a couple on prototyping boards which are working successfully in so far as my intentions for use on a DCC controlled model railway.

The attached document explains the basis of DCC command signals, why I have followed the scheme that I have and the basic structure of the programs in the two PICAXE chips used for each DCC Accessory Decoder.

Included also is a photo of my prototyping board modules.

In following posts I will provide some versions of the BASIC programs for the two PICAXE chips.
 

Attachments

westaust55

Moderator
Attached in this post are:

1. A timing diagram depicting the DCC system data packet intervals, actions of the first PICAXE chip and actions of the second PICAXE chip and how these are overlaid.

2. A zipped file with an Excel spreadsheet that will help users determine the values for the three bytes in each DCC packet for a given basic accessory command.
 

Attachments

Last edited:

westaust55

Moderator
The two files attached to this post are:

1. The program for PICAXE #1
This is for the 20X2 which receives the DCC data using the PULSIN command and saves the overall bit durations (less 80usec) in scratchpad memory ready for transfer to PICAXE #2.

2. The Demo #1 program for PICAXE #2.
This program reads the data from PICAXE #1 once 4 DCC data packets are received, decodes into the three bytes plus an error flag variable (in case there were timing errors and other errors).
This program also the displays some data about the accessory packets received.
I have included a number of added commands which are remarked out that can be enabled to see more information such as:
- the accessory address block,
- which of the 34 pairs in a blocks is selected
- which output of a pair is selected
- and/or alternatively the address number as used/seen using NCE DCC command systems (and even used by Team Digital for their decoder boards).
 

Attachments

Last edited:

westaust55

Moderator
The two files attached to this post are further examples.

Both look for specific DCC Accessory addresses (NCE addresses 400 to 404 inclusive and the "Rev"/"2" button" - but easily changed) and then acts upon the program sequence associated with that action.
See the spreadsheet calculator posted at Post 2 in this thread to determine your own addresses for NCE and other makes of DCC command system such as Digitrax, Lenz, ECoS, Hornby, etc.

Demo 2 drives the 9 pins of Port B directly as 8 channels for controlling some LED's or similar (respecting the PICAXE chip current capabilities).
Three of five sequences have been defined and the reader may add some extra routines in the two unused action segments.

Demo 3 drives a 16-bit shift register (in my case using 2 x cascaded 74HC595 8-bit shift registers chips in turn driving 2 x UDN2981 8-channel high side 'switch' chips).
Four of the five sequences have been defined for demo purposes and the reader may add some extra routines in the unused action segment or even add more action segments.

===================================================================================
I have now assembled and tested a total of 3 DCC accessory decoders on prototyping board. Takes me about 3 hours to assemble one.

Only one needed a few trials at selecting a "good" 10 nF capacitor for the 74HC123 timing duration.
The others plus first on a breadboard came out spot on at 80 usec pulses from the 74HC123 monostable chip.

If you do not have an oscilloscope then examining the value of the timing results for the PULSIN commands for a DCC "1" bit should allow you to get in the right ball park.
Looking for PULSIN values from the 20X2 @ 64 MHz in the range 55 to 65 would be a good indicator.

===================================================================================

Programming the 20X2 is nominally a 1 off so I program mine on my AXE091 board.
I have included a 3-way header on the protoboard so I can changed the "End User" program in PICAXE #2 using an AXE029 breadboard adaptor or similar circuit.
 

Attachments

Last edited:

macrobeak

New Member
Westaust55,
Well done, a very complete and professional presentation.
It looks like you have pretty well smashed it.
I am not much into model railways, but I am mulling over how this protocol can be used for other purposes.
 

Mad Mart Uk

New Member
Utterly Stunning
The documentation is excellent and would put MERG to shame!

I have been looking for something like this for what seems forever, I could never grasp the 'mechanics' of DCC from elsewhere until now.
Looks like my Signals project could be a reality at last - A BIG Thanks :D
 

Tasp

Member
I know this is an old post now.

However did I read that you have had pcb made up or are you still using proto boards?

If you haven't had boards made I am quite interested in doing so, I have a cost effective supplier and would like to use these for interfacing lighting/signals from a DCC command.
 

westaust55

Moderator
I know this is an old post now.

However did I read that you have had pcb made up or are you still using proto boards?

If you haven't had boards made I am quite interested in doing so, I have a cost effective supplier and would like to use these for interfacing lighting/signals from a DCC command.
Hello Tasp,

no, I have not designed or had made any PCB's. In fact just about to look at installing the four proto-board based examples I made under my layout - but first need to build a few more of the high side Darlington driver interface boards.

Feel free to use the design to build your own circuits.
 

westaust55

Moderator
For general information, have now assembled some high side driver boards using UDN2981A chips and the two boards (the PICAXE based decoder as per this thread + 16 channel driver board) were installed under the first module (village scene) on the weekend.
Prepared a final BASIC program sequence to control the 54 lights used for buildings and streets and all working well.
Accessory numbers:
400 turns off all lights
401 turns on all lights
402 runs a 90 step sequence for the lighting (~15 sec per step) emulating lights coming on in evening cycling through the night and going out in morning with a short (couple in minutes) period before the illumination sequence starts again
403 turns in street lights only
404 - currently spare

Now in coming days to create a sequence and do the decoder install for the station module.


EDIT: (now at PC rather than iPhone)
attached is the current BASIC program as used for lighting control for 1 module (Village) on model railway.
Includes a sequence held in Table memory( at lines 63 to 72) and the final routine (Action3 = lines 250 to 263) to read each word (2-bytes) of data forming 1 sequence step and update the 16 outputs at 15 second intervals.
What each of the 16 output channels controls is briefly described in program lines 208 to 226.
 

Attachments

Last edited:

intwoit2002

New Member
Excellent write up I have learned a lot from this. Also into model railways and look forward to what you are doing. Thanks very much for a very complete document.

Thanks,
Al
 

Mal Hodgson

New member
This is a truly superb write up. The documentation is of the highest quality and the time and effort you have put in to this is evident. I salute you for sharing this with us. I shall now be giving it a go!
Thank you.
 
Top