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.

help in creating a loop depend on the time you want.

Status
Not open for further replies.

chwoei

Newbie level 6
Joined
Dec 14, 2006
Messages
12
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,367
hi,

i am using a c programming, just want to ask if anyone knows how to create a loop like while(), for() or any others than have precise timing.
i want something like a loop that goes for 5 sec to check the condition. after 5 secs turn it off.


cheers,

CHWOEI
 


hi
generally accurate timing is exact for assembly only.
u can ues jump command to make a loop in mostly all microcontroller in that sense:
loop :
x++
if x=.... jump to...
else ....
( of course that is not a code!!!!!!!!!!)
if the loop doesnt give enough time make another loop inside it.
u could put the condition whereever u like
 

if you meant that you want to check a condition for 5 sec.

you can use delay for that after you check the condition, after that delay it. For example delay for 50ms and loop it for 100 times. (it won't be exact 5 sec but around 5 sec).

If you are using microcontroler, U can use timer interrupt and example:set it for around 50 ms. Your program will goes to timer interrupt procedure every 50 ms. And then you can make a variable as a flag that it haven't looping for 100 times (you can check your condition in timer procedures). After it's 100 times you just turn off timer interupt.
 

I agree if a timer is available use it with some counter for exact timing. If not then I suggest that you write the timing portion in assembly and call it from the C code. This will give you more accurate timing than the C code only but still not 100% due to the compiler overhead which is usually hidden from the coder.

Cheers
Slayer
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top