This is only a preview of the December 1994 issue of Silicon Chip. You can view 28 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Items relevant to "Dolby Pro-Logic Surround Sound Decoder; Pt.1":
Articles in this series:
Items relevant to "Clifford - A Pesky Little Electronic Cricket":
Articles in this series:
Articles in this series:
Items relevant to "A 3-Spot Low Distortion Sinewave Oscillator":
Articles in this series:
|
Many of us have had a dream
of building up a small general
purpose board with a CPU, a
bit of memory & some I/O lines.
Then we could write programs to
handle small applications. One
easy way to do it would be to
use the Stamp, a complete selfcontained microcontroller board
the size of a large postage stamp.
A look at the Stamp
microcontroller board
By BOB NICOL
If you take the conventional approach to designing a microcontroller
board, you have quite a few steps to
go through. But once you had the basic design produced, it would make
applications a lot easier. Ideas could
be tried out swiftly and easily, without
the need to get parts together, before
a start could be made. Such a device
could be used on many projects and
should a project fail, the board would
not be wasted but used again without
major changes.
Once one starts building such a
board, one will be up for paraphernalia
to do the job efficiently – an assembler,
an in-circuit emulator, and the need
to put your own PC board together.
And in the middle of all this, one is
probably struggling to learn a new
programming language. Now you will
be exposed to the write, burn, try,
debug, erase, edit, reburn, etc merrygo-round. And that time consuming
procedure will occur for each new
application of your board.
With all the above to cope with, it is
little wonder that few people turn the
dream into reality – there is too much
work involved. So here is a much
less expensive and more comfortable
alternative. It uses an EEPROM and
54 Silicon Chip
reprograms in around a second!
Called the Stamp, it is a small board,
measuring only 60 x 35mm (not much
bigger than a typical stamp). The board
uses a PIC16C56 microcontroller and
a memory chip, a ceramic resonator,
a 5V regulator, two resistors, three
capacitors, a transistor and a 14-pin
connector. Also on the board are the
battery connectors, a 3-pin header
for programming by a PC-compatible
computer, and a 10 x 14 plated-through
hole work area. The complete circuit
is shown in Fig.1.
Made by Parallax, USA, the Stamp
has 33 instructions to do some usual
and unusual things with eight I/O
lines. The Stamp is small and simple
and comes close to being a programmable integrated circuit. Take a look
at the list of application notes in Table
1 and you will see that although the
instruction set is small, sophisticated
tasks can be achieved by the Stamp.
At the time of writing, 19 application
notes are sent with each Stamp programming package.
Simplicity has been achieved by
using the PIC16C56 which includes a
BASIC-like interpreter. It has some familiar BASIC commands such as FOR,
NEXT and LET, plus some unusual
commands like MAX, MIN, PULSIN,
PULSOUT, BUTTON and POT.
An EEPROM is used to store a program. This same EEPROM may be used
to store data from the PC when initially
loading a program and via the WRITE
command which allows the Stamp to
write data into its own EEPROM. The
exact amount of memory available for
data storage is determined by what is
left spare in the 256 byte EEPROM after
storing your program. One has to be
careful not to overwrite the program
with data.
REM statements may be used in
your program; these are not sent to
the Stamp but kept in FILENAME.BAS
which is stored by the Stamp editor/
programmer.
To program the Stamp one needs
an IBM compatible PC, a Stamp programming cable, software and the
instruction book. To save the cost of
a power supply, the Stamp may be
powered by a 9V battery.
Writing software
To any one who has used a text editor, the editor/programming software
supplied with the Stamp will have a
familiar feel about it. It is a full screen
editor with all the usual file handling
PC
PROGRAMMING
CONNECTOR
DATA
8
VCC
VCC
4.7k
3
BUSY
2
16
15
VDD
4.7k
RA0 17
18
RA1
RTCC
RA3
RA2 1
11
IC1
PIC16C56XT
OSC1
OSC2
4MHz
MCLR
4
Q1
2N3906
RB0 6
VSS
5
OUT
VCC
(+5V)
2.2M
10
2.2M
VSS
5
USER
PROGRAMMABLE
I/O PORT
RB2 8
RB1 7
470k
CS
ORG
6
13
RB7
RB6 12
RB5 11
RB4 10
RB3 9
VCC
Table 1: Applications
4 D0
3
D1 IC2
2 CLK 93LC56
IN
COM
9V
Fig.1: the circuit of the Stamp uses a PIC16C56 microcontroller and a
93LC56 EEPROM. The 2N3906 is used for resetting the micro and is a
surface mount device on the copper side of the board.
functions, while movement through
text on the screen is via the normal
cursor keys, with HOME and END as
well as PAGE-UP and PAGE-DOWN
being appropriate commands. The
editor does not use a mouse, however
CUT, COPY, PASTE and SEARCH/REPLACE are easily accomplished using
keyboard strokes.
There are nine pages in the 63page instruction book ex
p laining
how to use the editor, four pages of
introduction, 12 pages for explaining
hardware, and 37 pages devoted to
commands. Using some of the commands requires a little extra circuitry,
as detailed below.
BUTTON is the command used for
connecting push buttons, keys, or
switches to the Stamp. The Stamp’s in+5V
10k
terpreter debounces the switch action;
all the user needs to do is specify pin
number, whether the transition will
be high to low or vice versa, and auto
repeat requirements. The two button
circuits are shown in Fig.2.
POT is a command which could be
used to read the angular setting of a potentiometer. The command also works
well with thermistors, light dependent
resistors, etc. When using POT the
programmer needs to specify which
pin the variable resistor is connected
to and set a scale factor.
There is a convenient setup facility in the program writing editor:
just press <ALT>P and you will be
guided through a setting up routine.
Measurement of the resistor value is
achieved by measuring the time taken
+5V
TO
I/O
PIN
10k
TO
I/O
PIN
Fig.2: these are two circuits
for use with the BUTTON
command. The button can
switch the input high or low.
5-50k
TO
I/O
PIN
0.1
0.1
Fig.3: the POT command uses
this circuit to charge a 0.1µF
capacitor and the charging time
is measured by the micro.
(1) LCD user interface terminal
(2) Interfacing an A/D converter
(3) Hardware solution for
keypads
(4) Controlling and testing servos
(5) Practical pulse measurements
(6) A serial stepper controller
(7) Sensing temperature with a
thermistor
(8) Sending messages in Morse
code
(9) Constructing a dice game.
(10) Sensing humidity and temp
erature
(11) Wireless infrared
communication
(12) Cheap sonar rangefinding
with the Stamp
(13) Using (extra) serial EEPROMs
(14) Networking multiple Stamps
(15) Using PWM for analog output
(16) Keeping Stamp private
(17) The solar powered Stamp
(18) One pin, many switches
(19) Using BUTTON effectively
to charge the capacitor in the circuit
shown in Fig.3.
PWM is virtually the reverse of the
POT command. PWM with appropriate circuitry will give an analog representation of a value contained in a
variable. This variable could have been
accessed by the Stamp from a serial
data input, a variable resistor input
from POT, or could be derived from
calculations done on variables, constants and look-up tables. The circuit
used is an RC integrator as shown in
Fig.4 but it will need to be followed
by an op amp buffer.
SERIN is the Stamp’s command for
reception of serial data from another
Stamp, a PC, logging device, a modem
or whatever. The programmer needs to
specify pin number and speeds from
300-2400 baud are available. One may
invert the mark/space of the bits; this
makes it easy to use other interface
ICs where a more sophisticated system
may be in use. The SERIN command
may be set to wait for a specific character or string before doing anything.
The circuit (Fig.5) is simply a resistor
between the ±10V serial input and the
designated I/O pin.
SEROUT is exactly the reverse of
SERIN and may be used to send mesDecember 1994 55
Table 2: Stamp Command Set
Branching
IF THEN
BRANCH
GOTO
GOSUB
Looping
FOR.NEXT
Numerics
(LET)
Compare and conditionally branch
Branch to address specified by offset
Branch to address
Branch to Subroutine, up to 16 allowed.
Establish a FOR-NEXT loop
Perform variable manipulation, such as A=5, B=A+2, etc.
Possible operations are add, subtract, multiply, divide,
maxlimit, minlimit, and logical operations, AND, OR, XOR,
ANDNOT, ORNOT and XORNOT. Note variables handle
integers only.
LOOKUP
Lookup data specified by offset, and store in variable. This
instruction provides the means to make a look up table.
LOOKDOWN Find target’s match number (0-N) and store in a variable.
RANDOM
Generate a pseudo random number.
Digital I/O
OUTPUT
Make a pin an output
LOW
Make pin output low
HIGH
Make a pin output high
TOGGLE
Make a pin an output, and toggle its state
PULSOUT
Output a timed pulse, by inverting a pin, for a time.
INPUT
Make a pin an input
PULSIN
Measure an input pulse
REVERSE
If pin is an output, make it an input, or if output, make it an
input.
BUTTON
Debounce button, perform an auto repeat, and branch to
address if button in target state.
Serial I/O
SERIN
Serial input with optional qualifiers and variables for storage
of received data. If qualifiers are given, then the instruction
will wait until they are received before filling variables or
continuing to the next instruction. Baud rates of 300, 600,
1200, and 2400 are possible. Data received must be with
no parity, 8 data bits and 1 stop bit.
SEROUT
Send data serially. Data format the same as SERIN command.
Analog I/O
PWM
Output PWM, then return to input. This can be used to
output analog voltages (0-5V) using a capacitor and
resistor.
POT
Read a 5-50kΩ potentiometer and scale the result.
Sound
SOUND
Play notes. Note 0 is silence, notes 1-127 are ascending
tones, and notes 128-255 are white noises.
EEPROM Access
EEPROM
Store data in EEPROM before downloading BASIC program.
READ
Read EEPROM byte into variable.
Time
PAUSE
Pause execution for 0-65536 milliseconds.
Power Control
NAP
Nap for a short period. Power consumption is reduced.
SLEEP
Sleep for 1-65536 seconds. Current consumption is reduced
to about 20uA.
END
Sleep until the power cycles, or the PC connects. Current
consumption is reduced to 20uA.
Program Debugging
DEBUG
Send variables to PC for viewing.
56 Silicon Chip
sages to a network of Stamps, pulling
each Stamp into use as needed. Again
the circuit is dead simple, as shown
in Fig.6.
SOUND puts out a tone on the specified pin. Pitch may be specified in the
command line or may be taken from a
variable. A conventional speaker may
be driven by putting a capacitor in
series as shown in Fig.7, while a piezo speaker can be directly connected
without the capacitor.
As with any program writing exercise, the jobs that may be done with the
Stamp are limited only by the user’s
imagination, skill with the commands,
and the facilities of the hardware supplied. To help the user get started, 19
application notes are supplied with
the Stamp programming kit. These are
listed in Table 1.
One of these application notes is reproduced here. This application note
presents a program in Parallax BASIC
that enables the BASIC Stamp to operate as a simple user interface terminal.
Many systems use a central host computer to control remote functions. At
various locations, users communicate
with the main system via small terminals that display the system status and
will accept inputs. The BASIC Stamp’s
ease of programming and built-in
support for serial communications
make it a good candidate for such user
interface applications.
The liquid crystal display (LCD)
used in this project is based on the
popular Hitachi 44780 controller IC.
These chips are the heart of LCDs
ranging in size from two lines of four
characters (2 x 4) to 2 x 40.
When power is first applied, the
BASIC program initialises the LCD. It
sets the display to print from left to
right and enables an underline cursor.
To eliminate any stray characters,
the program clears the screen. After
initialisation, the program enters
a loop, waiting for the arrival of a
character via the 2400 baud RS-232
interface. When a character arrives,
it is checked against a short list of
special characters (Backspace, control
C and RETURN).
If it is not one of these, the program
prints it on the display and re-enters
the waiting for data loop. If a backspace is received, the program moves
the LCD cursor back one space, prints
a blank (space) character to blot out
the character that was there, and then
moves back again. The second move
back is necessary because the LCD
automatically advances the cursor. If
a control C is received, the program
issues a clear instruction to the LCD,
which responds by filling the screen
with blanks and returning the cursor
to the left most position.
If a RETURN character is received,
the program interprets the message
as a query, requiring a response from
the user. It enters a loop, waiting for
the user to press one of the four push
buttons. When he does, the program
sends the character (0 through 3),
representing the button number back
to the host system. It then re-enters its
waiting loop.
Because of all this processing, the
user interface cannot receive characters sent rapidly at the full baud rate.
The host program must put a little
breathing space between characters;
perhaps a 3ms delay. If you reduce
the baud rate to 300 baud and set the
host terminal to 1.5 or 2 stop bits, you
may avoid the need to program a delay.
From an electronic standpoint, the
circuit employs a couple of tricks.
The first involves the RS-232 communication. The Stamp’s processor,
the PIC16C56, is equipped with static
protection diodes on its input/output pins. When the Stamp receives
RS-232 data which typically swings
between -12V and +12V, these diodes
serve to limit the voltage actually seen
by the PIC’s internal circuitry to 0V
and +5V. The 22kΩ resistor limits the
current through the diodes to prevent
damage.
Sending serial output without an
external driver circuit exploits another loophole in the RS-232 standard.
While most RS-232 devices expect
the signal to swing between at least
-3V and +3V, most will accept the 0
and +5V output of the PIC without
problems.
This setup is less noise immune
than circuits that follow the RS-232
rules. If you add a line driver/receiver
such as a MAX232, remember that
these devices also invert the signals.
You’ll need to change the baud mode
parameter in the instructions SERIN
and SEROUT to T2400 where T stands
for true signal polarity. If greater noise
immunity is required, or the interface
will be at the end of a long cable, use
an RS-422 driver receiver. This will
require the same changes to SERIN
and SEROUT. Another trick allows the
sharing of input and output pins be-
10k
FROM
I/O
PIN
ANALOG
OUTPUT
1
Fig.4: this integrator is used for
the PWM command but will
probably need to be followed
by an op amp buffer for many
applications.
FROM
I/O
PIN
10k
TO
OTHER
STAMPS
Fig.6: a loading resistor is all
that is required to implement
the SEROUT (serial data out)
command.
TO
±10V
22k
SERIAL
I/O
INPUT
PIN
Fig.5: just one resistor is needed
to implement the SERIN (serial
data in) command.
FROM
I/O
PIN
10
40
Fig.7: by using the SOUND
command, any of the I/O
pins may be used to drive a
40Ω speaker via a capacitor.
Note that if an 8Ω speaker is
used, a series resistor of 33Ω
will be required and this will
inevitably reduce the available
sound level.
Fig.8: the BASIC Stamp Programming package includes a number of application
notes, including one that enables the Stamp to operate a simple LCD user
interface terminal – see text.
tween the LCD and the pushbutttons.
What happens if the user presses
the buttons while the LCD is receiving
data? Nothing. The Stamp can sink
enough current to prevent the 1kΩ
pullup resistors from affecting the state
of its active output lines. And when
the Stamp is receiving input from the
switches, the LCD is disabled, so its
data lines are in a high impedance
state. These points allow the LCD and
the switches to share the data lines
without interference.
Finally, note that the resistors are
shown on the data side of the switches,
not on the +5V side. This is an inex-
pensive precaution against damage
or interference due to electrostatic
discharge from the user’s fingertips.
Currently the Stamp is available in
Australia at three levels: Starter level
is a programming kit containing software, instruction book, a programming
cable and one Stamp. This is priced at
$270 including sales tax. For a second
stage, extra Stamp modules are available at $79.85 each including sales
tax. Postage and packing on all orders
is $8.00. Send all orders to MicroZed
Computers, PO Box 634, Armidale,
NSW 2350. Phone (067) 72 2777 or
SC
fax (067) 72 8987.
December 1994 57
|