BS2pe application notes

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

Contents (updated 12/3/2005)

What is the BS2pe?


photo of BS2pe topThe BS2pe is based on an Ubicom SX48 chip clocked in turbo mode at 8 megahertz for about the same throughput as a BS2 or BS2e. It is a low power drain version of the BS2p. It is clocked at 8mhz instead of 20 mhz, which has a major effect on lowering the power consumption. The BS2pe is meant for battery powered applications where current drain is a primary consideration, and for data logging where additional eeprom is needed.   The photo to the left is the BS2pe module, with the  24 pin footprint, offering 16 general purpose i/o pins.

OWL2pe data loggerThe BS2pe OEM chip is also the basis of the OWL2pe data logger from EME Systems, pictured  to the right.   The BS2pe provides additional functions, including ADC, RTC, extended logging memory, power supplies, an industrial temperature rating, and 20 general purpose i/o pins.  The OWL2pe takes advantage of the data logging specifications of the Stamp chip.

A big new feature is that the BS2pe has 32k of eeprom memory organized as 16 banks of 2kbytes. This is twice as much as the other multi bank stamps, which have 8 banks of 2kbytes. This is extra 8 banks are for data logging or for other kinds of data storage. The extra banks are accessed via the READ WRITE and STORE commands. For example,

READ 100, x
WRITE 100, x

That selects the 16th bank, reads data from location 100, then selects bank 0, and writes the value of x to location 100 there.

The EEPROM in the BS2pe can be used for any purpose that requires data storage.  It can be acquired data, or configuration data, or or prompts or other information to display on an LCD screen, or phone numbers and addresses, or any kind of numerical control script.

There are 16 banks of 2k bytes.   8 of those banks, numbers 0 to 7 can be used for either programs or data and can be configured at compile time.   Banks 8 to 15 can be used only  for data, accessed at run time with the DATA, STORE, READ and WRITE statements.

To my way of thinking, the STORE command is indispensable in any large Stamp project.

The BS2pe has all of the same commands as the BS2p, including support for I2C and one-wire protocols, and LCD screens. There is also the 127 bytes of scratchpad RAM, which is very useful in large Stamp projects. The serial command modifier (SPSTR) allows a program to stream lots of data from the serial port (or from I2CIN and OWIN), directly into the scratchpad RAM buffer.

The BS2pe has one more wonderful feature to reduce power consumption. It wakes up and goes to sleep faster, which saves lots of power when operating in SLEEP mode. The next section is an evaluation of this feature and a peek at why it is important.

Short sleep interval means low average current


When the BS2pe wakes up from sleep, it takes 1/5 of a millisecond to wake up. All of the other BASIC Stamps (2, 2sx, 2e and 2p) take 80 times as long, 16 to 18 milliseconds. This has quite a large effect on the average power consumption when the Stamp executes a long SLEEP command or when a program ENDs. The BS2pe can do lots of useful work and still draw less average current than the other Stamps do while sleeping all the time.

(Technically speaking, the short wakeup time comes about because the fuse register in the SX48 chip in the BS2pe is set for minimal wakeup delay. This is only possible in the SX48 chip. It is not an option in the SX28 chips that run the BS2sx and BS2e, nor the PIC chip in the BS2.)

The short wakeup becomes important in execution of the SLEEP or END instructions. In executing a SLEEP 60 command, for example, the Stamp wakes up briefly once every 1.9 seconds to check on its status, to see if the 60 seconds is up. If the 60 seconds is not up, it goes right back to sleep. The average sleep current is the average of the current during the low current 1.9 seconds and the relatively high current during the brief wakeup interval.

The BS2pe chip draws 15 milliamps while operating, and 55 microamps while sleeping. The sleep-wake cycle is about 1.9 seconds at room temperature. When the BS2pe wakes up, it stays awake for only 0.15 to 0.25 millisecond, and during that short wakeup period draws only about 10 milliamps average. Here is a graph of what happens during the wakeup period.


BS2pe short sleep

The current during the brief wakeup period fluctuates a lot, as the clock oscillator and the chip operation are in the process of stabilizing.

When the chip goes back to sleep, it then waits another 1.9 seconds before another brief wakeup. And so on. The total current is the average of 10 milliamps for .15 milliseconds, and 55 microamps for 1.9 second. The average is computed as follows:

 averaged_current in microamps=
(sleep_time * sleep_I + wake_time * wake_I) / total_time
= {(1.9-0.00015) * 55 + (0.00015 * 10000)}/1.9
= (104.5 + 1.5) / 1.9
= 56 microamps.

This is comparable to the best overall sleep current of the original BS2.

Incidentally, the 55 microamps in total sleep is attributed to the quiescent current of the LT1121 voltage regulator (~25 microamps) and the operating current of the SX chip with the watchdog timer active (~20 microamps) plus the quiescent current of the memory chip. The quiescent current of the memory chip depends slightly on where the SLEEP instruction is located in memory. (See BS2power). The BS2pe uses a CAT24WC256 eeprom from Catalyst semiconductor, which has a relatively low current no matter where in memory the SLEEP instruction falls. However, if it really matters, you can optimize the sleep current by about 20 microamps by adjusting the position of the SLEEP instruction. The difference would be something like 75 microamps versus 55 microamps for the BS2pe.

Here is what happens when the BASIC Stamp finally wakes up from sleep, and starts to execute code. The actual PBASIC code execution (example, HIGH 0) begins about 0.5 millisecond after the wakeup. That is when you would see the pin P0 go high in response to the command, HIGH 0.


BS2pe wakeup from sleep

Another nice consequence of this short wakeup is that your Stamp can really wake up, execute quite a bit of code, and go back to sleep, all in the interval that any other Stamp is still yawning and drinking its morning coffee. For example, in 16 milliseconds, the BS2pe can execute up to 70 PBASIC instructions and then go back to sleep.

Lets say it wakes up once per minute to execute 70 instructions and then does a SLEEP 60. In that case, the average current would consist of 56 microamps for 60 seconds plus 15 milliamps for 16 milliseconds :

 {60 x 56 + 0.015*15000}/60.015
= (3360 + 225) / 60.015
= 60 microamps.

That is not bad for a data logger that can really get something done. Suppose that is operating on 4 AAA cells with a capacity of 1 amp-hour. Those would carry the data logger through almost 2 years of operation.

Here is the sleep and operating currents of the different Stamps (more info):

One more thing. During the wakeup period on any of the Stamps, all of the i/o pins become inputs. Some output devices (say a power supply) cannot tolerate this brief glitch and they may do weird and unexpected things. It is often possible to use a capacitor on the BS2 output to carry the system through. For example, the capacitor might hold the external power supply ON or OFF (which ever is the proper level) during the 16 millisecond or 0.25 millisecond glitch. This is much easier on the BS2pe, which is the only Stamp that has the shorter 0.25ms glitch.

BS2pe instruction timing


The BS2pe has an 8 mhz resonator, so it executes most instructions slower than the BS2p, which has a 20mhz resonator. The ratio of speeds is 8/20 = 2/5.  The BS2pe executes a HIGH 5 command in about 105 microseconds, in contrast to 140 microseconds for a HIGH 5 on the BS2 and BS2e. (The BS2p executes the HIGH 5 command in about 41 microseconds. more info). 

The BS2pe uses the same SERIN and SEROUT parameters as the original BS2 and has the same range of baud rates.

There are a few of the explicitly timed commands where the timing of the BS2pe statement was adjusted by design.  Here are those commands:

PULSIN pin, state_to_be_measured, variable
variable returns time interval in units of 2 microseconds,  up to 0.131070 second.
PULSOUT pin, period
pin output state is inverted for period = 2 * period microseconds up to 0.131070 second
RCTIME pin, state, variable
variable returns the time while the pin stays in "state", in units of 2 microseconds, up to 0.131070
COUNT pin, period, variable
counts the number of 1-0-1 or 0-1-0 cycles in period, where period is in units of 0.720 seconds (need to verify this)
SERIN, SEROUT timeouts, in units of 1 millisecond
PAUSE is in units of 1 millisecond.
The actual values differ from one Stamp to the next, due to variability in the ceramic resonator that determines the operating frequency of the Stamp.  It is usually within one percent of the correct value, 8 mhz for the BS2pe.   If greater accuracy is required, the timing must be calibrated against a more accurate standard.  For example, the OWL2pe has a more accurate crystal clock on board, in the form of a DS1307 real time clock chip.  It provides an accurate heartbeat pulse on pin x15.

COUNT is the only one that is different from the original BS2.   For example, here is how you would count out one second on different stamps.

Example, a Davis anemometer has a calibration value of 2.308 mph per hz. A 138.5 mph wind speed gives a 60 hertz signal. (138.5/60 = 2.308). The problem is to count for exactly the right amount of time to give a result directly in mph. That means, count for 2.308 seconds. That translates directly into 2308 milliseconds for the BS2, and for the BS2pe, 2.308*1389 = 3176.

Additional timing information:
RCTIME pin,startState,variable   duration returned to variable in units of 2 microseconds (like 2 an 2e), maximum 0.131072 second
PULSIN pin,targetState,variable       duration returned to variable in units of 1.875 microseconds, maximum 0.122880 second
PULSOUT pin,duration    duration in units of 2 microseconds (link 2 and 2e), maximum 0.131072 second
SERIN pin\fpin,baudmode,timeout,timedest,[x,y,x]   baudmode same as 2 and 2e, timeout or pacing in units of 1 milliseconds

<top> <index> <home> logo <>