Wakeup when watchdog timer AND external interrupt satisfied

Hi, I am using an atmega328p with external 8Mhz crystal and programming in the Arduino IDE.

I am trying to wake up my AVR from an external interrupt, ONLY after 30 seconds has passed.

The method I am using now is to set a watchdog timer for 30 seconds, then check the status of the interrupt pin on wake up, and if it has not triggered to set the external interrupt and sleep again. This is wasting power to wake up after the 30 seconds to check the pin status.

Is it possible to have an interrupt only wake up the AVR when both an external interrupt and watchdog timer have triggered. Cheers :slight_smile:

Interesting problem.

You might be able to set the watch dog timer to wake up at approximately 30 second intervals and , at each alternate interval , toggle the attachment of an external interrupt to the pin connected to your sensor.

When the sensor triggers, for how long does it hold the Arduino pin in the “triggered” state ? A few milliseconds or longer than 30 seconds?

For long sleep periods, you have to chain multiples of a maximum of 8 seconds.
In the low power consumption sleep modes, the only oscillator running is that of the watchdog timer, so you can’t use millis() for example.

Wake up events are independent.

The options I see are

  1. to keep track of time passed using the watchdog (roughly) or an RTC, and check the time when the other interrupt takes place.

  2. keep track of time as above, but enable the external interrupt after 30 seconds.

It takes very little time and energy to do either, so there is not much point in fine tuning the code.