New DCC decoder algorithm

Post all your DCC only problems, solutions and discoverys here.
Post Reply
tspotter
Posts: 17
Joined: Sun Feb 14, 2016 8:54 pm

New DCC decoder algorithm

Post by tspotter »

Yesterday I prototyped a new DCC decoder algorithm. Well it’s new to me. Has anybody used this idea before? I’d be amazed if they haven’t, as it’s so simple. I used a PIC 16F506 (obviously I could have used an 8-pin or even 6-pin version).

This is how it works:

1 Find the positive leading edge of the DCC waveform

2 Time 87us (not very critical)

3 Look to see if the level is 0 or 1 at this point - after the ‘1’ pulse (58us long), but before the end of the ‘0’ pulse (116us long with my Roco Multimaus).

4 0 and it’s a code ‘1’

5 1 and it’s code ‘0’

Here is a scope photo showing the DCC waveform at the input to the PIC (top), and the sampling points below (both 2V/div). For the sample points, I turned on an output pin at that point in the programme, for one clock cycle. The timescale is 50us/div.
Sampling.jpg
Sampling.jpg (53.42 KiB) Viewed 1899 times
I set up a single point decoder. The address was fixed in the software. I used a point from my Hornby Dublo layout - I only need a 1000uF capacitor charged to the DCC peak voltage of 16V. here is my set up:
Decoder prototype.jpg
Decoder prototype.jpg (74.18 KiB) Viewed 1899 times
On the scope is the Solenoid waveform (100ms on time, 200ms and 10V/div), with the characteristic avalanche breakdown at turn-off - I don't use any clamp diodes, as the energy is tiny. Also note the TO92 drive transistors which are fine for HD solenoids.

Comments welcome!
Julian
tspotter
Posts: 17
Joined: Sun Feb 14, 2016 8:54 pm

Re: New DCC decoder algorithm

Post by tspotter »

I have now achieved my original objective: a decoder entirely inside an electric point. In this case a Hornby Dublo point. So I now have a completely wire-free DCC electric point! I used my simple decoder algorithm - it works well on my layout.

The HD solenoid is 25 ohms. So I used 3 x 220uF SMD tantalum CDU capacitors (charged to the peak DCC voltage of 16V). The short wiring also helps here. The FET drivers are E-line - very low profile. All the other parts fit within the 4mm headroom. The PIC is the 12F510. The metal baseplate is 0V, with the ground-based parts soldered directly to it. The DCC ‘live’ input is the centre rail and again I have soldered directly to the terminals.

And here it is. I put a blanking plate in place of the normal terminals.
HD point.jpg
HD point.jpg (65.82 KiB) Viewed 1855 times
DCC point.jpg
DCC point.jpg (70.37 KiB) Viewed 1855 times
Julian
Bigmet
Posts: 10172
Joined: Tue Aug 14, 2007 2:19 pm

Re: New DCC decoder algorithm

Post by Bigmet »

tspotter wrote:I have now achieved my original objective: a decoder entirely inside an electric point...
Nice job. You have neatly done what -amazingly - the RTR track suppliers seem to be completely ignoring. Why no DCC 'plug and play' track system with a servo/decoder ready installed for each point movement? (Simple options for independent busses for both point operation and track supply would potentially make such a track system suitable for the entire RTR market from beginner to advanced user.)
Suzie
Posts: 450
Joined: Tue Dec 17, 2013 11:46 pm

Re: New DCC decoder algorithm

Post by Suzie »

Your algorithm is a semi-edge detection with sampling method. General consensus is that edge detection triggering is a bit prone to false triggering on spikes which tend to occur frequently in the track environment, so most algorithms use full sampling to achieve more reliable results. This is especially important if not using a balanced comparator input.

Model railways have a hostile electrical environment, and especially when you are taking a signal from the track directly you are likely to see a lot of noise in practice. Accessory packets typically will only be sent twice, which does not leave much scope for missed packets if you get two false triggers.

Full sampling will typically sample every 22 or 44uS and thereby ignore any number of spikes between samples. If using a modern high performance PIC processor that skips potentially hundreds of false spikes that would trigger a pin 'change of state' indication on the port pin.

If using edge triggering you need very advanced noise cancelling algorithms (produce a table of half-cycles and eliminate all the ones that are too short to be a '1' half bit before assembling the resulting bit stream in to a DCC packet) to ensure good results in the real world. It is quite easy to use software edge detection in the sample stream coming from the 44uS samples if the processor is not doing anything else where the noise has been quite effectively reduce to an insignificant amount.

If the signal input to the PIC was guaranteed clean then the direct edge detection is very sensible and will save a lot of processing overhead - a command station like the Hornby Select creates a lot of edges so probably would not work with your decoder.
tspotter
Posts: 17
Joined: Sun Feb 14, 2016 8:54 pm

Re: New DCC decoder algorithm

Post by tspotter »

Suzie
Thanks for your interesting post. The proof of the pudding is that - so far - the point has worked faultlessly on my layout.

I wouldn’t use edge detection in a loco decoder, but the accessory decoder electrical environment is more benign.

I agree that noise could cause a missed switch. But the likelihood of a false switch (i.e. the wrong point switched) is surely very unlikely, because the error byte masks out single bit errors?

There two things in my favour: I’m using a Multimaus which gives a clean, reliable DCC waveform. And I over-drive the DCC input to the PIC: a 47k resistor directly into the PIC pin. The input protection diodes limit this, of course, so it would take nearly a full amplitude noise spike to cause an error. Thought bubble: I could put a 100pF cap on the PIC input - a 4.7us filter might provide additional spike protection (even though I don’t seem to have problem, as of now).

Incidently, we know the model railway is a noisy environment, but has anybody quantified this with measurements?

At the end of the day what’s important for me is that I could build this decoder with my limited programming skills!
Julian
User avatar
Flashbang
Posts: 4089
Joined: Thu Oct 18, 2007 1:07 pm
Location: SE United Kingdom
Contact:

Re: New DCC decoder algorithm

Post by Flashbang »

Well done to you and if it works faultlessly even better!

Have you considered placing this article on the DCC pages of RMweb? Where many DCC specialists (and non specialists too!) frequent?
As this is the New Railway Modellers forum it may (perhaps?) be a little beyond the vast majority of the forums readers understanding or knowledge? But I enjoyed reading it as I'm sure several others have too.
[Image << Click the Icon to go to my website
Broken? It was working correctly when I left it.
Suzie
Posts: 450
Joined: Tue Dec 17, 2013 11:46 pm

Re: New DCC decoder algorithm

Post by Suzie »

A momentary short will cause the track voltage to drop below 2.5V, and your use of a single input pin will result in a negative edge followed by a positive edge being observed when the short is removed. This type of event is common where for example Peco Insulfrog points are used or wheel back to backs are a bit small.

I concur with Flashbang. Well done for creating something that works!

Suzie x
rosenblad
Posts: 328
Joined: Sun May 28, 2006 1:15 pm
Location: Norway

Re: New DCC decoder algorithm

Post by rosenblad »

Bigmet wrote: Nice job. You have neatly done what -amazingly - the RTR track suppliers seem to be completely ignoring. Why no DCC 'plug and play' track system with a servo/decoder ready installed for each point movement? (Simple options for independent busses for both point operation and track supply would potentially make such a track system suitable for the entire RTR market from beginner to advanced user.)
They certainly do Bigmet. Märklin/Trix do it with their C-track, and Roco do it with their GeoLine track Here's a photo of the GeoLine point with motor and decoder installed entirely within the ballast:

Image
Carpe Diem!
Post Reply