# Microcontroller input conditioning

I have the following circuit to condition signals reaching my microcontroller's pins.

This circuit reads both digital signals in the range 0 to 30V, and analog signals in the range 0 to 3.3V.

Components Explanation

• R2 and R3 are never populated both at the same time. They are pull-up/down resistors for digital signals.

• R1 serves dual role. On the one hand it is part of the RC filter along with C1, and on the other hand it is a current limiter for the D1.

• D1 just makes sure that voltage (in signals greater than 3.3V) will be clamped, protecting the uC.

However the D1 zener diode creates a problem. If I choose a 3V6 zener, then higher voltage than desired will reach the uC. If I choose a 3V3 zener, then weak analog signals tend to be clipper earlier (i.e. the zener starts conducting a small current earlier than its rated voltage). To make matters worse even if I could somehow ensure that the voltage will be clamped at exactly 3V3, and for any reason Vcc, is even a bit lower than 3V3, then the ADC will report wrong result.

What I need here is a circuit that will clamp voltage exactly at Vcc, with a sharp transition so as it will not affect the ADC range.

Any ideas?

• Have you considered using a high-voltage op-amp such as the LT6015? It can handle twice the voltage you are expecting, and if you power it from 3.3V it will just clamp at the output rail - this means digital 0-30V will come through as just 0-3.3V, and analog will pass through with a gain of 1 if you so desire, or you could even put gain on it on purpose. with a GBWP of 3+ Mhz, it should meet all your speed requirements for sure. If you want I can make this an answer Sep 27, 2016 at 3:08

Low voltage zeners have very soft knees and are unsuitable for this purpose. Also you will never be able to make a circuit clamp exactly at a given voltage - you need to define a minimum voltage at which the clamp begins to affect the input (to a specified degree such as .2%), and a maximum voltage that will occur after clamping (at some maximum input voltage). The closer the numbers are together (and the higher the maximum input voltage) the more difficult it becomes. If your ADC reference is significantly less than the supply voltage (as it typically is in a precision system) there can be a reasonable margin.

There also should be consideration as to where the current will flow when clamping (all inputs simultaneously if that is a possibility). The obvious method of clamping to the positive rail can cause problems by causing the rail to go out of regulation, and possibly damaging parts as a result.

For example 4 inputs with 30V in will require clamping more than 100mA, which is more than likely to cause serious issues.

I suggest considering biasing a shunt regulator (eg. TL431) to about 3.2 or 3.3V (eg from a 5V source >=1mA bias so 1.6K) and using Schottky diodes to clamp to the regulator voltage and 0V. You may still have problems with it affecting the input near full scale or keeping the input voltage to less than (say) 3.6V-- the Vf of a Schottky diode does change with current.

Edit:

Example:

You can share the clamp supply with more than one input, subject to the maximum current the TL431 can handle (100mA or less depending on thermal considerations).

simulate this circuit – Schematic created using CircuitLab

If you want to change C1, be sure to refer to the datasheet and avoid the 'tunnel of death' instability region under all conditions.

• Aha... I was just looking up for the TL431. Would you mind an example schematic using this component? Sep 25, 2016 at 21:32
• could one not use a crow-bar on the supply rail to prevent dangerous over-voltage from input current sources? Sep 25, 2016 at 22:56
• @KyranF Good question. Sure you could put a crowbar (or a clamp) on the power supply.. of course that has to be designed so that it won't go off at too high or too low a voltage so everything on the 3.3V bus is protected. On the plus side there is already a lot of bypass capacitance so it won't go anywhere too quickly. Sep 25, 2016 at 23:00

An alternative and more reliable ( and faster, I believe ) way of protection from over-voltage is to use a schottky diode on the front end, after the current limiting resistor (R1 in my example below).

This arrangement will protect against the 30V input maximum you suggest:

simulate this circuit – Schematic created using CircuitLab

This circuit has a front-end limiter by R1, which when input voltage is a maximum of 30V, the current is limited through D1 which is clamping to 3.3V (VCC) to ~10ma. D1 and D2 are Schottky Diodes, with low forward drops to help clamp as close to VCC as possible while also protecting the microcontroller's input CMOS diode clamps.

The capacitor C1 is there for your RC filter you wanted. Doesn't need to be loaded, or could be replaced in the same footprint with a pull-down resistor. could always add discrete pull up/down resistors near C1.

Most microcontrollers have an option for input pin modes with internal pull-up so you can save a component if you have this option.

If you had the option of NOT interfacing with 30V directly, I would be inclined to advise you do that rather than trying to connect directly to the MCU pin, even through this protection circuit. See this question and answer/s for high voltage to 3.3V interface: How is this circuit for interfacing 20V signal with 3v3 microcontroller

You may need to find a cunning way to pass through the analog signal though, maybe an analog buffer with an "enable" pin, and a similar protection circuit as this on its input.

• R1 was first, except for the pullup and pulldown pads which you've removed (internally programmable pullup/pulldown is a legitimate option, if the values available are reasonable -- but I can't see that having the pads for external resistors creates any issue). Sep 25, 2016 at 18:44
• R1 was NOT first, if you think about the sequence of events for an RC filter and for limiting current through the zener diode. The zener would have exploded very quickly if you put 30V on that input pin. Sep 25, 2016 at 18:49
• I think you're misreading the schematic in the question, the 30V signal is being applied at connector P1 (connecting to external signals is what connectors are for, also it's the only reading consistent with the explanation in the question prose), the net labelled "INPUT" is the microcontroller pin. Yes, it's right-to-left which is confusing but not uncommon for pins found on the right side of a MCU symbol. Sep 25, 2016 at 18:51
• @BenVoigt ah yes, i see now. thank you for pointing that out. Sep 25, 2016 at 18:54
• This also has the added benefit of protecting the input when the power supply is turned off. Though I suppose there could possibly be issues with accidentally powering up the circuit through the clamp diode. Sep 25, 2016 at 21:42

You've already got different component values for analog vs digital (no pull-up or pull-down resistors in analog configuration) so you aren't looking for software switching between the two modes.

Therefore it seems reasonable to have two different Zener choices?

In digital mode, the Zener forms part of a voltage divider, so you should select it to get the resulting voltage into the normal operating range, which is $V_{IH}$ up to $V_{CC}$. A 3.3V or 3V Zener should work admirably, possibly even as low as 2.5V (check your microcontroller datasheet for the value of GPIO $V_{IH}$).

In analog mode, you are going for overload protection, and no effect when the input is in range. So the resulting voltage needs to be within the absolute maximum ratings, not the operating range. Check your datasheet, but 3.6V is almost certainly acceptable (you're protecting excessive currents from flowing in parasitic diodes within the semiconductor, which turn on one diode-drop above $V_{CC}$).

To protect the input pins against signals applied when the power is off (or just residual power trapped in C1 when power is removed), you really should also to parallel that Zener with a low-forward-voltage diode (you can find 0.2V - 0.3V) connected to the $V_{CC}$ rail.

• There are cases of analog signals that the pull-up will be retained (i.e. while reading a thermistor). So this does not answer the question. Sep 25, 2016 at 18:52
• @user3634713: For a thermistor, you configure the Zener as for analog applications, i.e. the 3.6V component. Sep 25, 2016 at 18:54
• Maybe it was not that clear in my question, but in my specific use case, clamping greater voltages may be usual, and above Vcc the ADC malfunctions. So neither in analog cases such a large zener voltage is desirable. Essentially I need a circuit that will replace the zener, with more steep clamping characteristics. Sep 25, 2016 at 21:35

It don't think this is the best solution --overhead and more costly--, but if you can implement the logic below with 2 opAmps and a driver, you're done.

if(Vin > 3.3) {

if(Vin > 3.3) {
Vout = Vcc;
} else {
Vout = -Vcc;
//never reaches here.
}

} else {

Vout = Vin;
//Driver needed here
}

• An interesting way to look at it. This could be realized with a simple high-voltage tolerance op-amp buffer - such as the LT6015 or dual version LT6016. Sep 27, 2016 at 3:00