Hello All
Not sure what i am doing wrong but when i read timer1 using the atomic safe code in the spec sheet for the atmega i never get a value above 8 bits?
I read this constantly in my loop and store the max value after 100000 loops (also into an unsigned int). It is never more than 255.
I have no prescaler (therefore read that ckdiv8 is not set), the arduino is an atmega328p revision 3 with 16mhz crystal.
Atomic read as below.
unsigned int TIM16_ReadTCNT1()
{
unsigned char sreg;
unsigned int i;
/* Save global interrupt flag /
sreg = SREG;
/ Disable interrupts /
cli();
/ Read TCNT1 into i /
i = TCNT1;
/ Restore global interrupt flag */
SREG = sreg;
return i;
}
Any ideas?
Cheers
J