Gennady Palitsky wrote: > I believe this should be simple, but don't have an idea as of right > now. To generate delay I am using standard procedure: > > LOOP > decfsz COUNTER,1 > goto LOOP > ------------------ > As far as I understand, both DECFSZ and GOTO are 2 cycle > instructions, so 1 point change in COUNTER value gives me 4 cycles > change in delay time (am I wrong?). Gennady: Yes, you're wrong... The DECFSZ only takes two cycles on the FINAL iteration of the loop (when the GOTO is skipped); every other time through the loop, it takes just one cycle. The GOTO is a two-cycle instruction, so the total delay is X*3-1, where X is the value loaded into the counter before the loop. > Is there any way to generate delay which will give me 1:1 ratio (1 > point change in COUNTER value : 1 cycle change in delay time). Or > do I want too much? Try this; it generates delays with a resolution of one cycle, although it's limited to the range [20-271]. MOVLW X CALL DELAY .... ; This routine delays X cycles. Enter with X (in the range ; [20-271]) in the W register. ; ; Note that the delay is inclusive of the "MOVLW X", "CALL ; DELAY", and "RETURN" overhead, so a sequence like: ; ; MOVLW 100 ; CALL DELAY ; MOVLW 200 ; CALL DELAY ; ; will delay EXACTLY 300 cycles. DELAY: MOVWF COUNTER BTFSC COUNTER, 0 GOTO $+1 BTFSS COUNTER, 1 GOTO SKIP NOP GOTO $+1 SKIP: RRF COUNTER RRF COUNTER MOVLW 4 SUBWF COUNTER BCF COUNTER,6 BCF COUNTER,7 LOOP: NOP DECFSZ COUNTER GOTO LOOP RETURN As is always the case with code that I write online, this code has neither been tested nor even assembled. -Andy === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - Vista, California === http://www.geocities.com/SiliconValley/2499