Shop OBEX P1 Docs P2 Docs Learn Events
making an action every xx seconds — Parallax Forums

making an action every xx seconds

celestino_galancelestino_galan Posts: 44
edited 2005-08-09 18:03 in BASIC Stamp
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.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-09 13:57
    Hello,

    ·· 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
  • celestino_galancelestino_galan Posts: 44
    edited 2005-08-09 14:41
    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?
    Thanks
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-08-09 14:52
    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.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 8/9/2005 3:00:40 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-08-09 15:02
    Hello,

    ·· 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.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-08-09 16:23
    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.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-08-09 17:07
    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>

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 8/9/2005 5:13:49 PM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-08-09 17:55
    Paul -

    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
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-08-09 18:03
    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.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
Sign In or Register to comment.