In Nigle`s tutorial series, there is a example about delays:
I have been doing some math about this, and cant figure out how this can be 250ms.
Delay movlw d'250' ;1cycle
movwf count1 ;1cycle
d1 movlw 0xC7 ;1cycle
movwf counta ;1cycle
movlw 0x01 ;1cycle
movwf countb ;1cycle
Delay_0
decfsz counta, f ;1cycle
goto $+2 ;2cycles
decfsz countb, f ;1cycle
goto Delay_0 ;2cycles
decfsz count1 ,f ;1cycle
goto d1 ;2cycles
retlw 0x00 ;1cycle
[/code]
For the innerloop to run one time, it takes 1+2+2=5cycles, that would be 5*198=995 cycles for the first part of the inner loop, then we add the second little part. That would be 995+1+1+2+1+1=1001cycles for the whole first part.
The outer loops takes 1+2+1+1+1+1=7cycles to run 1 time, that would be 7*250=1750 cycles for the whole outer loop.
Total that would be 1750*1001+6=1751756cycles for the whole loop to run. And this is not 250ms. Could you please explain how this would be 250ms.
In advance, thanks.
Code:
Delay movlw d'250' ;delay 250 ms (4 MHz clock)
movwf count1
d1 movlw 0xC7
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
I have been doing some math about this, and cant figure out how this can be 250ms.
Delay movlw d'250' ;1cycle
movwf count1 ;1cycle
d1 movlw 0xC7 ;1cycle
movwf counta ;1cycle
movlw 0x01 ;1cycle
movwf countb ;1cycle
Delay_0
decfsz counta, f ;1cycle
goto $+2 ;2cycles
decfsz countb, f ;1cycle
goto Delay_0 ;2cycles
decfsz count1 ,f ;1cycle
goto d1 ;2cycles
retlw 0x00 ;1cycle
[/code]
For the innerloop to run one time, it takes 1+2+2=5cycles, that would be 5*198=995 cycles for the first part of the inner loop, then we add the second little part. That would be 995+1+1+2+1+1=1001cycles for the whole first part.
The outer loops takes 1+2+1+1+1+1=7cycles to run 1 time, that would be 7*250=1750 cycles for the whole outer loop.
Total that would be 1750*1001+6=1751756cycles for the whole loop to run. And this is not 250ms. Could you please explain how this would be 250ms.
In advance, thanks.