dacs.doc electric

 

The Basic Stamp

The scoop on embedded computers in homes and cars

By Rich Chernock

 

THESE DAYS, when one thinks of computers, one's thoughts gravitate toward powerful systems. It isn't unreasonable to work at home with a system whose processor is approaching gigahertz speeds, with multigigabytes of storage and a significant fraction of a gigabyte in memory. There is another class of computer that we all use constantly, but of which we are often unawares--the embedded computer. These are cheap, very small, and quite underpowered by the standards above. They are also widespread. The cost of processing has become so low that in many cases it is less expensive to use a microprocessor rather than a mechanical timer (washing machines) or a common integrated circuit (alarm clock). As an example, a recent model of Mercedes has upwards of 35 processors distributed around the car.

Most of these embedded computers are used in mass production products, programmed in assembly with the code burned into ROM. Development versions for many of these are available for experimentation at fairly attractive prices. There are a small number that have a tiny basic interpreter built in, making development quite simple. An example, which I've been successfully experimenting with recently is the Basic Stamp: it is inexpensive ($35), small (not much bigger than a 9V battery), and comes with a rather rich instruction set. Working with this type of system is a refreshing challenge due to the constrained resources--low speed and limited RAM. The Basic Stamp 1 has a grand total of 256 Bytes (not KB or MB!) of non-volatile RAM available for program storage and 16B for data. As you might guess, sloppy programming styles are a disaster in this type of system.

What can it do?

As described above, it appears that the capabilities of the embedded computer are too limited to do anything useful. Due to a very clever design, the opposite is true: quite interesting projects can be done with this system (one example is described below). There are eight bidirectional I/O lines (individually controllable) which can be used for communications with the outside world. The tiny basic programs are tokenized, resulting in the capability to store 80-100 complex instructions, which are executed at an average rate of 2000 instructions/second. The 16B of data are addressable as bits, nibbles, bytes, or words--in any desired mixture. Programming is as simple as hooking up a connection to a DOS or Windows PC (parallel or serial, depending upon the model) and downloading code. Simple debugging facilities are available. Due to the non-volatile RAM, any code will be executed upon power-up and retained until reprogrammed.

The built-in tiny basic interpreter, has a number of unusual instructions which account for much of the power of this small system: reading analog potentiometer values, pulse width measurements, pulse width modulation for power control, digital and serial I/O and timing capabilities. Each of these costs only one instruction, making maximum use of the limited memory space. If you need more capabilities (more instruction or data space, more I/Os), there are other more powerful models available at a slightly higher cost.

Remote Audio Control Project

PROBLEM. I like to listen to music while I'm home, and I have a fairly elaborate stereo system in the den of my house. I wanted to be able to hear the music in other rooms, especially the kitchen. Turning up the volume in the den was not a solution, since the levels in the den would become unbearable. In addition, I wanted a bit of flexibility--control over volume and tone remotely as well as the capability to listen to a different source (in case the kids took over the den). To make matters more difficult, there is about a 50-foot run to get cables between the two rooms. Since the cables ran next to power lines, it seemed most appropriate to keep all the low level signals close to the music source and run speaker wires into the kitchen.

CONVENTIONAL SOLUTION. A number of prepackaged solutions are available, ranging from the simple (running speaker wires from the receiver and using volume pads) to the complex (purchasing a multi-room amplifier with remote controls and source switching). The simple solution didn't really meet my needs, since it doesn't provide the flexibility I was after. The complex solution would work admirably but was priced an order of magnitude higher than I wanted to invest.

TECHIE SOLUTION. When I first thought about solving this problem, my techie tendencies came to the forefront, with imagined solutions as exotic as modulating a laser beam to transfer the music signal to the kitchen (I actually dreamed up a design that would have worked, but practical considerations won out). When sanity prevailed, I decided that this might be my first opportunity to use a Basic Stamp in a real project. I had a twenty-year-old stereo amplifier lying around gathering dust. In addition, I had just run across an IC from National Semiconductor, the LM1983 (a digitally controlled preamplifier); a $10 part, of which I managed to obtain a free sample. It seemed like the perfect opportunity to try out a Basic Stamp.

The LM1983 allows the digital setting of volume for each stereo channel, bass, treble and selection between three inputs. This control is performed using three serial lines: clock, Address/Data and Data. The timing requirements are very loose, allowing software control of the three lines through bit twiddling. It was very easy to write a subroutine in basic that took a numeric value and controlled the serial lines to transmit it. Three potentiometers were used to set volume, bass and treble (this could have been done with up/down switches, but knobs gave a familiar user interface). Again, reading the potentiometer values was easy: The built-in instruction not only reads the setting but also applies a predetermined scaling factor automatically.

The program ended up being very simple: a loop that continually read the potentiometer values. If a value changed, the communications subroutine was called, which sent the appropriate instruction to the preamplifier chip to make the change. There was no problem fitting within the constraints of the Stamp: seven of eight I/O lines were used and only 75% of the memory space was necessary.

The physical implementation was simple as well. A small box was mounted on the wall in the kitchen containing the Basic Stamp & potentiometers, with a run of six wire phone cable going back into the preamplifier in the den. The preamplifier drove the stereo amp, with speaker wires running back into the kitchen to speakers mounted on the wall.

RESULTS. Nearly perfect. After connecting everything, I discovered that the Basic Stamp didn't "boot" when power was applied (my best guess is that inductance in the long run of wire slowed down the power-on transient). Rather than do something exotic, I used a quick & dirty solution: adding a momentary contact switch interrupting the power supply line. Tapping the switch caused the power to be interrupted & the computer boots. I now have total control over the signal in the kitchen, independent of what is happening in the other room. As is usually the case with embedded systems, my family has no clue that they are using a computer when they change the volume.

Where can I get one?

The manufacturer of the basic stamp is Parallax Inc. (http://www.parallaxinc.com/).One distributor is DigiKey: http://www.digikey.com. Scott Edwards (http://www.seetron.com/) supplies an officially sanctioned clone kit at a bit of a savings.


RICH CHERNOCK is a senior engineer at IBM research working in the area of advanced digital television and data broadcast. You can e-mail Rich at mpeg2@earthlink.net.

BackHomeNext