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. However, there is a subtle bug in the BS2 memory
circuits, which can result in a sleep current of as much as 350
microamps. 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, such as remote data logging, the system can spend
a great proportion of its time in sleep mode, and the sleep current
is a major factor in the battery life. It is better not to leave that
NOTE (2008): The EEPROM currently used on the most recent Stamp I
looked at had much better performance. At worst the SLEEP current
was 58 microamps instead of 350, and the best SLEEP current was 17
microamps. However, there is still a caveat. This
note applies to all of the Stamps, but to what degree depends on the
interpreter EEPROM that is used on the Stamp module. The
EEPROMs from different manufacturer's have different characteristics,
and through time the manufacturer's make changes as they upgrade their
manufacturing processes, often with no notice or change in part
number. The Stamp uses the EEPROM in an "off-the-books"
manner, by addressing it one bit at a time instead of one byte at a
time, so the SLEEP instruction can leave it active at an address that
is not on a byte boundary. "Off-book" means that the
specifications for quiescent current drain in the data sheets may not
apply. It this issue is of concern for your
application, I suggest that you do the experiments
yourself. This note continues below after my comments about
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 the program. Nevertheless, it is still worthwhile to put the SLEEP instruction in a routine near the top of the program. Then the adjustment only needs to be made when the total number of GOSUBS in the program changes. Here's a 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
well var byte ' sleep duration
' define other variables/constants/data
goto main0 'skip over the bed time code
bed: ' bed time subroutine
' it goes here to fix it near the top in eeprom
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=.
' see below for explanation
sleep well ' no driven loads! no floating inputs!
' program goes here
well = 10 ' how long to sleep
' no driven outputs, no floating inputs!
' application dependent
gosub bed ' do it, and return here
' more program
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 <50 microamps current. (Assuming no driven loads, floating inputs etc.) If the current is around 300 microamps, try another possibility.
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! The above method of counting GOSUBs may not always work. I tried it on some shipments of BS2s and it did not work as expected. 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.
As noted above, the effect depends on the EEPROM, and applies across
the Stamp family. As an example, consider the Catalyst
EEPROMS used originally on the BS2pe. The current drawn by
the EEPROM itself was 3 to 15 microamps in the original CAT24WC256KI,
(chip marked CSI 24WC256KI), but that was discontinued, and their
most recent version is the CAT24C256XI, and in the ones I tested the
current was 75 microamps minimum to 1800 microamps
maximum. Quite bad. I was evaluating the
chips for my OWL2pe data logger, where low SLEEP current is
essential. I settled on the Microchip EEPROM, 24LC256I/SM,
which gives a current range from 20 to 190 microamps. In
micropower situations, I still have to align the SLEEP instructions,
but for most applications, even 190 microamps is not too
bad. Again, the messages is, if it is important to you,
In terms of overall current consumption, the original BS2 is
great. Current versions are less than 3 milliamps of
operating current and 20 microamps during SLEEP. The
BS2pe (as implemented on the OWL2pe data logger) draws about 16
milliamps when operating and 70 microamps while asleep. The
advantage that the BS2pe has is its shorter wakeup intervals while
SLEEPing, 0.15 millisecond versus 15 milliseconds.
See my article on the BS2pe.
BASIC Stamps operate with a Vdd power supply of nominally 5.0 volts, but they can operate on slightly higher and slightly lower voltages. What is of concern here is low voltages as might come about, say, as a battery voltage dips in a solar charge cycle, or in a system that occasionally has brief power failures. Sags in voltage are called brownouts, while a complete and sustained loss of power is called a blackout.
The following discussion applies only to the Stamps that rely on the
brownout detector that is internal to the SX28 or SX48 microprocessor
The original BS2 has an external brownout detector, so this note does
not apply to it. Pre-2008, all of the multislot BASIC Stamps
relied on the internal brownout detector, but in 2008, Parallax revised
the BS2e (rev E) and BS2sx (rev F) hardware to include an external
brownout detector, and in the future may also do so with the BS2p
family, but as of this writing, the BS2p family still relies on the
internal brownout detector.
That SX brownout detector has characteristics that can only be described as a "bug". But it is only a bug if you are using the SLEEP, NAP or END instructions and expect your system to behave well in those low-power modes as the battery voltage drops.
The affected BASIC Stamp operates fine down to 4.2 volts, but at that point a brownout detector puts the SX chip into a reset state. What happens at that point depends on what the Stamp was doing when it hits the brownout threshold, and on how low the voltage dips. Here are a few observations:
What of it? The troubling thing for the affected BASIC Stamp is
that the chip does not reset as a result of brownouts that occur
during sleep intervals. There is a possibility that variables would
be corrupted during the brownout, and there would not be a clue as to
why that had occurred. My observation is that the chip hangs onto its
variables quite well, even at low voltages, but it is certainly not
guaranteed. The integrity of the variables would be more sensitive to
influences of noise (EMF) and extreme temperatures. Another troubling
aspect of this behavior is that the current drain becomes quite high
if the chip goes into brownout. Usually a system uses the SLEEP mode
to conserve battery power, but the higher current in brownout could
deal a final blow to a marginal battery. On my OWL2pe
processor, the battery condition is monitored and when it is critical,
the firmware puts the logger into a hibernation mode in order to
forestall any pending brownout condition.
The SX internal brownout detector set at 4.2 volts has a serious
problem at low temperatures, and will go into never-never land at a
certain temperature that for different units will be in the range of -5
to -25 degrees Celsius, and typically at -15.
By never-never land, I mean that the SX clock oscillator keeps running,
the current consumption jumps, and the chip stops executing
code. This was a serious problem for my early OWL2pe data
loggers when they had to operate in outdoor winter environments down to
as low as -40 degrees Celsius. Using an environmental
chamber, I traced the problem to the BOR42 setting on the SX chip, and
was able to resolve the problem by using a special version of the BS2pe
chip that has a setting of BOR26. With that setting it
operates without fail in tests down to -65 degrees Celsius, well below
the -40 degree Celsius component ratings on the
OWL2pe. Parallax has resolved the problem as of 2008
on the BS2e (rev E) and BS2sx (rev F) modules by a hardware revision to
an external reset chip, and has extended the operating temperature
range -40 to +85 degC for those modules.