Electronic – 12V input on microcontroller pin

inputmicrocontrollerpinsvoltage

I'm trying to count pulses/sec. on a microcontroller pin in the ~5 to 100Hz range. The µC can operate at 5V input, so I have to get the voltage level down safely.

A simple resistor comes to mind, yet that leaves any surges open directly to the µC pin – meh.

I've come across this answer, but the question remains if that circuit is capable of "fast" 100Hz changes.

Is there a proven, reliable way (by means of an IC maybe?) of contacting 5V or 3.3V pins to "dirty" 12V inputs?
I have the 12V and 5V available to drive any "ready made" IC.

Best Answer

Use a circuit like this:

schematic

simulate this circuit – Schematic created using CircuitLab

R1 and R2 determine the voltage range, and perform the initial division. These resistors must be capable of some power. Typical is MELF 0.4W. All other can be chip resistors/capacitor.

R3 prevents any surges to cause harm to the schmitt trigger. R4 an R5 are optional to prevent any floating signals.
However, the combination R3/R4 can also be used to adjust the threshold, if necessary.

C1 and C2 determine the maximum speed. Combination R3/C2 can filter slow. C1 filters transients.

A separate schmitt trigger is used since you can get them really small and cheap. And it prevents routing a weak signal over long traces. Whilst also being a sacrificial part on major surges.

I've designed this circuit based on what I have seen inside PLC's. Above circuit is for 24V. Adjust resistors to match 12V according to IEC61131-2.

iec 61131-2
The concept of the standard is to ensure the input has to sink a minimum amount of current before considering it a '1'. The three types specify how much, and are applied based on environmental noise. This prevents glitches from touching it or nearby relays. The drawback is that R1/2 have to be of decent power rating and low resistance.