I seem to be having a weird issue regarding cbi/sbi instructions on Atmega8-16AU.
I have it connected to an external 16Mhz crystal.
I am able to verify that it is running at 16Mhz by using _delay_ms(1000)
and checking with a logic analyzer that indeed a delay of 1 second is produced during toggling of an output pin.
However when I call the following the assembly function:
asm_toggle:
sbi PORTC,4
cbi PORTC,4
ret
I would expect PC4 to be HIGH for 2 clock cycles ((1/16M)*2) or 0.125us. However when I check using a logic analyzer, the pin is actually HIGH for 1.5us! That's almost 24 cycles.
I understand that some cycles would be used for jumping and returning to the function from the main routine but that should not affect the actual HIGH time of pin PC4.
Can someone explain whats going on here. I have a feeling that I'm missing something very basic here.
There are no interrupts running and my fuse settings are
LFuse : 0xFF
HFuse : 0xC9