Searching \ for 'Continious delay' in subject line. ()
Help us get a faster server
FAQ page: techref.massmind.org/techref/timers.htm?key=delay
Search entire site for: 'Continious delay'.

Truncated match.
'Continious delay'
1998\03\05@230122 by

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?).
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?

Jefferson Audio Video Systems

> 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?).

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 - fastfwdix.netcom.com
=== Fast Forward Engineering - Vista, California
=== http://www.geocities.com/SiliconValley/2499
> Aan: PICLISTMITVMA.MIT.EDU
> Onderwerp: Continious delay
> Datum: vrijdag 6 maart 1998 9:16
>
> 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?).

I do not like to be the one to tell you, but yes, you're wrong. So there
:-)

A conditional command is a 1 -OR- 2 cycle command, depending on the
outcome of the compare.

Explanation:
If you don't skip the next command you can continue with the _pre-fetched_
next
command.
If you skip the next command (or perform a 'goto') , you'll have to ignore
the
pre-fetched next command (and lose a cycle), and get a new command.

Your delay-routine has a delay of 3 * (COUNT-1) +2 cycles
- When COUNT <> 1 -> Decfsz := 1 cycle, Goto := 2 cycles
- When COUNT == 1 -> Decfsz := 2 cycles, goto := <skipped>

> 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?

You could try to use the Timer-module, if your PIC has got one.