LuXo12
09-04-2008, 11:15 AM
Hi everyone
I am new to basic stamp so please be gentle.
Here is a description of what I am trying to do
I am currently working on a project where my basic tamp has to detect a status of another device (status of that device is determined by that device's led being on or off)
and based on the status the basic stamp should perform two functions.
The high signal is supplied to pin 0 by a relay (i used relay instead of a dip switch) that is controlled by a photo-resistor that is hooked up to the led it is monitoring.
The device my basic stamp is to monitor would be powered for close to 12hrs in day and off for another 12 hrs therefore the signal on pin 0 would be either high for 12 hrs or low for 12 hrs.
My program seems to be working fine for about first 2 hr after that it seems to be "restarting" and detects a low at pin 0 even though pin 0 is reeving high signal, only does that for about a minute as minute later (pin 0 detects high when pin 0 is receiving high)
This application has to be running 24/7 so my question is: Is it OK for pin 0 to be receiving a high impulse for about 12 hrs non-stop and then low for another 12 hrs?
OR
Is it does my code contain some sort of a syntax error that causes this behavior?
Here is my code
CounterOn VAR Bit 'To indicate status of Led 1= led On | 0 Led = Off
CounterOnOff VAR Bit 'This variable is used to display status Off - ONLY AFTER DEVICE HAS BEEN TURNED ON BEFORE
CounterXOn VAR Nib 'This variable is used to prevent program from constantly performing function when device is ON
I forgot to mention that once the status changes program is to perform the function only once!
CounterXOff VAR Nib 'This variable is used to prevent program from constantly performing function when device is OFF
I forgot to mention that once the status changes program is to perform the function only once!
DO
IF CounterXOn=13 THEN 'Puts the variable CounterXON at 2 so it never goes above the max NIB value
CounterXOn=2
ELSE
ENDIF
IF CounterXOff=13 THEN 'Puts the variable CounterXON at 2 so it never goes above the max NIB value
CounterXOff=2
ELSE
ENDIF
IF (IN0=1)THEN 'Detects status of device (in this case device is ON)
CounterOn =1 'Sets a value in a variable ConterOn (this variable is used later in the code)
CounterXOn = CounterXOn +1 'This counter will be used to control the number of times the functions that would be performed
CounterOnOff=0 'Resets value of CounterOnOff to 0 (so later function won't be perfomred)
CounterXOff=0 'Resets value of CounterOnOff to 0 (so later function won't be perfomred)
ELSE
ENDIF
IF (IN0=0) AND CounterOn=1 THEN 'IF Pin0 is at low and CounterON variable holds 1 then it means device was turned ON
CounterOnOff =1 'and CounterOnOff is set to 1 so it can be used later on in a program
CounterXOff = counterXOff +1 'This counter will be used to control the number of times the functions that would be performed
CounterOn=0 'Resets value of CounterOnOff to 0 (so later function won't be perfomred)
CounterXOn=0 'Resets value of CounterOnOff to 0 (so later function won't be perfomred)
ELSE
ENDIF
'This is where the magic takes place
IF CounterOn=1 AND CounterXOn=1 THEN 'IF pin0 is at high and CounterXOn is also equal to 1 (meaning this is the first and only time the following function
DEBUG "Status ON", CR 'would be perforemed)
GOSUB GetTemp_Subroutine 'Performs subroutine
GOSUB Read2Go_Subroutine 'Performs subroutine
Counterxon = CounterXOn +1 'Modifies CounterXOn value so this function will be only performed once.
ELSE
ENDIF
IF CounterOnOff=1 AND CounterXOff=1 THEN 'Because Pin0 is now at low and it was at high before it can now perform the following subroutines.
DEBUG "Status OFF", CR 'Sends a debug message to pc
GOSUB GetTemp_Subroutine 'Performs subroutine
GOSUB Six_Subroutine 'Performs subroutine
GOSUB Read2Go_Subroutine 'Performs subroutine
CounterXOff = CounterXOff+1 'Modifies CounterXOff value so this function will be only performed once.
ENDIF
PAUSE 75
LOOP
All subroutines perform same functions that is they control other relays.
One_Subroutine:
HIGH 15
PAUSE 100
LOW 15
PAUSE 100
RETURN
Three_Subroutine:
HIGH 8
PAUSE 100
LOW 8
PAUSE 100
RETURN
Five_Subroutine:
HIGH 10
PAUSE 100
LOW 10
PAUSE 100
RETURN
Six_Subroutine:
HIGH 11
PAUSE 100
LOW 11
PAUSE 100
RETURN
Seven_Subroutine:
HIGH 12
PAUSE 100
LOW 12
PAUSE 100
RETURN
Nine_Subroutine:
HIGH 14
PAUSE 100
LOW 14
PAUSE 100
RETURN
SR_Subroutine:
HIGH 14
PAUSE 100
LOW 14
PAUSE 100
RETURN
BegCall_Subroutine:
GOSUB Nine_Subroutine
GOSUB One_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
RETURN
GetTemp_Subroutine:
GOSUB Nine_Subroutine
GOSUB One_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
RETURN
Read2go_subroutine:
GOSUB One_Subroutine
GOSUB Five_Subroutine
GOSUB Five_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Seven_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
RETURN
CallAll_Subroutine:
GOSUB BegCall_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
GOSUB BegCall_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
GOSUB BegCall_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
GOSUB BegCall_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
GOSUB BegCall_Subroutine
GOSUB Six_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
GOSUB BegCall_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
RETURN
I am new to basic stamp so please be gentle.
Here is a description of what I am trying to do
I am currently working on a project where my basic tamp has to detect a status of another device (status of that device is determined by that device's led being on or off)
and based on the status the basic stamp should perform two functions.
The high signal is supplied to pin 0 by a relay (i used relay instead of a dip switch) that is controlled by a photo-resistor that is hooked up to the led it is monitoring.
The device my basic stamp is to monitor would be powered for close to 12hrs in day and off for another 12 hrs therefore the signal on pin 0 would be either high for 12 hrs or low for 12 hrs.
My program seems to be working fine for about first 2 hr after that it seems to be "restarting" and detects a low at pin 0 even though pin 0 is reeving high signal, only does that for about a minute as minute later (pin 0 detects high when pin 0 is receiving high)
This application has to be running 24/7 so my question is: Is it OK for pin 0 to be receiving a high impulse for about 12 hrs non-stop and then low for another 12 hrs?
OR
Is it does my code contain some sort of a syntax error that causes this behavior?
Here is my code
CounterOn VAR Bit 'To indicate status of Led 1= led On | 0 Led = Off
CounterOnOff VAR Bit 'This variable is used to display status Off - ONLY AFTER DEVICE HAS BEEN TURNED ON BEFORE
CounterXOn VAR Nib 'This variable is used to prevent program from constantly performing function when device is ON
I forgot to mention that once the status changes program is to perform the function only once!
CounterXOff VAR Nib 'This variable is used to prevent program from constantly performing function when device is OFF
I forgot to mention that once the status changes program is to perform the function only once!
DO
IF CounterXOn=13 THEN 'Puts the variable CounterXON at 2 so it never goes above the max NIB value
CounterXOn=2
ELSE
ENDIF
IF CounterXOff=13 THEN 'Puts the variable CounterXON at 2 so it never goes above the max NIB value
CounterXOff=2
ELSE
ENDIF
IF (IN0=1)THEN 'Detects status of device (in this case device is ON)
CounterOn =1 'Sets a value in a variable ConterOn (this variable is used later in the code)
CounterXOn = CounterXOn +1 'This counter will be used to control the number of times the functions that would be performed
CounterOnOff=0 'Resets value of CounterOnOff to 0 (so later function won't be perfomred)
CounterXOff=0 'Resets value of CounterOnOff to 0 (so later function won't be perfomred)
ELSE
ENDIF
IF (IN0=0) AND CounterOn=1 THEN 'IF Pin0 is at low and CounterON variable holds 1 then it means device was turned ON
CounterOnOff =1 'and CounterOnOff is set to 1 so it can be used later on in a program
CounterXOff = counterXOff +1 'This counter will be used to control the number of times the functions that would be performed
CounterOn=0 'Resets value of CounterOnOff to 0 (so later function won't be perfomred)
CounterXOn=0 'Resets value of CounterOnOff to 0 (so later function won't be perfomred)
ELSE
ENDIF
'This is where the magic takes place
IF CounterOn=1 AND CounterXOn=1 THEN 'IF pin0 is at high and CounterXOn is also equal to 1 (meaning this is the first and only time the following function
DEBUG "Status ON", CR 'would be perforemed)
GOSUB GetTemp_Subroutine 'Performs subroutine
GOSUB Read2Go_Subroutine 'Performs subroutine
Counterxon = CounterXOn +1 'Modifies CounterXOn value so this function will be only performed once.
ELSE
ENDIF
IF CounterOnOff=1 AND CounterXOff=1 THEN 'Because Pin0 is now at low and it was at high before it can now perform the following subroutines.
DEBUG "Status OFF", CR 'Sends a debug message to pc
GOSUB GetTemp_Subroutine 'Performs subroutine
GOSUB Six_Subroutine 'Performs subroutine
GOSUB Read2Go_Subroutine 'Performs subroutine
CounterXOff = CounterXOff+1 'Modifies CounterXOff value so this function will be only performed once.
ENDIF
PAUSE 75
LOOP
All subroutines perform same functions that is they control other relays.
One_Subroutine:
HIGH 15
PAUSE 100
LOW 15
PAUSE 100
RETURN
Three_Subroutine:
HIGH 8
PAUSE 100
LOW 8
PAUSE 100
RETURN
Five_Subroutine:
HIGH 10
PAUSE 100
LOW 10
PAUSE 100
RETURN
Six_Subroutine:
HIGH 11
PAUSE 100
LOW 11
PAUSE 100
RETURN
Seven_Subroutine:
HIGH 12
PAUSE 100
LOW 12
PAUSE 100
RETURN
Nine_Subroutine:
HIGH 14
PAUSE 100
LOW 14
PAUSE 100
RETURN
SR_Subroutine:
HIGH 14
PAUSE 100
LOW 14
PAUSE 100
RETURN
BegCall_Subroutine:
GOSUB Nine_Subroutine
GOSUB One_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
RETURN
GetTemp_Subroutine:
GOSUB Nine_Subroutine
GOSUB One_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
RETURN
Read2go_subroutine:
GOSUB One_Subroutine
GOSUB Five_Subroutine
GOSUB Five_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Six_Subroutine
GOSUB Five_Subroutine
GOSUB Seven_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
RETURN
CallAll_Subroutine:
GOSUB BegCall_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
GOSUB BegCall_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
GOSUB BegCall_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
GOSUB BegCall_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
GOSUB BegCall_Subroutine
GOSUB Six_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
GOSUB BegCall_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Six_Subroutine
GOSUB Three_Subroutine
PAUSE 30000
GOSUB Nine_Subroutine
GOSUB Nine_Subroutine
RETURN