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.