Car voltmeter on pic16f676. Voltammeter on PIC16F676. Do-it-yourself radio engineering, electronics and circuits. Implementation of a voltmeter from Vladimir

The materials of this article were published in the magazine Radioamator - 2013, No. 9

The article presents the design of a digital ammeter-voltmeter designed for collaboration with universal control board laboratory blocks nutrition. Its peculiarity is the absence of its own current sensor. When measuring current, the control board current sensor is used. The considered design is ideal for converting computer power supplies into laboratory power supplies direct current.

Converting computer power supplies into laboratory ones turned out to be in great demand. In search of control and protection circuit options, the “Universal control board for laboratory power supplies” was discovered (Radio Yearbook, 2011, No. 5, p. 53). The control board circuit turned out to be very simple and effective, satisfying all the control and protection requirements of a high-power laboratory DC power supply.

To indicate the output voltage and current, the design described in the above-mentioned article seemed very cumbersome and expensive, and we also consider it redundant to simultaneously indicate voltage and current in a power source of this class. At the same time, voltmeters built on a cheap PIC16F676 microcontroller with a three-digit LED indicator became very popular. Using such a ready-made voltmeter turned out to be not very convenient due to the difficulty of converting it to ammeter mode. Therefore, we decided to develop our own switchable ampere-voltmeter circuit with a clear indication of the measurement mode, also using a current sensor from the control board.

Basic specifications ampere-voltmeter:

  • supply voltage – 7…35 V DC;
  • voltage measurement range – 0…50.0 V;
  • current measurement range – 0.02…9.99 A;
  • voltage measurement step – 0.1 V;
  • current measurement step – 0.01 A;
  • switching the measurement mode - with a two-pole switch button with fixation;
  • indication of the measurement mode - a seven-segment indicator in the form of the letters “A” or “U”.

Description of the control board circuit

First, let's look at the diagram of the “universal power supply control board” shown in the figure:

It is assembled on one quad chip operational amplifier DA1 in this case is also intended to control a TL494 type PWM controller of a computer power supply. Schemes for converting computer power supplies using a PWM controller of this type have already been described many times, so we will not dwell on this. The circuit contains current measuring amplifiers on elements DA1.1, DA1.4 and voltage on elements DA1.2, DA1.3, from the output of which the control signal is supplied to the power supply PWM controller. Variable resistors R13, R14 change the reference voltage of the output amplifiers of the voltage and current measurement channels, respectively. If the load current does not exceed the value set by regulator R14, then the control unit will operate in the voltage stabilization mode set by regulator R13. In this case, the HL3 indicator will light up. If the current in the load reaches the value set by regulator R14, then, if switch SA1 is open, the control unit will go into output current limiting mode. In this case, the HL2 indicator will light up. If switch SA1 is closed, then when the set current in the load is reached, the output voltage will drop to zero and the HL1 indicator will light up. To exit the current cut-off mode, simply open switch SA1.

You can read more about the operation and setup of the control circuit in the original article: “Built-in universal control board for laboratory power supplies”

Description of the ampere-voltmeter circuit

Fundamental electrical diagram ampere-voltmeter is shown in the figure below:

The basis of the ampere-voltmeter is the DD1 microcontroller, which performs the function of analog-to-digital conversion of the input signal supplied to the RA0 input (IN circuit), and outputs the measurement result to a three-digit seven-segment LED indicator with common cathodes HG1. The measurement channel is switched using the SA1 button. The second pole of the SA1 button is used to supply a signal to the microcontroller (SW circuit), which is used when processing the measurement result.

The display is dynamic with a refresh rate of 100Hz. Due to the fact that the cathodes of the indicator are connected directly to the pins of the microcontroller, in order to reduce the load, each discharge is lit in 2 steps of 4 segments. To eliminate frequent blinking of the low-order digit of the indication, the refresh rate of the indicator readings is artificially reduced and is carried out 3 times per second. If the display capacity of the measured values ​​is exceeded, three dashes will appear on the indicator.

To indicate the selected measurement mode, a single-digit seven-segment indicator with a common cathode HG2 with a symbol of a smaller size than in HG1 is used. Segments “b”, “c”, “e” and “f” of the HG2 indicator are constantly lit. In the voltage measurement mode, switch SA1 supplies the SW circuit with a power plus, which, through resistor R11, ignites the “d” segment, forming the “U” symbol on the indicator. Wherein high level based on transistor VT1 keeps it closed. When switching to current measurement mode, a common wire is supplied to the SW circuit. Transistor VT1 opens, supplying power to segments “a” and “g”, and the symbol “A” is formed on the indicator.

The power supply for the ampere-voltmeter circuit is taken from the power supply of the PWM controller of the computer power supply unit and is stabilized using an integrated adjustable stabilizer DA1. The divider R3, R4 at the output of the stabilizer sets a voltage of about 3 V. This circuit supply voltage was chosen to ensure the ability to use the full range microcontroller ADC in current measurement mode due to low level input signal.

Construction and details

The elements of the control circuit and the ampere-voltmeter are assembled on printed circuit boards made of one-sided foil-coated fiberglass laminate measuring 40x50 mm and 58x37 mm, respectively. Printed circuit board drawings and element layouts are shown in the figure below. The drawings are shown from the installation side of the elements.

The control circuit board is routed in such a way as to be fixed to the terminals of variable resistors R13, R14. For ease of adjustment, output radio components are used in the design.

To ensure compactness, the design of the ampere-voltmeter mainly uses elements for surface mounting: resistors of form factor 1206 and capacitors 0805. It should be noted that the microcontroller chip is non-standardly installed in a DIP package. It is secured by surface mounting on the conductor side, with the ends of its leads bent outward. The SA1 switch is a PS-850L type button, used in older computers as a “turbo” switch.

Indicators HG1 (with a symbol size of 0.56 inch) and HG2 (0.39 inch) can be used any similar ones with a common cathode, preferably with a red glow color, since the “green” ones glow quite dimly.

Assembly and adjustment

You can read about the use of the control circuit and how to set it up in the original article. The ampere-voltmeter circuit does not need adjustment. It is only necessary to select the values ​​of resistors R1 and R2 in the input dividers of the current and voltage measurement channels, respectively. This is best done experimentally, using a digital multimeter as a reference ammeter-voltmeter.

It should be noted that the ammeter will not work well if the signal at the output of the power supply is very noisy. Therefore, you should carefully select capacitors C1, C2 of the control circuit. We have already assembled more than six power supplies with such a control circuit, and in some power supplies the ratings of capacitors C1, C2 had to be significantly increased compared to those indicated in the circuit.

Conclusion

Experience in operating power supplies with the control circuit described above has shown the inconsistency of using it for conversion computer power supplies in laboratory due to the significant level of output voltage ripple, the power supply really “sings”! To create laboratory power supplies it is now used

When the need arose for a measuring part for a laboratory power supply, considering various circuits from the Internet, I immediately chose seven segment LED indicators(a possible alternative is indicators like 0802, 1602 - expensive and difficult to read). Also, I didn’t want any switching - both current and voltage should be read at any time. By various reasons, the ready-made solutions found were not satisfactory 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 (purchased, by the way, in different time within 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

Implementation of a voltmeter from Vladimir

Added switches to the indicator anodes, which increased the brightness of the display and allows the use of more powerful displays.

Two signets for DIP14 and SO14

The circuit uses BC847 (KT3102) transistors.

During the update of the main article on the voltmeter, the voltage divider was replaced in the circuit and seals from Vladimir. Firmware for the voltmeter is in the main article.

Implementation of a network voltmeter from Wali Marat

The signet differs from the circuit by replacing resistors R2 and R3 with one 4.7k trimmer and the absence of a zener diode VD1.

A modified network voltmeter circuit was also sent; it features a better-quality circuit for stabilizing the voltmeter's supply voltage.

Photo of a network voltmeter

Implementation of a voltmeter/ammeter from Wali Marat

A 5.1V zener diode VD1 was added to all circuits from Wali Marat (indicated green), to protect the ADC input of the microcontroller from overvoltage.

Simple voltmeter AC voltage with a frequency of 50 Hz, made in the form of a built-in module that can be used either separately or built into a finished device.
The voltmeter is assembled on a PIC16F676 microcontroller and a 3-digit indicator and does not contain very many parts.

Main characteristics of the voltmeter:
The shape of the measured voltage is sinusoidal
The maximum value of the measured voltage is 250 V;
Frequency of measured voltage - 40…60 Hz;
The resolution of displaying the measurement result is 1 V;
Voltmeter supply voltage is 7…15 V.
Average current consumption - 20 mA
Two design options: with and without power supply on board
One-sided printed circuit board
Compact design
Display of measured values ​​on a 3-digit LED indicator

Schematic diagram of a voltmeter for measuring alternating voltage


Implemented direct measurement alternating voltage with subsequent calculation of its value and output to the indicator. The measured voltage is supplied to the input divider made on R3, R4, R5 and through the separating capacitor C4 is supplied to the ADC input of the microcontroller.

Resistors R6 and R7 create a voltage of 2.5 volts (half the power) at the ADC input. Capacitor C5, of relatively small capacity, bypasses the ADC input and helps reduce measurement errors. The microcontroller organizes the operation of the indicator in dynamic mode based on interruptions from the timer.

--
Thank you for your attention!
Igor Kotov, editor-in-chief of Datagor magazine


🕗 01/07/14 ⚖️ 19.18 Kb ⇣ 238 Hello, reader! My name is Igor, I'm 45, I'm a Siberian and an avid amateur electronics engineer. I came up with, created and have been maintaining this wonderful site since 2006.
For more than 10 years, our magazine has existed only at my expense.

Good! The freebie is over. If you want files and useful articles, help me!

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. As devices for displaying information in digital measuring instruments LCD modules with their own controller are often used. 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 maximum amount 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

If you find an error, please select a piece of text and press Ctrl+Enter.