By Don Carveth, www.Botgoodies.com, Oct. 2004, Rev. 0
A project I’ve long had in the back of my mind was a multifunction bench test instrument that used many of the capabilities of an AVR microcontroller. I have developed an infrastructure for the addition of an endless collection of test instruments on a create-as-needed basis and have included a number of instruments that were relatively easy to implement, with lots of board space for future development. After debating on user interface I decided to go with a PC Windows interface. This gave me much more flexibility than using an LCD display albeit with some loss of portability and ease of use. I was easily able to add trending, a logic analyzer, alarms and min/max/avg calculations.
I have used the meter for about a month and it is working well. Not all functions have been extensively tested although with all of the features on the board I was able to use it to test itself in many cases. I expect I will be tweaking and adding features for a long while. Operation and my initial evaluation of each feature is discussed below. Note that the titles Multi Meter and Mega Meter are used interchangeably throughout the documents and are equivalent.
The board is based on an ATMEGA128 using my own development board. All features can be implemented on lower level devices although not necessarily at the same time. I took advantage of the second 16 bit timer and figured the extra RAM and 2nd UART might be handy someday. Microcontroller programming is done under GCC 3.2. The PC interface was programmed using VB 6.
Here are the instruments included as of this writing:
1. Two 0 – 10 VDC voltmeters
2. One 0 – 30 VDC Hi-Z autoranging voltmeter with x10 jumper to give 0 -300 VDC range
3. 0 – 3 Amps high side ammeter
4. 4 channel logic analyzer
5. Frequency generator – 50% duty cycle square wave, 0 - 5 VDC, uC clock with divider, 1 Hz to about 8 MHz
6. Waveform generator – sine, triangle, square wave, 1Hz to 20+ MHz
7. Frequency counter
8. +5 VDC supply – 200 mA available
9. -5 VDC supply – 300 mA available
The board is based on an ATMEGA128 using my own development board – see my website for schematic. The board includes the 5V supply, RS-232 interface, ISP interface, 14.7 MHz crystal and all other basic operational features. All included functions can be implemented on lower level devices although not necessarily at the same time. I took advantage of the second 16 bit timer, the extra RAM and figured the 2nd UART might be handy in the future. I added a 4.096 volt reference, a -5 volt supply fed by a second wall wart and a +6 volt supply fed by the development board power source. The +6 volt supply allows the op amps to reach about 4.5 volts instead of 3.5. This eliminates the need for rail-to-rail op amps and allows a higher reference voltage than 2.5V, the alternate to 4.096V, helping to strengthen the input signal and reduce noise. A 14.7 MHz crystal was used instead of 16 MHz to allow 115 K Baud serial communication. The attached spreadsheet shows the AVR pin assignments.
All components were mounted on a proto board and wire wrapped in place. The connectors are simple wire loops to which an alligator clip or micro-clip can be attached. Logic ground, analog ground, +5VDC and -5VDC connections are included. 5.1 V zeners with series resistors were installed on most inputs as over voltage protection. All connections are labeled with colored labels created using Corel Draw.
c code, include executable file
The AVR program in written in c and compiled using GCC3.2. Specific device configuration info, calibration constants, etc. are defined in multimtr.h.
The program normally runs in an endless loop monitoring all analog inputs and frequency counter and periodically reporting values back to the PC. The logic analyzer function takes over completely when invoked and stops all other monitoring.
The UART input and output functions are in the UART.c file. Communication to the PC is via RS-232 serial port at 115K Baud using a simple protocol. The first transmitted character is an alpha character indicating the type of data packet. The data is sent as decimal digits in Ascii format, i.e. 980 is sent as “9” “8” “0”, three Ascii characters. This is not quite as efficient as a byte protocol but I already had the functions developed. To maximize performance this would be a possible optimization step. There is no checksum or other error detection included.
Commands from the PC to the microcontroller use a similar format, using alpha codes to designate the command, followed by decimal digits in Ascii. The microcontroller UART receive routine uses a receive interrupt routine to capture data.
PC VB code, includes .exe but may not work without full install
PC Install (4 MB), full installation program
The PC software is written in VB 6. It uses two components that may not be available to you – MSComm, excluded from VB Standard edition, and ProEssentials Pesgo (scientific graph) evaluation version. The evaluation version works but it prominently displays the ProEssentials banner (I believe the banner migrates to the center of the display after 60 days). The same features could be implemented, with considerably more effort, using MSChart.
The VB source code plus a full install package is attached.
A “terminal” window is included that monitors all incoming serial data, useful for troubleshooting. The “chart” window is used to chart incoming analog data over time. Use the “reset timers” button to reset the timebase used as the chart x scale. The “Logic” window is automatically invoked when the Logic analyzer is “Set”.
High and low alarms can be set for all analogs which turn red and beep. Min, max and average values are calculated since program start or since hitting the “Reset Min/Max” button. The “Data On/Off” button stops processing incoming microcontroller data and stops logging it to the terminal window. The “Update Rate” setting specifies how often the microcontroller sends data.
A configuration file, MultiMtr.cfg, stores basic configuration data including Comm Port, Baud rate and V3 zero adjust which is stored on program exit and reloaded on program start up.
0 – 10 VDC Voltmeters
The two 0 – 10 VDC voltmeters are very basic ADC inputs. A voltage divider converts 10 volts to about 4 volts. An internal calibration factor was applied so that the signal agreed with my multimeter. Of course the accuracy can only be as good as your calibration reference. The accuracy of these inputs degrades as the voltage reduces. The input impedance is only about 10K which is not good enough for some applications, but is good enough for many others.
0 – 30 VDC Hi-Z Autoranging Voltmeter
This was a little more challenging. I used an LM358 op amp in a non-inverting amplifier configuration. In this configuration the gain is equal to R feedback divided by R to ground plus 1. R to ground is changed in four steps by connecting one, or none, of 3 resistors to ground by setting an AVR pin output to 0. If the pin is not to be grounded it is set as an input (high Z). I have a calibration factor for each of the 4 steps. The AVR software decides which step should be used depending on the input voltage and reports the step to the PC to allow changing the display resolution. Also included is a x10 jumper than increases range to 300 VDC. I considered adding a negative voltage feature but the complexity increased. The input impedance is > 1 MegOhm. The PC window includes a zero adjust, the value of which is stored in the configuration file.
0 – 3 Amp Ammeter
The ammeter monitors current via a MAX471 high side current monitor chip. This feature is not the best as the current source must be at least 3V above board ground as the chip relies on the external power. The Mega Meter board ground must be connected to the ground of the board under test. There is no ranging so that accuracy declines at lower values, although the same ranging trick used with the voltmeters may work. Again, a calibration factor was applied.
4 Channel Logic Analyzer
Four digital inputs are monitored. All inputs are pulled high so they report as high if not connected. The software continuously looks for state changes. If any change of state of the 4 pins is noted then the value of the port plus a timestamp is saved in RAM. This continues until the number of events is reached (set “samples” on PC) then the data is sent to the PC as a batch and displayed on the Logic Analyzer chart. The clock is based on 16 bit TCNT3 with an overflow interrupt creating a 32 bit value. Brief testing indicates that this works up to about 50 KHz. This method keeps the data storage requirements low but there is more calculation overhead involved which reduces the frequency response. To increase the frequency response I would trigger based on an event then save the port status at fixed intervals to avoid saving the timestamp. The interval could be adjustable. You could also have the start point adjustable so that it begins recording on an event other than the first.
The microcontroller must be reset after completing its run and the “Done” button on the PC main window hit to set operation back to normal.
This a simple frequency generator using TCNT1, a 16 bit timer counter in normal mode (not PWM). The frequency is adjusted by modifying the value in OCR1A. This value can be set from the PC. Note that as the frequency rises the accuracy decreases as the output frequency is a divider of the main clock. With a 14.7 MHz clock we can only generate frequencies that are an integer divisor of 14.7 MHz. The PC screen includes an “actual” value that is calculated based on the value entered to account for this error. The output is a 0 to 5 volt square wave directly from the microcontroller output.
The frequency counter uses 16 bit TCNT3 in external clock mode to count incoming pulses. An LM358 op amp with adjustable gain is used to amplify incoming signals to the point that triggering occurs. The output from the frequency generator can be jumpered to this input for testing. The sample interval adjusts automatically. With no input the interval will automatically adjust to max, about 2 seconds. As the frequency rises the sample interval is decreased automatically. The resulting value is sent to the PC along with the analog data and displayed as “Hz”. The useful range is from about 20 Hz to about 1 MHz.
A waveform generator based on a MAX038 is included. It is really a separate entity from and not connected to the microcontroller - in fact I ended up installing it on a separate board, but the schematic is included. It puts out a -1 to 1 V sine, triangle or square wave, with adjustable duty cycle, from about 1 Hz to > 20 MHz. An LM358 op amp converts the -1 to 1 V signal to 0 to 3.5 V, useful for logic circuits. The design used is pretty much straight out of the MAX038 data sheet. Get the datasheet at www.maxim-ic.com. Here is the spreadsheet that I used to calculate the capacitor values.
Hopefully this has proved useful to you. If you have any questions about the article,
please contact the author at email@example.com.