Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 22nd May 2008, 08:55 AM   (permalink)
Default help with a delay function

i want to make a delay of, say 100uS using 1 Mhz oscilator, so i see a function like this can do the work,

Code:
void delay(unsigned char i)
{
	unsigned char n;
	unsigned int j;
	for (n=1; n<i; n++)
	{
		for (j=1; j<1535; j++);
	}
...but my problem is how to figure out how this function really do the delay of, say 1 seconds, etc. when it is called.

anyone to come to my rescue?

thanks,
t.man is offline  
Old 22nd May 2008, 09:10 AM   (permalink)
Default

Quote:
Originally Posted by t.man View Post
i want to make a delay of, say 100uS using 1 Mhz oscilator, so i see a function like this can do the work,

Code:
void delay(unsigned char i)
{
	unsigned char n;
	unsigned int j;
	for (n=1; n<i; n++)
	{
		for (j=1; j<1535; j++);
	}
...but my problem is how to figure out how this function really do the delay of, say 1 seconds, etc. when it is called.

anyone to come to my rescue?

thanks,
hi,
If you are using a PIC with a 1MHz crystal.? the internal cycle execution time will be 1MHz/4 ie: == 4uSec/execution cycle.

I dont program in 'C', but the idea is the same in assembler.
You count the total program execution cycles [bytes] around the loop, this gives the total delay period.

Do this help.?
__________________
Eric
"Good enough is Perfect"

PIC tutorials:
Gramo's: www.digital-diy.net/
Bill's: www.blueroomelectronics.com/

Last edited by ericgibbs; 22nd May 2008 at 09:12 AM.
ericgibbs is online now  
Old 22nd May 2008, 09:53 AM   (permalink)
Default

You can run it in the simulator and use the stop watch to time it. Alternatively, you could include the delay routines supplied by Microchip.

Mike.
Pommie is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
c++ sleep function danielsmusic Chit-Chat 4 11th August 2008 10:55 AM
Using ADC function of pic16f877 mesamune80 Robotics Chat 14 15th February 2008 05:24 AM
Cool function Analog Chit-Chat 7 5th March 2007 02:27 AM
Function Generator question: What is GATE function? Cifrocco General Electronics Chat 8 14th April 2005 04:11 AM
Function Generator Anonymous Electronic Projects Design/Ideas/Reviews 2 28th October 2002 07:43 PM



All times are GMT. The time now is 09:17 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker