Shop OBEX P1 Docs P2 Docs Learn Events
How to Pause the process for 45 minutes? — Parallax Forums

How to Pause the process for 45 minutes?

CamaneyCamaney Posts: 16
edited 2009-06-14 20:54 in General Discussion
I am using the latest version of SX/B with SX28 chips.

I am trying to create an alert of blinking LEDs every 45 minutes, but so far I haven't been able to PAUSE for that amount of time.

I am using the following comand:
PAUSE 2700000
based on 1000 = one second.

Can someone tell me what I am doing wrong?
Thanks.

Comments

  • RS_JimRS_Jim Posts: 1,771
    edited 2009-06-11 05:01
    I believe that pause only accepts an argument of 65535.· Try using the Sub Delay_MS which encapsulates pause into a single subroutine.· Each call to Delay_MS can be a word representing a minuite for example Delay_MS 60000 would delay 60 seconds. A for next loop of 0 to 45 calls to Delay_MS 60000 would net you a 45 minute delay.

    RS_JIM
  • John R.John R. Posts: 1,376
    edited 2009-06-11 14:36
    Keep in mind that anything over "seconds" is an eternity in time, at least for the microprocessor. Normally, you would not have a processor just "waiting" for that long, but it would often times either be doing something else, or waiting (looking) for "override" inputs.

    An alternative to the loops RS Jim mentioned, another way to do this is to set a variable to the current clock count + the number of ticks you need for your "delay" time. Then have a loop that does your other stuff, or checks for inputs, etc., and part of that loop does a compare to see if the count is >= your setting. If it is, do your thing, if not, repeat the loop.

    I'm not an expert by any means, but you may also be able to look at the "sleep" function. Is there a way you could externally trigger a "wake up call" (maybe a 555 timer).

    Another possibility is to incorporate a real time clock (RTC), and do a comparison based on the actual time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John R.
    Click here to see my Nomad Build Log
  • BeanBean Posts: 8,129
    edited 2009-06-11 16:41
    Camaney,
    If you want to minimize power. Then you could use SLEEP with a WATCHDOG wakeup.

    Basically, set the watchdog to it's maximum timeout (about 2.3 Seconds). When the program wakes-up it will increament a counter. When the counter reaches 1174 (45*60 / 2.3), then blink the LEDs.

    DEVICE SX28, TURBO, STACKX, OPTIONX, OSC4MHZ, WATCHDOG
    ' NOTE you will not be able to debug this program because of the watchdog
     
    IRC_CAL IRC_4MHZ
     
    FREQ 4_000_000
     
    ' Enable pullups for unused I/O pins
    UnusedRA PIN RA INPUT PULLUP
    UnusedRB PIN RB INPUT PULLUP
    UnusedRC PIN RC INPUT PULLUP
     
    LED      PIN RB.0
     
    WAITCNT  CON 10 ' in 2.3Sec units, 1174 = 45 MINUTES
     
    cntr     VAR WORD
     
    Program Start NOSTARTUP ' NOSTARTUP is important so the counter doesn't get zeroed
     
    Start:
      IF _TO = 1 THEN
        ' No timeout, must be power-up
        OPTION = %11111111 ' watchdog prescaler set to 1:128 or about 2.3sec
        cntr = 0
        SLEEP
      ENDIF
      INC cntr
      IF cntr >= WAITCNT THEN
        OUTPUT LED
        FOR cntr = 1 TO 10
          RESETWDT
          LED = 1
          PAUSE 100
          LED = 0
          PAUSE 100
        NEXT
        cntr = 0
      ENDIF
      SLEEP  
    END
    
    


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...



    Post Edited (Bean (Hitt Consulting)) : 6/11/2009 5:22:51 PM GMT
  • CamaneyCamaney Posts: 16
    edited 2009-06-12 01:18
    Thanks all of you guys, but since I want this to be run off batteries I am leaning towards saving power.

    Bean, I tried your code but when I run it tells me that _TO is not defined.

    Any thoughts?

    Thanks again.
  • BeanBean Posts: 8,129
    edited 2009-06-12 01:56
    Camaney,
    · Make sure you have the latest version of the compiler.
    · You can get it from here http://forums.parallax.com/showthread.php?p=780347
    · Download the zip file, extract the files and copy them to C:\Program Files\Parallax Inc\SX-Key v3.2.92\Compilers\SXB

    · Overwrite the existing files when asked.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...



    Post Edited (Bean (Hitt Consulting)) : 6/12/2009 2:01:27 AM GMT
  • CamaneyCamaney Posts: 16
    edited 2009-06-13 00:16
    It's working, thanks.

    For the sake of practicing and learning I also Tried RS_Jim suggestion and it did worked too. Thanks.
    I also wanted to try John R. suggestion but I am not that knowledgeable yet; '...set a variable to the current clock count + the number of ticks you need for your "delay" time.'

    Thank you all for your input, as I progress in my learning curve I am sure I will ask you again for help.
  • BeanBean Posts: 8,129
    edited 2009-06-13 01:38
    If you want to save battery life, you could run the SX as slow as 32Khz and/or from a lower voltage.

    This will NOT change the watchdog timeout because the watchdog runs from it's own oscillator.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    There is a fine line between arrogance and confidence. Make sure you don't cross it...

    ·
  • CamaneyCamaney Posts: 16
    edited 2009-06-14 12:46
    Thanks for tip Bean, I made the change.
  • CamaneyCamaney Posts: 16
    edited 2009-06-14 15:41
    I am still playing with this little project, now I am researching on how I can use potentiometer, read its value and use it for my WaitTimer, this way I can set up the alarm to wait for 15', 30, 45' or 60 minutes.
    Ideas are welcome.
    Thanks.
  • 5ms?5ms? Posts: 21
    edited 2009-06-14 20:54
    idea.gif What about this.
    
    ' -------------------------------------------------------------------------
    ' Variables
    ' -------------------------------------------------------------------------
    MilliSeconds                VAR    Byte
    HundredthsOfSeconds   VAR    Byte
    TenthsOfSeconds            VAR    Byte
    Seconds                     VAR    Byte
    Minute                       VAR    Byte
    Hours                            VAR    Byte
    Days                         VAR    Byte
    Weeks                       VAR    Byte
    
    
     -------------------------------------------------------------------------
    ' Subroutine Declarations
    ' -------------------------------------------------------------------------
    
    Update_Clock SUB 0
    
    ' -------------------------------------------------------------------------
    ' Program Code
    ' -------------------------------------------------------------------------
    
    Start:
      ' initialization code here
    
    Main:
      Update_Clock
     GOTO Main
    
    
    
    Update_Clock:
      INC MilliSeconds
      IF MilliSeconds = 10 THEN
         MilliSeconds = 0
         INC HundredthsOfSeconds
        IF HundredthsOfSeconds = 10 THEN
           HundredthsOfSeconds = 0
           INC TenthsOfSeconds
          IF TenthsOfSeconds = 10 THEN
             TenthsOfSeconds = 0
             INC Seconds
            IF Seconds = 61 THEN
               Seconds  = 0
               INC Minute
              IF Minute = 61 THEN
                 Minute = 0
                 INC Hours
                IF Hours = 25 THEN    
                   Hours = 1
                   INC Days
                  IF Days = 8 THEN    
                     Days = 0
                     INC Weeks
                   IF Weeks = 52 THEN
                      Weeks = 0     
                  ENDIF            
                 ENDIF        
               ENDIF        
              ENDIF
            ENDIF
          ENDIF 
        ENDIF 
      ENDIF
       RETURN
    
    


    Something to think about anyway. rolleyes.gif

    Hope it helps.
Sign In or Register to comment.