Shop OBEX P1 Docs P2 Docs Learn Events
Dealing with the sleep glitch — Parallax Forums

Dealing with the sleep glitch

photomankcphotomankc Posts: 943
edited 2009-07-31 13:27 in BASIC Stamp
I have the code for my first project pretty well complete but had one issue come up that is bugging me still although not pressing anymore. The basic idea is a universal USB charger that runs on 6AA NiMH batteries and provides a 5V ~400mA output via USB as a convenience device when I don't want to bust out wall wart chargers or we are camping, etc. The stamp is there to provide:
- Voltage monitoring and feedback via three LEDs that lindicate charge when a button is pressed.
- Delayed shutdown interface using the LEDs to provide three different timeouts to prevent battery depletion by devices that never stop charging and the regulator
- Shut the entire regulator down and sleep when the pack voltage hits 6.1V under load to prevent deep discharge of the batteries.

All my basic functions are working but I ran into one snag that got me curious. I use an NPN power transistor to control the load and let the Stamp cut of the load when needed. I used a 1.5K resistor from the stamp to the transistor to limit base current but try to also keep it saturated. Higher values seemed to produce a pulsation in the regulator's LED and my IPod did not like that at all. My original idea was to NAP wherever possible for delays to reduce power consuption of the already loss ridden regulator circuit. However if I tied the transistor base high with a resistor value small enough to keep it 'on' when the sleep glitch appeared on the output from the stamp, when it came time to shutdown and END the stamp program the transistor would pulse on at each watchdog wake-up of the Stamp and it was enough to keep pulsing the charging loads on and off... not good. If I tie it low, then the opposite happens and any NAPS in the Stamps main loop cause the transistor to pulse towards off and thus keep triggering charging devices to think they were disconnected and reconnected. Not good either.

Ultimately my time-delay circuit and the loop-counting method of timing it uses in absence of any time keeping in the Stamp require me to not use NAP anyway. The variation in timing with NAP throws everything off and can accumulate some big errors over the 1 and 3 hour auto-off timer durations. I left the base of the transistor floating and that seems to work the best of everything else, but with no NAPs in the main loop now I could probably tie it low to help keep it stable. But my question still remains. What's the easiest way to keep that glitch from causing outputs you need held in certain, non-default, state by the Stamp from pulsing? I thought maybe a latch of some kind but that adds another DIP to the final product and I don't want to do that. Just curious if others have run into this and have a solution for future reference.

A programmable USB charger! Totally impractical and yet still so cool!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-07-30 19:01
    The problem is well documented. The I/O pins are periodically put into input mode for a short time during a NAP or SLEEP. If your circuitry can't tolerate this, you will need a pulldown to provide a default off voltage. The specific value needed depends on your circuitry.
  • photomankcphotomankc Posts: 943
    edited 2009-07-30 19:41
    Yeah I've seen the cause of it and knew it was issue but since I would be napping when it's both high and low tieing it to one rail or the other won't deal with it. The latch idea was the only thing I could think of but it would have to be able to operate on the unregulated battery voltage to be useable here. Just seeing if anyone had a similar design that they solved.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2009-07-30 23:46
    If you use a n-mosfet instead of a transistor, you can store the desired state on a capacitor. Even the gate capacitance of the mosfet itself can suffice. Dynamic memory. When the chip flips to its input briefly, the pin retains the foregoing output state for the necessary 18 milliseconds or less. A pulldown or pullup resistor can still be used, so long as the RC time is long enough.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • photomankcphotomankc Posts: 943
    edited 2009-07-31 13:27
    I gotcha. The MOSFET won't need current at the gate just the stored charge from the capacitor to hold the gate voltage. Cool. Thanks!
Sign In or Register to comment.