Want a loop to run for a certain amount of time. What to do?
SeanDF
Posts: 12
Hi Everyone,
New to the forum, and I am currently working on a project for a industrial application. The program should be very easy to write, and so far I am having success. I started using the Basic Stamp 2, as I do not know C or Assembly language. My knowledge of BASIC goes back to the Commodore 64 days. However, I did not spend much time messing with those machines, as I was 13 at the time. But I did remember it being pretty easy to learn, thus I selected the Basic Stamp for this industrial application.
I'll go ahead and list my simple code that I wrote. I'm using the BOE as of now, and my LED's are all working properly to indicate the desired functions.
' {$STAMP BS2}
' {$PBASIC 2.0}
TEST:
PAUSE 3000
INPUT 14
IF IN14 = 1 THEN IGNITION
IF IN14 = 0 THEN FAILED
IGNITION:
INPUT 14
IF IN14 = 0 THEN FLAME_ON
LOW 12
HIGH 13
PAUSE 2000
LOW 13
PAUSE 100
GOTO IGNITION
FAILED:
HIGH 12
HIGH 13
PAUSE 200
LOW 13
PAUSE 200
GOTO FAILED
FLAME_ON:
INPUT 14
IF IN14 = 1 THEN FAILED
IF IN14 = 0 THEN FLAME_ON
LOW 13
GOTO FLAME_ON
Now, what I'm looking for here is to make the IGNITION routine loop for 20 seconds, then GOTO FAILED, unless of course pin 14 goes to 0, whereas the program will go to the FLAME_ON·routine. Maybe I need a counter in that part of the program.? I'm not sure.·I have checked around for various examples of how to do this in the Syntax manual. I really cant find a way to make it possible. Also, I'm having another problem as well. If the program makes it to the FLAME_ON routine, and pin 14 goes to 1, after I make pin 14 0 again, it will delay before going to FAILED. I'm looking at almost 5 seconds of delay before going to FAILED. Why is that?
Thanks guys, and I really look forward
New to the forum, and I am currently working on a project for a industrial application. The program should be very easy to write, and so far I am having success. I started using the Basic Stamp 2, as I do not know C or Assembly language. My knowledge of BASIC goes back to the Commodore 64 days. However, I did not spend much time messing with those machines, as I was 13 at the time. But I did remember it being pretty easy to learn, thus I selected the Basic Stamp for this industrial application.
I'll go ahead and list my simple code that I wrote. I'm using the BOE as of now, and my LED's are all working properly to indicate the desired functions.
' {$STAMP BS2}
' {$PBASIC 2.0}
TEST:
PAUSE 3000
INPUT 14
IF IN14 = 1 THEN IGNITION
IF IN14 = 0 THEN FAILED
IGNITION:
INPUT 14
IF IN14 = 0 THEN FLAME_ON
LOW 12
HIGH 13
PAUSE 2000
LOW 13
PAUSE 100
GOTO IGNITION
FAILED:
HIGH 12
HIGH 13
PAUSE 200
LOW 13
PAUSE 200
GOTO FAILED
FLAME_ON:
INPUT 14
IF IN14 = 1 THEN FAILED
IF IN14 = 0 THEN FLAME_ON
LOW 13
GOTO FLAME_ON
Now, what I'm looking for here is to make the IGNITION routine loop for 20 seconds, then GOTO FAILED, unless of course pin 14 goes to 0, whereas the program will go to the FLAME_ON·routine. Maybe I need a counter in that part of the program.? I'm not sure.·I have checked around for various examples of how to do this in the Syntax manual. I really cant find a way to make it possible. Also, I'm having another problem as well. If the program makes it to the FLAME_ON routine, and pin 14 goes to 1, after I make pin 14 0 again, it will delay before going to FAILED. I'm looking at almost 5 seconds of delay before going to FAILED. Why is that?
Thanks guys, and I really look forward
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
I then added FOR I = 1 TO 10 at the beginning of the routine, and·replaced·GOTO IGNITION with next, and it works perfectly.
Thanks for your help.
Something has to have changed. Show us the code as it is now.
Most likely its to do with what happens in your loop while waiting for for the 21 seconds to elapse. Because the Stamp doesn't do more than one thing at a time, you may be expecting a particular action which is triggered by something that is not being checked.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
Heres the code as it is now.
' {$STAMP BS2pe}
' {$PBASIC 2.0}
I VAR Byte
Test:
PAUSE 3000
INPUT 14
IF IN14 = 1 THEN IGNITION
IF IN14 = 0 THEN FAILED
IGNITION:
FOR I = 1 TO 10
INPUT 14
IF IN14 = 0 THEN FLAME_ON
LOW 12
HIGH 13
PAUSE 2000
LOW 13
PAUSE 100
NEXT
FAILED:
HIGH 12
HIGH 13
PAUSE 175
LOW 13
PAUSE 175
GOTO FAILED
FLAME_ON:
INPUT 14
IF IN14 = 1 THEN FAILED
IF IN14 = 0 THEN FLAME_ON
LOW 13
GOTO FLAME_ON
Maybe ther's a simpler or better way to write this. I'm just begining to work with the STAMP, and I'm sure I have alot of learning to do. Thanks for your help!
·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Instead of using GOTO's (most developers HATE them as it's too hard to follow program flow) perhaps in FAIL and FLAME_ON you might put "RETURN" at the end and use a GOSUB instead of a GOTO. This would then return to the next line of code in your program and would help prevent it from locking up.
If you can please explain what pins 12, 13 and 14 are, I'll be able to help you make more sense of it as I've had to make assumptions in the code.
Also, why were you using 2.0 PBASIC syntax instead of 2.5? Is there any reason for this as I run a BS2pe using 2.5 syntax fine?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Flying is simple. You just throw yourself at the ground and miss.
"I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image."
Stephen Hawking
Post Edited (Morrolan) : 7/15/2008 8:12:41 AM GMT
·· Attached is·what I got out of your original program. I think it confirms the previous post about its execution.
·· Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
Post Edited (stamptrol) : 7/14/2008 5:04:08 PM GMT
I have read alot about polling, but this doesnt seem to give me the option of the 3 seconds.
And, now i thought about this a lil bit further, after thinking that the STAMP can only process one command at a time, I came up with this idea. Just not sure how to code it.
this would be ideal:
power on
test pin 0
if pin 0 = 1 store·a constant·memory
pause 100
(repeat the "if - pause" commands 29 more times :30 x 100 = 3000, which gives the 3 second cycle)
then look to the memory and if the value stored equals the value that was triggered by voltage on pin 0 in the test cycle, goto another routine, or if the stored value doesnt equate to a value that would be stored by a voltage on pin 0, then goto another routine.
I hope this is making some sense of what im trying to do. Not sure at this point if this out of the STAMPS functionality or not. Im going to use a BS2PX....
Any ideas anyone?
Post Edited (SeanDF) : 7/16/2008 2:37:20 AM GMT
' {$PBASIC 2.5}
A CON 1
B CON 0
C CON 1
D CON 0
STATUS VAR Byte
TEMP VAR Byte
TIME VAR Byte
DEBUG "TESTING PILOT STATUS", CR
INPUT 0
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100 '1 Second
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100 '2 Seconds
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100
IF IN0 = 1 THEN PUT 25, A
PAUSE 100 '3 Seconds
GET 25, TEMP 'Access Scratch Pad RAM
DEBUG DEC TEMP, CR
IF TEMP = a THEN FAILED 'Determine RAM Value and GOTO Correct Routine
IGNITION:
HIGH 3 'Ignition Relay On
HIGH 2 'Gas Relay On
FOR TIME = 1 TO 10 'Time for 10 Cycles of 2.1 second per Cycle
GOSUB FLAME_DET
IF STATUS = C THEN FLAME_OK
DEBUG "SPARK.", CR
HIGH 1 'LED Blink Loop
PAUSE 100
LOW 1
PAUSE 2000
NEXT
FAILED:
DEBUG "PILOT HAS FAILED. RESTART REQUIRED.", CR
LOW 3
LOW 2
HIGH 1
PAUSE 175
LOW 1
PAUSE 175
GOTO FAILED
FLAME_DET:
IF IN0 = 1 THEN PUT 27, C
IF IN0 = 0 THEN PUT 27, D
GET 27, STATUS
RETURN
FLAME_OK:
DEBUG "FLAME DETECTED AT PILOT.", CR
HIGH 1
HIGH 2
GOTO IGNITION
Well, here is the latest program. This one seems to work alot better, although I'm still having a few quircks that I'm having. One is electronic I'm sure, as if my PIN 0 goes high, but never returns to LOW which it looks for (i.e., the PIN floats after going high), then the program might stall for a few seconds. I will be trying to fix this today.
My next issue, which I'm not sure is program related, or just a quirck in the STAMP is on power on. Sometimes, the STAMP goes right to the first instruction, and works properly. And sometimes when reset, or cycled on and off, it will seem like it jumps right to FAIL routine. Other times, it won't do anything.
http://www.parallax.com/Portals/0/Downloads/docs/books/edu/Wamv2_2.pdf
Do you have your input hook up this way you do not need the switch
I would DEBUG your inputs to see if they are working the way you want
them·to
Ones the input are working right then you can·remove the DEBUG statements
INPUT 7······························ ' Make P7 an input
· DEBUG "State of P7: ",
······· BIN1 IN7, CR
I am using this my self in a project that i am working on right now and this is
how I trouble shoot what is not working
I hope this helps you
·[font=Arial,Italic size=1][font=Arial,Italic size=1] [/font][/font]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 7/16/2008 12:50:58 PM GMT