Creating Leak detection sensor code
I have been trying to write code to detect a leak on a sensor for a Micro project. I am trying to run a subroutine counter. While the counter is running I would like it to monitor a specific input on the BS2. When the counter is finished, I want to return to the main program. If the monitored input changes during the alloted time count, I want to enable a specific output. I am using 9 inputs and want to detect for each. Here is a sample of the code I have written so far but it is not functionning the way I want,
'
I/O Definitions
Reset PIN 5
'
Variables
eCount VAR Word
Target VAR Word
'
Constants
Target = 10
'
Main Program
Main:
DO
IF (IN15 = 1) THEN
Debug
ELSEIF (IN14 = 1) THEN
GOSUB LeakCounter
Debug
ELSEIF (IN13 = 1) THEN
Debug
ELSEIF(IN12 = 1) THEN
Debug
ELSEIF (IN11 = 1) THEN
Debug
ELSEIF (IN10 = 1) THEN
Debug
ELSEIF (IN9 = 1) THEN
Debug
ELSEIF (IN8 = 1) THEN
Debug
ELSEIF (IN7 = 1) THEN
Debug
ENDIF
LOOP '
'
'
'
'
Subroutine
LeakCounter:
eCount = eCount + 1
PAUSE 1000
FOR eCount = 1 TO 10
NEXT
IF eCount = 1-9 AND IN13 = 1 THEN GOSUB buzzer:
ENDIF
DEBUG ? eCount, CLREOL
IF eCount = target THEN
GOTO Main:
ELSEIF (IN14 = 0)THEN
GOSUB Buzzer
ENDIF
Buzzer:
FREQOUT 3, 1000, 1500
PAUSE 100
IF Reset = 1 THEN
GOSUB Buzzer
ELSEIF Reset = 0 THEN
GOTO Main
ENDIF
DEBUG CLS
Any comments or suggestions would be appreciated
'
I/O Definitions
Reset PIN 5
'
Variables
eCount VAR Word
Target VAR Word
'
Constants
Target = 10
'
Main Program
Main:
DO
IF (IN15 = 1) THEN
Debug
ELSEIF (IN14 = 1) THEN
GOSUB LeakCounter
Debug
ELSEIF (IN13 = 1) THEN
Debug
ELSEIF(IN12 = 1) THEN
Debug
ELSEIF (IN11 = 1) THEN
Debug
ELSEIF (IN10 = 1) THEN
Debug
ELSEIF (IN9 = 1) THEN
Debug
ELSEIF (IN8 = 1) THEN
Debug
ELSEIF (IN7 = 1) THEN
Debug
ENDIF
LOOP '
'
'
'
'
Subroutine
LeakCounter:
eCount = eCount + 1
PAUSE 1000
FOR eCount = 1 TO 10
NEXT
IF eCount = 1-9 AND IN13 = 1 THEN GOSUB buzzer:
ENDIF
DEBUG ? eCount, CLREOL
IF eCount = target THEN
GOTO Main:
ELSEIF (IN14 = 0)THEN
GOSUB Buzzer
ENDIF
Buzzer:
FREQOUT 3, 1000, 1500
PAUSE 100
IF Reset = 1 THEN
GOSUB Buzzer
ELSEIF Reset = 0 THEN
GOTO Main
ENDIF
DEBUG CLS
Any comments or suggestions would be appreciated
Comments
eCount = eCount + 1
PAUSE 1000
FOR eCount = 1 TO 10
NEXT
Try this
LeakCounter:
eCount = eCount + 1
FOR eCount = 1 TO 1000 ' and adj this value so that = about ten seconds that way your BS2 is sitll running in the loop
' This value can go to a value : as high as 65535
Where are you tell this to reset in your code
IF Reset = 1 THEN
GOSUB Buzzer
ELSEIF Reset = 0 THEN
one othe thing after your routine you need to have RETURN command
ELSEIF (IN14 = 0)THEN
GOSUB Buzzer
ENDIF
Buzzer:
FREQOUT 3, 1000, 1500
PAUSE 100
IF Reset = 1 THEN
GOSUB Buzzer
ELSEIF Reset = 0 THEN
GOTO Main
ENDIF
DEBUG CLS
you could do this
ELSEIF (IN14 = 0)THEN
FREQOUT 3, 1000, 1500
PAUSE 100
IF Reset = 1 THEN
GOSUB Buzzer
ELSEIF Reset = 0 THEN
GOTO Main
ENDIF
DEBUG CLS
If target really is a constant maybe better with: target CON 10 instead of wasting variables.
eCount = eCount + 1 should also be a waste here when the next thing is FOR eCount = 1 to 10 (or 1000). Why let target be bigger and then back to 1 again on the next line?
You need to put something after each DEBUGs too, but I guess you are aware of that.
Also remember to decide Stamp and kind of Pbasic on top of your program, like:
' {$STAMP BS2}
' {$PBASIC 2.5}
Maybe your Buzzer-subr should have been only like this:
Buzzer:
FREQOUT 3, 1000, 1500
PAUSE 100
RETURN
..and put the rest of the stuff in the main loop or in a higher level subroutine?
Just a thought, good luck with your project.