Solved! Go to Solution.
void interrupt RTI_Interrupt_Routine(void){ RTI_count++; if(RTI_count >= MAX_RTI_COUNT){ RTI_count = 0; //Reset counter SRTISC = RTI_OFF_1s; //Turn off RTI Normal_Mode = 1; //Resume normal operation } else{ Sleep_Mode = 1; //Otherwise, sleep } }
Explanation: RTI_count is the variable to imcrment periodically upon interrupt. MAX_RTI_COUNT is the time in seconds you want to sleep for. SRTISC is the RTI control register and RTI_OFF_1s = 0x07. Turn off RTI so it doesn't keep interrupting your program when you don't want it to. Normal_Mode and Sleep_Mode are flags that are used by the main program to put the device back to sleep or wake it up (other peripherals). You could try putting the command directly into the ISR for sleep or wake up. The MCU is periodically sleeping and then waking up on RTI. To minimise power consumption during this brief ON time from the check in the ISR turn off anything that may consume power, other peripherals, internal settings etc. Because you are performing a simple check in the ISR, the ON time will be very small compared to the SLEEP time so power consumption should be not much more than in SLEEP operation. You could work out the current and hence power consumption from the electrical characterisitcs in the data sheet and also by knowing the time taken to complete the check and then go back to sleep. Hope this helps, Wiresim.