Deep sleep wakeup on both rising and falling wkp


#1

I have a photon that is hooked to a super small battery and solar panel. I was using just regular sleep mode with a wakeup on wkp pin rising. That worked good for a few weeks and I noticed I drained the battery. So i decided I needed to go even more low power and go into deep sleep instead to achieve my goal. The neusance problem I am noticing is that the photon wakes from deep sleep on both a wakeup pin rising and a wakeup pin falling. Is that the normal behavior of the wakeup pin or is there a way to fix this with my code?

My code is simple wakeup send message delaying enough to send and then go back to sleep.

void setup() {
pinMode(WKP, INPUT_PULLDOWN);
}

void loop() {
Particle.publish("mail", "on");
delay(5000);
System.sleep(SLEEP_MODE_DEEP, 604800);
}


#2

@bscuderi, the WKP pin will wake the Photon on the first rising edge. What do you have connected to that pin?


#3

The pinMode() setting is irrelevant for System.sleep() - the sleep call will set the required pin mode implicitly.

And I can assure you that a properly wired WKP pin won’t wake from deep sleep on a falling edge, so there must be something else causing the wake (e.g. power supply related)


#4

I have the 3.3 volt pin wired to the common on a reed switch. Then back to the wakeup pin. I’m finding that the photon wakes up both on open and on close.


#5

@bscuderi, the reed switch bounces like any mechanical switch. What you are most likely seeing is the wake on each rising edge from the bounce. The first rising edge will wake the Photon.


#6

Ahhh makes sense so it’s unavoidable with a reed switch? I mean for my purpose it doesn’t matter it’s fine I just have the publish send a webhook then the service only sends me a push notification once a day when it receives the webhook. So it’s irrelevant I was just trying to cut the uneccesary boot ups. And yeah scruffr I’ll delete the pinmode code. It wasn’t in there originally until just now actually since i was troubleshooting and I thought floating may have caused my issue but it definitely made no difference.


#7

@bscuderi, the Photon should only wake once and with the delay(5000), there is no chance it will “wake” again. Depending on how long your reed is activated by the magnet, you could add an RC circuit to slow the rise of the WKP signal and remove any bouncing affect.


#8

Are you seeing the device wake when you place the magnet near the reed switch and also when you remove the magnet?
If this is the problem, you’ll see the bounce @peekay123 mentioned either way causing a rising edge.

One way to counteract this would be an RC circuit as already suggested, or to go for a Hall effect sensor instead of the reed.


#9

I second @ScruffR’s advice about using a Hall effect sensor instead of a reed switch. They have built-in hysteresis that “allows clean switching of the output even in the presence of external mechanical vibration and electrical noise” (quote from the Allegro A3211/A3212 data sheet). Debouncing shouldn’t be a problem with one of these, and they don’t wear out like mechanical devices.


#10

Note that the wakeup pin is actually NOT edge triggered on the STM32 - it’s level triggered. If you attempt to sleep with the pin high, the device will wake immediately. Switching to a hall sensor will generally make the signal cleaner, but still won’t let you sleep when in a triggered state.

Two ways around this:

  • in software, wait for PA0 to go low before you enter sleep (works for short, deterministic wake signals)
  • Use an XOR gate with an RC to generate a positive pulse on PA0 only when the input changes

An XOR gate outputs a high level when the inputs are different - so you connect the signal direct to the A pin, and the signal delayed by an RC to the B pin. Note that if you are using a reed switch and a pull-up then you’ll need to buffer the signal before feeding it to the circuit.

Note that you’ll generally also want to connect the actual input to the MCU, so when you wake you can read the input’s absolute level. Make sure the XOR has schmitt trigger inputs.


#11

Interesting the device was able to sleeep with the pin high just fine and would stay asleep. However, it would wake again the second my reed switch changed it to a low state. So basically I open the mailbox door it would wake and publish its event and then sleep. And if I still had the mailbox open it would stay asleep but then wake and publish again the second I closed the mailbox. Not a huge deal since only the first opening of the day is actually the mailman. Its just an annoyance that some mailbox trips if longer than a few seconds registered as multiple events. Not to mention an unnecessary use of its power , although it should have plenty.
And thanks for the electrical lesson guys I had no idea that switch bounce was a thing. I just assumed it was my code I’m learning all this as I go. I may get some supplies to wire the R-C cuircuit thing or I may live with it I haven’t decided.
As always thanks for the speedy input guys. :slight_smile: