BASIC Stamp power supply, SLEEP & brownout

(c) 1998, 2001 EME Systems, Berkeley CA U.S.A.
<stamp index> <home>

Contents: (updated 12/20/2002)


Here is a table of values of operating and sleep currents for the different stamps. These are typical values based on a small sample of chips. Maybe 15% chip to chip variation. In making data loggers for remote locations I am often interested in how long the battery will last. This is a concern in almost all battery operated equipment.

Stamp

operating current

sleep current

wakeup current

wakeup interval

averaged sleep current

BS2

7 milliamps

30 microamps

2 milliamp

18ms / 2.3s

50 microamps

BS2e

22 milliamps

50 microamps

19 milliamps

16ms / 1.9 s

210 microamps

BS2sx

65 milliamps

50 microamps

64 milliamps

16ms / 1.9 s

580 microamps

BS2P

42 milliamps

50 microamps

23 milliamps

16ms / 1.9 s

240 microamps

BS2Pe

16 milliamps

50 microamps

10 milliamps

0.2ms / 1.9 s

55 microamps

definitions:

operating current
When running a program, no loads driven, no floating inputs.
sleep current
When only the watchdog timer is operating, during the deep part of the SLEEP cycle. Again, no floating inputs, no driven loads. Note this is in microamps. See special note below on the sleep bug for the BS2.
wakeup current
When the watchdog timer causes the chip to wake up, approximately once every 2 seconds, the current rises almost immediately to this level. The chip may decide to go back to sleep (more microamp level sleep current, or it may decide that the sleep interval is over, and then transition to full operating current. Note that the wakeup current is generally less than the full operating current. It is considerably less for the BS2, which leads to the overal low averaged sleep current.
wakeup interval
The sleep interval is not well controlled, and varies from chip to chip and with temperature. At room temperature, the values for the SX chips I have tested have been near 1.9 seconds, while the original Microchip parts are near 2.3 seconds. Note that an oscilloscope and current shunt are required to measure the current during this short interval. The interval itself is around 16 milliseconds for the SX chips, and a bit longer , ~18ms, for the original Microchip parts on the BS2. Observe that the wakeup interval for the BS2pe is much shorter than the values shown for the other stamps.
averaged sleep current
This is a weighted average, of the high current that is measured during the brief wakeup interval, averaged with the microamp level current that is measured during the longer sleep interval. This is a current level that would be achieved only with a long sleep cycle, for example SLEEP 3600. During this cycle, the stamp would sleep for one whole hour before coming back to the full operating current, but during that long interval it wakes up once every 1.9 to 2.3 seconds to check on its status. For example, the BS2e: 16ms/1900ms * 19 ma + (1900-16 ms)/1900ms * 0.05 ma = 0.21 ma.

Of course, if the chip spends most of its time in the operating mode, the overall current will be the operating current, plus whatever is used by the other loads in the circuit. Observe that the original BS2 is the champ when it comes to low operating current, both in continuous operation and in extended sleep periods. The BS1 was even less power hungry 1.2 milliamps operating current and 30 microamps sleep current.

The microprocessor that in my opinion has the best power management features is the Texas Instruments MSP430. But it is not anywhere as easy to use as the Stamps!

EME Systems' OWL2 data loggers usually operate on a cycle of 6 seconds sleep, and after each six seconds the logger wakes up to check the status of sensors and to compute accumulations, averages etc. At the end of each logging interval (say 10 minutes or one hour) there is a longer operation as it puts the data in memory. The average current is system dependent, but is usually less than 5 milliamps overall. Some sensors, e.g. current loops or sensors that require a long warm-up time or extended calculations will exact a higher average current. Example calculation: BS2e 1 second operating, 5 seconds sleep. 24ma*1/6+0.2ma*5/6 second=4.2 milliamps. Same thing, BS2: 7ma*1/6+0.05*5/6= 1.2 ma. Lower currents can be obtained if the sensors only need to be read once per long interval. Then the overall current can approach the level of the averaged sleep current.

 

BS2 sleep bug

top

The BS2 is advertised to have a current drain of less than 50µamps in sleep mode, and experience has shown that current production units are running a best sleep current of around 30 µamps. (Note: is talk about the original BS2) However, there is a subtle bug in the BS2 memory circuits, which can result in a sleep current of as much as 350 microamps. This is a known bug. It depends on exactly where in memory the SLEEP instruction is encountered by the interpreter. The SLEEP instruction has to fall at a "good" position in the eeprom, or else the sleep current drain will be greater than 300 microamps instead of less than 50 microamps. If you just let it fall where it may, you have something like a 50-50 chance for it to fall in a good position. In some applications, this sleep current is a major factor in the battery life. It is better not to leave it to chance.

I had thought to put my one SLEEP instruction near the beginning of my programs, so as to fix its position in the eeprom for once and for all to minimize current. But that didn't work as easily as planned, because each GOSUB instruction adds code at the top, above the program in eeprom. In fact, each GOSUB adds exactly 14 bits at the top of memory. It is still worthwhile to put the SLEEP instruction in a routine near the top of the program, so that adjustment only needs to be made when the total number of GOSUBS in the program changes.

Here is the skeleton of a program, to demonstrate how the sleep routine fits in near the top, and how the exact position of the SLEEP command is adjusted:

zb var bit    ' bit variable for pre-sleep adjustment
zz var byte ' sleep duration

top:
goto main0 'skip over the bed time code

bed: ' bed time subroutine comes near the top of the program
zb=1 ' play with zb to minimize current
' case 0) use zb=15
' case 1) use zb=1
' case 2 & 3) comment it out ' zb=.
sleep zz ' no driven loads! no floating inputs!
return

main: ' program goes here
debug "Here we are",cr zz = 10 ' how long to sleep
' no driven outputs, no floating inputs!
' application dependent
gosub bed ' do it, and return here
goto main
end

Here's the trick, hardware and thinkware versions:

1) Measure the stamp current during sleep. Try zb=1, zb=15 or comment out the zb= statement. One of these 3 possibilities will result in <70 microamps of deep sleep current. (Assuming no driven loads, floating inputs etc.) If the current is >300 microamps, try another possibility.

or

2) Count the number of gosubs in the program, divide by 4 and look at the remainder.

That's it. The above program as it stands has one gosub, so zb=1.

How to count gosubs? Use the ALT-F find "gosub"; ALT-N again and again; keep a mental tally. Don't count remarks of course! The FIND function in the BS2 editor is case sensitive. If you're not sure that all of them are cased the same, you might want to use a more capable text editor to do the count.

As a practical matter, there are installations where it is difficult to measure the sleep current, so counting gosubs is an attractive alternative. I wish the bug would just go away! (Caveat: The above method of counting GOSUBs may not always work. Test it on your own batch of stamps! But the business of measuring the sleep current, and trying either zb=15. zb=1 or no zb at all was always able to yield the minimum sleep current.)


Note that this workaround is effective only if the BS2 has the Microchip EEPROM. For a short period of time, Parallax was shipping BS2s with an ATMEL EEPROM, for which the above workaround is not effective at all. Parallax stopped using the ATMEL parts as soon as the problem was discovered.


In the BS2, the effect of the sleep bug is quite dramatic and can result in sleep currents that range from 25 microamps at best up to 450 microamps at worst. This can have a huge effect on the averaged sleep current. On the other hand, for the BS2sx and BS2e, the sleep current (not averaged) ranges from 46 microamps at best up to about 58 microamps at worst, and has no appreciable effect on the averaged sleep current. Also in the BS2P.


Brownout behavior, a bug?

top

BASIC Stamps operate with a Vdd power supply of nominally 5.0 volts, but they can operate on slightly higher and slightly lower voltages. How low? Say, what happens if battery voltage dips in a solar charge cycle, or the system experiences a power failures or someone leaves the power adapter unplugged? Sags in voltage are called brownouts., while a complete and sustained loss of power is called a blackout. When the Stamp enters brownout state, it may enter a mode where a constant drain of current is much larger than you were anticipating, especially if you had been counting on the SLEEP command to minimize power consumption. Also, with the more recent Stamps, there is a possibility of data corruption, due to some strange behavior of the brownout detector circuit in the SX microprocessor chip.

Stamp

BS2

BS2e

BS2sx

BS2P

brownout volts

4.3 off, 4.6 on

4.3 off, 4.3 on

brownout current

2 ma @ 4.3 volts

13 ma @ 4.3 volts

reset current

same as operating

same as operating

operating current

8 ma @ 5 volts

24 ma @ 5 volts

sleep current

0.03 ma @ 5 volts

0.05 ma @ 5 volts

reset pin 22

low in reset (i/o)

no change (input)

The brownout threshold for all stamps is about 4.3 volts, however, this can vary individually from Stamp to Stamp. The behavior for the original BS2, which has a reset chip added onto the carrier board alongside the PIC microprocessor, is different compared to the BS2e, BS2sx and BS2p, which rely on the reset circuit that is built into the Ubicom microprocessor chip.

The BS2 reset chip has hysteresis, that is, the point where it stops operating is 4.3 volts, but the voltage must rise back up to 4.6 volts before it will start operating again. The other Stamps have a fairly sharp threshold of about 4.3 volts either way.

Any of the BASIC Stamps operate continue to operate on power supply voltages down to roughly 4.3 volts, but of course the operation at the marginal voltages would be subject to noise on the power supplies. Below the 4.3 volt point, a brownout detector puts the Stamp in a reset state. On the BS2, this reset chip pulls pin 22 on the carrier board low. On the BS2e, BS2sx and BS2P, the pin 22 on the carrier board is an input only. When the Stamp 2e, 2sx or 2p enters the reset state, nothing happens on pin 22.

What happens subsequent to a drop below the brownout point depends on what the Stamp was doing when it hits that point, and on how low the voltage dips. Here are a few observations:

If you bring the reset pin low intentionally, with Vdd at 5 volts nominal, the chip draws power equal to its operating current. This applies to all of the Stamp modules.

The reset state is not a low power mode!

The Stamp 2e and 2sx use the Ubicon (formerly Scenix) SX28 microprocessor chip. I have tested the Scenix SX18 chip in a circuit with the watchdog disabled. (The watchdog timer is always enabled on the BASIC Stamp, so I was curious how it contributed to the observations above.) If the SX chip is in sleep mode when Vdd goes below the brownout threshold, the power supply current stays at about 35 microamps so long as the chip Vdd supply is less than the brownout threshold. The SX18 does not execute a reset when it recovers from brownout. Vdd has to falls below the 0.6 volt mark that causes a Power-On reset condition, or else a reset will not occur out of the sleep mode. Thus, if the chip enters a brownout and then recovers while it is asleep, the chip has no way of "knowing" that the brownout occured. In contrast, when the chip is operating, not sleeping, any brownout will lead to a full reset.

What of it? There are two gotchas to consider.

(1) On the SX based Stamps, there is a possibility that variables might be corrupted during a brownout. There would not be a clue as to why that had occurred. It is really better if the chip resets (as does the vanilla BS2), because then at least the program comes up in a known state. On the other hand, my observation is that the chip hangs onto its variables quite well, even at low voltages. It is not guaranteed, though. The integrity of the variables would be more sensitive at low voltages to influences of noise (EMF) and extreme temperatures.

(2) A more troubesome aspect of the brownout behavior is that the current drain becomes quite high if the chip goes into brownout. That is true of both the SX and (to a lesser degree) the vanilla BS2. Usually a system uses the SLEEP mode to conserve battery power. But it does not matter if the brownout occurs during sleep or during operation--it is a high power mode in either case. The higher current in brownout could deal a final blow to a marginal battery, and make it very difficult to recharge.

A battery saver circuit, brownout cutoff switch.

The circuit here is a brownout cuttoff switch for use with a 6 volt gel cell rechargeable battery. If the battery voltage drops below 5.3 volts, the power to the load and CPU (BASIC Stamp) is completely cut off. Then, when the battery voltage rises back above 6 volts, the power switches back on and the CPU is cleanly reset. This circuit avoids the brownout problem mentioned above. This circuit draws less than 40 microamps, which is much less than the Stamp draws in the brownout state. When the power is shut off, the charger (solar panel or whatever) can replenish the battery before it drops below the point of no return.

The MN13812 from Panasonic is a low current (2 µamp) voltage detector & reset circuit. Its CMOS output would normally be connected to a microprocessor reset input. If the voltage across the MN13812 falls below 4.6 volts, its output goes high. That output would normally be used to reset a microprocessor. In this circuit it is connected to a p-channel mosfet. When the output goes high, the gate of the mosfet is connected to the source, so the transistor is OFF, interrupting power to the load. When the output of the MN13812 is low, the gate is 4.6 volts below the source, which turns the transistor ON, connecting power to the load. The LP0701 from Supertex is a low-threshold p-channel lateral mosfet that has a Vgs(th) of 1 volt, and an Rds of 1.5 ohms at 4.6 volts, at currents of up to at least 0.5 amp. The ratio of resistors sets the threshold. With the values shown it turns off below 5.3 volts, and back on above 6 volts. The MN13812 itself has some hysteresis, but the 200k resistor adds more, to prevent oscillation that might occur if the battery voltage immediately decreased as the power turned on. The 0.1uF capacitor is necessary to prevent oscillation. It is possible to switch power to two or more circuits by paralleling mosfets. The load circuits should include current limiting and ESD protection if that might be a problem. It is possible to decrease the current consumption of the circuit by using higher value resistors. The bias current of the MN13812 is fairly constant with temperature. Here are some alternative choices of component values:

...coming sooner or later.

Stamp oscillator, possibility of lower frequencies, lower power, timing.

top

I have also looked at the stamp oscillator, thinking of ways to decrease current drain.

1) By tying an LC circuit to the crystal input (in parallel with the built-in capacitor) it is possible to make the crystal run in a subharmonic mode. This takes some experimentation. A few microhenries in series with ~20pf will do the trick, to bring the BS2e oscllator from 20mhz down to a 1/3 subharmonic at about 6 megahertz. This reduces the current consumption considerably.

2) The current can also be decreased by driving the crystal input with a low-frequency oscillator. All the internal timing slows down proportionately. The current does not go to zero at low frequencies. The minimum for the BS2e is about 0.5 millamp when the clock is stopped, with the clock input tied to ground or to +5 volts. The watchdog operates and kicks in after 2.3 seconds and the current shoots up to the brownout level. There is a minimum operating frequency, which I have not yet found. This is so that the watchdog will not time out. 32khz is too low.

Here is what happens with the clock when the stamp goes to sleep: Both the xtal input and xtal output go to a low level. When the stamp wakes up, the xtal output goes quickly to a high level at 5 volts, and drops down below 2.5 volts, and then the oscillations start. The initital transient before the oscillations start is nearly 1 millisecond in duration. The Stamp actually waits for 15 to 18 milliseconds before it starts executing code. That delay is built into the PIC chip, and is meant to allow time for the oscillation to stabilize before time-critical operations are started. The delay is excessive when the PIC is operated with a ceramic resonator, because resonators start up much faster than crystals. Unfortuantely for low power systems, the extra 15 to 18 milliseconds of delay drives up the current that the Stamp consumes when it is sleep and wake cycle.


<top> <index> <home> logo < mailto:info@emesystems.com >