Searching \ for 'Accurate time delays' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: piclist.com/techref/timers.htm?key=delay
Search entire site for: 'Accurate time delays'.

Truncated match.
PICList Thread
'Accurate time delays'
1999\07\28@213425 by Wesley Moore (Yallara)

flavicon
picon face
I am attempting to use this delay code from:
http://www.dontronics.com/rtc.html#pic2

>From what I can work out the equation gives the number of instructions
which are executed. I am using a PIC16F84 (10Mhz) and want to know who to
convert instructions to time. I have gone through th F84 data sheet and it
doesn't specificly say how many clock cycles are used per instruction. It
says 'cycles' but this is 1 or 2 and 0.1uS sounds a bit small.

Thanks for your help in advance.

Wesley

The routine is below, it may have been mucked up by the mail program
(wrapping). The link above will take you to the original version.

delay           movlw   0x001           ;standard delay routine. increase
w value
               movwf   count1          ; for increased delay
               movlw   0x001           ;can set up any delay by calling
delay1 (NB!)
               movwf   count2          ; with pre-set values in count1,
2, 3
               movlw   0x020           ;ex Myke Predko, piclist 4 Jan97
               movwf   count3          ;delay, (no of instructions)=
delay1          decfsz  count3,same     ;2 + 5*(count3-1) +
               goto    $-1             ;2 + (5*255 +2+5) * (count2-1) +
               decfsz  count2,same     ;2 + (5*255*256 +2 + 5*255 +2+5)
*(count1-1)
               goto    $-3             ;  =
               decfsz  count1,same
;5(count3-1)+1282(count2-1)+327684(count1-1)+6           &nbp;
               goto    $-5             ;        return                  ;

1999\07\28@215857 by Jim Robertson

flavicon
face
At 11:33 29/07/99 +1000, you wrote:
>I am attempting to use this delay code from:
>http://www.dontronics.com/rtc.html#pic2
>
>From what I can work out the equation gives the number of instructions
>which are executed. I am using a PIC16F84 (10Mhz) and want to know who to
>convert instructions to time. I have gone through th F84 data sheet and it
>doesn't specificly say how many clock cycles are used per instruction. It
>says 'cycles' but this is 1 or 2 and 0.1uS sounds a bit small.

The internal cycles are the clock speed divided by 4. So at 4Mhz the
instruction
time is 1uS or 2uS. At 10Mhz it is 0.4uS or 0.8uS.

Instructions that modify the program counter take two internal cycles and
these
are CALL, GOTO, RETLW, RETURN or anything that uses the PC as a destination
such
as a ADDWF PC.

Jim



{Quote hidden}

Regards,

Jim Robertson
NEWFOUND ELECTRONICS
________________________________________
Email: spam_OUTnewfoundTakeThisOuTspampipeline.com.au
http://www.new-elect.com
MPLAB compatible PIC programmers.
________________________________________

1999\07\28@223721 by Wagner Lipnharski

picon face
you wrote:
<<
>From what I can work out the equation gives the number of instructions
which are executed. I am using a PIC16F84 (10Mhz) and want to know who
to convert instructions to time. I have gone through th F84 data sheet
and it doesn't specificly say how many clock cycles are used per
instruction. It says 'cycles' but this is 1 or 2 and 0.1uS sounds a bit
small.
>>

Don't forget that a crystal is not *that* accurate... a regular ±50ppm
per ¡C is expected from commercial crystals, so a 4MHz unit can oscilate
from 3,999,800 to 4,000,200 Hz, inside the same temperature degree.  It
means that each 20 thousand oscillations, it can gain or lose one count,
per temperature Celsius degree change.  Moving the unit from 20 to 28¡C,
it can slide the frequency from 4,000,000 to 4,001,600 Hz.  ECS produce
some crystal and oscillators that goes up to ±100ppm/¡C...

It is hard to find information about the stated frequency precision, but
experience shows that no one 4MHz crystal oscillates at 4MHz, except
inside of a calibrated thermal chamber.

Wagner.

1999\07\28@233758 by Tony Nixon

flavicon
picon face
Hi all,

This is probably old hat, but you never know. I was shown it at the
microchip seminar. The delay routines' feature is that it doesn't change
anything but the stack.

A free beer for the first correct answer on how many stack levels it
uses ;-)

Delay131072     call Delay16384
Delay114688     call Delay16384
Delay98304      call Delay16384
Delay81920      call Delay16384
Delay65536      call Delay16384
Delay49152      call Delay16384
Delay32768      call Delay16384
Delay16384      call Delay2048
Delay14336      call Delay2048
Delay12288      call Delay2048
Delay10240      call Delay2048
Delay8192       call Delay2048
Delay6144       call Delay2048
Delay4096       call Delay2048
Delay2048       call Delay256
Delay1792       call Delay256
Delay1536       call Delay256
Delay1280       call Delay256
Delay1024       call Delay256
Delay768        call Delay256
Delay512        call Delay256
Delay256        call Delay32
Delay224        call Delay32
Delay192        call Delay32
Delay160        call Delay32
Delay128        call Delay32
Delay96         call Delay32
Delay64         call Delay32
Delay48         call Delay32
Delay32         call Delay4
Delay28         call Delay4
Delay24         call Delay4
Delay20         call Delay4
Delay16         call Delay4
Delay12         call Delay4
Delay8          call Delay4
Delay4          return

--
Best regards

Tony

'The Engine' - Design your own programmer.

http://www.picnpoke.com
Email .....picnpokeKILLspamspam@spam@cdi.com.au

1999\07\28@234404 by Dmitry Kiryashov

flavicon
face
Tony Nixon wrote:
>
> Hi all,
>
> This is probably old hat, but you never know. I was shown it at the
> microchip seminar. The delay routines' feature is that it doesn't change
> anything but the stack.
>
> A free beer for the first correct answer on how many stack levels it
> uses ;-)

%.

How about shipping ? ;-)

WBR Dmitry.

1999\07\28@235522 by Wagner Lipnharski

picon face
It uses just four stack level... :) By the way, I guess your original
was 131072, but man, the stack gets very hot after this time delay,
isn't?

{Quote hidden}

1999\07\29@003205 by Wagner Lipnharski

picon face
ooops, my mistake, it tooks infinite stack levels
;)

{Quote hidden}

1999\07\29@003217 by Wesley Moore (Yallara)

flavicon
picon face
Thanks very much. I had noticed that it seemed to be divied by 4 but
wasn't sure thanks for the clarification.

Wesley

On Thu, 29 Jul 1999, Jim Robertson wrote:

{Quote hidden}

1999\07\29@003240 by Tony Nixon

flavicon
picon face
Wagner Lipnharski wrote:
>
> It uses just four stack level... :) By the way, I guess your original
> was 131072, but man, the stack gets very hot after this time delay,
> isn't?

Ding!!

No prize

> > Delay131072     call Delay4

Oops! This should read

Delay 131072    call Delay16384

--
Best regards

Tony

'The Engine' - Design your own programmer.

http://www.picnpoke.com
Email .....picnpokeKILLspamspam.....cdi.com.au

1999\07\29@004302 by Tony Nixon

flavicon
picon face
> How about shipping ? ;-)
>
> WBR Dmitry.

No worries.

I was going to Email it from the Get It Free brewery.
That way it won't get shaken up :-)

--
Best regards

Tony

'The Engine' - Design your own programmer.

http://www.picnpoke.com
Email EraseMEpicnpokespam_OUTspamTakeThisOuTcdi.com.au

1999\07\29@005935 by Tony Nixon

flavicon
picon face
Wagner Lipnharski wrote:
>
> ooops, my mistake, it tooks infinite stack levels
> ;)

Ding!!

No prize

One more boo boo and it's your shout |-)

--
Best regards

Tony

'The Engine' - Design your own programmer.

http://www.picnpoke.com
Email picnpokespamspam_OUTcdi.com.au

1999\07\29@030301 by Eric Smith

flavicon
face
Tony Nixon <@spam@Tony.NixonKILLspamspamENG.MONASH.EDU.AU> wrote:
> A free beer for the first correct answer on how many stack levels it
> uses ;-)

I can always use a free beer.  It looks to me like it should take anywhere
from one stack level (for a "call Delay4") through six (for "call Delay32768"
through "call Delay131072").

1999\07\29@030718 by Michael Rigby-Jones

flavicon
face
> -----Original Message-----
> From: Tony Nixon [SMTP:KILLspamTony.NixonKILLspamspamENG.MONASH.EDU.AU]
> Sent: Thursday, July 29, 1999 4:35 AM
> To:   RemoveMEPICLISTTakeThisOuTspamMITVMA.MIT.EDU
> Subject:      Re: Accurate time delays
>
> Hi all,
>
> This is probably old hat, but you never know. I was shown it at the
> microchip seminar. The delay routines' feature is that it doesn't change
> anything but the stack.
>
> A free beer for the first correct answer on how many stack levels it
> uses ;-)
>
>
Assuming one stack level to actually call the delay routine, then I make it
a maximum of 6 and a minimum of 1.

Mike Rigby-Jones.


{Quote hidden}

1999\07\29@032544 by Tony Nixon

flavicon
picon face
Michael Rigby-Jones wrote:

> Assuming one stack level to actually call the delay routine, then I make it
> a maximum of 6 and a minimum of 1.

You win.

PS If you want the beer, send me an address.

--
Best regards

Tony

'The Engine' - Design your own programmer.

http://www.picnpoke.com
Email TakeThisOuTpicnpokeEraseMEspamspam_OUTcdi.com.au

1999\07\29@032954 by Michael Rigby-Jones

flavicon
face
I'd like to accept the honour, but Eric's post landed in my inbox just as I
clicked send :o)

Cheers

Mike

{Quote hidden}

1999\07\29@084316 by Wagner Lipnharski

picon face
hu uh, got you, take a look at your coding at my reply... :)
it is infinite... hehe

Tony Nixon wrote:
{Quote hidden}

1999\07\29@194930 by Gennette Bruce

flavicon
face
The architecture of the PIC requires 4 steps for every single instruction,
so rather than divide the clock frequency internally they just chose to use
4 oscillations per command (clock / 4).

Commands that do 2 things - an evaluation and a change to the program
counter use 8 oscillations. for example-

  goto somelabel

         uses 4 oscillations to work out the goto,
         then 4 more to change the program counter (PCL)

But be careful when counting, a 2 part command that doesn't do the second
part only uses 4 oscillations as in-

  btfss somefile,somebit

         will use 8 oscillations if somebit is set,
         but only 4 oscillations if somebit is clear

Take care.

Bye.

       -----Original Message-----
       From:   Wesley Moore (Yallara) [SMTP:wmooreEraseMEspam.....CS.RMIT.EDU.AU]
       Sent:   Thursday, 29 July 1999 14:10
       To:     EraseMEPICLISTspamMITVMA.MIT.EDU
       Subject:        Re: Accurate time delays

       Thanks very much. I had noticed that it seemed to be divied by 4 but
       wasn't sure thanks for the clarification.

       Wesley


1999\07\31@223931 by Dwayne Reid

flavicon
face
>Hi all,
>
>This is probably old hat, but you never know. I was shown it at the
>microchip seminar. The delay routines' feature is that it doesn't change
>anything but the stack.
>
>A free beer for the first correct answer on how many stack levels it
>uses ;-)
>

I must be out to lunch, but I only see 6 levels used.

dwayne


Dwayne Reid   <RemoveMEdwaynerEraseMEspamEraseMEplanet.eon.net>
Trinity Electronics Systems Ltd    Edmonton, AB, CANADA
(780) 489-3199 voice          (780) 487-6397 fax

Celebrating 15 years of Engineering Innovation (1984 - 1999)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Do NOT send unsolicited commercial email to this email address.
My posting messages to Usenet neither grants consent to receive
unsolicited commercial email nor is intended to solicit commercial
email.


'Accurate time delays'
1999\08\03@104806 by tmariner
flavicon
face
Hello Wesley,

To do precision delays to the resolution of a single instruction time we use
a scheme in two parts:

First a macro that sets the constants for the coarse delay (4 instruction
cycles) and the fine delay (1 instruction cycle):

       ;**************************************
       ; Delay for precise amount of time
       ;**************************************
       Delayus MACRO   DelayTime
               MOVLW   ((((DelayTime-DelayOffset)*.1000)/(INSTTIME))%4)+1
;Complement of LS
2 bits
               MOVWF   FineDelay
               MOVLW   (((DelayTime-DelayOffset)*.1000)/(INSTTIME))/4 ;Coarse D
elay
               CALL    DelayService            ;Do Delay
               ENDM

The Routine it calls, DelayService performs the actual delay:

       ; Delay for precise amount of time
       DelayService
               MOVWF   Temp1           ;save Value
       DelayServ1
               NOP
               DECFSZ  Temp1   ;Count /4
               GOTO    DelayServ1
               MOVF    FineDelay,W     ;fine delay
               ADDWF   PCL     ;get 1 instruction resolution
               NOP             ;here for 3
               NOP             ;here for 2
               NOP             ;here for 1
               RETURN  ;here for 0

Some of the terms may need explanation:

       DelayTime - The time in us to delay.
       DelayOffset - Overhead to perform the delay including the macro call and
the entry to      DelayService
       INSTTIME is the instruction time in ns

Obviously be careful of crossing page boundaries on the ADDWF PCL and the
saving of PCLATH during interrupts.

Hope it helps.

Tom

> {Original Message removed}

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