Reset during Sleep
Buddie
Posts: 29
Hello.
I am building a project with a BS2px. My project reads an I2C RTC (Real Time Clock) and every five minutes it checks the value of a photoresistor using RCTIME. It also records this value into an external 4-wire serial·EEPROM. When the value rises above a certain level, the·program activates a relay and goes into a sleeping loop. It wakes up every 10 seconds and increments a counter.·When the counter·reaches a multiple of 5,·it updates an LCD. However, this sleeping loop only works a few times before the stamp resets and begins the program all over again. I cannot deteremine why this is happening. I am driving no loads·except the relay (by a transistor).·Any help would be greatly appreciated!
Thanks.·
I am building a project with a BS2px. My project reads an I2C RTC (Real Time Clock) and every five minutes it checks the value of a photoresistor using RCTIME. It also records this value into an external 4-wire serial·EEPROM. When the value rises above a certain level, the·program activates a relay and goes into a sleeping loop. It wakes up every 10 seconds and increments a counter.·When the counter·reaches a multiple of 5,·it updates an LCD. However, this sleeping loop only works a few times before the stamp resets and begins the program all over again. I cannot deteremine why this is happening. I am driving no loads·except the relay (by a transistor).·Any help would be greatly appreciated!
Thanks.·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i
This is the section of code that fails. It loops a few times but eventually resets during one of the SLEEPs.
' {$STAMP BS2px}
' {$PBASIC 2.5}
DOUT· PIN· 2
DIN·· PIN· 3
CLK·· PIN· 4
CS··· PIN· 5
But·· PIN· 7
RC··· PIN· 8
LCD·· PIN· 9
Relay PIN· 6
But2· PIN· 10
trans PIN· 13
address VAR· Bit(7)
_out··· VAR· Byte
Reps··· VAR· Byte
_data·· VAR· Byte
junk··· VAR· Byte
spot··· VAR· Byte
Addr··· VAR· Word
_min··· VAR· Byte
sec···· VAR· Byte
result· VAR· Word
control VAR· Byte
hr····· VAR· Byte
_con·· VAR Bit
Main:
· POLLMODE 0
· TOGGLE Relay
· 'HIGH trans
· 'PAUSE 100
· 'LOW trans
· IF (OUT6 = 1) THEN
··· SEROUT LCD, 396, [noparse][[/noparse]"?x00?y3", "Lights ON!"]
· ELSEIF (OUT6 = 0) THEN
··· SEROUT LCD, 396, [noparse][[/noparse]"?x00?y3", "Lights OFF!"]
· ENDIF
On_Time:
· result = 4
· DO
· Addr = 1
· I2CIN 0, %11010001, Addr, [noparse][[/noparse]_min]
· Addr = 2
· I2CIN 0, %11010001, Addr, [noparse][[/noparse]hr]
· junk = (((10 - hr)*60) - _min) + 15
· IF (result//5 = 0) THEN
··· SEROUT LCD, 396, [noparse][[/noparse]"?x00?y2", "Mins. Left: ", DEC junk]
··· SLEEP 10
··· result = result + 2
· ELSE
··· SLEEP 10
··· result = result + 2
· ENDIF
· LOOP UNTIL (But2 = 1 OR (hr.LOWNIB = 0 AND _min > 15))
· LOW Relay
· 'HIGH trans
· 'PAUSE 100
· 'LOW trans
· SEROUT LCD, 396, [noparse][[/noparse]"?f", "Sleeping"]
· SLEEP 65535
· DEBUG "Running"
· RUN 1
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i
Main:
· POLLMODE 0
· TOGGLE Relay
··IF (OUT6 = 1) THEN·SEROUT LCD, 396, [noparse][[/noparse]"?x00?y3", "Lights ON!"]·ELSE SEROUT LCD, 396, [noparse][[/noparse]"?x00?y3", "Lights OFF!"]
On_Time:
· result = 4
· DO
···· Addr = 1
···· I2CIN 0, %11010001, Addr, [noparse][[/noparse]_min]
···· Addr = 2
·· · I2CIN 0, %11010001, Addr, [noparse][[/noparse]hr]
··· ·junk = (((10 - hr)*60) - _min) + 15
· · ·IF (result//5 = 0) THEN·SEROUT LCD, 396, [noparse][[/noparse]"?x00?y2", "Mins. Left: ", DEC junk]
·· · SLEEP 10
·· · result = result + 2
·· · LOOP UNTIL (But2 = 1 OR (hr.LOWNIB = 0 AND _min > 15))
·
· LOW Relay
· SEROUT LCD, 396, [noparse][[/noparse]"?f", "Sleeping"]
· SLEEP 65535
· DEBUG "Running"
· RUN 1
Can't think what might cause a reset there.· What behavior does the program exhibit on a reset?· Could that 18-hour SLEEP (third line from bottom) look the same as a reset?
In any case, I'd put a DEBUG after each line (DEBUG "aargh1·· " -- DEBUG "aargh2·· " etc. to see exactly where it goes haywire.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
Interestingly, when I put my DMM in line with the power supply to measure current, this problem no longer occurs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
What values would you recommend for closer to the stamp?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
Thanks!