Go Down

Topic: Ballpark estimate: Weakest save pull-up? (Read 499 times) previous topic - next topic

ElCaron

Hi, for a window sensor, I need a pull-up for a reed switch, to detect if the window is opened or closed. I have already gotten SPDT reed switches, so I can set window-closed state to open. Still windows might be open for a longer period of time, so pull-up current matters.
What is the highest "safe value" where my pin isn't effectively floating? Ballpark, of course, safe value without looking into the RF characteristics of the involved traces.

Coding Badly


If you are that concerned with power, disconnect the pullup from power.

If you, power the pullup, wait one microsecond for the pin synchronizer*, test the pin, disconnect the pullup, once every one millisecond you will reduce the power consumption by ... answer left as an exercise for the reader.

Certainly, no human could traverse a window in less than 2 milliseconds.

Of course, to be most effective, after disconnecting the pullup the pin should be switched to a low output so it does not float or the pin should be disabled.


* The precise amount of time to wait is two processor clock cycles.

ElCaron

#2
May 19, 2017, 09:51 am Last Edit: May 19, 2017, 09:53 am by ElCaron
Well, then I am concerned about the power of my MCU :) The switch is supposed to work as a pin change interrupt to wake it up from sleep.
The whole thing is supposed to run on a coin cell, I hope for battery lifetimes in the order of magnitude of at least a year.

saximus

Could this be one of those few situations where a pull-down would actually work better for your requirement?

ElCaron

#4
May 19, 2017, 10:10 am Last Edit: May 19, 2017, 10:14 am by ElCaron
Could this be one of those few situations where a pull-down would actually work better for your requirement?
I don't really see what this would change. With a pull-up, the switch connects to ground, with a pull-down the switch connects to VCC. Same current should flow.

Also, I am trying a secondary use of an already existing PCB I made for an I2C based temp/hum sensor. The SDA pin is in one corner of the PCB, I just placed a GND hole on the other corner to connect the reed switch to. So I only have GND on the other end :)
Well, if there is an advantage in pulling down, then of course I could cut traces and install wires ...
But on the other hand: I use 330kOhm + 100kOhm for a voltage divider in another project to read the voltage of a LiPo (much larger, so I am fine with the current). The voltage reads very accurately, and with that I mean stable to a few mV (+- 1 in the 10bit ADC of the ESP8266, but that could also be the ESP). So should a few MOhm still be save for a digital signal?
On the other hand, I seem to approach the boundaries, there, else an Arduino pin with 100MOhm input resistance couldn't float, could it?

Coding Badly

Well, then I am concerned about the power of my MCU :) The switch is supposed to work as a pin change interrupt to wake it up from sleep.
Of course, to be most effective, after disconnecting the pullup the pin should be switched to a low output so it does not float or the pin should be disabled.

saximus

#6
May 19, 2017, 10:14 am Last Edit: May 19, 2017, 10:22 am by saximus
I don't really see what this would change. With a pull-up, the switch connects to ground, with a pull-down the switch connects to VCC. Same current should flow.
A quick look at the circuit should show you the fundamental difference. You only have current when the switch is closed in a pull-down arrangement.

Edit: I just realised you could be in either open or closed for an extended period of time so power "wastage" is a factor in either case. Apologies for not reading correctly.

ElCaron

Quote
Edit: I just realised you could be in either open or closed for an extended period of time so power "wastage" is a factor in either case. Apologies for not reading correctly.
I don't really think a pull-up or -down has anything to do with that. If the switch is closed, current flows. It does not matter in what direction.
The important thing is to keep the switch open as much as possible. Assuming a window is closed most of the time (i.e., the switch is in the magnetic field), I covered that with the SPDT reed switch (I haven't seen any that are SPST).

Code: [Select]
Of course, to be most effective, after disconnecting the pullup the pin should be switched to a low output so it does not float or the pin should be disabled.
I still don't get this. If I do that, my switch is essentially disabled, isn't it? How am I supposed to wake my MCU?

Boardburner2

Can you not use a wake timer and poll it every millisecond ?
No i have not done any sums.

MarkT

Hi, for a window sensor, I need a pull-up for a reed switch, to detect if the window is opened or closed. I have already gotten SPDT reed switches, so I can set window-closed state to open. Still windows might be open for a longer period of time, so pull-up current matters.
What is the highest "safe value" where my pin isn't effectively floating? Ballpark, of course, safe value without looking into the RF characteristics of the involved traces.
So long as you have a 100nF capacitor between the pin and ground you can have very large resistor values,
such as 4M7.

The analog pin needs a low enough impedance, so a capacitor will do fine.  It will also remove lots of
EMI coming in from the long wire runs which is good.

With 100nF and 4M7 you'll see a time constant of half a second which is probably fine.  You have to start to
worry about leakage current with very large resistance values - so if the switch may get damp and somewhat
conductive when open, perhaps 100k is a better value.  In general a lower value is more robust, but your
power/energy budget may override this.

Another approach is to switch the pullup/pulldown on just before reading the switch, and disabling it afterwards,
but that takes more pins.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Coding Badly

...but that takes more pins.
Except when the internal pullup is used; if it can be used.


Jiggy-Ninja

#11
May 19, 2017, 09:14 pm Last Edit: May 19, 2017, 09:16 pm by Jiggy-Ninja
Hi, for a window sensor, I need a pull-up for a reed switch, to detect if the window is opened or closed. I have already gotten SPDT reed switches, so I can set window-closed state to open. Still windows might be open for a longer period of time, so pull-up current matters.
What is the highest "safe value" where my pin isn't effectively floating? Ballpark, of course, safe value without looking into the RF characteristics of the involved traces.
You have double-throw reed switches?

That makes it easy. No external hardware needed, just more pins with their internal pullups. Simply connect the common pin to GND, and both switch contacts to two different digital inputs.

During setup, pinMode them both to INPUT_PULLUP, then digitalRead them both and INPUT the one that reads LOW (switch closed). If both read LOW or both HIGH, you've got a problem.

So now the open contact has a pullup resistor that draws no current, and the closed contact is shorted to GND with no pullup to waste current. Neither input is floating, and neither draws any current.

Only poll the switch input that has the pullup enabled. Ignore the other one of the pair. When you see the pullup go LOW, this means the switch has been actuated. Immediately disable the pullup resistor on the now-closed contact and enable the pullup on the other input, which is now open.

With this changeover setup, the pullups will only conduct for a very brief moment when the switch transitions. A side benefit of using a SPDT switch this way is that they require no additional debouncing hardware or algorithm. Once the NO contact closes, you immediately start ignoring it and monitor only the NC contact. Even if the NO contacts bounce, you're ignoring that input anyway so they won't register. Then when NC closes again you immediately start ignoring it and change back over to the NO input.
Hackaday: https://hackaday.io/MarkRD
Advanced C++ Techniques: https://forum.arduino.cc/index.php?topic=493075.0

ElCaron

@MarkT
Thanks, that was the answer I hoped for.

@Boardborner2
I highly doubt that starting up an MCU every few milliseconds that could potentially sleep for days does any good.


Another approach is to switch the pullup/pulldown on just before reading the switch, and disabling it afterwards,
but that takes more pins.
Am I not seeing something here, or do you guys keep forgeting that I cannot disable sensing, since my MCU is supposed to sleep? At least if you don't hint at Jiggy-Ninja's approach, which would have been absolutely unclear to me.
Which bringt me to:

@Jiggy-Ninja
THANKS, that is the answer I couldn't have hoped for. This, ladies and gentlemen, is complete and utter brilliance.
Especially since I already mentioned that I am putting I2C pins to a second use and therefore have the second pin conveniently available. This answer totally made my day.

Smajdalf

With double throw switch you may simply connect input to the common pin and any pull-up to one contact and pull-down to the other. No current will ever flow except for filling parasitic capacitances and leakage currents.
On 8-bit (i.e. Uno) use "byte" instead of "int" if possible - it is faster and saves resources!

ElCaron

With double throw switch you may simply connect input to the common pin and any pull-up to one contact and pull-down to the other. No current will ever flow except for filling parasitic capacitances and leakage currents.
Since I am reusing a PCB and and only have 2 I2C pins with pullups on one end and a ground pin on the other, I cannot do that.

Go Up