Hi,
I have a project using an Atmega16 where the timer should be interrupting once a second, but my sconds variable in not being incremented. If I use this line:
PORTD = ~PORTD;
The leds connected to that port flash, if I write my seconds variable to that port only bianry one is indicated, whcih suggests to me that the timer is not running or the firmware is being reset.
Could someone shed some light on this for me please? I have disabled the watch dog timer too My code is below:
Andrew
const uint16_t interval = 4000000/65536;//Work out interval from CPU frequency
void Init_Timer1()
{
// Set up counter. Fclk = 4Mz
TCCR1B = 1 << WGM12 | 1 << CS12; // Fclk / 256, clear on match
OCR1A = interval; // Timer ticks at 4000000/(256*interval) (1s)
TIMSK |= (1 << OCIE1A | 1 << TOIE1);
asm("sei");
}
ISR(TIMER1_COMPA_vect)
{
wdt_reset();
power_save_timer++;
seconds = seconds+1;
PORTD = seconds << 2;// Used to verify timer is running
if (seconds>59)
{
seconds=0;
minutes++;
}
if(minutes>59)
{
minutes=0;
hours++;
}
if(hours>23) hours=0;
}Message
My timer does not seem to be incrementing an integer
2010-05-08 by Andrew
Attachments
- No local attachments were found for this message.