Multi minute delay or counter?
Cismontguy
Posts: 10
Hello, I am just getting back into the Basic Stamp programming after 10 year of being away from programing. I want to create a routine that will turn a relay on for 10 minutes, off for 5 minutes. I was using a counter (sample for 2000 ms) but am looking for a better method of time interval control? Can you guys point me in the right direction for some instructions on delays? I do not need anyone to write the code for me. I am just trying to learn again the options available for delay?
Thanks,
Cismounguy
'Robotics with the Boe-Bot - Relaycontroller.bs2
'10 minute on 5 minute off timer.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Indicates that the program is running"
counter VAR Word
FREQOUT 4, 2000, 3000 ' signal that the program is running.
DO
GOSUB Running
GOSUB N_running
LOOP
Running:
FOR counter = 1 TO 2000
HIGH 13 ' drives pin 13 high
DEBUG ? counter ' displays counter .
NEXT
RETURN
N_running:
FOR counter = 1 TO 2000
LOW 13 ' drives pin 13 high
DEBUG ? counter ' displays counter .
NEXT
RETURN
Thanks,
Cismounguy
'Robotics with the Boe-Bot - Relaycontroller.bs2
'10 minute on 5 minute off timer.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Indicates that the program is running"
counter VAR Word
FREQOUT 4, 2000, 3000 ' signal that the program is running.
DO
GOSUB Running
GOSUB N_running
LOOP
Running:
FOR counter = 1 TO 2000
HIGH 13 ' drives pin 13 high
DEBUG ? counter ' displays counter .
NEXT
RETURN
N_running:
FOR counter = 1 TO 2000
LOW 13 ' drives pin 13 high
DEBUG ? counter ' displays counter .
NEXT
RETURN
Comments
' {$STAMP BS2}
' {$PBASIC 2.5}
minutes VAR Byte
seconds VAR Byte
DEBUG "Program is running"
FREQOUT 4, 2000, 3000 ' signal that program is running
do ' start forever loop
high 14 ' relay on
for minutes=1 to 10
for seconds=1 to 60
pause 1000' pause 1 sec
next
next
low 14' relay off
for minutes=1 to 5
for seconds=1 to 60
pause 1000' pause 1 sec
next
next
loop ' repeat forever
(fixed listing)
If seconds is a word, you can create very long delays.
Back in your main program you count how many times you use the 100 ms loop. That way, your main loop doesn't have to sit waiting for a long PAUSE to expire before seeing that something else needs doing.
Cherers,
http://laspace.lsu.edu/aces/Document/Parallax%20Docs/Industrial%20Control.pdf
This is where the Propeller shines. Need a 100ms main loop? No problem. This loop will always run 100ms -- as long as you loop code takes less than 100ms (that's the only rule).
You see, Cismontguy, the Propeller is really fun and doesn't take much more effort than the BS2.
For the record, I'm not trying to put you off the BS2 -- when I worked for Parallax I wrote a book called StampWorks. That is to say, I love the BS2 as well.
CismontGuy
http://www.parallax.com/sites/default/files/downloads/122-28176-Process-Control-Text-v1.0.pdf
Here is Jon's StampWorks text - Experiment 27 is on controlling a Stepper Motor
http://www.parallax.com/sites/default/files/downloads/27297-StampWorks-Manual-v2.1.pdf
Cismontguy
'Robotics with the Boe-Bot - Relaycontroller.bs2
'10 minute on 3 minute off timer.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Indicates that the program is running"
minutes VAR Word
Seconds VAR Word
FREQOUT 4, 2000, 3000 ' signals that the program is running.
DO 'start forever loop
LOW 10 'relay on
HIGH 12 ' Green LED on
LOW 13 'red LED off
DEBUG "Power ON"
FOR minutes = 1 TO 10
FOR seconds = 1 TO 60
PAUSE 1000 ' pause 1 sec
NEXT
NEXT
HIGH 10 'relay on
LOW 12 ' Gren LED on
HIGH 13 'Red LED on
DEBUG "Power OFF"
FOR minutes = 1 TO 3
FOR seconds = 1 TO 60
PAUSE 1000 ' pause 1 sec
NEXT
NEXT
LOOP 'repeat forever
There is also a SLEEP command which can be used for long delays in units of seconds. It is quite accurate for long delays. It does have a drawback though, that the pin that is supposed to be a constant output actually turns into an input briefly every couple of seconds. The LEDs would appear to blink every 2.3 seconds. Your external relay control circuit would need a capacitor or something like that to carry it on or off through those glitches.