augustinetez
Active Member
Quick question regarding where to measure # of cycles/pulse duration during simulation of some code (example below) - mainly to make sure I'm doing it right -the brain is on holiday and something is niggling that the below might not be 100% accurate.
Scenario: Pulse overall is 1 second divided in to 'mark' of 100mS and 'space' of 900mS generated by a delay loop in the PIC.
Pulse is output by setting & clearing PORTA,0.
Please note that the code below has not been fine tuned for the 900mS space duration.
I have been measuring the 100mS using breakpoints in the Oshonsoft sim at line 2 & line 19 and the overall duration of 1 Second from line 2 until it loops back to line 1.
My reasoning for measuring at those points is that PORTA doesn't change state until after it processes the BSF/BCF commands and that the total duration measurement of 1Sec is from the moment PORTA goes high to the point immediately before it goes high on the next loop through.
Scenario: Pulse overall is 1 second divided in to 'mark' of 100mS and 'space' of 900mS generated by a delay loop in the PIC.
Pulse is output by setting & clearing PORTA,0.
Please note that the code below has not been fine tuned for the 900mS space duration.
I have been measuring the 100mS using breakpoints in the Oshonsoft sim at line 2 & line 19 and the overall duration of 1 Second from line 2 until it loops back to line 1.
My reasoning for measuring at those points is that PORTA doesn't change state until after it processes the BSF/BCF commands and that the total duration measurement of 1Sec is from the moment PORTA goes high to the point immediately before it goes high on the next loop through.
Code:
p6a
1 bsf PORTA,0
2 movlw D'3' ;PIC Time Delay = 0.09999980 s with Osc = 20MHz
3 movwf CounterC
4 movlw D'138'
5 movwf CounterB
6 movlw D'84'
7 movwf CounterA
loop6
8 decfsz CounterA,1
9 goto loop6
10 decfsz CounterB,1
11 goto loop6
12 decfsz CounterC,1
13 goto loop6
14 NOP
15 NOP
16 btfss PORTA,3 ; is switch pressed?
17 goto incrat
18 bcf PORTA,0
19 movlw D'23' ;PIC Time Delay = 0.90000040 s with Osc = 20MHz
20 movwf CounterC
21 movlw D'213'
22 movwf CounterB
23 movlw D'21'
24 movwf CounterA
loop6a
25 decfsz CounterA,1
26 goto loop6a
27 decfsz CounterB,1
28 goto loop6a
29 decfsz CounterC,1
30 goto loop6a
31 goto p6a