AVR Digital Voltmeter

By Murray Greenman ZL1BPU

A simple multi-channel versatile DVM which uses the PC for display, and is powered by the serial port.


INTRODUCTION

Most electronics hobbyists these days find a digital voltmeter indispensable. Indeed, having more than one is a positive advantage! This little project with six voltmeters in one inexpensive box therefore has some very useful features for the hobbyist.

The unit is quite inexpensive - two ICs and a couple of transistors. One of the ICs is an AT90S4433 AVR micro controller - also inexpensive, and quite powerful. A feature of this chip is that it has six 10-bit Analog to Digital conversion inputs, allowing measurements with a resolution of about 0.1% of full scale. The AT90S4433 processor used is now discontinued, but has been replaced with a cheaper, higher specified device which is largely code and pin compatable - the ATMEGA8.


The very simple prototype - not much to it!
Click on image to view full size

Because the micro can be operated in an extra-low current "snooze" mode, it is possible to operate the unit from the small currents supplied by the PC serial port. Some of the features of the unit are:



The PC Voltmeter Display
Click on image to view full size

DESCRIPTION

Power for the unit comes from the "handshake" lines of the PC RS232 serial port. A low dropout regulator provides 5V with sufficient current to operate the highly efficient microprocessor. The RS232 transmit signal from the microprocessor requires a negative voltage, and rather than include an expensive and current-hungry negatve supply inverter, this voltage is derived from the mostly idle PC transmit data line, which is normally negative.

The microprocessor operates in snooze mode, where the A-D converter operates at about 3 kHz, and via an interrupt wakes up the processor briefly to process the results. Periodically, the processor is again woken by a timer, in order to sample the data at an accurate rate and transmit the data to the PC. When each task is done, the processor goes back to sleep. The processor is fast, and achieves these tasks very quickly. Thus the average current drawn by the device is very low.

The A-D converter operates much faster than the output sampling rate, so in "Voltmeter" mode, oversampling (decimation) is employed to remove sampling jitter and noise, and to add two bits of further resolution to the data (12 bit), using a Digital Signal Processing technique.

The resolution is equivalent to 1 in 4096 (0.024%) or just over 1mV for 5V full scale. That's not to say that the accuracy is anywhere near this, because it isn't, but that's usually less of an issue. The unit can be easily trimmed to 0.5% accuracy by adjusting the reference voltage, trimming the input resistors, or trimming the scaling factors in the PC setup file, which is by far the simplest method.

In "Scope" mode, just one of the channels is transmitted, but the sampling rate is increased by a factor of 10, and the averaging is omitted, so the data has 10 bit resolution. The Scope mode is too slow to display 50 Hz hum correctly.

The sampling rates are 10 Hz per channel in Voltmeter mode and 100 Hz in Scope mode. The default mode is Voltmeter mode.



The Oscillocope Display (detail)
Click on image to view full size

An interesting feature of the Scope display is that it features an autoscaling effect, where the same data is presented at three dirrerent "gain" settings, using software trickery. This provides a sensible display even if the signal is too small to reach full scale.

The PC display is a DOS executable, which will operate from DOS, Win 3.x, Win95 or Win98, on any valid serial port. Because the source code is also provided, the user can adapt the program to suit the purpose. The example program switches itself and the micro between Voltmeter and Scope modes, showing how this technique can be used for other applications. It would be very easy to write a chart recorder or data logger application, writing the data to a file format suitable for spreadsheet analysis and graphing. See the software section for more information on how to use the PC software.

The unit can be very small. Even built on "Veroboard", it can be under 100mm square. Perfect for building into some important piece of equipment, or as a piece of test equipment with no "front panel".

Note that this project isn't a completed product - it is a collection of ideas, firmware, software and hardware, that you can mix and match to make exactly what you need. This has been one of the most popular of all the projects, but before you ask, there is no kitset and no parts are available from the author.

COMMS PROTOCOLS

VOLTMETER
The Voltmeter mode transmits eight channels, in channel number order, four ASCII characters per channel, in a 32 byte frame terminated with <CR><LF>. The frames are transmitted every 100 ms in 19200-N-8-1 format.

04D40FFC0000009600A301F100000004
04D40FFC0000009600A101F000000004
04D40FFC00000096009F01F000000004
04D40FFC00000095009E01F100000005
04D40FFC00000095009E01F300000005
04D40FFC00000096009F01F000000005
04D40FFC00000097009E01ED00000005
04D40FFC00000097009F01EB00000005
Voltmeter Mode data observed with Windows TERMINAL

SCOPE
The Scope mode transmits one channel (Channel 0), three ASCII characters per sample, 10 samples per frame, in a 32 byte frame terminated with <CR><LF>. The frames are transmitted every 100 ms in 19200-N-8-1 format. While this mode could be speeded up by transmitting only eight bits and using a binary format, the speed is still ultimately limited by the modest speed of the A-D converter. If a higher speed oscilloscope is required, use one of the excellent PC sound card oscilloscopes.

19F19019019019019C19D19D19D19B
19D19119019019019C19E19D19D19D
19E19119019019019C19E19B1AA1AA
1AE1901AD1A81AE1AF1AE1A91AA19D
19E19119019019019C19F1AA000000
000000001000001000000000001000
Scope Mode data observed with Windows TERMINAL

MODE CONTROL
Switching between modes is achieved by transmitting a single byte, "V" (Voltmeter) or "S" (Scope) from the PC to the micro in 19200-N-8-1 format. Repeated commands and incorrect characters are ignored. The mode is switched at the start of the next frame. There may be one or more invalid frames of data at the switch-over point. Valid frames will always have 32 or 30 characters with a <CR><LF> terminator. The PC program used should test for this validity. There should be 30 or 32 characters between each <LF> and the following <CR>; 32 in Voltmeter mode, and 30 in Scope mode.

WHY A SPECIAL PC PROGRAM?
Of course since the data is sent in "human readable" (ASCII) form, it is possible to monitor the data using a Terminal program, such as was used to capture the above examples. This is still a good method to use if you wish to capture the raw data to a file, but the PC program offers many advantages - conversion to real data units, scaling, digital and bar-graph display, as well as trend graphing and data logging. In addition, the display is stable, rather than continually scrolling up the screen.

DATA CHANNELS

A-D Channels
Channels 0 - 5 are analog data channels. The basic input is voltage, 0 to +5V, so the resolution is 5V/4096 = 1.22 mV. All six channels operate identically: the PC software sets the range, data labels, calibration and offsets to suit each user input configuration, although the default setup is shown in the PC screen shot.

The data can be scaled in the PC, where floating point arithmetic is easy to achieve. In the sample program both scaling and offsets are allowed, and the factors are defined in a setup file. The scaling allows easy calibration on a per-channel basis. Smaller signals can be handled easily at reduced resolution.

Negative scaling factors can be used, for example with thermistors or optical sensors which give reduced voltage or resistance with increased temperature or light level. Offsets are useful for applications such as temperature measurement, where zero does not represent 0°C.

In Scope mode only Channel 0 is transmitted. The data range is 000 to 3FF and the resolution 4.88 mV.

Frequency
Channel 6 is a digital frequency counter channel. At present this output always reads 0000, as the hardware and code are not yet developed. It is intended that this channel will operate as a frequency counter with 16 bit resolution, i.e. 1 Hz to 65 kHz or 1 kHz to 65 MHz. The same scaling and offsets apply to PC use, so prescalers and IF offsets can be catered for.

Time
Channel 7 sends time in seconds since the processor was reset. After about 18 hours (65535 sec) the time overflows to zero. The data is in the range 0000 to FFFF. The time is synchronous with the data samples, i.e. there are 10 frames per second increment.

HARDWARE

The schematic is very simple. Just two ICs, two transistors, a crystal, two connectors and a handful of small components. A 3.6864 MHz crystal is best, but a 4 MHz crystal will work fine if the software is changed to give the correct serial port data rate (see the software section).



The PC Voltmeter Schematic
Click on image to view full size

The "signal conditioning" circuitry is shown on the left, with all channels configured as >5V inputs. Of course since every one of the six analog inputs to the left of the circuit can be used for something different, each one can have a different input circuit. With no series resistor, i.e. with one of the series resistors R11 - R16 replaced with a link, the DVM will provide a 0 to +5V range.

Note that the microprocessor will be damaged by input voltages over 5V, or below zero, even if present only briefly. For ranges higher than +5V, the input can be effectively protected by a pair of low leakage signal diodes such as 1N4148s, to clamp the input between 0V and the +5V supply. Connect the anode of one diode to 0V, the cathode of the other to +5V. The other ends of the diodes should be connected together and connected directly to the microprocessor A-D input. For voltage ranges above 15V the series resistor and the microprocessor's own input protection should suffice.

The +5V input is the first example shown in the diagram below. Typical signal conditioning circuits for other applications are also shown. Note that each one has a 100k Ohm resistor to ground. These are resistors R1 to R6 in the main schematic. For voltage inputs, choose a series resistor R11 to R16 which drops the full-scale voltage minus 5V at a current of 50µA.

Rseries = (Vfullscale - 5) x 20,000 Ohms
For example, for 25V full scale the upper resistor would be 400k Ohms (two resistors, 220K + 180k in series), but watch the tolerances! For ratiometric temperature, resistance and optical inputs, short the series resistor R11 to R16 and connect the sensor between the input and +5V. This will be obvious from the examples.


DVM Signal Conditioning Circuits

SERIAL CONNECTIONS

The schematic shows seven serial port connections, TXD, RXD, DTR, DSR, RTS, CTS and GND. No other connections are necessary. For use with a PC, you will probably need a 9 pin female connector (DB9F). The pin numbers shown correspond to the pins on the DB9F connector. With this configuration, the device will plug directly into the PC serial port, or it can be connected by a short pin-for-pin modem cable (i.e. not a "null modem" cable. Some PCs have 25 pin serial ports. A 25 - 9 pin adaptor is the simplest soluition here, although of course a DB25 connector could also be used.

In both modes the PC software controls the serial port to assert CTS and DTR active (+ve) to power the micro. While the serial port can typically source 20mA from each of these outputs, it may take the current from both CTS and DTR pins to operate the DVM since the port output voltage needs to remain above 6V to ensure a reliable 5V supply. If the supply voltage is too low, the DVM will still operate but accuracy will be poor.

SOFTWARE

It is possible to purchase just the executable code, or both the executables and source code. In both cases the PC software is also supplied. Two versions of the micro code are supplied in each case, one for 3.68MHz, the other for 4.00MHz. See the Micro Page for details.

Copyright © M. Greenman 1997-2005. All rights reserved. Contact the author before using any of this material.
home HOME