A simple modular AC voltmeter based on the PIC16F676. A simple built-in ampervoltmeter on PIC16F676 Do-it-yourself network voltmeter on a microcontroller

Last summer, at the request of a friend, I developed a circuit for a digital voltmeter and ammeter. As requested, this measuring device should be economical. Therefore, a single-line liquid crystal display was chosen as indicators for information output. In general, this ammeter was intended to control the discharge of a car battery. And the battery on the engine of a small water pump was being discharged. The pump pumped water through the filter and again returned it over the pebbles to a small pond in the country.

In general, I did not delve into the details of this quirk. Not so long ago, this voltmeter again came to my hand 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 of the microcontroller was lost, it naturally stopped functioning, and since the LCD has its own controller, the data loaded into it earlier, the voltage on the battery and the current consumed by the pump , remained on the indicator screen. Previously, I did not think about such an unpleasant incident, now it will be necessary to take this matter into account in the program of devices and their schemes. And then you will admire the beautiful numbers on the display screen, but in fact everything has burned down for a long time. 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 basis of the circuit is the PIC16F676 microcontroller and the LCD indicator. Since all this works exclusively in the warm season, the indicator and controller can be purchased at the cheapest. The operational amplifier was also chosen appropriate - LM358N, cheap and having an operating temperature range from 0 to +70.
To convert the analog values ​​(digitization) of voltage and current, a stabilized microcontroller supply voltage of +5V was selected. And this means that with a ten-bit digitization of the analog signal, each digit will correspond to - 5V = 5000 mV = 5000/1024 = 4.8828125 mV. This value in the program is multiplied by 2, and we get - 9.765625mV per one bit of the 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 readings of the current value, a scaling amplifier is used, assembled on one of the operational amplifiers of the DA1 - DA1.2 chip. The gain adjustment of this amplifier is carried out using a resistor R3 of 33k. It is better if both trimmers 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, DD1 chip, is a repeater. Serves to reduce the impact on the digitization of noise and impulse noise, due to one hundred percent, negative, frequency independent feedback. To reduce noise and interference when converting the current value, a U-shaped filter is used, consisting of C1, C2 and R4. In most cases, C2 can be omitted.

As a current sensor, resistor R2, a domestic factory shunt for 20A is used - 75SHSU3-20-0.5. With a current flowing through the shunt at 20A, a voltage of 0.075 V will drop across it (according to the passport for the shunt). This means that in order for the controller to have two volts, the gain of the amplifier should be approximately 2V / 0.075 = 26. Approximately - this is because we have a digitization resolution of not 0.01 V, but 0.09765625 V. Of course, you can 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 - 50 volts, and the ammeter - 20 amperes, although with a shunt rated for 50 amperes, it will measure 50A. So that it can be successfully installed in other devices.
Now about the refinement, which includes the addition of an indicator LED. Minor changes have been made to the program and now, while the controller is working, the LED blinks at a frequency of about 2 Hz. The LED glow time is 25ms, for economy. It would be possible to display a blinking cursor on the display, but they said that with an LED it is more visual and effective. Look like that's it. Good luck. K.V.Yu.


.

One of the variants of the finished device, implemented by Alexey. Unfortunately, I don't know the last name. Thank you for your work and photos.


This device is implemented on the PIC16F676 using the built-in ten-bit ADC. The voltmeter can measure voltage up to 30V DC and can be used in desktop power supplies or various instrument panels.
To display the voltage, three seven-segment indicators with a common anode are used. The output of information to the indicators is carried out dynamically (by multiplexing), the refresh rate is about 50 Hz.

Voltmeter circuit:

Divider output voltage
By default, on a PIC microcontroller, the ADC voltage reference is set to VCC (+5V in this case).
It is necessary to make such 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 large 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.02932V/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.
A 5.1V zener diode is designed to protect the ADC from exceeding the allowable 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 47kΩ and 10kΩ resistors, therefore, the more accurately the components are selected, the more accurate the readings will be.
The voltmeter is calibrated with a 10 kΩ trimmer, set the resistance to about 7.5 kΩ and monitor the readings with another device.
You can also use any stabilized source of 5 or 12 volts for tuning, in this case rotate the trimmer until you get the correct value on the display.

Project in Proteus:

Voltammeter on PIC16F676

This project is a dc ammeter (or voltammeter if you prefer). Range - up to 99.9V and 9.9A (or 99.9A, depending on the firmware).


Its peculiarity lies in the fact that it is built on a common PIC16F676 microcontroller, however, despite this, it has the ability to simultaneously display the measured voltage and current on four-character (or three-character) seven-segment indicators, both with a common anode and with a common cathode (set one resistor). When using a four-character display, the last segment displays the character "U" for voltage and "A" for current. The ampervoltmeter can work with one indicator, while using the "B" button you can choose what will be displayed on it - voltage or current. In the event that both indicators are set, this button can be used to swap their assignment. Button "H" is used to correct the ammeter readings and align the linearity of these readings, if necessary.

up feb 2014: The development can now be found at:

The diagram of the voltammeter is shown below. As already mentioned, it is built on the common PIC16F676 microcontroller, on which, in particular, simple voltmeters and ammeters are assembled.


Click on the diagram to enlarge
In view of the limited number of pins for this MK, register 74HC595 is used. This microcircuit has no analogues with the same pinout, but it is not scarce and is often used in such circuits to connect indicators to the MK. To protect the outputs of the MK from overload and increase the brightness of the indicators, switches on transistors are used. When using indicators with a common cathode, it is necessary to use transistors of a different structure, connecting their collectors not to + 5V, but to ground, while the resistor at pin 11 of the microcontroller must be rearranged to a different position. You may need to match the resistors at the output of the register and in the bases of the transistors to match your indicators and transistors.

As mentioned earlier, the "B" button allows you to swap the assignment of indicators in case there are two of them. If there is only one indicator, then this button can alternate the display of voltage and current. When you press the "H" button, the indicators will flash. While they are flashing, you can use the "B" and "H" buttons to correct the ammeter readings. After the correction, the blinking will stop and the correction factor will be written to the non-volatile memory. The display mode set with the "B" button is also stored in non-volatile memory.

After switching on, the indicators do not start to glow immediately, but after a delay of several seconds. The frequency of change of indications is about 9 Hz.

One of the printed circuit board options for four indicators with a common anode. In the figure, circles are circled around the necessary corrections: you need to remove the jumper going to the ground, and add one small jumper.


files for the project.


We continue to deal with the implementation options for a voltmeter - an ammeter based on a microprocessor.
Do not forget the archive with the files, we will need them today.

If you want to put large indicators, you will have to solve the issue of limiting the current consumption through the MK ports. In this case, it is necessary to put buffer transistors on each bit of the indicator.

Large indicators


So, the scheme considered earlier will take the form shown in Fig. 2. Three transistors VT1-VT3 of the buffer stage were added for each bit of the indicator. The installed buffer stage inverts the output signal of the MK. Accordingly, the input voltage based on VT2 is inverse with respect to the collector of the specified transistor, which means it is suitable for supplying a comma to the output. This makes it possible to remove the transistor VT1, which was previously in the circuit in Fig. 1, replacing the latter with a decoupling resistor R12. Do not forget that the values ​​​​of the resistors in the base circuits of transistors VT1-VT3 have also changed.
If you want to put indicators with unconventionally large dimensions, then you will have to put low-resistance (1 - 10 Ohm) resistors in the collector circuit of these transistors to limit current surges when they are turned on.

The logic of the MK for this option needs only a slight change in the program in terms of inverting the output signal of the bit control, namely the ports RA0, RA1, RA5.
Let us consider only what will change, namely the subroutine already known to us under the conditional name “Dynamic Display Formation Function” in Listing #2(see the folder "tr_OE_30V" in the archive or the first part of the article):

16. void Indicator ()( 17. while (show_digit< 3) { 18. portc = 0b111111; // 1 ->C 19. if (show_digit == 2)( delay_ms(1); ) 20. porta = 0b100111; 21. show_digit = show_digit + 1; 22. switch (show_digit) ( 23. case 1: ( 24. if (digit1 == 0) ( ) else ( 25. Cod_to_PORT(DIGIT1); 26. PORTA &= (~(1<<0)); //0 ->A0 27. ) break;) 28. case 2: ( 29. Cod_to_PORT(DIGIT2); 30. PORTA &= (~(1<<1)); //0 ->A1 31. break;) 32. case 3: ( 33. Cod_to_PORT(DIGIT3); 34. PORTA &= (~(1<<5)); //0 ->A5 35. break;) ) 36. Delay_ms(6); 37. if (RA2_bit==0) (PORTA |= (1<<2);// 1 ->A2 38. Delay_ms(1);) 39. if ((show_digit >= 3)!= 0) break; 40.) show_digit = 0;)


Compare both options. The signal inversion on port RA (line 20 of Listing #2) is easy to read because it is written in binary form. It is enough to combine the conclusions of the MK and the binary number. In lines 19 and 37, a little strange conditions appeared that were not there at the beginning. In the first case: "delay the logic zero signal on the RA1 port during the indication of the second bit." In the second: "if the RA2 port has a logical zero, inversion." When you compile the final version of the program, you can remove them, but they are needed for simulation in PROTEUS. Without them, the comma and the “G” segment will not be displayed normally.
Why? - you ask, because the first option worked great.

In conclusion, remember the words of the blacksmith from the film "Formula of Love": "... if one person has built, another can always take it apart!".
Good luck!

Reader's vote

The article was approved by 27 readers.

To participate in the voting, register and enter the site with your username and password.

The device presented here is useful if you have a power supply with an output voltage of 0-10 V. It is these measurement limits that are "embedded" in the circuit shown in the figure. It is based on an Atmega8 (U1) microcontroller in a standard DIP package. It may seem cumbersome, but was chosen because of its wide popularity, and also because programmers for this microcontroller are very common. Atmega8 is used by most radio amateurs and you can find many circuits with this microcontroller on the Internet. Therefore, if you do not like this voltmeter, Atmega8 will not be left idle.

Digital voltmeter on Atmega8. The scheme is basic.

Voltmeter measurements will be displayed on a digital seven-segment three-digit indicator (DISP1). Let me give you some information about it.

7-segment digital LED display is an indicator consisting of seven LEDs arranged in the shape of the number 8. By turning on or off the corresponding LEDs (segments), you can display numbers from zero to nine, as well as some letters. Usually several digital indicators are used to create multi-digit numbers - for this, the indicators are provided with a segment in the form of a comma (dot) - dp. As a result, one indicator has 8 segments, although they are called 7-segment by the number of digital segments.

Each segment of the indicator is a separate LED that can be turned on (lit) or off (not lit) depending on the polarity of the voltage applied to them. Indicators come with both a common cathode and a common anode. This is a common connection of all LEDs (segments). In addition, indicators can contain several digits, in which case each digit is called a digit or sign. For example, a three-digit (three-digit) seven-segment indicator contains three digits. It is such an indicator that is needed for this device.


The design uses a red glow indicator GNT-2831BD-11 with a common anode. Resistors R1-R8 determine the current in the indicator and, consequently, its brightness. Their resistance must not exceed the maximum output current (40 mA), even when all 8 LEDs are lit at once. The circuit uses a single-ended 10-bit ADC (analogue-to-digital converter) found in the AVR. The output value range is 0-999. When the limit of these values ​​is reached, the symbol "---" will appear.

A voltage divider of resistors R9, R10 and R11 is installed at the input of the voltmeter (in), providing a measurement range of up to 10 V with an error of 0.01 V. At pin 23 of the microcontroller U1, the divider generates a voltage that should not exceed 2.5 V. Input resistance voltmeter close to 1mΩ. To calibrate the voltmeter, apply a precisely known voltage to its input and, by moving the tuning resistor R11, achieve the same readings on the indicator.

The update rate of the voltmeter is about 4 Hz. The circuit is powered by a stabilized 5 V source. The current consumption of the device is about 25 mA (most of the consumption falls on the indicator). Place components C1 and C2 as close as possible to the microcontroller.

Correctly set bits are shown in the figure below.


If you need measurement limits up to 100 V, change the value of R10 to 9.1 mΩ and R11 to 2.2 mΩ. Then you will get the desired measuring range with an error of 0.1 V and an input resistance of about 10 mΩ. In this case, you will also have to change the location of the indicator dot so that it is displayed behind two characters, and not behind the first, as in the diagram. To do this, leave pin 28 of the U1 chip free, and connect pin 27 to the common wire. Now, instead of characters in the form of 0.00, 00.0 will be displayed.

Loading...Loading...