Shop OBEX P1 Docs P2 Docs Learn Events
Stemp acting eraticaly after several hours of operation — Parallax Forums

Stemp acting eraticaly after several hours of operation

LuXo12LuXo12 Posts: 31
edited 2008-09-06 01:58 in BASIC Stamp
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

Comments

  • azmax100azmax100 Posts: 173
    edited 2008-09-04 05:12
    I think you need a diode across the relay coil.
  • ercoerco Posts: 20,256
    edited 2008-09-04 07:08
    Many examples of Stamps running 24/7 without issues. Your problem could be a battery or power supply problem. What are you using for power?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • JonathanJonathan Posts: 1,023
    edited 2008-09-04 14:41
    As mentioned above, you may have power supply issues, or you may need a diode across the relay. I wonder if you really need the relay at all. Can't you just connect, via a resistor, the LED? What voltage is the LED running at? If it is too high voltage for the stamp, you could use a voltage divider to drop the voltage. If you really need it to be isolated from the Stamp, how about using a CDS cell or photo-transistor? The relay will use a fair amount of energy 1/2 of the time, and it seems that you could do without it.

    Another thing you could do to trim your code:

    whichLED var byte

    whichLed = *whichever LED you want to light"

    led_sub:
    high whichLED
    pause 100
    low whichLED
    pause 100
    return

    There are some other ways you could trim your program as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • LuXo12LuXo12 Posts: 31
    edited 2008-09-05 00:46
    Thanks for you help i will try it with a diode
    As for the relay that is being used in place of a dip switch (monitoring status of led) i need it as the led that is being monitored is in a remote location several yards away and there is no way for me to move either device closer
    The power supply I am using to power the stamp has the output of 5.0 volts and 1.98 Amps
    The voltage on the input Pin0 is 5.0 volts and 0.01 Amp

    Is it possible that the stamp gets too hot and that's why it acts that way?

    Is it possible that the supply has two many amps?

    Thanks in advance.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-05 01:20
    The power supply ratings of 5V at 1.98A indicate the capacity of the power supply.· 5V is the nominal voltage produced and, if the supply is regulated, shouldn't vary much from that.· The 1.98A is the maximum current that can be drawn from the power supply.· If you attempt to draw more than that, you might blow a fuse or the output voltage might drop below 5V or the output voltage might drop near zero if protective circuitry (fold back) is triggered.· Any excess current capacity simply goes unused.

    It's possible the Stamp can get too hot.· If devices are connected to the I/O pins that draw a lot of current, the processor chip can get warmer.· Usually, the processor chip will be damaged before it gets significantly hot from this.· The maximum current per I/O pin is roughly 20mA.· Groups of 8 I/O pins can provide roughly 50mA and the whole processor chip can handle about 150mA.· The processor chip will normally get warm as well.

    There's a voltage regulator on the Stamp module that gets warm when it's used.· If you're supplying 5V to the Stamp to the Vdd pin, the regulator is bypassed.· If you're trying to power the Stamp with 5V to the Vin pin, it won't work because 5V is too low for the regulator on the module.· Vin needs to be at least 6V.
    ·
  • LuXo12LuXo12 Posts: 31
    edited 2008-09-05 01:36
    Thanks for all your replies

    Based on Mike's reply I assume that the power supply is OK

    Could it be that there is a logic error in my code, especially in the loop portion of it?


    Thanks in advance
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-09-05 12:57
    1. The BS2 is VERY good at recieving signals directly from a light sensor.

    2. It's not clear what the relay is doing for you. If it's merely closing a switch, you may need a 'pull-up' resistor of 10 Kohms to give you a reliable 'one' when the switch is open.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-09-06 01:58
    LuXo12

    I have had the same type of problem with using relay that draw over 30 mill amps @ 12 volts

    ·What·I had to do is use a Optic Sensor· like a 4N25 and a··
    transistor like a·2N2222A or you could use a UNL2803 as well

    If you need any help in how use this set up just let me know

    These set ups work great and do not give any trouble

    Here is a link where·I post a code routine that check to see if you are hang up
    because of the set up using a relay

    http://forums.parallax.com/showthread.php?p=748879

    I hope that you find it use full· it has worked for me

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 9/6/2008 2:05:16 AM GMT
Sign In or Register to comment.