making an action every xx seconds
celestino_galan
Posts: 44
How can I program to make an action avary xx seconds.
I mean, I am making a robot and "he" is doing a lot of things, such as measure distance with 2 sonars in order to avoid obstacles,· it has 2 bumper sensors... etc. And I would "him" to do something (measure temperature...) every 1 minute, not constanstly (sorry for the word), but without disturbing the other tasks.
Basic stamp hasn't a clock, I think, so what can I do?
Could anybody help me?
Thank you very much.
I mean, I am making a robot and "he" is doing a lot of things, such as measure distance with 2 sonars in order to avoid obstacles,· it has 2 bumper sensors... etc. And I would "him" to do something (measure temperature...) every 1 minute, not constanstly (sorry for the word), but without disturbing the other tasks.
Basic stamp hasn't a clock, I think, so what can I do?
Could anybody help me?
Thank you very much.
Comments
·· You could use an external clock, such as the DS1302, and compare the current time with the last time you executed the command.· Otherwise, if your timing doesn't need to be precise, you could simply run a background counter and do the routine when the counter rolls over.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Is the counter allways counting at the same time or depends on the other tasks?
Thanks
Also, even with an external timer you are not gaurenteed to obtain the temperature exactly every 60 seconds. The stamp does not have interrupts, therefore you must periodically check to see if the external timer has expired, adding this overhead will cause the timing to be off as well.
The main reason for going with an external timer is not having to estimate the time between counter increments and calaculating how many·counter ticks happen for 1 minute to elapse.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 8/9/2005 3:00:40 PM GMT
·· I will clarify my counter concept for you.· Say you have a loop doing all the things you want done, such as scanning sensors, updating displays, etc.· In your loop you may have a line such as:
Now, Counter is most likely a WORD variable, and could be called in a subroutine to increase the count range, but for simplicity we'll stick with one level.· Each time the counter increases, you check to see if it is 0.· When it reaches 0 you can execute your periodic task.
· As for calibrating it.· That depends on the length of time of the delay, as well as how many iterations of the loop are executed every second.· As I said, you may need a nested counter more than one level to increase duration.· But once you know the information you can reset the counter variable to a specific value prior to re-entering your loop to control the approximate time.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
For $12 or so, the first co-processor listed will generate a real-time clock signal -- 50 mSec works well. This will tie your program to the clock, with some simple PBasic multi-tasking code. Once you know that each loop through your program is guaranteed to take 50 mSec, you can do all kinds of definite real-time actions -- like counting up 50 mSec intervals to know when 1 minute has happened.
<EDIT> Nevermind, found what I was looking for on thier site, just had to dig a little deeper than I expected. Sample BS2 programs are under the application notes, not under product detail as I expected </EDIT>
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 8/9/2005 5:13:49 PM GMT
If you feel like doing your search again you can try "David Lawrence" in lieu of Rhombus-Tek as that's who owns the domain name. Just a thought.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10