Posted on by & filed under Electronics.

 Introduction

For this this project you can either choose to use the MAX186 or
the MAX187. The differences between these two chips are described
below.

a 3 pin interface to communicate with the Stamp, CS(chip select),
DOUT(serial data), and SCLK(serial clock). It requires no external
reference voltage or external clock, its all built in to the chip.

The Max186 is an 12 bit 8 Channel ADC. Eight Channels means it can
measure 8 different voltages at once. There are many sensor around
today that output a voltage and to take the reading from them you
need to measure a voltage. Analog to Digital converters are a way
to interface the Basic Stamp, or other microcontrollers to the
analog world. They can measure hundreds of volts depending on the
voltage divider you use.

The reason for a voltage divider is because the MAX186 ADC can
only take an input voltage of 4.096V. A voltage divider a way the
divide the voltage you want to monitor. For instance say you want
to monitor a 12V car battery. But the MAX186 can only handle 4V
right. So how would you do this? Simple, a voltage divider. To
measure 12 Volts you want to divide
the voltage by 3. So all you need it a 220K resistor and a 100K.
Put them in series and connect your 12V to the 220K and GND to the
other end of the 100K. Then your output to the Op-amp comes from
the middle where the two resistor are connected.

Here is a formula to figure out the output. Vout=(R2/RT)*Vin
Now put the 12V into the formula Vout = (100K/320K)*12V= 3.75V Now
just times the 3.75V by 3.2 in your stamp program to get 12 Volts.
If you want to measure 100V, for instance, use a 1M and and a 33K.

Now here is what the op amp is for. The op-amp is in a voltage
follower configuration. This is a special case of a non-inverting
amplifier where all of Vout is fed back to the inverting input.
The straight feedback connection causes a voltage gain of approximately
one and a Av (Current gain) of one. The most important feature of
the voltage follower are its very high input impedance and
its very low output impedance. These features make it a ideal
buffer amplifier for interfacing high impedance sources and low
impedance loads. In other words it isolates the input from the
ADC. Another feature of the op-amp is its noise filtering. The two
inputs of the op-amp go directly into a differential amplifier
which compares the inputs and cuts the noise out completely. Most
of today’s sensors, that put out a voltage are very sensitive
(such as the LM35) which puts out 10mV/degree C and if you have
the slightest bit of noise and your readings are going to be off
by quite a bit. If you want more detailed info on the MAX186

Also the Max186 is available from Maxim
samples and they will send them to you, but be warned, it may take
a while for them to ship it. If you want to buy the MAX186 it will
run you about \$50! They can be purchased at Digi-Key
or other electronics vendors.

Below is the code for interfacing with the MAX186 A/D converter to the
Basic Stamp II.

 MAX187 Code MAX186 Code SCLK con 0 CS con 1 SerData_in con 2 adc var word main: gosub convert gosub print goto main print: debug dec adc return convert: low CS Shiftin Serdata_in,SCLK,MSBPOST,[adc12] high CS return Channel var nib Chsel var byte ADCin var word X var nib cs con 1 serDin con 2 serDo con 3 serclk con 4 high cs main: low cs channel =0 lookup channel, [142, 206,158,222,174,238,190,254],chsel shiftout serDo, serclk, msbfirst,[chsel] shiftin serDin, serclk, msbpost ,[ADCin12] high cs goto main

BASIC Stamp is a registered trademark
of Parallax, Inc.

Shaun is the webmaster of a
basic stamping page click
here to visit his site.

### 3 Responses to “A Simple And Free ADC For Your Microcontroller”

1. #### Mike Blankenship

Hi,

Nice article. Im using the MAX187 in one of my projects just like you have in your article :

My resolution is very good but on the output of my Voltake follower Im picking up a 70Khz signal !!! I followed the Max187 Grounding reccomendations but I still have this noise. Im also using a BSp240. I believe this is the Internal clock from the ADC. Have you seen this beofre? Any advice would be appreciated

2. #### Van Zander

Mike,
Any luck with your noise problem? I’m using a similar design – I have two MAX192 (8 channel, 10bit version of the MAX186) and a 74HN595 (shift register latch) using the same bus. I’m using the chip select on the ADC’s and ‘latch’ on the 595’s to select the chips. No problem on the output to the chips- but my results from the ADC are mostly random. I’m suspecting noise.

I’m using a pair of 74LS259 decoders to selectively supply 5v to the sampled channel – Im measuring an automotive thermo-resistor (going through a divider).

The circuit Shaun provides above worked on a breadboard – but once I put it all on a PCB, I’m getting noise. I should probably get an o-scope to see where the noise is. Based on your comment, I wonder if my Basic Stamp 2pe is also the source of the noise. The capacitors in Shaun’s circuit are probably ‘tuned’ to eliminate noise at a particular frequency.

Shaun says he is using a BS2 (20MHz), your BS2p40 is 20MHz turbo, my BS2pe is 8MHz turbo. I suspect that changing the .1uf cap to match would help. Thoughts?

3. #### Andrew

The code for the ADC for pbasic is incorrect here and at Shaun’s website. The code could simply be fixed by setting serDin to 3 and serDo to 2. I was getting random values for the most part till I switched those numbers, and then i was getting the correct values.