Do-it-yourself digital voltmeter ammeter on pic. A simple modular AC voltmeter on PIC16F676. Description of the control board circuit

Nowadays, measuring instruments based on microcontrollers with a built-in ADC are becoming increasingly popular, especially since the availability and capabilities of such microcontrollers are constantly growing, the circuitry is being simplified, and their assembly is becoming feasible even for novice radio amateurs. LCD modules with their own controller are often used as information display devices in digital measuring instruments. This solution has disadvantages: the need for additional backlighting with high current consumption, a limited selection of displayed characters, and high cost. Therefore, it is easier and more convenient to use seven-segment three-digit LED indicators.

Voltmeter wiring diagram

Schematic diagram of a voltmeter on MK


Schematic diagram of a voltmeter on PIC16F676 - second option

PP voltmeter on PIC16F676

This is a simple voltmeter up to 30 volts based PIC16F676 microcontroller with a 10-bit ADC and three 7-segment LED indicators. You can use this circuit to measure up to 30 VDC. PIC16F676- this is the basis of this scheme. The microcontroller's internal ADC with voltage divider resistors is used to measure the input voltage. Then a 3 digit comm anode 7 segment display is used to display the final converted voltage. To reduce current consumption, the circuit uses dynamic indication. You can download firmware for various indicators here.

Device operation

A voltage divider is assembled on resistors R1 and R2, and a multi-turn construction resistor R3 is used to calibrate the voltmeter. Capacitor C1 protects the voltmeter from impulse noise and smoothes the input signal. Zener diode VD1 serves to limit the input voltage at the microcontroller input so that the controller input does not burn out when the input voltage is exceeded.

Reading calculations

A 10-bit ADC allows you to get a maximum number of 1023. So with 5 volts we get 5/1023 = 0.0048878 V/D, which means if the value is 188, then the input voltage is: 188 x 0.0048878 = 0.918 volts. With a voltage divider, the maximum voltage is 30V, so all calculations will be 30/1023 = 0.02932 volts/division. So if we now get 188, then 188 x 0.02932 = 5.5 Volts. You can further simplify and reduce the cost of the circuit by replacing the ALS indicators with a simple one

The ampere-voltmeter is designed to measure current 0-9.99A and voltage 0-100V with a resolution of 0.01A and 0.1V, respectively.

The operational amplifier can be replaced with LM2904, the LCD display should be on the HD44780 controller. The number of characters is 2x8... You can also use a 2x16 character display, but in this case most of the display will remain unused. In such a situation, in the device where the ampere-voltmeter will be built, it is recommended to cut a window only for the working part of the display on which information will be displayed. Important! Directly on the displays, as a rule, a current-limiting resistor is installed in the backlight power circuit. If there is no resistor, then you need to install it yourself in the open circuit going to LED +. The resistor resistance is 6...100 Ohms, depending on the desired backlight brightness...

Setting up the device is simple: first, use the “contrast” resistor to set the required display contrast, and use the “set U” and “set I” resistors to adjust the accuracy of the voltmeter and ammeter readings. It is advisable to make adjustments at the upper limits of the voltmeter and ammeter readings. If, after adjustment, the ammeter without load displays any current value, select the operational amplifier so that without load the current value is 0.00A!

Photo of the device!

Connecting an ampere-voltmeter to the power supply.

List of radioelements

Designation Type Denomination Quantity NoteShopMy notepad
MK PIC 8-bit

PIC12F675

1 To notepad
Shift register

CD74HC164

1 To notepad
Operational amplifier

LM358

1 Replacement: LM2904 To notepad
Linear regulator

LM7805CT

1 To notepad
LCD displayHD447801 8x2 To notepad
C1, C2, C4, C5 Capacitor0.1 µF4 To notepad
C3 Electrolytic capacitor100 µF1 To notepad
Resistor

100 Ohm

2 To notepad
Resistor

91 kOhm

1 To notepad
Resistor

5.1 kOhm

1 To notepad
Resistor

680 Ohm

1 To notepad
Resistor

0.01 Ohm

1

The circuit in Fig. 1 is a development of the previous design idea for using an analog input in a microcontroller that does not have a built-in ADC, and also uses technical techniques from another design idea for controlling a seven-segment LED indicator without external key transistors. This circuit has a serial channel and only needs a twisted pair cable to transmit the measured values ​​to a personal computer.

The serial link was tested using Microsoft's Hyper Terminal program configured with 115,200 baud; 8 bits, parity, 1 stop bit; without hardware control.

Briefly, the program controls one seven-segment LED indicator at a time via lines RA0 and RB7. Setting the RA0 output to one and using RB7 as an input activates the indicator with a common anode DS3. Setting output RA0 to zero and using RB7 as an input activates the common cathode indicator DS2. Using RA0 as an input and setting the output of RB7 to one will activate the common anode indicator DS1, and using RA0 as an input and setting the output of RB7 to zero will activate the common cathode indicator DS0. After successful activation of one indicator, only one of the lines RB0 ... RB6 is configured as an output to control one LED segment. This circuit is no longer limited to VDD supply voltage - 3V or lower - since the LEDs are back-to-back, so the forward voltage drop across one LED limits the reverse voltage across the other. Using red LEDs requires 1.6V.

Figure 2 illustrates new aspects of the design idea. Q1, R5, and R6 act as an equivalent variable resistor, RX, which charges capacitor C3. Instead of connecting RX to ground, simply connect it to one I/O line - such as RB0 - of the microcontroller. If RB0 is turned on as a zero state output, then the first analog channel is activated and the measurement routine counts the charge pulses to a value of 66% of VDD; then, according to the table, the resulting delay value is converted into a three-digit millivolt value. To increase the number of analog inputs, you can connect up to seven variable resistor circuits in parallel - such that each is connected between C3 and one I/O line, RB1...RB7. It is important that the I/O lines are connected to the indicators and also enable or disable analog channels. When one analog channel is driven low by the I/O line, the other lines are high impedance and act as inputs, which disables all other channels. Accordingly, the indicators are disabled.

A simple serial channel has also been added to the circuit in Fig. 1 without adding external components. If you connect two I/O lines, RA1 and RA2, configured as outputs to the RXD (Pin 2) and GND (Pin 5) of the RS 232 connector, you can create, with the help of a program, positive and negative voltages relative to the ground of the RS 232 port PC. When RA1 is one and RA2 is zero, RXD has a positive potential of 5 V relative to the ground of the RS 232 port in the PC. When RA1 is zero and RA2 is one, RXD has a negative potential of -5 V relative to the ground of the RS 232 port in the PC.


This device is implemented on PIC16F676 using a built-in ten-bit ADC. The voltmeter can measure voltages up to 30V DC and can be used in benchtop power supplies or various instrument panels.
Three seven-segment indicators with a common anode are used to display voltage. Information is displayed on the indicators dynamically (multiplexing), the refresh rate is about 50 Hz.

Voltmeter circuit:

Divider output voltage
By default, on a PIC microcontroller, the ADC reference voltage is set to VCC (+5 V in this case).
It is necessary to make a voltage divider that will reduce the voltage of 30V to 5V. It is easy to calculate Vin / 6 ==> 30/6 = 5, the division factor is 6. Also, the divider must have a high resistance in order to influence the measured voltage as little as possible.

Calculation
ADC - 10bit means the maximum number of samples is 1023.
The maximum voltage value is 5V, then we get 5/1023 = 0.0048878 V/Count. In this case, if the number of ADC points is 188, then the input voltage is 188 * 0.0048878 = 0.918 volts

Using a voltage divider, the maximum voltage is 30V, then 30/1023 = 0.02932 V/Count.
And if the number of ADC points is 188, then the input voltage is 188 * 0.02932 = 5.5 V.

The 0.1uF capacitor makes the ADC more stable, since ten-bit ADCs are quite sensitive.
The 5.1V zener diode is designed to protect the ADC from exceeding the permissible voltage.

Printed circuit board:

Photo of the finished device:

Accuracy and Calibration
The overall accuracy of the circuit is quite high, it completely depends on the resistance values ​​of the 47 kOhm and 10 kOhm resistors, therefore, the more accurately the components are selected, the more accurate the readings will be.
The voltmeter is calibrated using a 10 kOhm trimmer resistor; set the resistance to about 7.5 kOhm and monitor the readings with another device.
You can also use any stabilized 5 or 12 volt source for adjustment; in this case, rotate the trim resistor until you get the correct value on the display.

Project in Proteus:

Today I’ll tell you how to make a universal, simple measuring device with the ability to measure voltage, current, power consumption and ampere-hours on a cheap microcontroller PIC16F676 according to the following scheme.

Schematic diagram of a voltamperwattmeter

The printed circuit board on DIP parts turned out to be 45x50 mm. Also in the archive there is a printed circuit board for SMD parts.

For microcontroller PIC16F676 There are two firmware: in the first - the ability to measure voltage, current and power - vapDC.hex, and in the second - the same as in the first, only the ability to measure amperes/hours has been added (not always needed) - vapcDC.hex.

The resistor, indicated in gray on the printed circuit board, is connected depending on the indicator: if we use an indicator with common cathodes, then the resistor (1K) coming from the 11th leg of the MK is connected to +5, and if the indicator has a common anode, then we connect the resistor to the common wire.

In my case, the indicator and the common cathode, the resistor was located under the board, from the 11th leg of the MK to +5.

Briefly press the " button IN"activates the operating mode indication: voltage “-U-”, current “-I-”, power “-P-”, ampere/hour counter “-C-”. Some examples of op-amp LM358 have a positive offset at the output, it can be compensated by digital correction of the meter. To do this, you need to switch to current measurement mode, “-I-”. Hold the " button for 7-8 seconds N" until the inscription "-S.-" appears on the indicator. Then use the " IN" And " N» adjust the offset “0”. If the buttons are pressed, the indicator directly shows a constant; when pressed, the current readings are corrected. Exit the mode - simultaneously pressing the keys " IN" And " N". The result is the indication “-3-”, that is, recording in non-volatile memory. The ampere/hour counter is reset by holding the " button N" 3-4 sec.

In my case, I only put the button " IN", to switch the operating mode. Button " N"I don’t put it, since current correction is not required if the op-amp LM358 new, then it has practically no displacement, and if it does, it is insignificant. I do not put the segment indicator on a separate board, which can be easily attached to the device case, for example, built into a converted ATX power supply.

We connect power to the assembled device, supply the measured voltage and current, adjusting the voltmeter and ammeter readings using trimming resistors according to the multimeter readings.

As a result, the entire construction of the voltamperwatt meter cost 150 rubles, without foil fiberglass. Ponomarev Artyom was with you ( stalker68), see you again on the pages of the site Radio circuits !

Discuss the article VOLTAMPERWATTMETER