PDA

View Full Version : Code snippet: time execution for each line: help please



xnihilo
- 6th April 2008, 14:49
Could someone be kind enough and tell me how many instruction cycles each line of this code will use because I need to know what time this routine takes to execute.
I'm using a PIC16F684 and its internal oscillator at 8MHz



databyte = %00000000

'wait for the header pulse to end and check if duration is about 2400us+/-100us
j = 0
WHILE (porta.0 == 0)
PAUSEUS 20
j = j + 1
WEND
IF (( j < 115) || (j > 125)) then abort 'wrong pulse duration

FOR i = 0 to 7

j = 0
WHILE (porta.0 == 1) 'wait until the bit prefix (600us no-pulse) ends
PAUSEUS 20
j = j + 1
WEND
IF ((j < 25) || (j > 35)) then abort 'wrong no-pulse duration, we want it to be 600us+/-100us

j = 0
WHILE (porta.0 == 0)
PAUSEUS 20
j = j + 1
WEND
IF ((j > 25) && (j < 35)) THEN
databyte.0(i) = 0
GOTO bypass
ENDIF
IF ((j > 55) && (j < 65)) THEN
databyte.0(i) = 1
GOTO bypass
ENDIF
GOTO abort 'wrong pulse duration
bypass:

NEXT i

abort:

mister_e
- 6th April 2008, 15:46
There's few way to measure it
a) Toggle a led between a code snip, and mesure it with a scope
b) using MPLAB stopwatch
c) using the following method
http://www.picbasic.co.uk/forum/showpost.php?p=1272&postcount=2

and if you want to elaborate a bit more
http://www.picbasic.co.uk/forum/showpost.php?p=39033&postcount=9

If you're using the above solution with Timer, don't forget to adjust your results with Timer ticks.