Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help with a delay function

Status
Not open for further replies.

t.man

New Member
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,
 
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.?
 
Last edited:
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.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top