Question
ATtiny816 Standby comparator wake on interupt
Looking for some advise on the best way to sleep and wake an ATtiny816, running megatinycore in arduino.
I have the built in comparator configured like so:
#include <Comparator.h>
// Configure Piezo knock detection comparator parameters
Comparator.input_p = comparator::in_p::in0;
Comparator.reference = comparator::ref::vref_0v55;
Comparator.input_n = comparator::in_n::vref;
Comparator.hysteresis = comparator::hyst::large;
// Initialize comparator
Comparator.init();
Comparator.attachInterrupt(tapInterrupt, RISING);
// Enable the Analog Comparator to run in standby mode, and set to low power mode
AC_t& AC_struct = Comparator.getPeripheral();
AC_struct.CTRLA |= AC_LPMODE_bm | AC_RUNSTDBY_bm;
// Start comparator
Comparator.start();
This works great, and its triggering the tapInterrupt fine. The issue is now I want to place the chip in standby mode to save battery, like so:
wdt_disable();
set_sleep_mode(SLEEP_MODE_STANDBY);
sleep_enable();
sleep_cpu();
sleep_disable();
The issue is even though I have set the comparator to carry on running in standby, the interrupt isn't triggering, which I'm assuming is because of this section in the ATtiny816 manual:
In Standby sleep mode, the AC is disabled by default. If the Run in Standby Mode (RUNSTDBY) bit in the Control A (ACn.CTRLA) register is written to
1
, the AC will continue to operate, but the Status register will not be updated, and no interrupts are generated if no other modules request the CLK_PER, but events and the pad output will be updated.
So I guess from that, I need to enable some other module/peripheral to remain active in standby, but my question is what else should I enable in standby that would fulfil this requirement, and also use the least amount of battery?, and how would I enable it in Arduino?
I have seen idle power mode would also work, but ideally I want it to use as little battery as possible.
Update: So I've had a play around with PIT, but because the comparator interrupt needs to be very responsive, as its basically acting like a switch to turn on the circuit, by the time its slept, woke up, checked for the comparator interrupt for a long enough time to make it feel responsive, then gone back to sleep again, it doesn't really save much power. I really need to get the comparator continuously working, while the rest of the chip is in standby, if that's possible?
This is what I have now to keep the RTC going, in the hopes that it would keep the comparator working during Standby:
// Set the sleep mode
set_sleep_mode(SLEEP_MODE_STANDBY);
// RTC initialization and configuration
while (RTC.STATUS > 0)
{
; /* Wait for all register to be synchronized */
}
RTC.CLKSEL = RTC_CLKSEL_INT32K_gc; /* 32.768kHz Internal Ultra-Low-Power Oscillator (OSCULP32K) */
RTC.PITCTRLA = RTC_PERIOD_CYC16384_gc /* RTC Clock Cycles 16384, resulting in 32.768kHz/16384 = 2Hz */
| RTC_PITEN_bm;
RTC.CTRLA = RTC_RUNSTDBY_bm;
However it still seems that the comparator interrupts still don't work. But then if you can't use the comparator during StandBy, I don't understand the purpose of having the RUNSTDBY flag, if you then can't actually use it in standby?