Shop OBEX P1 Docs P2 Docs Learn Events
Pause longer than 65535 — Parallax Forums

Pause longer than 65535

StevezilaStevezila Posts: 35
edited 2009-09-30 16:05 in BASIC Stamp
I have an application in which·I want to take a sample every twenty minutes. the problem is that when I try to pause for that long I get the message that pause is longer than 16 bits. Pause is only 16 bits or 0-65535. Sleep is the same 0-65535 aside for entering twenty 60 sec. pause cmds how can I get· a BS2 to excute only once every twenty minutes.


Thanks in advance for your replies

Steven

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2009-09-22 19:21
    Just set up a loop to execute the pause command repeatedly to give the required timing.

    Or, make a subroutine of say 10 seconds delay. From the main program, call it repeatedly to get the total time needed. This has the added benefit of letting the processor do something else each time it comes back from the subroutine. Otherwise, the Stamp is "blind" during the long PAUSE.

    Cheers,

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-09-22 20:26
    SLEEP is in units of seconds, not milliseconds, so SLEEP 1200 gives you 20 minutes. Long time intervals like that can be pretty accurate, because the Stamp recalibrates its RC sleep timer against the resonator time base. SLEEP 64800 gives 18 hours. If you need it to be very accurate though with respect to clock time, you will need an external timer or RCT chip.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-09-22 20:31
    Neat. What does "recalibrates its RC sleep timer against the resonator time base" mean? Because the BS2 only HAS a resonator time-base. Unless there's some "RC sleep timer" I'm not aware of?

    And in any event, to 'recalibrate' something means you have to compare it to some 'standard', right? Thus your suggestion for an external RCT chip. I'm just curious what you meant by the quote above.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-09-22 20:57
    During execution of SLEEP and NAP the Stamp makes use of the PIC or SX chip's watchdog timer, which is an RC timer that runs independent of the resonator. The SLEEP command sets the watchdog timer for ~2 second intervals, while NAP uses shorter intervals (15, 30, 60, 125, 250, 500, 1000, 2000 milliseconds approxately). Longer SLEEP intervals round to seconds, and the Stamp calibrates the watchdog timer against the resonator. Here is what the manual says (SLEEP-command reference):

    To ensure accuracy of SLEEP intervals, the BASIC Stamp periodically 
    compares the watchdog timer to the more-accurate resonator time base. It 
    calculates a correction factor that it uses during SLEEP. As a result, longer 
    SLEEP intervals are accurate to approximately ±1 percent.
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • dw101sdw101s Posts: 27
    edited 2009-09-22 21:33
    stamptrol had the right idea. You could set up a program like this:

    time var Word

    Do
    "Take measurement"
    For time = 0 to 20
    Pause 60000 ' one minute
    Next
    Loop
  • bhendrixbhendrix Posts: 9
    edited 2009-09-24 03:39
    DW101s, I was just going to display that code! great minds huh LOL
  • MichelBMichelB Posts: 154
    edited 2009-09-30 13:05
    time var Word

    Do
    "Take measurement"
    For time = 0 to 20
    Pause 60000 ' one minute
    Next
    Loop
    I modified your code as follows:

    time·· VAR·· Word

    DO
    · FOR time = 0 TO 20
    · PAUSE 60000·· ' One minute
    · HIGH 15········· ' LED
    · PAUSE 1000
    · LOW 15
    · NEXT
    LOOP

    I noticed that the pause is always one minute instead of 20 minutes.
    where is my error?
    ·
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-09-30 13:45
    The Pause IS one minute -- that's why you pile up 20 of them using the FOR loop, to make 20 minutes.

    It's also possible lighting the LED is resetting your BS2, if you have a low battery, or your LED is actually a lamp.

    And thanks for the update, Tracy, I was not aware the BS2 used an RC circuit for the watch-dog timer.· Fascinating.
  • MichelBMichelB Posts: 154
    edited 2009-09-30 14:11
    What I want (as the start of this thread) is that the LED lights 1 second every 20 minutes, or an other action every 20 minutes.
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-09-30 15:11
    Then you need to put the "NEXT" BEFORE the "High 15"
  • MichelBMichelB Posts: 154
    edited 2009-09-30 15:56
    Yes dear allanlane5, now it runs. Thank you for the lesson I'm learner.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-09-30 16:05
    For the record, using SLEEP it would be done as follows:

    DO
      SLEEP (20 * 60 - 1)   ' 20*60-1 seconds
      HIGH 15          ' LED
      PAUSE 1000
      LOW 15
    LOOP
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.