Digital Voltmeter

by frank26080115 in Circuits > Sensors

42621 Views, 61 Favorites, 0 Comments

Digital Voltmeter

DSC02188 (Small).JPG
output.gif
schem.gif
This is an instructable for beginners to teach you how to use an analog to digital converter

This will let you measure a ratio between a higher reference voltage and an input voltage. You need to calculate the actual voltage yourself because the basic stamp cannot calculate numbers below 1 (such as a percent)
Both the binary data and the decimal value will be displayed in the basic stamp debug window

This is done on a basic stamp 2 because it is the only microcontroller I have right now.
(I'll be making a programmer and cool toys for the PIC16F877A and PIC16F628A very soon.)

You will also need a 5v voltage regulator and a 3v voltage regulator (it's not really needed)
5v for the higher reference voltage, and the 3v for the test reading voltage (it's not really needed)
Your development board should already have a 5v supply though

And a MCP3001 analog to digital converter from Microchip at http://microchip.com/ , another converter can be used if it uses the same method to transmit the measurement result, and you may need to modify the code

datasheet:
http://ww1.microchip.com/downloads/en/devicedoc/21293b.pdf

Understanding Resolution

DSC02188 (Small).JPG
The resolution of a A/D converter means the accuracy, and it ranges from 8 bit and higher, the more bits, the more accurate results you can get

8 bit resolution has a maximum decimal value of 255, which means you can measure 255 different voltages ranging from 0 to whatever reference voltage you are using

16 bits has a maximum decimal value of 65535, big difference in accuracy, but only twice the storage needed

Say, if you wanted to make a voice recorder, and you needed the top sound quality, you need to get better resolution because it will make the sound so much more accurate, but the file size will be bigger

Serial Communication

pdf1stpage.gif
maxandpinfuct.gif
spitimeline.gif
This particular A/D converter, MCP3001, uses a SPI serial interface, after reading it's database, it all becomes very clear.

There are three pins connecting your microcontroller (the basic stamp) to the converter:

Clock, (aka "CLK", or "CK") is used to synchronize data transmission, it lets two different components send bits at the same speed, a single bit is sent in one clock cycle.
a clock cycle is putting the clock pin high (aka "on", "positive", or "+") then low (aka "off", "negative", or "-") , basically generating a square wave

Data, (aka "DAT", "DT", or "D out") is what outputs the reading values, it will output either a 1 or a 0 in one clock cycle, and your microcontroller stores that bit

Chip Select, (aka "CS", or "SS", SS means slave select, same thing though) is useful when you have multiple serial interfaced devices connected to just one microcontroller, only the chip that is "selected" will work, on this converter, putting the CS pin to high means not selected, while putting the CS pin low means you want to use that chip, and it begins to work

For A/D converters, sometimes the converter needs time to take a sample, for the MCP3001, you need to give it two clock cycles while it takes the sample, then the bits starts to stream in to your microcontroller, those are then stored in the memory of your microcontroller

The code will use the basic stamp's shift in command which makes this process easier, if you are using something else, you can manually make the clock high, read one bit, put the clock low, pause, and repeat until all 10 bits are read and stored

For more information, please read the MCP3001's datasheet
the images below are from the datasheet, READ IT
http://ww1.microchip.com/downloads/en/devicedoc/21293b.pdf

The Circuitry

Connect the chip select pin on the converter to pin 0 on the basic stamp, clock to pin 1, data to pin 2

"V ref" is the reference voltage input, connect that to the 5v voltage regulator's output

"V in +" pin is the reading input, and it should be connected to some sort of probe, or the 3v regulator for testing purposes

"V in +" pin is the reading input, and it should be connected to some sort of probe, or the 3v regulator's output
"V in -" pin is also a reading input, and it should be connected to some sort of probe, or the ground (which means negative)

Vss is connected to the ground, and Vdd is connected to the 5v regulator output

The battery on board your basic stamp's development board should be enough to power the entire thing, so connect the positive battery terminal to the input of both regulators, and the negative terminal to all the grounds on the regulators and the Vss pin on the converter

You can breadboard this just for fun, or if you want you can solder it to a microcontroller and add a lcd screen or something

The Code

This code is written in PBASIC which is used only for the basic stamp, the "shifin" command makes it very easy, if you have a AVR or PIC chip or something else, you should probably find a sample code for SPI interfaces, or bit bang (manually outputing the bits one by one, look it up) the whole input process, which is not hard with this A/D converter

Download the basic stamp code in this step, I hope I commented the code well

Downloads

Program It, and You Are Done

output.gif
schem.gif
Program the basic stamp or whatever you are using, and test out your new digital voltmeter

What ever you are measuring must be lower than the reference voltage

Do not reverse the probe polarity, it may damage your converter