Author Topic: Different voltage inputs for switches - MCU protection  (Read 2617 times)

0 Members and 1 Guest are viewing this topic.

Offline MolsonBTopic starter

  • Newbie
  • Posts: 5
  • Country: ca
Different voltage inputs for switches - MCU protection
« on: January 13, 2019, 04:09:27 am »
Hi everyone, first post on here.

I have a MCU (Teensy 3.6 = MK66FX1M0VMD18) that will have a whole range of on/off switches and sensors attached. They can either be ground, 5v or 12v. I'm looking for a circuit that can handle all the different kinds of inputs and level them to either 0v to 3.3v.

The circuit attached uses the BAT54s double Schottky diodes to clamp to the rails. When then input is higher then 3.3v, the schottky forward voltage 0.2v brings the input signal to 3.5v (3.3v + 0.2v) which is getting close to the max 3.6v of the MCU. Could I reduce the 3.3v rail to the schottky diodes, to say 3v, to help not go over the MCU voltage?

I don't really like the amount of current shunted to the power bus, but I'm open to ideas.
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11260
  • Country: us
    • Personal site
Re: Different voltage inputs for switches - MCU protection
« Reply #1 on: January 13, 2019, 04:24:49 am »
A classical MOSFET level shifter like shown here https://playground.arduino.cc/Main/I2CBi-directionalLevelShifter should work.
Alex
 
The following users thanked this post: MolsonB

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Different voltage inputs for switches - MCU protection
« Reply #2 on: January 13, 2019, 05:52:40 am »
Hi MolsonB

Attached is a schematic for an MCU input translator/protector which puts no current into the 3V3 supply line:

With a high input or no input the circuit consumes 70.5uA and with a low input the circuit consumes 350uA.

If you can stand a logic inversion it can be done with one transistor.

You can also have a version without the input pull-up function if required.
« Last Edit: January 13, 2019, 06:17:53 am by spec »
 
The following users thanked this post: MolsonB

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Different voltage inputs for switches - MCU protection
« Reply #3 on: January 13, 2019, 07:16:51 am »
+ MolsonB

Attached below is schematic for a general translator/protector with an inverting logic function:
 
The following users thanked this post: MolsonB

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Different voltage inputs for switches - MCU protection
« Reply #4 on: January 13, 2019, 10:49:31 am »
If you've got *lots* of inputs, active buffers like the replies above have excessive component counts and need too much board area compared to a simple Schottky clamped series R limiter with shunt C filtering.   However dumping current into the supply rail is a *BAD* idea, as if you dump in more than the rail's load current the rail voltage will rise and probably destroy whatever ICs it feeds (unless the rail is shunt regulated).

The solution to that problem is to provide a seperate shunt regulated clamping rail.  You *could* just use a Zener + a pullup resistor, but they typically have fairly poor tolerance, and highish slope resistance so its very easy to find the clamping voltage is actually over Vcc.  A TL431 shunt regulator is a better option, but it still doesn't track the Vcc rail so again, the tolerances can stack up unfavourably.

Here's a reasonably simple Vcc rail relative clamping circuit for multiple inputs.  The top section is the circuit for one input, repeat N times.  R2 provides additional protection to the MCU during ESD events or other transients that overload the clamping rail, by limiting the current into the MCU's internal input protection.   If you use a series Schottky pair (e.g. BAT54S) for the diodes, that's only four parts per input.  Further component count & board area savings for multiple inputs are possible if you use resistor arrays for R1 and R2 and a multi-channel clamping diode matrix.  C1 and R1 should be  chosen on per application basis for the desired low pass corner frequency and to limit the input current that has to be clamped. 
N.B. for large R1*C1 time constants the MCU pin should either be analog capable, in analog mode or be a Schmidt trigger input, as the time spent between Vil and Vih thresholds during transitions may be excessive for an ordinary digital input. 

The clamping rail is regulated to a voltage slightly below Vcc by Q1 and Q2. Vbe_Q2*R5/R4 sets the voltage below Vcc, and should be adjusted to suit the clamping diodes used.  R6 (in combination with Vcc and the drop across Q2)  sets the maximum base current available to Q1, which multiplied by its min. HFE sets the maximum current the clamping rail can sink, subject to Q1's max Ic and dissipation.   C2 and C3 improve its performance clamping fast transients.  R3 keeps the clamping rail biassed to minimise interaction between inputs.  Ideally Q1 and Q2 should be closely thermally coupled so their Vbe tracks.

LTsice sim attached.
 
The following users thanked this post: MolsonB

Offline MolsonBTopic starter

  • Newbie
  • Posts: 5
  • Country: ca
Re: Different voltage inputs for switches - MCU protection
« Reply #5 on: January 14, 2019, 04:02:14 am »
Thank you guys.
Ian, that is what I was thinking to have a separate rail to dump the current and to lower the rail volts so the BAT54s stay under 3.3V when you include their forward voltage. Thank you again very much for your in depth explanation and how to design the clamping rail.

By "lots" of inputs, I have 20 so far. Maybe increase to a max of 25. I'll have some with a pull up resistor, and some with a jumper to bypass the pull-up, those will be my + active switches.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19523
  • Country: gb
  • 0999
Re: Different voltage inputs for switches - MCU protection
« Reply #6 on: January 14, 2019, 10:04:00 am »
How about the 74HC4050? It can be powered from 3.3V, yet still accept input voltages all the way up to 15V and has six channels.
https://www.nxp.com/docs/en/data-sheet/74HC4050.pdf
 

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Different voltage inputs for switches - MCU protection
« Reply #7 on: January 14, 2019, 11:01:09 am »
Intentionally taking the input of a MOS MCU above its supply rail is living dangerously and is unnecessary. A transistor collector with pull-up resistor is a much safer approach and has absolutely no tolerancing issues. Neither does it force current into the MCU supply rail or any auxiliary rail. Also, it provides better isolation between the input signal and the MCU input.

The auxiliary rail protector is non-modular. Every auxiliary rail protector has to have the additional auxiliary voltage rail. So, if you just want one auxiliary rail protector on a board, you would still incur the overhead of the additional rail circuitry. The auxiliary rail approach also has single point failure for all the inputs. Also, as has been stated, there are tolerancing issues.

In addition, the transistor approach has the potential for fast operation which the catching diode approach does not. The transistor approach also provides a nice clean 0V and 3V3 input to the MCU, rather than relying on the actual input signal, and is much less dependent on the source impedance of the input signal, especially the NMOSFET protector.

The NMOSFET protector, because of its high input impedance (470k), does not load the input device, to the same degree as the BJT protector (10k). The catching diode protectors have a very high input impedance which drops to 10k around 3V7, when the catching diodes start forcing current into the MCU 3V3 supply rail. Thus, there is an abrupt change in the input impedance.

As to the difference in complexity. That is undeniable, for the BJT protector, but there is little difference in component count between the NMOSFET protector and the auxiliary rail protector, especially when you take into account the auxiliary rail circuitry (be interesting to see an actual schematic) and wiring, not to mention decoupling capacitors. Also, the auxiliary rail protector schematic does not include an input pull-up function, which the OP shows on his schematic. But, in practical terms, none of the circuits will use that much PCB area because of the very small size of SM components. And, of course, you can get multiple transistors in a pack to save space, if really necessary.

My advice is not to mess about with input protection- do the job the best you can and use a MOSFET protector if you can tolerate an inverting logic function, or a two MOSFET protector if you need a non-inverting function.

But if you want a simple, low-component-count input protector, the resistor/Zener diode circuit shown in the attached schematic will do the job nicely.  It only has one tolerancing consideration: the Vz of the Zener diode, and that is well defined on the data sheet, and it does not force current into any supply rail or allow the MCU input to go above its supply rail.

http://www.comchiptech.com/admin/files/product/CZRQR52C2-HF%20THRU%20CZRQR52C39-HF-RevB.pdf
« Last Edit: January 14, 2019, 12:01:18 pm by spec »
 
The following users thanked this post: MolsonB

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19523
  • Country: gb
  • 0999
Re: Different voltage inputs for switches - MCU protection
« Reply #8 on: January 14, 2019, 11:50:14 am »
How about the CD40109B? It can work up to 18V.
http://www.ti.com/lit/ds/symlink/cd40109b-q1.pdf

I was also going to suggest the CD4504B, but it's not specified for 3.3V operation, although I think it probably work at that voltage, just very slowly.
https://www.ti.com/lit/ds/symlink/cd4504b.pdf

Talking of speed, I notice lots of the solutions proposed here are very slow, more so than even the ICs I've just mentioned, with a 3.3V supply. The speed of the ones with zener/Schottky diode clamps could be improved by bypassing the resistors with AC coupling capacitors with a value on the order of the input capacitance and a much lower value resistor (47R to 200R) to limit any surges.

Hi everyone, first post on here.

I have a MCU (Teensy 3.6 = MK66FX1M0VMD18) that will have a whole range of on/off switches and sensors attached. They can either be ground, 5v or 12v. I'm looking for a circuit that can handle all the different kinds of inputs and level them to either 0v to 3.3v.

The circuit attached uses the BAT54s double Schottky diodes to clamp to the rails. When then input is higher then 3.3v, the schottky forward voltage 0.2v brings the input signal to 3.5v (3.3v + 0.2v) which is getting close to the max 3.6v of the MCU. Could I reduce the 3.3v rail to the schottky diodes, to say 3v, to help not go over the MCU voltage?

I don't really like the amount of current shunted to the power bus, but I'm open to ideas.
You're right to be concerned about the current being injected into the power bus, but exceeding the maximum input voltage of the MCU input will not damage it, so long as the current is limited to a safe level. The MCU input will have both a maximum input current and voltage specification. The maximum voltage specification will be the maximum voltage which can be connected, before the internal diode will start to conduct and the maximum current is what the diode can handle. If the input voltage is 3.5V and the supply voltage is 3.3V, then no appreciable current will flow into the input pin. The solutions involving zener clamping or diverting the clamping current to a separate power rail, which can sink the current, will not cause any problems with the power supply rail rising or input current being exceeded.
 

Offline MolsonBTopic starter

  • Newbie
  • Posts: 5
  • Country: ca
Re: Different voltage inputs for switches - MCU protection
« Reply #9 on: January 15, 2019, 06:54:21 am »
How about the 74HC4050? It can be powered from 3.3V, yet still accept input voltages all the way up to 15V and has six channels.
https://www.nxp.com/docs/en/data-sheet/74HC4050.pdf

Okay I'm liking the 6 channel IC here. I'll still have to add on some external pull-ups, so any floating switches will be HIGH until switched on (LOW). For the switches that are on with power (HIGH), I'll add some jumpers/headers to deactivate the pull-ups.
 

Offline spec

  • Frequent Contributor
  • **
  • Posts: 833
  • Country: england
  • MALE
Re: Different voltage inputs for switches - MCU protection
« Reply #10 on: January 15, 2019, 07:23:29 am »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19523
  • Country: gb
  • 0999
Re: Different voltage inputs for switches - MCU protection
« Reply #11 on: January 15, 2019, 12:52:24 pm »
How about the 74HC4050? It can be powered from 3.3V, yet still accept input voltages all the way up to 15V and has six channels.
https://www.nxp.com/docs/en/data-sheet/74HC4050.pdf

Okay I'm liking the 6 channel IC here. I'll still have to add on some external pull-ups, so any floating switches will be HIGH until switched on (LOW). For the switches that are on with power (HIGH), I'll add some jumpers/headers to deactivate the pull-ups.
If the pull-up resistors are a high enough value, then this will be unnecessary. Another option is to add a transistor and a diode to control whether the pull-ups are enabled or not.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Different voltage inputs for switches - MCU protection
« Reply #12 on: January 15, 2019, 02:46:30 pm »

Okay I'm liking the 6 channel IC here. I'll still have to add on some external pull-ups, so any floating switches will be HIGH until switched on (LOW). For the switches that are on with power (HIGH), I'll add some jumpers/headers to deactivate the pull-ups.
If the pull-up resistors are a high enough value, then this will be unnecessary. Another option is to add a transistor and a diode to control whether the pull-ups are enabled or not.
Whether or not you can use high value pullup resistors is heavily dependent on your switches.  If they don't have precious metal or carbon or conductive elastomer contacts, they are likely to be unreliable in a dry switching application (i.e. without significant load current).  To fix that you need some wetting current and enough voltage to drive it to ensure any oxide film that has built up on the contacts breaks down when they close.  In the absence of specific recommendations from the switch manufacturer, a good rule of thumb for wetting voltage and current is min. 10V, min 10mA.   Of course that's not possible if your switches are working at 5V or lower logic levels, so select switches that are designed for dry contact switching (i.e. no wetting current), or do the best you can to provide an adequate wetting current and hope the low voltage doesn't bite you in the ass if a thicker than normal oxide film builds up during an extended period of disuse.

There's another trap for the unwary - switches designed for dual use, dry contact and power switching often have a very thin precious metal film flash plated on their contact faces. The first time you switch a significant load power with them, especially closing on a significantly capacitive load, or opening on an inductive load, that precious metal coating  gets disrupted by the arc, exposing the underlying contact metal, which can then oxidise so thereafter that switch will require a wetting current.

Obviously one doesn't want to waste 10mA through each switch if you have a lot of switches so its common to use a small capacitor across the switch contacts to momentarily provide the wetting current at the moment of closure, but that has its own problems, as unless you include a resistor to limit the max discharge current and provide damping, the capacitor will ring with the inductance of the switch wiring, generating high amplitude EMI that is likely to be problematic for any unshielded MCUs or CMOS logic in the vicinity.

A further note: if you are monitoring a high side switch, and its normal load is for any reason open circuit, you *will* require a pulldown resistor.  Therefore if you are contemplating jumpers to connect/disconnect pullup/pulldown resistors, connect one end of the resistor permanently to the input and have three pins in a row for the jumper, centre to the other end of the resistor, and the others to ground and a suitable supply rail (protected by a small polyfuse feeding all the pullup/pulldown selection jumpers as defence against gross user idiocy), so you can set pullup, pulldon or none with a simple 2 pin jumper cap.  If your anticipated users are particularly dumb, you may decide to use four pins, with the extra pin past the ground pin for jumper parking.

I'm also concerned about the low logic '0' threshold for the direct to logic (whether that's clamped or via a HV tolerant buffer) solutions.  When working with 12V signals, that doesn't leave much noise margin so depending on the EMI environment, there may be a considerable risk of a false '1' level  being detected.   To avoid this it may be preferable to use a potential divider to scale down the input voltage, which also scales up the input thresholds seen in front of it by the same ratio.
 

Offline MolsonBTopic starter

  • Newbie
  • Posts: 5
  • Country: ca
Re: Different voltage inputs for switches - MCU protection
« Reply #13 on: January 15, 2019, 02:59:39 pm »
Yeah we are just talking about simple rocker & toggle switches, and some power (HIGH) inputs from relays to tell when they are active.  Some relays will be 5v and some will be 12v. There's a bit more to it then that, but that's the simple version. It's just a cheap Ardiuno board that monitors a bunch of inputs and broadcasts to the wireless network, so nothing to crazy going on.

Correct Ian, I should of expanded my though. When I'd design the jumper pins, I would do three pin so you can pick either a pull up or pull down resistor for the ones where they will be HIGH inputs.

I'll still need room for the resistor and cap for debouncing to the IC chip, but it saves a lot of space over the BAT54s footprint. My brain feels fried on other project and I'm not thinking straight anymore about this one. lol So how about this question on which pull-up voltage to use. For my power inputs (relays) that are 5v, and others that are 12v. Should their corresponding inputs have different pull-up volts? Or can I lump everything under the same pull up rail ? 3.3v, 5v, or 12v

Thank you again guys for all your input, it has helped a lot.
« Last Edit: January 15, 2019, 04:27:44 pm by MolsonB »
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Different voltage inputs for switches - MCU protection
« Reply #14 on: January 15, 2019, 05:06:49 pm »
I've put together a quick LTspice sim of the 74HC4050 input clamping (very rough model), an input protection network (not yet optimised) and pullup, and a active low switch with capacitive wetting, and a generator for various voltage ESD tests using the HBM (100pF capacitor discharged through 1500 ohms).   When the ESD test voltage is set to 0 it activates the switch at the input for the wetting current test.

Its got two .tran commands so you can select the timescale when you first run it.  Non-selected sim commands get auto-commented out on run so you either have to edit ; to . to reactivate them or click Undo immediately the run finishes, which restores them and doesn't affect the run results.

Key parameters to check are peak wetting current through SW1, and input current through R2 for ESD events. A PCB spark gap right at the switch connector could make a big difference for the latter.

I haven't considered debouncing at this time.  IMHO its a bit dodgy to use a 74HC4050 for hardware debouncing with a RC network as (looking at its datasheet), it doesn't have Schmitt trigger inputs.  Unfortunately Schmitt input buffers with HV tolerant inputs that will output 3.3V logic levels seem to be unobtanium - if anyone knows of any with comparable max. Vin please post it!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf