how make loop for specific time?

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
hertz89
Posts: 19
Joined: Sat Mar 22, 2014 6:30 pm
Been thanked: 3 times
Contact:

how make loop for specific time?

Post by hertz89 »

hi
how make loop for specific time? i am using pic 16f627 with 4MHZ

thanks

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: how make loop for specific time?

Post by medelec35 »

Hi hertz89,
You not stated how long you would like the loop to last for, so I have created a loop to last for 500ms.

There are several ways.
Here are two that I can think off:

One way is:
Timed loop1.png
Loop lasts for: 5ms * 100 = 500ms
(6.7 KiB) Downloaded 2493 times
Another is to use a timer interrupt.
Within the loop you can get it to exit only when a variable say TimerFlag is set to 1.
Just before the start of the loop, set timer TimerFlag to 0.
Allow the timer to count specific time period, then when this time period has elapsed then set TimerFlag to 1.
Then loop will automatically exit.

If you get stuck then if you post your flowchart we can see if we can help you out.

Martin
Martin

hertz89
Posts: 19
Joined: Sat Mar 22, 2014 6:30 pm
Been thanked: 3 times
Contact:

Re: how make loop for specific time?

Post by hertz89 »

thanks medelec35 ....good solution

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: how make loop for specific time?

Post by medelec35 »

Hi hertz89,
You're welcome.
So long as the solution helps.
Out of curiosity did you have a particular time in mind?

Martin
Martin

Post Reply