Built-in voltmeter on PIC12F675. Ampere-voltmeter on pic12f675 - measuring equipment - tools Pic12f675 indicator from nokia voltmeter

Today I’ll tell you how to make a universal, simple one 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 shown in gray on 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 voltamperwattmeter 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

I've been working on radio electronics for several years now, but I'm ashamed to admit that I still don't have a normal power supply. I power the assembled devices with whatever comes to hand. From all sorts of half-dead batteries and transformers with diode bridge without any voltage stabilization and output current limitation. Such perversions are quite dangerous for the assembled structure. Finally decided to assemble a normal power supply. And I started the assembly with an ampere-voltmeter. Of course, it was necessary to start from another, but as it already is. Since I’ve been doing a little programming, I decided to develop a display meter myself. The screen is a display from Nokia-1202. I’ve probably already tortured everyone with this display, but it’s 3 times cheaper than the 2x16 HD44780 (at least for us). Quite a solderable connector and generally good characteristics. Briefly speaking - a good option for voltage and current meter.

Electrical circuit of a digital ampere-voltmeter for power supply

Drawing of a digital ampere-voltmeter board

The first and second lines display the average voltage and current values ​​from 300 ADC measurements. This is done for greater measurement accuracy. The third line displays the load resistance calculated using Ohm's law. First I wanted to make sure that the power consumption was output, but I made a resistance. Maybe later I'll change it to power. The fourth line displays the temperature measured by the DS18B20 sensor. It is programmed to measure temperatures from 0 to 99 degrees Celsius. It must be installed on the heatsink of the output transistor, or on some other circuit element where there is strong heating.

You can also connect a cooler to the microcontroller to cool the transistor radiator. It will change its speed when the temperature measured by the DS18B20 sensor changes. There is a PWM signal on pin PB3. The cooler is connected to this output via a power switch. It is best to use a MOSFET transistor as a power switch. At a temperature of 90 degrees the fan will have maximum speed. The temperature sensor may not be installed. In this case, the fourth line will simply display OFF. We connect the cooler directly. The output of PB3 will be 0.

There are two firmware options in the archive. One for the maximum measured current of 5 amperes, and the second up to 10 amperes. The maximum measured voltage is 30 volts. According to calculations, the gain factor of the op-amp LM358 is chosen to be 10. For different firmware, you need to select a shunt. Not everyone has the ability to measure hundredths of an ohm and precision resistors. Therefore, there are two trimming resistors in the circuit. They can correct measurement readings.

There is also a printed circuit board in the archive. There are slight differences in the photo - it has been slightly adjusted there. One jumper has been removed and the size is 5 mm smaller in height. The stability of the ampere-voltmeter readings is high. Sometimes it floats only by hundredths. Although I only compared it with my Chinese tester. This is quite enough for me.

Thank you all for your attention.

ARCHIVE:

Modernized version

I only added a display of a tenth of the power.

Here I modified it to measure up to 50A. Shunt 0.01 ohm. The op-amp gain is approximately 6 to 7. It will be necessary to recalculate the resistors. The fuses are the same as before.

I would like to present to your attention a modernized version of the display meter for laboratory block nutrition. The ability to turn off the load when a certain preset current is exceeded has been added. The firmware of the improved voltammeter can be downloaded below. Circuit diagram of a digital current and voltage meter.

Several details were also added to the diagram. From the controls there is one button and a variable resistor with a value from 10 kilo-ohms to 47 kilo-ohms. Its resistance is not critical for the circuit, and as you can see, it can vary over a fairly wide range. Changed a little and appearance on the screen. Added display of power and ampere hours.

The trip current variable is stored in the EEPROM. Therefore, after switching off, you will not need to configure everything again. In order to enter the current setting menu, you need to press the button. By turning the variable resistor knob, you need to set the current at which the relay will turn off. It is connected via a transistor switch to pin PB5 of the Atmega8 microcontroller.

At the moment of shutdown, the display will indicate that the maximum set current has been exceeded. After pressing the button we will go back to the maximum current setting menu. You need to press the button again to switch to measurement mode. Log 1 will be sent to output PB5 of the microcontroller and the relay will turn on. This kind of current monitoring also has its disadvantages. The protection will not work instantly. Triggering may take several tens of milliseconds. For most experimental devices, this drawback is not critical. This delay is not visible to humans. Everything happens at once. No new PCB was developed. Anyone who wants to repeat the device can slightly edit the printed circuit board from the previous version. The changes will not be significant.

If you have any questions, please contact the forum. Thank you for your attention. Boozer completed the ampere-voltmeter.

ARCHIVE:
Forum

When there was a need for a measuring part for a laboratory power supply, considering various schemes 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. 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 (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 switching 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 errors at currents close to 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 SMD housing size 0802. 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 this device, the author used an original method of controlling a four-digit seven-element LED indicator signals from only four pins of the microcontroller. The microcontroller program provides an automatic calibration mode for the voltmeter.

The now traditional connection of an LED digital indicator to a microcontroller via a serial to parallel code converter 74HC595 requires the use of three pins of the microcontroller to control the code converter and one more pin for each digit of the indicator. Therefore, a four-digit indicator requires seven pins. This does not make it possible to use such indicators with small-pin microcontrollers, for example, with PIC12F675, which has only six pins (not counting the power pins).

In the second step, the rising edge at pin 12 of the 74HC595 writes the zero contents of the shift register to the holding register. This turns off the indicator completely.

At the third stage, information is loaded into the shift register of the 74HC595 microcircuit using a serial code generated by the microcontroller at pin 14 of the microcircuit. Its pin 11 receives clock pulses.

At the fourth stage, with an increasing level difference at pin 12 of the 74HC595 microcircuit, information from its shift register enters the storage register, and due to the high levels at the cathodes, the indicator bits remain extinguished.

At the fifth stage, on the common cathode of the discharge, for which the parallel code output to the outputs of the 74HC595 microcircuit is intended, the program sets the low level, turning on its elements in accordance with this code. At this point, interrupt processing ends, and the set state of the indicator remains unchanged until the next interrupt.

To control an eight-bit indicator, eight microcontroller outputs are required. In this case, signals from the additional four pins simply control the levels at the cathodes of the discharges. It is worth noting that in this case it is possible to use indicators with both common cathodes and common anodes, connecting elements or discharges to the outputs of the code converter, respectively. For the reasons stated below, it is preferable to organize the dynamic display element-by-element in the first case, and bit-by-bit in the second.

Now let's talk about a voltmeter that uses the described principle.

Basic specifications

Measured voltage, V............... 0...80

Measurement resolution, V......0.1

Accuracy.............0.5% + units. ml. resolution

Supply voltage, V............7...15

Current consumption, mA, no more...................................30

The voltmeter circuit is shown in Fig. 1. It uses element-by-element dynamic display. At every moment of time high level installed on the anodes of one group of elements of the same name of all digits of the HG1 indicator. At the common cathode terminals of the discharges in which these elements should glow, a low level is set, otherwise a high level. Please note that elements of the same name can be included simultaneously in all categories, but in each category in this moment only one element is included at a time. That is why we chose to connect the anodes of the elements to the outputs of the DD2 microcircuit, the load capacity of which is higher than the outputs of the microcontroller.

Rice. 1. Voltmeter circuit

With an interruption period of 2 ms, the image refresh rate on the indicator is 64 Hz and its blinking is invisible to the eye. The chosen method of dynamic indication also made it possible to halve the number of resistors (R4-R7) limiting the current through the indicator LEDs.

The microcontroller PIC12F675-I/P (DD1) remains unoccupied in the dynamic indication of the I/O lines GP0 and GP3. The first is used as an ADC input; the measured voltage is supplied to it through a divider R1R2. On line GP3, in the absence of jumper S1, thanks to resistor R3, a high logical level is set, which serves as a signal that switches the voltmeter into calibration mode. If the jumper is installed, the level on this pin is low and the voltmeter operates normally.

When you first turn on the voltmeter with the missing jumper S1, the HG1 indicator will display the rightmost sign flashing. In this state, a voltage as close to 80 V as possible should be applied to the input of the device, monitoring it with a standard voltmeter. With a short-term connection of the contact pads intended for jumper S1, the device will calculate and remember the calibration coefficient and will use it in the future.

However, 80 V is a fairly high voltage, and difficulties in obtaining it are possible. In this case, while indicating the reference voltage value, the device must be turned off and turned on again. , will appear on the indicator, and at the next switching off and on - , , again and further in a circle. Calibration should be performed at the highest voltage available. The higher the reference voltage, the more accurate the calibration. If at the time of calibration the input voltage differs too much from the reference voltage, the coefficient will not be calculated and displayed on the indicator

After calibration, turn off the voltmeter and finally install jumper S1, otherwise the next time you turn it on you will have to repeat everything again. The voltmeter can operate without calibration if jumper S1 is already installed when it is first turned on. In this case, it uses the coefficient written in the program, but the error may exceed 10%. A dot in the far right digit of the indicator will warn you about this.

Analog-to-digital conversion is performed in the “sleep” mode of the microcontroller to reduce interference from its operating components. It automatically exits this state upon completion of the transformation.

The device is powered by a voltage of 5 V, obtained using an integrated voltage stabilizer DA1. You can use the 78L05 stabilizer instead of the one indicated in the diagram only as a last resort, since the stability of its output voltage is an order of magnitude worse. Without degrading the parameters, you can use the LP2951 stabilizer. Zener diode VD1 for a voltage of 5.6 V together with the internal protective diode of the microcontroller protects the latter from damage when the measured voltage exceeds the permissible value. Without a limiter, the supply voltage of the microcontroller in this situation may increase critically.

The device is assembled on a printed circuit board measuring 40x36 mm from one-sided foil-coated fiberglass laminate with a thickness of 1.5 mm, shown in Fig. 2. Most resistors and capacitors are size 0805 surface mount. Resistor R1 for reliable operation at increased voltage is used with an output power of 0.5 W. Capacitor C1 can be installed both ceramic and lead oxide, for which the board has a seat designated C1." The FYQ-3641AHR-11 indicator can be replaced with another from the 3641A series or a three-digit 3631A series without remaking the board. A photograph of the assembled device board is shown in Fig. 3.


We continue to understand the options for implementing a voltmeter - ammeter based on a microprocessor.
Don't forget the archive with the files, we will need them today.

If you want to install 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 install buffer transistors on each digit of the indicator.

Large size indicators


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

The operating logic of the MK for this option only requires a slight change in the program in terms of inverting the output signal for controlling the bits, namely ports RA0, RA1, RA5.
Let's consider only what will change, namely the subroutine already known to us under the code name “Dynamic indication generation function” in Listing No. 2(see 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 inversion of the signal on the RA port (line 20 of Listing No. 2) is easy to read, since it is written in binary form. It is enough to combine the outputs of the MK and the binary number. In lines 19 and 37, slightly strange conditions appeared that were not there at the beginning. In the first case: “delay the logical zero signal at port RA1 during the indication of the second digit.” In the second: “if there is a logical zero on port RA2, inversion.” When you compile the final version of the program, you can remove them, but for simulation in PROTEUS they are needed. 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 built it, another can always take it apart!”
Good luck!

Reader vote

The article was approved by 27 readers.

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