Shop OBEX P1 Docs P2 Docs Learn Events
Reset during Sleep — Parallax Forums

Reset during Sleep

BuddieBuddie Posts: 29
edited 2008-11-24 22:39 in BASIC Stamp
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.·

Comments

  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-21 01:10
    How about showing us your code? Attaching it is easy.· A drawing of your circuit would be good, too.· Whence is the relay coil current drawn?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-21 01:20
    If you're using GOSUB / RETURN and you have a missing RETURN or too many RETURNs for the number of GOSUBs, that can produce the behavior you've noticed.
  • BuddieBuddie Posts: 29
    edited 2008-11-21 18:06
    The relay runs off of the power supply before it is regulated to 5v.

    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 HayesCarl Hayes Posts: 841
    edited 2008-11-21 20:47
    Well, that "RUN 1" at the end would cause a reset unless therre is code in Slot 1 to do something. I assume the code you show here is in Slot 0.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • BuddieBuddie Posts: 29
    edited 2008-11-21 23:21
    No, this code is just part of the entire project. It is in slot 4. However, the program resets while in the loop, before it reaches the RUN command.
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-22 17:51
    Interesting.· Just to make it easier for myself, I have slightly rewritten as follows (my post continues after the code):

    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
  • BuddieBuddie Posts: 29
    edited 2008-11-22 23:11
    Sometimes the program restarts to the beginning and sometimes it just goes into la-la land. In that case, I have to reload the program. It is not the 18-hour sleep causing the reset. Interestingly, if I replace all the SLEEPs with PAUSES, the program works fine...
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-22 23:36
    I suspect that when it's in la-la land it's in the 18-hour SLEEP. Also, though I don't know what your "Relay" pin does, I would point out that it will not stay LOW during a SLEEP. Instead it will go to INPUT for about 18 ms, every 2.3 seconds. See the manual on SLEEP. All your other output pins, no matter in which Slot they're used, will do the same. For all I can tell, that might cause something else to go haywire elsewhere in your hardware, causing a reset.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • BuddieBuddie Posts: 29
    edited 2008-11-23 19:44
    I know that it has not reached the 18-hour sleep because it prints "Sleeping" on an LCD beforehand.

    Interestingly, when I put my DMM in line with the power supply to measure current, this problem no longer occurs.
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-23 20:08
    Ah, that part about the DMM is a clue. Try adding bypass capacitors across the power bus, as close to the Stamp as you can manage to place them. I'd add one electrolytic (for the slower glitches) and one ceramic, mica, or polystyrene (for the faster glitches).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • BuddieBuddie Posts: 29
    edited 2008-11-23 20:14
    I have two electrolytic caps near my regulator - 100 uf on the input, 10uf on the output.

    What values would you recommend for closer to the stamp?
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-23 21:34
    Closer to the Stamp I would use almost any value, say 0.01 or 0.001 microfarad. Non-electrolytic, because electrolytics have large impedances at high frequencies. I think you may be suffering from extremely brief transients (perhaps resulting from the cycling that occurs during SLEEP), and an electrolytic capacitor is an open circuit to very brief transients -- no good at all. Use a small value non-electrolytic capacitor as close to the Stamp as you can get it, perhaps right next to the chip between pins 21 and 23.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • BuddieBuddie Posts: 29
    edited 2008-11-24 22:39
    Problem fixed with a 1000uf electrolytic cap right next to stamp between Vdd and Vss. Will try your idea too...much smaller caps!

    Thanks!
Sign In or Register to comment.