Quote Originally Posted by Bruce
Code:
I VAR BYTE SYSTEM

LOOP1: ; 150 cycles. Not very fast
    For I=10 TO 1 STEP -1
    NEXT I
    
LOOP2: ; 90 cycles. A lot better
    I = 10
    REPEAT
     I=I-1
    UNTIL I=0

ASM   ; 31 cycles. Pretty fast
LOOP3
     MOVLW 0xA
     MOVWF I      ; I=10
INNER
     DECFSZ I,F   ; I=I-1. IF I=0 skip next instruction
     GOTO INNER  ; Loop until I=0
ENDASM

FINISH:
    GOTO FINISH

I will probably go for Loop 2 implementation..

(Assembly isn't an appealing choice!!)

However, is there any way to estimate the time required to implement this Loop (2). I need to calculate the time needed to decrement the counter, compare its current value to the end value & the repetition (go back to start of loop) of the body time...

I'm using a 20 MHz crystal as clock....

if it can't be estimated from BASIC code... can the .asm file generated by compiler in assembly help me estimate delay time in executing loop knowing the time for each assembly line code???

This is what i'm trying to do; generation of 40kHz pulses (25us)

Loop:

counter = 16

(set one o/p pin high
pause (delay) by 11 us
set o/p pin to low (zero)
puse (delay) by 10 us

decrement counter & compare it

repeat loop again

i need the total time of loop to be 25 microseconds....

HELP PLEASE!!!