Author Topic: Basic input protection for MCU  (Read 6373 times)

0 Members and 1 Guest are viewing this topic.

Offline blazini36Topic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: us
Basic input protection for MCU
« on: April 03, 2024, 08:17:20 pm »
Working on something with an STM32. The STM32 can technically handle 5v inputs on most GPIO pins. I'm using 5v for consistency across other devices. This is for a slightly harsh environment but nothing too crazy. I don't see much purpose in using optocouplers as I'm not isolating anything. I'm using these basic circuits on all digital and analog inputs. The analog inputs are just for reading potentiometers. Thoughts?

2095877-0
2095883-1

 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 808
  • Country: ca
Re: Basic input protection for MCU
« Reply #1 on: April 03, 2024, 10:01:49 pm »
Resistors are loading potentiometers, creating substantional non-linearity. Depends on value of the pot's, characteristics Volts vs Angle will more resemble logarithmic.
 Make sense to lower voltage by resistor in power line connected to upper leg of the pot, than down-regulate /divide output.
Capacitors on analog inputs are must - not an option, when dealing with ST adc.
 
 

Online radiolistener

  • Super Contributor
  • ***
  • Posts: 3627
  • Country: ua
Re: Basic input protection for MCU
« Reply #2 on: April 04, 2024, 01:12:38 am »
Note that not all STM32 GPIO are 5V tolerant, you're needs to check datasheet for exactly your chip...
 

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14987
  • Country: fr
Re: Basic input protection for MCU
« Reply #3 on: April 04, 2024, 01:21:18 am »
So basically you use a 5V rail just to bias the pots when everything else is 3.3V? That's not very convenient and I'm not sure I'd get the idea if this is so. You said consistency, but what consistency exactly, please elaborate. Because if it's about wiper voltage vs position and you have to attenuate anyway, that's pretty moot. Anyway, as said above, you can't do it this way, it's going to load the pots leading to a completely different law. Just bias the pots with 3.3V, unless we have missed something major with your system.
 

Offline blazini36Topic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: us
Re: Basic input protection for MCU
« Reply #4 on: April 04, 2024, 07:35:43 am »
Note that not all STM32 GPIO are 5V tolerant, you're needs to check datasheet for exactly your chip...
I know, they're pins with the "FT" IO level. I said "most" as I was acknowledging this but for all intents and purposes that doesn't matter as everything in question is an FT

So basically you use a 5V rail just to bias the pots when everything else is 3.3V? That's not very convenient and I'm not sure I'd get the idea if this is so. You said consistency, but what consistency exactly, please elaborate. Because if it's about wiper voltage vs position and you have to attenuate anyway, that's pretty moot. Anyway, as said above, you can't do it this way, it's going to load the pots leading to a completely different law. Just bias the pots with 3.3V, unless we have missed something major with your system.
No, everything else is 5v (external of the PCB), not 3.3v. Consistency meaning as part of a system everything in the system is 5v. It's easier to use 3.3v to feed the pots but the pots are not mounted to the PCB, they're mounted to a panel where the rest of the IO is 5v. While it's most likely to be reading pots, the analog channels may be reading some other analog thing and 5v is the "field voltage" or the supply to that analog thing.

To be honest I hate analog anything, I'm not super familiar with analog circuits. The analog input connectors are there just to be there, I usually use encoders. Since they're taking up PCB space they should work reasonably well. Never used an op amp so I was trying to avoid them but I suppose an op amp setup for unity gain avoids the "loading" issue? Most examples I see of using op amps to scale the input voltage use a resistor divider on the non-inverting input, so I assume that's going to have the same issue as just using a resistor divider by itself. I don't see too many examples of a resistor divider on the output of the op amp so thoughts?

I stuck the cap on the  analog input here, I can't find any guidance on that so I took a guess
2096735-0
 

Offline inse

  • Frequent Contributor
  • **
  • Posts: 674
  • Country: de
Re: Basic input protection for MCU
« Reply #5 on: April 04, 2024, 09:33:23 am »
I would suggest a simple approach: skip the buffer and simply have a voltage divider from 5V to 3.3V with a total resistance 10x the potentiometer.
This will not influence the linearity of the pot and the 10nF will provide sufficient low impedance for the S/H stage.
« Last Edit: April 04, 2024, 09:35:07 am by inse »
 

Offline Wolfram

  • Frequent Contributor
  • **
  • Posts: 392
  • Country: no
Re: Basic input protection for MCU
« Reply #6 on: April 04, 2024, 11:14:36 am »
What do you want to protect against? I like to aim for at least some basic ESD protection, and guarding against accidental connection to the highest voltage available in the system (on the LV side that is, not mains, generally). The easiest way to do this is with series resistance, and more is better. For slow signals like potentiometer inputs, 10k in series then 100 nF to GND is a good starting point.
 

Offline blazini36Topic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: us
Re: Basic input protection for MCU
« Reply #7 on: April 04, 2024, 03:16:36 pm »
Is there any problem with using the op amp with a resistor divider on the output? Op-amps are cheap, $0.60 for a dual op amp @ qty1 so if there's no issue with the circuit I just posted...why not?
 

Offline blazini36Topic starter

  • Regular Contributor
  • *
  • Posts: 69
  • Country: us
Re: Basic input protection for MCU
« Reply #8 on: April 04, 2024, 08:45:51 pm »
I would suggest a simple approach: skip the buffer and simply have a voltage divider from 5V to 3.3V with a total resistance 10x the potentiometer.
This will not influence the linearity of the pot and the 10nF will provide sufficient low impedance for the S/H stage.

Yeah I think you're right. I found some LM358s in my stash and started messing with what I said above. I realized that the max output of most op amps is some some voltage below it's VCC, in this case it's about 1.5v. So it effectively clips the upper range of a pot supplied with 5v on the output of the op-amp so the ouput divider is clipped as well which defeats the purpose. I'd have to supply the Op Amp with about 6.5v to get upto 5v on the output to divide and it seems like more trouble than it's worth.

So in that case, at the moment I'm just thinking of using the same circuit in the first post but with 2 100k resistors for the divider and a 0.01uf cap on before the analog input of the MCU for something like a 10k pot. What are the implications if say a 1k pot is used?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf