Shop OBEX P1 Docs P2 Docs Learn Events
Time counter (20 hours) — Parallax Forums

Time counter (20 hours)

Pierre20Pierre20 Posts: 5
edited 2010-08-28 13:11 in BASIC Stamp
Hi

with BS2

How can I make a time counter of 20 hours.

Exemple: I want that when 1 is high for 20 hours, a buzzer turns on.

Thank you

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-27 19:44
    A PAUSE statement can produce maximum delays of about a minute. By putting a PAUSE in a loop, you can produce longer delays. Unfortunately, the Stamp can't do anything else while it is waiting although your program can test an I/O pin. 20 hours is 1200 minutes, so you could have a program somewhat like this:
    testInput PIN   1
    theBuzzer PIN   2
    minutes  VAR  WORD
    
    input testInput   ' make sure pin 1 is an input
    startOver:
    low theBuzzer   ' make sure pin 2 is a low output
    minutes = 0   ' start the 20 hour interval
    waitForMinute:
    pause 60000 ' wait for a minute to pass
    minutes = minutes + 1   ' keep count of minutes
    if testInput = 0 then goto startOver  ' if test input turns off before 20 hours, start over again
    if minutes < 1200 then goto waitForMinute
    high theBuzzer  ' 20 hours has gone by with test input always on
    pause 10000 ' let buzzer sound for 10 seconds
    goto startOver
    

    Note that this doesn't take care of the case where the test input goes off briefly while the Stamp is waiting for a minute to pass. You may need external hardware for that sort of situation. It's possible to use shorter "ticks", but you start running into accuracy problems.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2010-08-27 20:22
    Using precision components (R, C), you could make a long period oscillator with a 7555 and count its transitions. Might be advantageous to use SLEEP, too.

    [Something or other about some blasted thing from ehkss-mawss will likely follow.]

    Post Edit -- A super low-power CMOS crystal counter/divider, lots of ways to make it happen.
    ** I'm violating my policy of not making suggestions. I'm back-sliding, must... stop. **
  • Pierre20Pierre20 Posts: 5
    edited 2010-08-28 13:11
    PJ Allen wrote: »
    Using precision components (R, C), you could make a long period oscillator with a 7555 and count its transitions. Might be advantageous to use SLEEP, too.

    [Something or other about some blasted thing from ehkss-mawss will likely follow.]

    Post Edit -- A super low-power CMOS crystal counter/divider, lots of ways to make it happen.
    ** I'm violating my policy of not making suggestions. I'm back-sliding, must... stop. **

    Thank you for your help. I will try the both.
Sign In or Register to comment.