Electronic – 12 V input on 3.3 V GPIO, TVS pulled down or Schottky pull up

diode-clampgpioinput

I am building my own PLC that has to accept permanent inputs of up to 30 V DC into a STM32F with 3.3 V inputs.

The switched input will have to work with 8-30 V, but 90% of the time the input voltage will be fixed at 12 V or 24 V. Inputs will only ever be switches such as limit switches, so I am not bothered about detecting inputs less than 8 V or inputs from sensors, etc., I'm also not worried about speed as realistically the fastest the switches will move is every 1 s; I just need to be sure that my microcontroller is protected.

I want a universal circuit I can use in multiple products/projects of similar types so component count, cost and PCB space has to be at a minimum so I don't really want to use optocouplers.

Two electronic engineers have recommended the following, but I'm not too sure what way is best:

Enter image description here

Should I use the top one or the bottom one? Any why?

Best Answer

This is actually an age old problem with PLCs and not nearly as simple as your intended solutions.

The biggest issue you have is that as well has having a wide variety of potential logic voltages you need to be able to handle, the actual logic levels can be far higher than the 3.3V rail you are using internally. Some sensors and devices have logic thresholds up above 5V. As such simply using a cut-off circuit as you have indicated will not detect the low level from such sensors.

The input stage of PLCs needs to be much more flexible.

Even if the low level logic level is acceptable these circuits each suffer from different issues.

Zener / TVS Limiting.

enter image description here

This circuit has the benefit that, for a known input voltage, the zener can be sized to never allow the voltage to exceed the rail voltage. Normally you would chose a zener with a smaller reverse voltage than the rail, but higher than the high level logic threshold.

However, the zener will spend a lot of it's life reverse biased, as such you pay a penalty in the form of reverse recovery time when the input signal drops which will delay your signal a smidge.

The other issue with the Zener, is the actual voltage it will limit at is dependent on the current through it. As such that voltage will depend on the signal voltage to some extent. You therefore need to design the resistor for the maximum input voltage, and recalculate for lower voltages to see if the zener is not limiting the voltage below your \$V_{IH}\$ level.

Over-Rail Limiting Diode

enter image description here

Using the diode up to the rail has the issue that the output voltage will still exceed Vcc all be it only by a little. However, that can still be detrimental to the input. Further, in this case the reverse recovery time means, for fast input edges, a high voltage will make it through very briefly.

So

Since both of these circuits include a high resistor at the input, both of them require whatever is driving the input to have a low output impedance. Of the two, the zener version provides better protection but at the cost of performance. Neither of them will work if \$V_{OL}\$ of the attached sensor > 1.5V or so.

Alternatives


Opto-Coupling.

A common method used by PLCs is to use opto-couplers.

schematic

simulate this circuit – Schematic created using CircuitLab

This method gives you the added benefit of isolation and ground separation. The issue with it is you need some form of signal conditioning between the sensor and the input to ensure the LED is lit at the right threshold, and that the correct amount of current is fed through the LED. That conditioning could be the simple resistor shown above, or a complex circuit which includes a comparator of some sort.

The speed of the opto-coupler is also a limiting factor. However, this method is commonly used because it gives you complete flexibility.

Analog Input Conditioning

Another method is to accept the signal in an analog form, compare it to a variable reference with hysteresis, and generate the logic level that way.

schematic

simulate this circuit

Obviously the components, including the comparator, need to be chosen to accommodate the maximum input voltages. The circuit shown is fairly simple, it can get much more complex with filters, regulators, ESD protection etc.

Combination

For isolation reasons, you could combine the above, and have the comparator power a constant current driver to the LED of an opto-coupler.

If I were developing a product, I would assemble all that on a small plug-in module that could be plugged into card edge sockets on a "mother" board, like they use for cards in PCs. That way you can easily replace them should one get fried. That method also lets you make other input types available, for example, a fibre-optic input.