Hacker News new | ask | show | jobs
by tonyd256 4485 days ago
I used the WDT to make a platform for sensing any sensor in second intervals. Using the reed switches as external interrupts would have been specific to this application. Also, the ATMega328P doesn't allow you to set the interrupt to fire on CHANGE when using the lowest power mode.

For a door opening and closing a 1 second delay is fine. If it misses an event with that delay then it was probably a fluke. Think of it as a buffer to prevent false readings.

2 comments

This isn't to suggest that using the WDT in interval mode is the wrong approach, and I know there's a certain amount of elegance to doing everything with one chip, but you could still use the level interrupt by adding a 7486 (standard quad XOR gate). For the gate's inputs, you would use the reed switch and a output pin from the AVR, and the gate's output would go to the external interrupt line. If the ISR toggles the state of the output pin each time it runs, the gate's output is only in the IRQ-asserted state for as long as it takes the ISR to fire up--so you don't get constant interrupts while the switch is closed, only a single one on the opening and closing transitions.

The 74LVC86 variant only draws a dozen, or so, microamps, which is dwarfed by the current in the 10k pull-down resistor when the reed is closed, and comparable to the standby current of the radio in the new radio.

I totally agree. There are definitely some more things like this that I could have done to reduce power further and use normal external interrupts. I was going for more of a general purpose sensor board though and wanted to keep it minimal. I could also have used the HIGH and LOW level interrupts on those pins and just change which it triggers on every time it triggered. But I decided to go with the WDT.
Interesting! I guess that I'm not using the lowest power mode[1], but for months now I have had a ATMega328P (running on 3-AA batteries) monitoring doors w/reed switches. I haven't had any trouble w/interrupts not firing on change.

1: I'm using Rocket Scream's LowPower.PowerDown for what it's worth.

Cool, there probably isn't a huge difference between idle and deep sleep modes so I'm sure it could still last a long time. In deep sleep you can still use the HIGH & LOW level interrupts but just not the CHANGE one.