go away spammer

Author Topic: actual time using delay.h  (Read 2851 times)

0 Members and 1 Guest are viewing this topic.

Offline hoheihoTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
actual time using delay.h
« on: February 26, 2011, 04:50:00 PM »
i am currently using PIC18F4550 chips with 1Mhz internal clock.How can i calculate the actual time with delay function?
There is a exmaple on the web but i didn't understand it
Delay100TCYx(30) with 8MHz clock -> 8MHz clock = 2MHz instruction clock = 500ns
500ns * 100 * 30 = 1.5us which is the actual time

For my calculation, 1MHz have 1MHz/4 = 250 000 instruction cycle but how to calculate the next step to get the actual time?

Offline hopslink

  • Robot Overlord
  • ****
  • Posts: 202
  • Helpful? 14
Re: actual time using delay.h
« Reply #1 on: February 26, 2011, 05:49:30 PM »
If you are running the same code then it will take 8 times longer or 12us since your clock is 8x slower...

The first step in their calculation is to find the time per instruction cycle which for the PIC18 series is 4/FOSC. So in their example 4/8000000 = 500ns. For you this becomes 4/1000000 = 4us.
Finally they multiply by the total number of instruction cycles in the delay loop (100) and the number of loop iterations (30) to get a total time. 

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: actual time using delay.h
« Reply #2 on: February 26, 2011, 06:59:07 PM »
Correction:
If Fosc = 8MHz then Fcyc = 2MHz and Tcyc = 500nsec.

For the Delay function in the C library look at the header and source files in the compiler's library folders for how to use that function correctly. You will need to define the clock rate of your PIC.
« Last Edit: February 27, 2011, 10:18:02 AM by waltr »

Offline hoheihoTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: actual time using delay.h
« Reply #3 on: February 27, 2011, 10:14:30 AM »
Thanks!! Now i can work them out :)
Thanks for the help

 


Get Your Ad Here

data_list