Polarity Detection

Hey guys,

Is there a way to detect polarity? I'm designing a custom DCC function decoder (yes, WestAust...), which is going perfectly fine... except now I've realised I might wanna see if I can make it work on DC too.

A little basic background - DCC is a communication protocol for model railways encoded in a 12-20V DC alternating square wave power signal, so for the purposes of power delivery can be considered AC. My decoder can decode the signals encoded within this signal no problem. However, many people still use "traditional" DC control - a simple analogue 0-12V power signal, which is connected straight to the motor inside a model train - reversing the polarity reverses the train.

As the decoder is designed to work with "AC", the reverse polarity won't affect it in terms of powering up correctly (as soon as the power reaches about 5V, as the MCU is running at 3.3V). However, on DC I want to be able to detect the polarity, so I can tell which direction the train is going, to activate the correct sets of head / tail lights. And, of course, this detection method is going to have to be able to handle the high frequency "AC" of DCC when in "normal" operation...

Does anyone have any suggestions?

Cheers!
 
Haud on, I think I'm having a classic Tech Support moment - soon as I posted this I had a eureka moment... could anyone confirm if this would work?

This is a diagram of my DCC input (the connection between the track and the microcontroller, sensing the DCC signal)... as the optocoupler is, by definition, polarity sensitive, I could use it for polarity detection!! 🤦‍♀️🤦‍♀️

The only change I made to the original diagram is replacing the current limiting resistor with a constant current LED driver - this ensures that the optocoupler is correctly driven at both the 12-20V DCC levels, and low-end DC levels...

I'm kicking myself now!23084
 

Pongo

Senior Member
According to the data sheet for the NSI50010YT1G:

MAXIMUM RATINGS (TA = 25°C unless otherwise noted)
Reverse Voltage VR 500 mV
 

Pongo

Senior Member
If you mean the LED diode then no, using that as a protection diode at those voltages is not a good idea.

According to the datasheet for the 6N136:

ABSOLUTE MAXIMUM RATINGS (Tamb = 25 °C, unless otherwise specified)
INPUT
Reverse voltage VR 5 V

I would suggest running the numbers for a simple resistor zener resistor solution. Then the forward voltage of the zener (about 1,2 volta) will protect the LED from reverse voltage.
 

hippy

Technical Support
Staff member
I would likely have gone for a simple current limited opto -
Code:
          ___    .---------------.
DCC+ >---|___|---|----.       .--|---> SIG
                 |   _|_   | /   |
                 |  _\ /_  |<    |
                 |    |    | \   |
DCC- >-----------|----'       `--|---. 
                 `---------------'  _|_ 0V
 
If you mean the LED diode then no, using that as a protection diode at those voltages is not a good idea.

According to the datasheet for the 6N136:

ABSOLUTE MAXIMUM RATINGS (Tamb = 25 °C, unless otherwise specified)
INPUT
Reverse voltage VR 5 V

I would suggest running the numbers for a simple resistor zener resistor solution. Then the forward voltage of the zener (about 1,2 volta) will protect the LED from reverse voltage.
Sorry, I meant diode D2 in my schematic :)
I would likely have gone for a simple current limited opto -
Code:
          ___    .---------------.
DCC+ >---|___|---|----.       .--|---> SIG
                 |   _|_   | /   |
                 |  _\ /_  |<    |
                 |    |    | \   |
DCC- >-----------|----'       `--|---.
                 `---------------'  _|_ 0V
Aye, that was the original plan - however would that work fine with lower voltages such that you find at analogue 0-12V levels, as well as the high frequency 12-20V DCC signals?
 

hippy

Technical Support
Staff member
I would likely have gone for a simple current limited opto
Aye, that was the original plan - however would that work fine with lower voltages such that you find at analogue 0-12V levels, as well as the high frequency 12-20V DCC signals?
It won't work below 1.3V, or whatever the minimum Vforward is, and probably becomes unreliable before then.

But the problem is finding something which can work down to near 0V as well as up to 20V.

Maybe some sort of external op-amp-comparator which can handle high voltages but also cope with lower currents ?
 

Pongo

Senior Member
I would likely have gone for a simple current limited opto -
Code:
          ___    .---------------.
DCC+ >---|___|---|----.       .--|---> SIG
                 |   _|_   | /   |
                 |  _\ /_  |<    |
                 |    |    | \   |
DCC- >-----------|----'       `--|---.
                 `---------------'  _|_ 0V
Need an opposite polarity diode across the LED to avoid violating the Absolute Max Reverse voltage of 5 volts.
 

Pongo

Senior Member
What is the minimum voltage you want to
It won't work below 1.3V, or whatever the minimum Vforward is, and probably becomes unreliable before then.

But the problem is finding something which can work down to near 0V as well as up to 20V.

Maybe some sort of external op-amp-comparator which can handle high voltages but also cope with lower currents ?
What is the minimum voltage to be detected? Assume 20 volts is the maximum.
 

AllyCat

Senior Member
Hi,

Yes I was going to suggest an OptoIsolator (protected as Pongo suggests) as it gives reasonably "idiot proof" safety where multiple or unknown power supplies might be involved. But provided that all voltages are properly defined relative to each other (e.g. all earth rails linked) then in principle just three resistors are sufficient to make a satisfactory measurement - two as a potential divider (Input to Earth) and a "bias" resistor to a/the supply rail:

The PICaxe input pin could detect either an ADC value, a Digital Threshold (around 1.5 volts) or an internal comparator measurement (relative to the internal DAC). Typically you would choose the bias resistor such that when zero volts is applied to the divider input,, then the mixing point (PICaxe input pin at the junction of the three resistors) would be at the Digital or Comparator Threshold voltage, or half of the ADC reference voltage, etc.

Even more "minimalist" configurations are possible, for example using an internal Weak Pullup to bias the pin, or the PIC's DAC can be used directly in association with just one external resistor (to the DACout pin).

Cheers, Alan.
 
It has to be said, I'm not interested as such in detecting the amplitude or anything - the entire circuit won't work until at least 5V (allowing for the voltage overhead for my 3.3V regulator), so below 1.2V isn't too much of a problem!

And remember that at the 12-20V range, I'm going to he decoding digital signals which are encoded in the power signal...

I suppose I could add a series diode to the optocoupler branch, which would introduce even more voltage drop, but again only about 1.2V - for a total of 3V or so... As I'm not concerned about anything below 5V that shouldn't be a problem
 

westaust55

Moderator
Would this work for you.
DCC Detector.png

A commonly used circuit in DCC schemes (when opto-coupling is used) to detect the DCC signal.
The 1N4148 with a reverse voltage rating of 20 V protects the 6N136/6N137 opto-coupler LED from damage.
 
Would this work for you.
View attachment 23086

A commonly used circuit in DCC schemes (when opto-coupling is used) to detect the DCC signal.
The 1N4148 with a reverse voltage rating of 20 V protects the 6N136/6N137 opto-coupler LED from damage.
That would work perfectly - I'm guessing I could also use the above circuit with the LED driver, as D01 would protect it from the reverse voltage?
 

StefanST

New Member
... However, many people still use "traditional" DC control - a simple analogue 0-12V power signal, which is connected straight to the motor inside a model train - reversing the polarity reverses the train.
... However, on DC I want to be able to detect the polarity, so I can tell which direction the train is going, to activate the correct sets of head / tail lights. And, of course, this detection method is going to have to be able to handle the high frequency "AC" of DCC when in "normal" operation...
If you need to distinguish the polarity in a “traditional” DC control, try the modified westaust55 design scheme.

Screenshot_2019-08-04 Polarity Detection2.png
 
Top