Lowest parasitic loss for MCU to confirm a switched state.   - Page 1
Forum section: electronics / projects

author: viper
author_rank: Regular Contributor
timestamp: October 12, 2025, 09:41:35 pm
content: I will trying to explain. Have a pair of dry contacts in a relay that will be used only to confirm the switched state of another matching pair in parallel. All I need is for the MCU to know whether that pair of contacts are open or closed. The contacts would live most of their life in the closed position BUT when the device is not plugged in, that creates an open contact state, in which whether pull, down, sideways, something will continue to consume.I'd like to use a single GPIO, but I can budget two if really needed. I was sort of thinking 100K pull up from the 3.3V common rail, through the contacts, return to GPIO. Next to no power lost while circuit is closed. But when opened, the GPIO is now floating. And if I activate the internal 45K PD in the MCU, the PU and PD would just feed each other constantly.What am I missing?

author: brucehoult
author_rank: Super Contributor
timestamp: October 12, 2025, 09:56:58 pm
content: Quote from: viper on October 12, 2025, 09:41:35 pmWhy would the GPIO be floating? Avoiding that is the entire point of having a PU/PD.A PU means that there is a connection between 3.3V and GND through the PU resistor and the contacts. The GPIO is connected between the resistor and the contacts. When the contacts are closed the GPIO is at 0V, when the contacts are open the GPIO is "pulled up" to 3.3V by the resistor.I don't know what arrangement you are thinking of, but if it's not as above then you have at most a current-limiting resistor not a PU, and that is unnecessary anyway as GPIOs are very high resistance and can safely be connected directly to either GND or 3.3V.Why would you have internal PD and external PU fighting? If you have external PU then simply don't enable the internal PD. Or, enable the internal PD and connect the GPIO to 3.3V via the contacts. The sensing polarity will be reversed -- no problem for software to deal with -- and the wasted current will be (based on 100k vs 45k) twice as much which might or might not matter.

author: viper
author_rank: Regular Contributor
timestamp: October 12, 2025, 10:16:03 pm
content: The switch will be several feet from the MCU on a cable. It would be practical to current limit any sort of V, which is one reason for an R coming off the 3.3V rail.I guess where I am stuck is say I go with a 1M series resistor off the 3.3V rail, then through the switch contacts, then return to a GPIO to get an I. If I open that switch, the GPIO is now 'floating', correct? I would need some sort of pull down on that side of the circuit to ensure it drops below threshold? Or am I overthinking that part?But really, if I go with 1M resistors, the series loss is nearing 1uA. I guess I wanted to confirm if I really need that extra pull down. If that still doesn't make sense, I can trying to better explain or just make a quick diagram.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: October 12, 2025, 10:35:04 pm
content: Quote from: viper on October 12, 2025, 10:16:03 pmThat may be more of an issue. How fast does this need to react ?Quote from: viper on October 12, 2025, 10:16:03 pmI'm not seeing any problem. The contacts switch to GND, and the 1uA pulls up ? You have easily sensed states, limited by the port leakage specs ?You may want a shunt element of a series RC to avoid noise pickup and to give the contacts some operating current.There are also pin keeper style circuits that need a higher current to snap, then they hold at a lower current.

author: brucehoult
author_rank: Super Contributor
timestamp: October 12, 2025, 11:01:23 pm
content: Quote from: viper on October 12, 2025, 10:16:03 pmNOOOOOOOOO!!!!Re-read my message. The existence of a several feet or metres long cable from the electronic to the switch changes nothing.That is the wrong topology. You sense the voltage BETWEEN the resistor and the switch, NOT after both.1M might be ok, depending on the MCU's input impedance, but you'd have to check the data sheet. Many common MCUs have around 1M input impedance or around 1-3 µA leakage current, so you might not get much voltage swing. And the switching time can be slow with such a low current because of the maybe 5pF capacitance on the GPIO pin itself, plus of course your several feet long cable. The built in PU/PD is typically around 50k for a reason. 100k or 200k is probably fine, but I'd want to really carefully check before trying 1M.

author: viper
author_rank: Regular Contributor
timestamp: October 12, 2025, 11:55:32 pm
content: Great feed back guys! I agree regarding the pullup resistor sizing. Right now I am designing at 1M, which would be about 3uA, but won't hurt my feelings if I have to lower that a touch if reliability becomes a concern. This is all being done up for a proto board so that will be checked and tuned if needed.What I ended up doing is probably same as you both are recommending. 3.3V > R1M > loop back towards GPIO > R100k (series) > to GPIO. Then pull a leg right after that R1M and that is my two wires going to the switch contacts, then back to board ground. So if contacts are open or cable is unplugged, status stays high, and next to no power used. If switch is closed, this pulls circuit firmly to ground, max power is from the R1M.The series 100K by the GPIO pin, and a 100nF cap from pin to ground for filtering. I don't yet know if there will be problems but probably best to play like there will be.Oh, regarding switching state speed, VERY lazy! Probably fine with 500mS. I probably would ignore looking for the bit change for around that long, but not toss any alarms until after several seconds. I mention this because if you guys were thinking about more capacitance, I am all ears. The cable will be about 4ft long, not sure if we will have to with twisted, but it will be around higher voltage AC wires. Trying to avoid shielding and such.

author: langwadt
author_rank: Super Contributor
timestamp: October 13, 2025, 12:06:09 am
content: periodically switch the gpio to output and charge a cap across the switch through a resistor, then switch the gpio to input, if the cap is shorted input will stay low, else it will stay highextra points for the cap helping wet the contacts

author: PCB.Wiz
author_rank: Super Contributor
timestamp: October 13, 2025, 02:23:22 am
content: Quote from: viper on October 12, 2025, 11:55:32 pmVery light pullups, will be noise prone in the open circuit case. A filter cap can help, but you do not want a cap straight across the contacts.100R~1k in series with a cap limits the current spike, but still lowers the impedance from 1M.A pin-keeper can be made from a Dual BSS84 + 3 R, or a 74LVC1G18 + 1 R, and that gives an active pullup, (can be as low as 100R~1k) until the switch over-drives.That give much lower impedance when HI, so helps avoid shielding without costing too much in response time.Pinkeepers also give a good current impulse during contact close.How often do the contacts change?You may need to ponder your very low current for very long times on static/corroding contacts.A pulse current polling scheme as mentioned above may give low average current, but avoid dry contact effects.

author: viper
author_rank: Regular Contributor
timestamp: October 13, 2025, 02:42:21 am
content: Very good points about the very light current vs mechanical contacts. Probably a sure bet reliability issues could pop up. The switch is primarily used only as a safety device so it should not active very much at all. We might say 100 cycles/year. I can totally see where a tiny 3uA can get lost!I like the ideas of a "pin keeper", though have to admit that is another subject to evaluate. Sounds like charging a cap and doing a controlled fast discharge to 'wet' the contacts?As much as I don't want to, it's probably smarter to evaluate a little complex setup here. Because the state change does not really need to be read quickly, I might be able to just use higher power and do a sort of PWM arrangement? If I can catch the change of state without 1-2 seconds, all is good. I was thinking about simple pulses from the MCU. If they go low, that means they found a path to ground (closed switch). If state is high, open switch or missing. Something along those lines I guess?Have not run numbers but maybe move that into the mA range? Maybe even at that, mechanical contacts suck?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: October 13, 2025, 02:57:27 am
content: Quote from: viper on October 13, 2025, 02:42:21 amWith MCU bidirectional pins and some implicit load C, you can simply pulse a pin high driving 100R~10k for say 10~100us, and then tristate and read back the pin.If it reads low, the remote switch is on. If you pulse 100us every 100ms, 1mA currents average 1uA (ignoring MCU overheads, you may have other wakeups this can piggyback on)Quote from: viper on October 13, 2025, 02:42:21 amIn another thread, I referenced contact rated current numbers of name brand TACTILE buttons of 10uA~50mA and also common is 0.1mA~50mA

author: PCB.Wiz
author_rank: Super Contributor
timestamp: October 13, 2025, 03:38:37 am
content: Quote from: viper on October 13, 2025, 02:42:21 amNot quite, there is no cap.A pinkeeper for a contact sense, is a positive feedback output enable.Consider a tristate CMOS gate with +ve output enable, that acts like a PFET to Vcc when OE hi, and floats when OE low.For 0 to Vth the circuit sees your light pullup, above Vth the OE is ON and the PFET + (say) 1k resistor pulls up, so it snaps high, and holds high with a low 1k impedance.As you pull the pin low, the current increases until Vth, when the PFET suddenly lets go, and the pinkeep floats.Some quick reality check numbers (for 240V 50Hz) parasitic cable cap-to-mains:10pF into 3M3 injects 3.42Vp = very sensitive, think fingers on a scope probe.10pF and 33nF//3M3 drops to 200mV, 100pF ~2V better but still needs care.100pF and 1k is ~10mV, the low impedance keeper is getting more immune.

author: brucehoult
author_rank: Super Contributor
timestamp: October 13, 2025, 06:41:04 am
content: Quote from: PCB.Wiz on October 13, 2025, 02:57:27 amI note that 4-20 mA current loop has been an industrial / automation standard since the 1950s. I remember the VT100 terminals scattered around my university in the early 80s used 20mA current loop rather than RS-232 as current loop worked reliably at 9600 bps with cable runs of several hundred meters.

author: viper
author_rank: Regular Contributor
timestamp: October 13, 2025, 07:31:41 pm
content: You guys are friggin on top of it! Here is where I am, though I will admit I have never switched pin modes like this so I don't know how fast the MCU can do it, but this is an easy one.I'm looking at GPIO > R1k > switch contacts > GNDvvC50-100nFvGNDLooking at a single 5ms pulse 1x/sec. Immediately flip gpio to highZ, should still be high for a determined period. If low when going to high Z, either switch is open or unplugged. The bigger cap will slow this down, but also assist with filtering. ? On the right track here? I realize this might need tuning but can probably dial in on the software side unless signal is that dirty.As far as power use, the pulses are 3mA but the average energy used over time is next to nothing. I just need to make sure an ESP32 can actually send these pulses in sleep mode.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: October 13, 2025, 11:49:51 pm
content: Quote from: viper on October 13, 2025, 07:31:41 pmIf you can find a timer that runs in sleep, and are ok using 2 pins, you can set a low duty PWM to pulse poll the pin, and when the pin allows a change in voltage, it interrupts the MCU.

author: viper
author_rank: Regular Contributor
timestamp: October 17, 2025 04:07:37 am
content: Quote from: PCB.Wiz on October 13, 2025, 11:49:51 pmI do believe there are no PWM/poll issues with the ESP32 in light sleep. As for any deeper sleep modes, I am not concerned at all about that switch. Ignore it, it just becomes an energy conservation deal. The whole circuit will go quiet until there is a charger present again.