Basic input protection for MCU - Page 1
Forum section: electronics / projects

author: blazini36
author_rank: Regular Contributor
timestamp: April 03, 2024, 08:17:20 pm
content: 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?

author: MasterT
author_rank: Frequent Contributor
timestamp: April 03, 2024, 10:01:49 pm
content: 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.

author: radiolistener
author_rank: Super Contributor
timestamp: April 04, 2024, 01:12:38 am
content: Note that not all STM32 GPIO are 5V tolerant, you're needs to check datasheet for exactly your chip...

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 04, 2024, 01:21:18 am
content: 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.

author: blazini36
author_rank: Regular Contributor
timestamp: April 04, 2024, 07:35:43 am
content: Quote from: radiolistener on April 04, 2024, 01:12:38 amI 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 FTQuote from: SiliconWizard on April 04, 2024, 01:21:18 amNo, 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

author: inse
author_rank: Super Contributor
timestamp: April 04, 2024, 09:33:23 am
content: 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.

author: Wolfram
author_rank: Frequent Contributor
timestamp: April 04, 2024, 11:14:36 am
content: 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.

author: blazini36
author_rank: Regular Contributor
timestamp: April 04, 2024, 03:16:36 pm
content: 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?

author: blazini36
author_rank: Regular Contributor
timestamp: April 04, 2024, 08:45:51 pm
content: Quote from: inse on April 04, 2024, 09:33:23 amYeah 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?