Searching \ for 'PIC Timing Routines' 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/devices.htm?key=pic
Search entire site for: 'PIC Timing Routines'.

Truncated match.
PICList Thread
'PIC Timing Routines'
2000\01\25@144850 by James Paul

flavicon
face
All,

I am in need of a 10 mS and a 100 mS routine to run on a PIC.
I know I can write them, but if there are some out there, it
would be quicker to use those already written.  If you have
such an animal, and would feel like sharing it, or have a
pointer to one, please let me know ASAP.  I am trying to do
a quick and dirty test fixture, and time is short.   Help me
out if you can.

                                      Thanks and Regards,

                                             Jim

spam_OUTjimTakeThisOuTspamjpes.com

2000\01\25@151014 by Quitt, Walter

flavicon
face
TIP:

This is 1 interrupt.  Set up a timer for 10ms.
Every interrupt service the 10ms stuff.  Keep
a countdown var (in the file register space)
and when it reaches zero, reset it and service
your 100ms stuff.

Setting a timer for your PIC is well described
in the Data Sheets and App Notes from Microchip.
This is about a dozen lines of code.

GL,
Walt...

{Original Message removed}

2000\01\25@151834 by Sean Breheny

face picon face
Hi Jim,

You might want to take a look at

http://www.people.cornell.edu/pages/shb7/lop.html

especially the "results" section. It gives three types of PIC delay loops,
along with parameters for two of them which will give exact 10,000 100,000
and 1 million cycle delays.

Sean

At 11:46 AM 1/25/00 -0800, you wrote:
{Quote hidden}

| Sean Breheny
| Amateur Radio Callsign: KA3YXM
| Electrical Engineering Student
\--------------=----------------
Save lives, please look at http://www.all.org
Personal page: http://www.people.cornell.edu/pages/shb7
shb7spamKILLspamcornell.edu ICQ #: 3329174

2000\01\25@152050 by Alice Campbell

flavicon
face
;------------------------------------------
;call with no. of ms in work
delay_xms               ;uses temp, temp1  check for reg. conflicts
       movwf   temp1   ;1      # ms in work
ms_dely
       movlw   .110    ;1  for fast crystal makes 1 millisecond
       movwf   temp    ;1
dlylp   clrwdt                   ;1pretty short duty cycle i use wdt a lot
       nop             ;1
       decfsz  temp,f  ;1
       goto    dlylp   ;2
       decfsz  temp1   ;1
       goto    ms_dely ;2
       return
;-------------------------------------------------------------
alice



{Quote hidden}

2000\01\25@153936 by Don McKenzie

flavicon
face
James Paul wrote:
>  I am in need of a 10 mS and a 100 mS routine to run on a PIC.
>  I know I can write them, but if there are some out there, it
>  would be quicker to use those already written.  If you have
>  such an animal, and would feel like sharing it, or have a
>  pointer to one, please let me know ASAP.  I am trying to do
>  a quick and dirty test fixture, and time is short.   Help me
>  out if you can.

; PAUSE time
; A general-purpose delay routine that puts the PIC into a do-nothing
; loop for a 16-bit number of milliseconds (1 to 65535) at 4 MHz.
Requires
; 16 cycles of overhead for call, return and other processing.

found at:
http://www.dontronics.com/convert2.html#pause

Don McKenzie    EraseMEdonspam_OUTspamTakeThisOuTdontronics.com      http://www.dontronics.com

World's Largest Range of Atmel/AVR and  PICmicro Hardware and  Software.
Free Basic Compiler and Programmer http://www.dontronics.com/runavr.html

2000\01\25@161417 by Sean Breheny
face picon face
Hi Alice,

What xtal freq. is this meant for? I count 551 cycles for the inner loop,
so it would be around 2.2 Mhz as far as I can see. Is that right?

Sean

At 12:08 AM 1/25/00 PST, you wrote:
{Quote hidden}

| Sean Breheny
| Amateur Radio Callsign: KA3YXM
| Electrical Engineering Student
\--------------=----------------
Save lives, please look at http://www.all.org
Personal page: http://www.people.cornell.edu/pages/shb7
shb7spamspam_OUTcornell.edu ICQ #: 3329174

2000\01\25@164132 by Andrew T Kelley

picon face
4 MHz clock.

Attached is the asm code.

Andrew

On Tue, 25 Jan 2000 11:46:16 -0800 James Paul <@spam@jimKILLspamspamJPES.COM> writes:
{Quote hidden}

Content-Type: application/octet-stream; name="delays.asm"

Attachment converted: wonderland:delays.asm (????/----) (00015DEF)

2000\01\25@165759 by Alice Campbell

flavicon
face
Ouch!  shoulda checked that better before i sent it.  It is for a
4MHz and the constant should have been 200 for 1001 cycles.  0xff
lashes with wet noodle to me.

alice.

{Quote hidden}

2000\01\26@153616 by Stan Ockers

flavicon
face
                           Subject:                        Time:    1:22
PM
                           RE: Pic Timing Routines
1/26/00
                                                            Date:
Alice Campbell wrote

> and the constant should have been 200 for 1001 cycles.

But 1001 isn't 1000, and what about all the overhead in the outer loop
and the call and return?  Pickey, pickey.

I find that four instructions/loop works better.  See if the following
makes any sense.
All of the following assumes a 4 mHz crystal.

loops of the form:
dlylp       nop
               decfsz temp, f
               goto dlylp
take 4 usec for each time through except the last which takes 3.  If
initializing the counter took 1 usec and we used W to save a register we could
come up with an exact 1 msec delay:

msecdly:    movlw .249         ; one less time thru accounts for call and
return
mseclp:     addlw H'FF'          ; subtract one from W
                 btfss STATUS, Z   ; reached zero yet?
                 goto mseclp          ; no, subtract again
                 return                 ;  2 + 1 + 248 *4 + 3 + 2 =
1000 usec

If we envelope this with an outer loop having a certain number of usec
overhead  we have to somehow subtract out the overhead if the time is to
come out right.  We can't subtract 1 from the number and call the routine
that number of times because the 1 represents over 1000usec.  Each outer loop
is also of this form and represents 4 usec overhead.  The number we want
to use to initialize the inner loop is not 249 but:
      ( nbr = number of millisecond we want to delay)
249 - (nbr/4) - (#instructions used to calculate nbr/4)

how about this:

delay_xms:               movwf temp            ; save # msecs delay
                                 bcf STATUS, C        ; clear carry
                                 rrf temp, W           ;  divide by 2
and save ..
                                 movwf nbr             ; in nbr, (temp
not changed)
                                 rrf nbr, f              ;  divide by 2
again
                                 comf nbr, f            ; compliment nbr
                                 incf nbr, f             ; twos
compliment
                                 movlw D'247'        ; 249 -2,(for about
8 instruction overhead)
                                 addwf nbr, f           ; subtract out
outer loops overhead, save in nbr
innerinit:                  movf nbr, W          ; initialize inner loop
dlylp:                         addlw H'FF'            ; subtract one from
W
                                 btfss STATUS, Z     ; reached zero yet?
                                 goto dlylp               ; no, subtract
again
                                 decfsz temp, f        ; now decrement
outer loop counter
                                 goto innerinit        ; more outer
loops
                                 return

This won't work out exactly because of the integer division but it should
be closer than
the code you suggested.

I haven't tried this, ( or even tried to assemble it yet ), but I would
be interested in any comments anyone has.

Stan

2000\01\27@082510 by Stan Ockers

flavicon
face
                           Subject:                        Time:    7:24
AM
                           RE: Pic Timing Routines
1/27/00
                                                            Date:
Please ignore my previous post on this topic, it was totally wrong.  I
apologize for any inconvenience I may have caused.

Stan

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