Good day!
Tell me, please, I’m puzzling for a couple of hours ... In the microC there is a function Delay_ms. For example, Delay_ms (11). It sets the delay to 11 milliseconds.
Clock frequency - 8 MHz. In assembly language, this instruction looks like this:
;Delay_ms(11); LDI R17, 115 LDI R16, 72 L_main8: DEC R16 BRNE L_main8 DEC R17 BRNE L_main8 DEC performed 1 clock, BRNE - 1 clock, if there is no transition, 2 clock cycles, if there is. Now, if you count the number of ticks, you can find out the time (11 milliseconds).
I'm trying to count the number of ticks like this:
((1+2)*71 + 2) * 115 * (1+2) + 1 = 74 176 Now, to find out the time delay, it is necessary to divide by the frequency:
74 176 / 8*10^6 = 0,009272 = 9 мс Total, instead of 11 milliseconds, I get 9. Tell me, please, what did I lie to? I assume that there is an error in counting the number of cycles, but I do not see it.