Stamp
exploded! Okay, all kidding aside, it’s not terribly complicated, but it is very sophisticated and if one doesn’t proceed deliberately, things can get out of hand in a big hurry.
Think about it, the uM-FPU is a coprocessor for floating-point mathematics — something that we all [should]
know is NOT a trivial process. Floating-point requires a
gigantic amount of processor resources; hence, most
micros don’t have FP built in. In fact, it wasn’t all that long
ago that our PC processors started coming with FP built in.
Many of us remember the good old days when we had to
crack open our PC to add a floating-point coprocessor (my
first was an 80287 for my IBM PC Model 50) to speed up
math-intensive applications like CAD.
Using a coprocessor for a small micro like the BASIC
Stamp makes sense to me — most of my projects do not
require FP math, so why waste the resources when I can add
FP only when needed? But that’s just my opinion, and I know
that many of you think differently. For those that are looking
for a way to add FP math to your BASIC Stamp projects,
we’re going to work through converting our DS1620 project
for use with the uM-FPU. Now, I will admit without reservation, that this project is not even coming close to scratching
the surface of capabilities of the uM-FPU; but it will get you
going, and will prepare you for more complicated tasks.
Figure 3 shows the connections for the uM-FPU using
SPI mode. The uM-FPU is fairly flexible in its connections
and has separate input and output data pins (SIN and
SOUT) for micros that can’t use the same IO pin for input
and output. Since the BASIC Stamp can do that without any
problems, we simply put a 1K resistor between those pins to
prevent any conflicts. Notice that the uM-FPU has a CS pin.
This is not a Chip Select as we might first assume. What this
pin actually does is configure the communication mode of
the uM-FPU. When tied low (as we’re doing), the
uM-FPU uses SPI communications; when tied
high, it uses I2C communications (yes, clock and
SIN/SDA must be pulled up). The latter mode is
convenient when using the BS2p family and
when there’s already an I2C bus in the project.
Getting to the meat of things, the uM-FPU
is a processor with its own language. Briefly,
the device uses 16 32-bit registers to hold values, and two pointers (A and B) to direct the
operations. If, for example, we wanted to multiply register 1 by register 2, then add register 3
and place the result in register 4, the uM-FPU
instructions would look like this:
an arcane language for a chip that I wouldn’t use very
frequently anyway. I nearly scrapped the idea of using the
uM-FPU until I remembered a comment in the docs about
an IDE for the uM-FPU. And since Cam was kind enough
to send me the chip, I thought I should at least give that a
look before walking away.
Hallelujah! What a difference a simple program can
make in my attitude toward the uM-FPU! The IDE makes it
so we don’t have to learn the uM-FPU language — it will
take very traditional looking code and covert it to uM-FPU
instructions for us. The program even lets us select the
compiled output format, including the BASIC Stamp
running is SPI mode. Now we’re talking! So, before you get
too involved in the uM-FPU programming commands,
download the IDE and give it a try – it will save you hours
of frustration. Figure 4 shows the IDE with the first pass
DS1620 code loaded up. You can see our input in the top
window and the compiled output (set for BASIC Stamp
SPI) in the bottom window. Let’s look at the input code.
RawT EQU F1
Counts EQU F2
Slope EQU F3
TempC EQU F4
TempF EQU F5
work VAR Word
tC VAR Word
tF VAR Word
RawT = work
Counts = work
Slope = work
TempC = RawT - 0.25 + ((Slope - Counts) / Slope)
tC = ROUND (TempC * 100)
TempF = (TempC * 1.8) + 32.0
tF = ROUND (TempF * 100)
Figure 4. uM-FPU IDE.
SELECTA+4
XOP, LEFT
FSET+1
FMUL+2
XOP, RIGHT
FSET
FADD+3
I don’t know about you, but my plate is
pretty full and I really don’t have time to learn
JULY 2005
29