Hello! I'm currently looking at timers, and have come upon the situation where timer 1 seems to be going at half the speed I am expecting when TCCR1A bit WGM10 is set, for a top of 0x00FF
Code:
void wasteabout1second(){//actually takes 2 seconds...
noInterrupts();
asm volatile(
//count about 16 million clocks
" ldi r21, 244 \n"// = 16000000/65535
" clr __tmp_reg__ \n"
" sts 0x85, __zero_reg__ \n"//reset timer1
" sts 0x84, __zero_reg__ \n"
" sbi 0x16, 0 \n"//clear timer1 overflow flag
"loopstart: "
" sbis 0x16, 0 \n"
" rjmp loopstart \n"//if no overflow, loop
" sbi 0x16, 0 \n"//clear the timer overflow flag. 256 cycles have passed?
" dec __tmp_reg__\n"
" brne loopstart \n"
" dec r21 \n"//once zero, roughly 256*256*241 cycles passed = 15.79m cycles
" brne loopstart \n"
"sei \n"//re enable interrupts for serial
: //outputs
: //inputs
: "r21"//clobbers
);
};
void setup() {
Serial.begin(115200);
TCCR1C = 0;
TCCR1B = bit(CS10);//set timer1 no clock divider
TCCR1A = bit(WGM10);//set timer1 to 0x0000 - 0x00FF
}
void loop() {
wasteabout1second();
Serial.print("\n");//show timestamp (or toggle an led or whatever instead)
}
Am I doing something wrong? Cheers if you can help!