maxbayne
Newbie
hiii i try to config timer2 (8bit) inside atmega32a
same configration tested over timer0 and worked perfect but when i tried it over timer2 not working
i try to generate timer every 1 second so i used count with some times to overflow the timer like i overflow timer 61 count so it mean take 1 second
i used info to calc the overflow count from this site
https://eleccelerator.com/avr-timer-calculator/
this code work fine with timer0 and generate 1 second timer but with timer2 it generates 125 ms
if i change the timer2Counter to checked with 488 it generate 1 second
why 61 working with timer0 and not working with timer2 while timer0 is same as timer2
any help plz where is the issue , i tested this with real hardware and same result
this is my code
same configration tested over timer0 and worked perfect but when i tried it over timer2 not working
i try to generate timer every 1 second so i used count with some times to overflow the timer like i overflow timer 61 count so it mean take 1 second
i used info to calc the overflow count from this site
https://eleccelerator.com/avr-timer-calculator/
this code work fine with timer0 and generate 1 second timer but with timer2 it generates 125 ms
if i change the timer2Counter to checked with 488 it generate 1 second
why 61 working with timer0 and not working with timer2 while timer0 is same as timer2
any help plz where is the issue , i tested this with real hardware and same result
this is my code
C++:
#include "avr/interrupt.h"
int main(void)
{
//Configuration ----------------------------------------------------
//Config Port A as Output using some helper function
GPIO::Port_Direction(GPIO_PORT_A,GPIO_DIRECTION_OUTPUT);
//Set Timer Initial Value = 0
TCNT2=0;
//Set Timer Mode To Normal and Prescaler 1024
TCCR2=0b00000101;
//Enable Global Interrupt using register (SREG)
BITWISE_SET_BIT(SREG,SREG_I); //or use sei();
//Enable Timer2 Interrupt using register (TIMSK)
BITWISE_SET_BIT(TIMSK,TOIE2);
//Loop ----------------------------------------------------
while(1)
{
GPIO::Pin_Clear(GPIO_IO_PA1);
delay_ms(1000);
GPIO::Pin_Set(GPIO_IO_PA1);
delay_ms(1000);
}
}
int timer2Counter;
ISR(TIMER2_OVF_vect)
{
timer2Counter++;
//if i use 488 which (61*8) it work correct and generate 1 second timer , but if i use 61 generate 125ms this issue only with timer2 but with timer0 61 worked fine
if(timer2Counter==61)
{
GPIO::Pin_Toggle(GPIO_IO_PA2);
timer2Counter=0;
}
}