started — to experiment. It’s fun; it’s a lot of fun. And I
promise that you won’t soon forget what you learn from
your experiments — especially those experiments with
Okay, let’s experiment. For reasons I can’t explain, a
bunch of customers seem to have come up with the
ADC0832 (two-channel ADC) and are wondering why the
application code for the ADC0831 floating around doesn’t
work with it. (That sound you just heard was the old-timers
smacking themselves on the forehead and exclaiming,
“Duh!”) The reason, of course, is that the ADC0832 is
NOT the same as the ADC0831. It’s in the same family,
yes, but it is not the same part, so it will require different
connections and code.
For our experiments this month, we will need just a few
parts: the ADC0831 and ADC0832 (or ADC08832) that we
just mentioned, a couple of 10K trim pots, and a project
board to connect things to the BASIC Stamp. You can use
anything handy: the BOE, the NX-1000, or — my new
favorite — the Parallax Professional Development Board.
Let’s start with the ADC0831. I will admit that I’ve kind
of glossed over the details of this part in the few projects
where I used it, because I (incorrectly) assumed that it —
and code for it — had been around for such a long time
that everyone who used the BASIC Stamp had an understanding of how the ADC0831 works and how to apply it.
As is occasionally the case ... I was wrong.
Grab your parts and connect the circuit shown in
Figure 1. For the time being, make sure that you have the
pot connected to Vref moved to the + 5 V position (confirm
with a multimeter). Before we get on to the code, let’s have
a look at a couple of technical details that the manufacturer
provides in the form of a timing diagram. The timing
diagram shows the signals in and out of a device and the
relationships vis-à-vis time. Figure 2 shows the essential
signal timing for the ADC0831.
What this diagram shows us is that we must take the
CS (chip select line) low to initiate a read of the ADC0831.
Why? Well, maybe we can’t find an ADC0832 and we need
two distinct channels. By using separate CS lines to control
each device, two ADC0831s can share the Clock (CLK)
and Data Out (DO) lines. After the CS line is brought low,
the CLK line needs to be pulsed activate the device. After
that, eight additional clock pulses cause the data bits to be
shifted out of the ADC0831.
At first, we may be inclined to write a subroutine that
looks like this:
PULSOUT Clk, 50
SHIFTIN Dio, Clk, MSBPOST, [adc\8]
It all makes sense, right? We bring the CS line low, blip
the clock line with a pulse to wake the ADC0831, shift
eight bits in, and then finish up by returning the CS line
high. Anything wrong with that? Nope, not a thing. Can the
routine be improved? You bet.
Through understanding and experimenting (there’s
that dreaded “e” word ...), we find that we can remove the
PULSOUT instruction and shorten the code to look like this:
SHIFTIN Dio, Clk, MSBPOST, [adc\9]
The first question that probably comes to mind is “How
can you use nine clock pulses with an eight-bit value?” We
can do that by understanding what happens to a value
when we use SHIFTIN. Let’s get gory with details, shall we?
When using MSB mode, the target variable is shifted
left (MSB goes into la-la-land and a 0 is placed in Bit0),
then the data line is sampled (in this case, after the clock-POST mode because the ADC0831 makes data bits available
after the clock pulse falls), and that bit is placed into the
Bit0 of our target variable. When we get to that ninth clock,
the first bit sampled gets shifted from the MSB (Bit7, in this