Searching \ for '[PIC]: Inline delay code (was: LCD Problem Revisit' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/io/lcd/pic.htm?key=lcd
Search entire site for: 'Inline delay code (was: LCD Problem Revisit'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Inline delay code (was: LCD Problem Revisit'
2001\02\15@105532 by Drew Vassallo

picon face
>...                  ;place the following at the end of an
>...                  ; existing called subroutine.
>DELAY10  GOTO DELAY8 ;GOTO results in 2 cycle delay
>DELAY8   GOTO DELAY6
>DELAY6   NOP         ;NOPs are 1 cycle delay
>DELAY5   NOP
>RETN     RETURN      ;CALL+RETURN is equal to 4 NOPs

This is basically equivalent to using "goto $+1" instructions, which you can
do inline.  The only program memory you're saving here is by re-using the
'return' instruction already in place from another subroutine.  Of course,
if you don't NEED a delay at the end of that subroutine, you've got to
create a separate "delay" routine, which won't save you that instruction.

The second benefit is that if you use this delay code a lot, you don't have
to duplicate it every time.  Otherwise, just to generate individual delays
inline, using "goto's" is fine, but gets lengthy for longer delay counts.

Finally, you only save instructions for calls >9 cycles using this method
for inline code.  And you don't save as much for odd numbered cycle delay
counts because of the required nops.
(for <9 cycle delays, the "goto" method is equal to the "return" method)

Example #1: 5 instructions, 9 cycle delay
 goto $+1
 goto $+1
 goto $+1
 goto $+1
 nop

Call example:  5 instructions, 9 cycle delay
 call retn
 goto $+1
 goto $+2
retn  return
 nop

Example #2: 5 instructions, 10 cycle delay
 goto $+1
 goto $+1
 goto $+1
 goto $+1
 goto $+1

Call example:  4 instructions, 10 cycle delay
 call retn
 call retn
 goto $+2
retn  return

You'll save this 1 instruction up to a 14 cycle delay.  Then, for each delay
that is a multiple of 4 cycles greater, you save an additional instruction
by using this "return" method.

Example #3: 7 instructions, 14 cycle delay
 goto $+1
 goto $+1
 goto $+1
 goto $+1
 goto $+1
 goto $+1
 goto $+1

Call example:  5 instructions, 14 cycle delay
 call retn
 call retn
 call retn
 goto $+2
retn  return

Of course, there's always the familiar 4-instruction delay loop, which is
good for a multiples of 3 cycles, plus 1 extra for initialization:

 movlw <cycles_to_delay/3>
 movwf Counter
Loop  decfsz Counter, f
 goto Loop

--Andrew

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

--
http://www.piclist.com hint: To leave the PICList
spam_OUTpiclist-unsubscribe-requestTakeThisOuTspammitvma.mit.edu


2001\02\15@132818 by mike

flavicon
face
While we're on the subject of inline delays, here's a handy 'delay any
number of cycles' (within reason!) macro I did when messing with
generating TV timings :

usage : wait(n) delays n cycles, n = 0 to about 1024.


shortwait macro del  ; used by main wait macro
if (del>3) && (del<8)  call del7+(7-(del))
endif
 if del <4   if del>=2   goto $+1
 endif
 if ((del) & 1) == 1
 nop
 endif
endif
endm

; main macro - generates code to wait for (del) cycles)

wait macro del
if (del)<0
error 'negative delay'
endif
if (del)>=8  movlw ((del)-8) /4  call delay
shortwait ((del-8) % 4)  else
shortwait (del)
endif
endm

delay   addlw 0ff  skpnc  goto delay
return
del7 goto del5  ; 7 cycle delay
del6 goto del4  ; 6 cycle delay
del5 nop           ; 5 cycle delay
del4 return       ; 4 cycle delay

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2001\02\15@204842 by rottosen

flavicon
face
For a more deluxe (but of course larger) delay macro, see the results of
the SX Microcontroller Serial Video Display contest at:
http://www.sxList.com/techref/ubicom/lib/io/dev/video/servid.htm

The delay used by SERVID has to have a lot larger range than 1024 cycles
since the SX is running at over 40 million instructions per second. :-)

-- Rich


Mike Harrison wrote:
{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2001\02\15@222335 by Bob Ammerman

picon face
part 1 461 bytes content-type:text/plain; (decoded 7bit)

I have a variation on this that doesn't waste so much space by calling an
N*4 delay routine followed by an invocation of the short delay macro.

Instead, I prefix my N*3 delay routine with a few instructions and branch to
the right one for the desired
delay.

See attached. (just hacked out of a working source file).

Bob Ammerman
RAm Systems
(contract development of high performance, high function, low-level
software)





part 2 1107 bytes content-type:application/octet-stream; (decode)

part 3 105 bytes
--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...