Im trying to figure out the wake / interrupt on the AVRtiny 1. My interrupts are working for the Hall effect sensor, But when the system goes to sleep I would like the AVR to wake when the Hall effect changes or the wake pin is clicked. Can anyone give me some direction?
I am running the ARV at 1mhz at 3v. running milliamps is 4 and sleep is 1.8. I would like to get the sleep mA closer to .7, any advice lowering my sleep amperage would be appreciated.
// wake pin
#define PC0_INTERRUPT PORTC.INTFLAGS & PIN0_bm
#define PC0_CLEAR_INTERRUPT_FLAG PORTC.INTFLAGS &= PIN0_bm
#define PC0_LOW !(PORTC.IN & PIN0_bm)
#define F_CPU 3333333UL //sleep function
//RTC ISR //////////////////////////////////////////////////////
ISR(RTC_CNT_vect)
{
RTC.INTFLAGS = RTC_OVF_bm;
}
void setup()
{
PORTC.DIR &= ~PIN0_bm; //seta PA7 to input DISPLAY button
PORTC.PIN0CTRL |=PORT_PULLUPEN_bm;
PORTC.PIN0CTRL |=PORT_ISC_FALLING_gc; // enables pull up and configures interrupt for PA7
}
void loop() {
ISR(PORTC_PORT_vect){
if(PC0_INTERRUPT){wakeDisplay();PORTC.INTFLAGS &= PIN0_bm;} //PC0_CLEAR_INTERRUPT_FLAG DISPLAY PORTA.OUT ^=PIN4_bm;
if(PC1_INTERRUPT){pulseCounter();PORTC.INTFLAGS &= PIN1_bm;} //PC1_CLEAR_INTERRUPT_FLAG HALL
}
}
// SLEEP SETUP
void sleep2()
{
//Configure pins: ////////////////////////////////////////
// Set all pins to low power mode:
for (uint8_t i = 0; i < 8; i++) {
*((uint8_t *)&PORTA + 0x10 + i) |= 1 << PORT_PULLUPEN_bp;
}
for (uint8_t i = 0; i < 8; i++) {
*((uint8_t *)&PORTB + 0x10 + i) |= 1 << PORT_PULLUPEN_bp;
}
//RTC INIT: //////////////////////////////////////////////
while (RTC.STATUS > 0) {} // Wait for all register to be synchronized
RTC.PER = 1024*10; //10 secs between wakes.
RTC.INTCTRL = 0 << RTC_CMP_bp
| 1 << RTC_OVF_bp; //Overflow interrupt.
RTC.CTRLA = RTC_PRESCALER_DIV1_gc //NO Prescaler
| 1 << RTC_RTCEN_bp //Enable RTC
| 1 << RTC_RUNSTDBY_bp; //Run in standby
RTC.CLKSEL = RTC_CLKSEL_INT1K_gc; // 32KHz divided by 32, i.e run at 1.024kHz
_delay_ms(6000); //Consumes high power for 6secs before going into eternal sleep (to see a change in measurement on the DMM).
//Enable interrupts //////////////////////////////////////
sei();
//Main loop: /////////////////////////////////////////////
while (1) {
set_sleep_mode(SLEEP_MODE_STANDBY);
sleep_enable();
sleep_cpu(); //Go into sleep
//On awakening
_delay_ms(2000); //Stay still for power measurement with DMM.
}
}