Hi, I wrote a macro for a delay procedure as follows:
;--------------------------------------------------------- ;@0=COUNT (16-bit value to count to, each count takes 8 clock cycles) .MACRO delay_counts ;load count into temp2:temp ldi temp2, high(@0) ldi temp, low(@0) DELAY_START: ;decrement the counter pair subi temp, 1 ;1 cycle sbci temp2, 0 ;1 cycle ;test the counter pair clr temp3 ;1 cycle cpi temp, 0 ;1 cycle cpc temp2, temp3 ;1 cycle brne DELAY_START ;2 cycles .ENDMACRO
Say for example one wanted a 7ms delay, one would use it as follows:
;Example of a 7 ms delay .equ fosc = 14745600 .equ f_wait = (fosc*0.007/8)-4 ;7ms, delay routine takes 8 clock cycles, and 4 cycles to initialise delay_counts f_wait //do stuff after the delay
If you look at the delay routine, you will see each iteration takes 7 cycles. However when I scoped my routine I have found it actually takes 8!
Where is the extra clock cycle being introduced?
I have check the cycles for each instructions 3 times already.
Does it preform a NOP after the branch?
Thanks for any help from you gurus!