Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

1 sec delay in embedded c

Status
Not open for further replies.

sujeethaa

Junior Member level 3
Junior Member level 3
Joined
Nov 18, 2012
Messages
26
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
bangalore
Activity points
1,464
hi all

could any one pls tell me the coding to calculate 1 sec delay in embedded c for 8051 controller without using timer!!!
i.e using for loop and pls explain it

thanks in advance
 

using one of the timer produce delay of 50m seconds and repeat that for 20 times
 

the idea is use interrupt timer for fixed period and then find out integral multiple of 1 sec by fixed time.... use loop to count for multiple factor will solve your problem
 

the idea is use interrupt timer for fixed period and then find out integral multiple of 1 sec by fixed time.... use loop to count for multiple factor will solve your problem

for(i=0;i<1275;i++);



whether this will give 1ms delay!!!

so that i can repeat it for 1000 times

thanks in advance

-----
sujeethaa
 

if you are using only this code in the polling mode and use proper constant and your crystal is 12 Mhz....but there is a catch as in case of micro-controller like 8051 the instruction clock is 1/12 of clock frequency .....mostly 1 Mhz in case of 12 Mhz.... so better way to exact delay better to use interrupt timer....

Good Luck,

Milind
 

if you are using only this code in the polling mode and use proper constant and your crystal is 12 Mhz....but there is a catch as in case of micro-controller like 8051 the instruction clock is 1/12 of clock frequency .....mostly 1 Mhz in case of 12 Mhz.... so better way to exact delay better to use interrupt timer....

Good Luck,

Milind

I m using 8051 with 11.0859MHz frequency!!!
 

as jjeevan said it is possible but in polling mode please keep the loop for 1000 in case of 11.92 Mhz crystal to get 1ms delay i.e. for(i=0;i<1000;i++);

Good Luck
 
hi...
with 11.085MHz your instruction clock would be 1.085microsecond long. Take this into consideration and use a loop for generating the 1 sec delay. u will also have to consider the time taken by the increment/decrement instructions while setting the count for the loop.
hope that helps...

cheers...,
Vijay
 
hi,
the for loop shown above will work but during conversion into assembly, the code will split into different ASM instructions having different execution/machine cycles. so the time dalay may not be exact.
if u are using keil, u can view the assembly code of FOR loop. from that u can calculate the time taken to execute one complete FOR loop. then u can multiply that delay(in for loop) to get 1 milisecond.with this delay will be more accurate. but the best way is to use software interrupt OR timer.
guys, correct me if something is wrong.
 

thank u all
!!!


I will try in both the methods and get u back!!

thanks for your support
 

Use your compiler to measure the time the loop takes. That way, you can accurately measure the time your delay routine takes, and adjust it as required.

Also, check your compiler documentation/manual. It should provide library functions for generating delays. eg in mikroC, you have the delay_ms function. So, to generate a 1s delay, all you'd need would be:
Code:
delay_ms(1000);

Hope this helps.
Tahmid.
 

Use your compiler to measure the time the loop takes. That way, you can accurately measure the time your delay routine takes, and adjust it as required.

Also, check your compiler documentation/manual. It should provide library functions for generating delays. eg in mikroC, you have the delay_ms function. So, to generate a 1s delay, all you'd need would be:
Code:
delay_ms(1000);

Hope this helps.
Tahmid.

hi Tahmid

i m using Keil c compiler .. it dnt have any such library functions
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top