View Full Version : making an action every xx seconds
08-09-2005, 09:26 PM
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.
08-09-2005, 09:57 PM
ˇˇ 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.
Parallax Tech Support
08-09-2005, 10:41 PM
Yes but is there a way to "calibrate" this counter?
Is the counter allways counting at the same time or depends on the other tasks?
08-09-2005, 10:52 PM
The basic stamp is single threaded, meaning it can only do one thing at a time. Therefore while it its doing other things it cannot update the counter. Thats why Chris put the "if your timing doesn't need to be precise" caveat to his statement. If it is critical you need to add an external circuit to do the timing for you, but for your applicationˇyou don't really need the precision.ˇIs it absolutley critical to measure the temp exactly 1 minute apart, wouldn't you still get valid information if it is sampled every 59 or 61 seconds?
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.
Post Edited (Paul Baker) : 8/9/2005 3:00:40 PM GMT
08-09-2005, 11:02 PM
ˇˇ 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:
Counter = Counter + 1
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.
Parallax Tech Support
08-10-2005, 12:23 AM
You might try this: http://www.rhombus-tek.com/co-processors.html
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.
08-10-2005, 01:07 AM
Fascinating co-processor allan, thier mention of "patent pending" caused me to look for thier application to get more detail of how they accomplish the task (detail on the site is a bit lacking, deferring to "buy it and we'll include a CD", though for $12 its not that much of a risk). Unfortunately I could find no record of such an application so either they just applied for one, the application isn't assigned to Rhombus or the application is under a "do not publish" order. But none of this matters really, as long as the product performs as they advertise, it is worth the money.
<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>
Post Edited (Paul Baker) : 8/9/2005 5:13:49 PM GMT
08-10-2005, 01:55 AM
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.
08-10-2005, 02:03 AM
No help, its not a big deal, it is likely they case was filed in the last 18 months, in which case the application hasn't been published yet. Searching unpublished applications is a difficult task, not worth the effort for curiousity sake.