All about renovation and decoration of apartments

A simple modular AC voltmeter on PIC16F676. Simple built-in ampere-voltmeter on PIC16F676 Automotive voltmeter on pic16f676

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


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 desktop sources power supply 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 Microcontroller PIC, the ADC voltage reference is set to VCC (+5V 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:

Last summer, at the request of a friend, I developed a circuit for a digital voltmeter and ammeter. According to the request, this measuring device must be economical. Therefore, a single-line liquid crystal display was chosen as indicators for displaying information. In general, this ampere-voltmeter was intended to monitor the discharge of a car battery. And the battery running on the motor of a small water pump was running low. The pump pumped water through the filter and again returned it over the pebbles into a small pond in the country house.

In general, I did not delve into the details of this quirk. Not long ago, this voltmeter came into my hands again to finalize the program. Everything works as expected, but there is one more request to install an LED to indicate the operation of the microcontroller. The fact is that one day, due to a defect in the printed circuit board, the power to the microcontroller was lost, naturally it stopped functioning, and since the LCD display has its own controller, the data previously loaded into it, the voltage on the battery and the current consumed by the pump , remained on the indicator screen. Previously, I had not thought about such an unpleasant incident; now I will have to take this matter into account in the program of devices and their circuits. Otherwise, you will admire the beautiful numbers on the display screen, but in reality everything has already burned out long ago. In general, the battery was completely discharged, which, as he said, was very bad for a friend then.
The diagram of the device with an indicator LED is shown in the figure.

The circuit is based on a PIC16F676 microcontroller and an LCD indicator. Since all this works exclusively in the warm season, the indicator and controller can be purchased at the cheapest. The operational amplifier chosen was also appropriate - LM358N, cheap and having an operating temperature range from 0 to +70.
To convert analog values ​​(digitize) voltage and current, a stabilized microcontroller supply voltage of +5V is selected. This means that with ten-bit digitization of an analog signal, each bit will correspond to - 5V = 5000 mV = 5000/1024 = 4.8828125 mV. This value is multiplied by 2 in the program, and we get 9.765625 mV per one bit of binary code. And for the correct display of information on the LCD screen, we need one digit to be equal to 10 mV or 0.01 V. Therefore, scaling circuits are provided in the circuit. For voltage, this is an adjustable divider consisting of resistors R5 and R7. To correct the current readings, a scaling amplifier is used, assembled on one of the operational amplifiers of the DA1 - DA1.2 microcircuit. The transmission coefficient of this amplifier is adjusted using a 33k resistor R3. It is better if both tuning resistors are multi-turn. Thus, when using a voltage of exactly +5 V for digitization, direct connection of signals to the microcontroller inputs is prohibited. The remaining op-amp, connected between R5 and R7 and the RA1 input of the DD1 chip, is a repeater. Serves to reduce the impact of noise and impulse interference on digitization, due to one hundred percent, negative, frequency-independent feedback. To reduce noise and interference when converting the current value, a U-shaped filter consisting of C1, C2 and R4 is used. In most cases, C2 does not need to be installed.

As a current sensor, resistor R2, a domestic factory shunt of 20A is used - 75ShSU3-20-0.5. With a current flowing through the shunt of 20A, a voltage of 0.075 V will drop across it (according to the datasheet for the shunt). This means that in order for there to be two volts at the controller input, the amplifier gain should be approximately 2V/0.075 = 26. Approximately, this is because our digitization resolution is not 0.01 V, but 0.09765625 V. Of course, it is possible apply homemade shunts by adjusting the gain of the DA1.2 amplifier. The gain of this amplifier is equal to the ratio of the values ​​of resistors R1 and R3, Kus = R3/R1.
And so, based on the above, the voltmeter has an upper limit of 50 volts, and the ammeter has an upper limit of 20 amperes, although with a shunt rated for 50 amperes, it will measure 50A. So, it can be successfully installed in other devices.
Now about the modification, which includes the addition of an indicator LED. Small changes have been made to the program and now, while the controller is working, the LED blinks at a frequency of approximately 2 Hz. The LED glow time was chosen to be 25ms to save money. It would have been possible to display a blinking cursor on the display, but they said that with an LED it would be more visual and effective. Look like that's it. Good luck. K.V.Yu.


.

One of the options for a finished device implemented by Alexey. Unfortunately I don't know the last name. Thanks to him for his work and photos.

When the need arose for a measuring part for a laboratory power supply, considering various diagrams from the Internet, I immediately chose seven segment LED indicators (a possible alternative is indicators of type 0802, 1602 - expensive and difficult to read). Also, I didn’t want any switching - both current and voltage should be read at any time. For various reasons, found ready-made solutions didn't work and I decided to design my own circuit.

The proposed device is intended for use in conjunction with various power supplies and allows you to measure voltage in the range from 0 to 99.9 Volts with an accuracy of 0.1 Volt and current consumption in the range from 0 to 9.99 Amperes with an accuracy of 0.01 Amperes. The device is assembled on a cheap PIC12F675 microcontroller, which is the most inexpensive and widespread of those with a 10-bit ADC, two 74HC595 registers and two 4 or 3-bit LED indicators. The total cost of the parts used, in my opinion, is minimal for such designs with simultaneous indication of voltage and current.

Description of the circuit operation.

The voltage is displayed by the HL1 indicator, and the current by the HL2 indicator. The same-name segment pins of the indicators are combined in pairs and connected to the parallel outputs of the DD2 register, the common bit pins are connected to the DD3 register. The registers are connected in series and form a 16-bit shift register, controlled by three wires: pins 11 are clock, 14 are information, and information is written to the output latches based on the drop on pin 12. The indication is normal dynamic - through the outputs of register DD3, the common terminals of the indicators are sequentially sorted, and from the outputs of DD2, through current-limiting resistors R12-R19, the segments corresponding to the selected digit are switched on. Indicators can be either with a common anode or with a common cathode (but both are the same).

The microcontroller controls the indication on pins GP2, GP4, GP5 in interrupts from the TMR0 timer with an interval of 2 ms. Inputs GP0 and GP1 are used to measure voltage and current respectively. In the first three digits of the indicators, the actual measured values ​​are displayed, and in the last digit: in the upper indicator there is a “V” sign, and in the lower indicator there is an “A” sign. In the case of using 3-digit indicators, these signs are applied to the device body. No program changes are required in this case.

The measured voltage is supplied to the MK through the divider R1-R3, and the current is supplied from the output of the op-amp LM358 through resistor R10, which, together with the internal protective diode, protects the input of the MK from possible overload (the op-amp is powered by a voltage of +7..+15 Volts). The gain of the op-amp is set by the divider R5-R7, approximately equal to 50 and regulated by the trimming resistor R5. Low-pass filter R4C2 smoothes the voltage from the shunt. Each measurement is made within just 100 µs. and without this chain, the instrument readings will “jump” at any unevenness of the measured current (and it is rarely strictly constant). Capacitor C1 in the voltage measurement circuit also serves the same purpose. Zener diode D1 protects the op-amp input from overvoltage in the event of a broken shunt.

Particular attention should be paid to the chain R8, R9. It applies an additional offset of approximately 0.25 millivolts to the input of the op-amp. The fact is that without it there is a significant nonlinearity of the op-amp gain at low values ​​of the measured current (less than 0.3 A). On different copies of microcircuits this effect manifests itself to varying degrees, but the error at the above indicated values ​​of the measured current is too high in any case. When setting R8 and R9 to the values ​​​​indicated in the diagram (the ratings can be proportionally changed while maintaining the same ratio, for example, 15 Ohms and 300 kOhms), the current measurement error caused by this effect does not exceed one least significant digit. With all the copies of microcircuits I have, no selection of the indicated resistors was required. In the general case, the minimum resistance R9 is selected, at which the indicator still shows zeros in the absence of the measured current, and increases it by 1.5-2 times. It is interesting that among many similar designs where the same microcircuit is used, not a single article contains even a hint of this problem. Apparently, I was the only one who had the “wrong” op-amps (acquired, by the way, at different times over 10 years). In any case, I categorically do not recommend, in order to “simplify the design,” excluding from the circuit elements C1, C2, R3, R8, R9, which are usually absent in such circuits - this is still a measuring device, and not a toy flashing numbers!

Good accuracy and stability of readings, in addition, is ensured by complete “separation” from the microcontroller of relatively high-current pulse circuits for controlling indicators by powering each circuit from a separate 78L05 stabilizer. And even weak interference from the operation of the microcontroller itself has little effect on the result, since each measurement is made in the “SLEEP” mode with the clock generator “muted.”

The microcontroller is clocked from an internal oscillator to save pins. The reset input through circuit R11, C3 is connected to “pure” +5V. When turning on and off a power supply unit in which the design is used, significant interference is possible, therefore, to prevent the program from freezing, the WDT timer is turned on.

The device is powered from any stabilized voltage of 7-15 Volts (no more than 15V!), through stabilizers DA2, DA3. Capacitors C4-C8 are standard blocking capacitors. To ensure low error at currents close to the upper limit, the op-amp supply voltage must be at least 2 Volts greater than the microcontroller voltage, so power is supplied to it before the stabilizers.

The device is assembled on a printed circuit board measuring 57 by 62 millimeters.

Printed circuit board of the device.

To reduce the dimensions of the board, most of the resistors and capacitors are used in an SMD package of size 0802. The exceptions are: R1 - due to power dissipation, R12 - to simplify the board topology, electrolytic capacitors and tuning resistors. Capacitors C1 and C2 are ceramic, but if they are not available, they can be replaced with electrolytic tantalum. Zener diode - any, with a stabilization voltage of 3-4.7 Volts. The indicators can be replaced with FIT3641 or three-digit 3631 or 4031 series without changing the board design. If necessary, it is even possible to use larger indicators such as 5641 and 5631 without changing the design (in this case, the microcontroller is soldered directly without a block, small-sized trimming resistors are used, the indicator is soldered on top of the microcircuits, grinding off the four protrusions from the bottom at the corners of the indicator). Screw terminals are used to connect the device to external circuits. A frequently encountered problem with the manufacture of a measuring shunt was solved by using a ready-made 10A limit shunt from a faulty D83x series multimeter, absolutely without any rework. In my opinion this is best option- I think many radio amateurs have a faulty Chinese multimeter. As a last resort, it can be made from nichrome (or better yet, constantan) wire.

The output of the power supply is connected to the point "Ux" and further, from the same point to the load. The common wire is supplied to the "COM" point, and is already supplied to the load from the "COM-Out" point. With this connection, the voltage on the indicator increases by 0.1 Volt at maximum load current. By software, this error is reduced by half to half the sampling error (0.05V maximum). To avoid increasing this error, you should choose a shunt resistance that does not require changing the circuit ratings during setup (approximately 7-14 mOhm). The appropriate supply voltage for the device is supplied to the "Upp" pin.

Photos of the finished device

The microcontroller program is written in Assembly language in the MPASM environment. For both types of indicators, the program is the same, with the exception of one directive. At the beginning of the source text of the program (file AV-meter.asm) in the “ANODE EQU 0” directive, the parameter has the value 0, which corresponds to working with indicators with a common cathode. To use indicators with a common anode, change the value of this parameter to 1, and then re-translate the program. Also included are ready-made firmware for the microcontroller for both indicators with a common anode and a common cathode. When loading a HEX file into programs like , or , the configuration word is loaded automatically.

Setting up the circuit is extremely simple. Having applied a voltage close to the maximum to the input, use trimmer R2 to set the required value on the upper indicator. Then, connect a 0.5-2 Ohm resistor to the output of the device as a load and adjust the voltage to set the current close to the maximum. Using the R5 trimmer, the readings on the lower indicator corresponding to the standard ammeter are set.

The attached file contains the firmware, source code, model and board.

List of radioelements

Designation Type Denomination Quantity NoteShopMy notepad
DD1 MK PIC 8-bit

PIC12F675

1 To notepad
DD2, DD3 Shift register

CD74HC595

2 To notepad
DA1 Operational amplifier

LM358N

1 To notepad
DA2, DA3 Linear regulator

L78L05

2 To notepad
D1 Zener diode

1N4734A

1 3.6-4.7 V To notepad
HL1, HL2 IndicatorFYQ36412 FIT3641 To notepad
C1, C2 Capacitor4.7 µF2 SMD 0805 To notepad
C3 Capacitor10 nF1 SMD 0805 To notepad
C4 100uF x 10V1 To notepad
C5, C7 Capacitor100 nF2 SMD 0805 To notepad
C6, C8 Electrolytic capacitor20uF x 16V2 To notepad
R1 Resistor

39 kOhm

1 0.5 Watt To notepad
R2, R5 Trimmer resistor

1 kOhm

2 To notepad
R3 Resistor

1.2 kOhm

1 SMD 0805 To notepad
R4 Resistor

3 kOhm

1 SMD 0805 To notepad
R6 Resistor

1.5 kOhm

1 SMD 0805 To notepad
R7 Resistor

100 kOhm

1 SMD 0805 To notepad
R8 Resistor

150 Ohm

1 SMD 0805 To notepad
R9 Resistor

In addition, it is possible to use one or two indicators. Moreover, if four digits are used, then the rightmost digit displays the stylized units of measurement “V” or “A”. But, there is a limitation on the use of indicators with OA. When the emitter followers are turned on in this way, the indicators become illuminated by measuring currents. Thus, with a 2-indicator circuit, it is advisable to use indicators with OK, in which case the measured currents will not affect the opening of the transistor switches.
If buttons are installed, then pressing button "B" on the left indicator will display the current mode of this indicator, "-U-" or "-I-". Further holding will change the mode. For a version with one 3-digit indicator, this function will help you remember what mode the device is in, and for a 2-digit indicator version, it will swap the displayed voltage and current values. In any case, the function of suppressing insignificant zeros is applied to the voltage, i.e., if the voltage does not exceed 9.9V, then we will not see the first zero (“_Х.Х”) on the indicator.
Kn "N" allows you to enter the current offset correction menu. This may be necessary if, to improve the linearity of the current readings, the op-amp was shifted to the linear section. Thus, by correction you can remove “extra” readings. After briefly pressing the button on the left indicator (if there are two of them), the message “ShI” (current offset) will appear and the indicator will begin to flash. While it is flashing, you can use the buttons to adjust the offset. After a few seconds, the indicator will stop flashing and the data will be written to non-volatile memory. At the same time, the indicator display mode will be saved in memory, which will appear the next time you turn it on.
Displayed voltage 0.0...99.9V, current 0...99.9A (or 0.0...9.99A, depends on the firmware file and OS settings of the op-amp).

Refinement of the current meter assembly:

The author of the improvement is impuls. Simsim idea.
The whole point is to organize the op-amp bias into the linear section,
followed by correction of the readings in the service menu.



You do not have access to download files from our server
PP files for 2x3 and 2x4 indicators, kindly provided by evg339

PP files for 2x3 and 2x4 indicators placed vertically, reworking the PP from evg339, kindly provided by VolosKR


You do not have access to download files from our server


You do not have access to download files from our server


You do not have access to download files from our server

Firmware file for indicators with OA
You do not have access to download files from our server
Firmware file for indicators with OK
You do not have access to download files from our server

Modification of the input voltage divider:


Attention! Divisor by 10


Firmware file below


The polarity of the indicators determines the position of the 1K resistor with 11 n. controller.

Option with measuring inputs for voltage - RA0 and current - RA1^

Firmware file for example, 1:10 i.e. up to 50V, 2x3.2x4.1x3.1x4 indicators and measuring inputs 13 and 12 controller legs You do not have access to download files from our server

Firmware file for example, 1:20 i.e. up to 100V, 1x3.1x4 indicators and measuring inputs 13 and 12 controller legs. You do not have access to download files from our server

Firmware file for example, 1:20 i.e. up to 100V, current measurement, 1x3, 1x4 indicators and measuring inputs 13 and 12 of the controller legs have been changed. You do not have access to download files from our server

Yes! There is no need for a voltage trimmer. Now, let's build with buttons.

Coviraylhik summed it up (thanks to him):

vaDCw2L8UAra0ra1.hex small letter v, div. e.g., 1:10 to 50V,
vaDCw2L4ra01.hex is for one indicator, ( selection V,A one button)
vaDCw2L8UAra01i.hex Standard up to 100V _0.0V , 0.00A div. voltage, 1:20
vaDCw2L8UAra01X.hex Standard up to 100V, but point 00.0A moved

Related publications