dramrattan
Member
Hi,
I'm trying to understand how to arrive at the timing values stated in the lecture unit attached. On page 6, there is a snippet which states that the delay should be 1ms however i think it should be 1us since it is a 4MHz clock. Here is the code:
delay_1ms movlw 0xF9 ; 0xF9 = 249
nop
usec4 addlw 0xFF ; add -1, cannot use decrement, why?
btfss STATUS,Z
goto usec4
return
The value 249 is used because it needs to go through 256 cycles in order for one instruction to take place right?...The 249 + 2 (cycles for call) + 1 (cycle for loading of W) + 4 (cycles for loop) = 256 cycles
Therefore, if all this is correct, could someone help me understand (which is also on page 6):
This routine can be expanded through the use of a variable to allow times in multiples of 1 ms.
For example
; routine is passes the amount of ms to delay in W
; it uses an additional register variable msec_count
delay_ms movwf msec_count
msecloop movlw 0xF8 ; 0xF8 = 248
call usec4 ; 248 * 4 + 2 (call) = 994
nop
nop
decfsz msec_count,F
goto msecloop
return
How come decrement could be used in the second snippet and not the first?...The 248 * 4 + 2 = 994 is what is confusing me i think...because it is using that to generate the multiples of 1ms delays right?...but i don't understand how they arrive at that.
Thanks for any help.
I'm trying to understand how to arrive at the timing values stated in the lecture unit attached. On page 6, there is a snippet which states that the delay should be 1ms however i think it should be 1us since it is a 4MHz clock. Here is the code:
delay_1ms movlw 0xF9 ; 0xF9 = 249
nop
usec4 addlw 0xFF ; add -1, cannot use decrement, why?
btfss STATUS,Z
goto usec4
return
The value 249 is used because it needs to go through 256 cycles in order for one instruction to take place right?...The 249 + 2 (cycles for call) + 1 (cycle for loading of W) + 4 (cycles for loop) = 256 cycles
Therefore, if all this is correct, could someone help me understand (which is also on page 6):
This routine can be expanded through the use of a variable to allow times in multiples of 1 ms.
For example
; routine is passes the amount of ms to delay in W
; it uses an additional register variable msec_count
delay_ms movwf msec_count
msecloop movlw 0xF8 ; 0xF8 = 248
call usec4 ; 248 * 4 + 2 (call) = 994
nop
nop
decfsz msec_count,F
goto msecloop
return
How come decrement could be used in the second snippet and not the first?...The 248 * 4 + 2 = 994 is what is confusing me i think...because it is using that to generate the multiples of 1ms delays right?...but i don't understand how they arrive at that.
Thanks for any help.