Searching \ for '[PIC]:1sec Delay Algorithm [16F877]' 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/microchip/time.htm?key=delay
Search entire site for: '1sec Delay Algorithm [16F877]'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:1sec Delay Algorithm [16F877]'
2001\01\03@231228 by Dilan Amarasinghe

flavicon
picon
If any body got a delay algo for PIC16F877, please send me in.

Thanks in Advance.

Dilan

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\01\03@233341 by David VanHorn

flavicon
face
At 10:14 AM 1/4/01 +0530, Dilan Amarasinghe wrote:
>If any body got a delay algo for PIC16F877, please send me in.

There's two approaches to delays:  "Sit and spin", and timer.

With sit and spin, you set a file register to some value, and decrement it
to zero.

Delay:
        clrwdt                          ;
        movlw   07Fh                    ;Whatever value is appropriate
        movwf   Delay1                  ;

Delay_Loop:
        decfsz  Delay1,1                ;Loop here till Delay=0
        goto    Delay_Loop              ;

This won't be anywhere near a second, unless your clock is very slow, but
you can do an outer loop like this:

Pin_Delay_Start:
        movlw   07Fh            ;
        movwf   Delay           ;Inner loop delay is multiplied by this value

Outer_Delay_Loop:
        movlw   07Fh            ;
        movwf   Delay2          ;Determines the inner loop delay

Inner_Delay_Loop:
        decfsz  Delay2,1        ;
        goto    Inner_Delay_Loop;
        ;When Delay2=0, then we decrement Delay once

        decfsz  Delay,1         ;
        goto    Outer_Delay_Loop;

Now, your delay is much longer.

The other way is to set a timer for an int at regular intervals, and then
decrement a delay timer (file register), but that's a bit more complicated
to set up.


--
Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics


2001\01\04@082332 by Drew Vassallo

picon face
This should get you 0.985 seconds, which seems ok, unless you need better
precision:

;; Uses 2 registers as counters plus W
Delay_1sec
       movlw   0x03        ; 3 * .328secs = .985 seconds
       movwf   Counter2
       clrf    Delay_Count ; 256 loops @ 256*5us each ~= .328secs
       clrw
Delay_L
       addlw   0x01
       btfsc   STATUS, Z   ; check for overflow past 0
       decfsz  Delay_Count
       goto    Delay_L
       decfsz  Counter2
       goto    Delay_L
       return

If you need better precision, you can preload Delay_Count with a lower value
to make it overflow faster for the first loop, then increase Counter2 from
0x03 to 0x04 to get that extra 15ms you need to bring it to 1.000 seconds.
I'll let you do the math.

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

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@082951 by Drew Vassallo

picon face
Very sorry - I made a mistake and forgot to add an instruction in my first
posting.  Also, this routine is timed for 4MHz clock.
See correction here:

>This should get you 0.985 seconds, which seems ok, unless you need better
>precision:
>
>;; Uses 2 registers as counters plus W
>Delay_1sec
>        movlw   0x03        ; 3 * .328secs = .985 seconds
>        movwf   Counter2
>        clrf    Delay_Count ; 256 loops @ 256*5us each ~= .328secs
>        clrw
>Delay_L
--------> nop                ; forgot to add this to make it 5us
>        addlw   0x01
>        btfsc   STATUS, Z   ; check for overflow past 0
>        decfsz  Delay_Count
>        goto    Delay_L
>        decfsz  Counter2
>        goto    Delay_L
>        return

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

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@084007 by Drew Vassallo

picon face
Heh, well, I guess it's been so long since I looked at the routine that I
forgot I *did* make it 5us each loop by changing the way the zero bit is
checked.
Forget the added "nop" in my second posting.... sigh, it's too early in the
morning for this!  (The routine here is correct, I'm sure about it.)

This should get you 0.985 seconds, which seems ok, unless you need
better precision:

;; Uses 2 registers as counters plus W
Delay_1sec
       movlw   0x03        ; 3 * .328secs = .985 seconds
       movwf   Counter2
       clrf    Delay_Count ; 256 loops @ 256*5us each ~= .328secs
       clrw
Delay_L
       addlw   0x01
       btfsc   STATUS, Z   ; check for overflow past 0
       decfsz  Delay_Count
       goto    Delay_L
       decfsz  Counter2
       goto    Delay_L
       return

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

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@093750 by James Paul

flavicon
face
 All,

 Or just add NOP's to fine adjust the routine.

                             Regards,

                               Jim



On Thu, 04 January 2001, Drew Vassallo wrote:

{Quote hidden}

spam_OUTjimTakeThisOuTspamjpes.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@094622 by Drew Vassallo

picon face
>   All,
>
>   Or just add NOP's to fine adjust the routine.
>
>                               Regards,
>
>                                 Jim

The problem with this is that even if you just add one "nop" inside the
innermost loop, it drives the total time up to 1.17 seconds.

You'd have to add 58 "nops" or 29 "goto $+1" after the first loop counter
(Delay_Count) decrement to get 15ms extra time.  But then you'd have to
alter the way the zero bit is checked so that it skips on "set" and add a
"goto Delay_L" after it.

You're better off just taking the .985 seconds :)

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

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\04@134009 by James Paul

flavicon
face
Or add them outside the loop(s).

                     Regards,

                       Jim



On Thu, 04 January 2001, Drew Vassallo wrote:

{Quote hidden}

.....jimKILLspamspam@spam@jpes.com

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2001\01\05@151329 by Paul Erkiert

flavicon
face
One I like for 1 Second and is useful for a clock. Use 4Mhz Xtal prescale TMR0 for divide 64 count 125 interrupt's for a time of 8 milliseconds and then 125 of them for the Second (64*125*125=100000uSecond)

Paul Erkiert

paulspamKILLspamg4bks.fsnet.co.uk

http://www.g4bks.fsnet.co.uk/

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body


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