Which PIC are you using?
One easy way would be to increment a counter variable in your Timer1 int handler, and turn off all LEDs & enter sleep mode once it reaches a certain value.
During normal operation, reset the counter var in the INT_INT handler.
Timer1 increments counter on each interrupt, external interrupt clears it. Just monitor the count value in your main loop.
Just remember that if you enter sleep mode, Timer1 stops unless you have an external crystal for your Timer1 clock source.
The problem I have is I can not stop Timer1 because that is where the PWM burst happens.
If I stop this timer I have no way to wake it up so I can not go in sleep mode.
I can only get the LEDs off based on a counter and I guess compare it with its own value from the previous loop.
What I can't figure out is, how many loops I get in one minute? and how much can I count with a word variable?
Perhaps I need to use nested counters? or is there a better way?
A word var can count up to 65,535. If your Timer1 interrupts happen every 20mS, then count up to 3000.
It won't be right on the money for 1 second with your delays, HPWM, etc, in your Timer1 interrupt handler, but you can adjust for overhead if you need it closer to 1 second exactly.
You could also use a Timer0 interrupt to increment your counter.
Bookmarks