Digital Voltmeter code + Proteus Simulation (using PIC24 (16bit PIC microcontoller) ) .

This post is all about how to build digital voltmeter. You may download code and Proteus Simulation from the download section at the bottom of this post. I am using MPLAB X IDE, C30 Compiler and Proteus Simulation on v8.0 This code will work on PIC24, DsPIC33 and DsPIC30 (16bit microcontroller) by slightly changing the code.

In this post I supposed that you know following things if not then please go through following posts before proceeding with this.

Proteus Simulation:

            In the following figure 1. I used a variable resistor as a dummy voltage divider so simulate the difference in voltages from (0 to 50VDC). This digital voltmeter will only measure voltage from 0 to 5volts (Warning!!! Measuring greater than 50 volts may damage microcontroller permanently). I used potential divider with 90kOhm and 10kohm. Which ensures that at 50 volts there is 5 volts max at the PIN of microcontroller (AN0 or RA0). In real you may remove variable resistor and replace it with a probe. This will be your home made voltmeter for measuring voltage upto 50 volts max.

Figure 1. Proteus Circuit

In the following figure 2. When I change value of voltage at channel 0 of ADC with the help of variable resistor. The voltage measure by the probe named R3(1) as shown in figure 2 is same as shown on LCD. For instance by the help of animation I shown different voltage values at different voltage applied to R3 resistor.
Figure 2. Proteus Simulation


In the following figure 3. This is main function in which I first initialize LCD, then I configure ADC with Channel 0. And a loop which only calls a function named DisplayVoltage() which is responsible for displaying voltage value on LCD.

Figure 3. Main function

In the following figure 4. We have DisplayVoltage() which has a string that is printed directly and a variable named “PotentialDivider” whose value depends on what R3 and R2 for this particular example it is calculated by this “ voltageoutput = (R2/(R2 + R3))*Vcc”. Whereas I have max voltageoutput is 5volts. R2 = 10k, R3 = 90k, vcc = ? which we want to measure. So I get this vo * 10 = vcc which is shown in figure 4 line no. 24. In line no. 21 I simply convert that adc value into voltage by this formula voltage = (ADCvalue/ADC resolution) * Vref. And then multiply that with 1000 in order to get value in millivolts. So at last I got vcc value in variable named VoltageMeasured which is shown on LCD by passing it to a function named WriteIntegerAsFloatUptoFiveFigures() as parameter. Note that I type cast these variable from unsigned int to float and from float back to unsigned int to make calculations more accurate.

Figure 4. Display voltage.

Reading Suggestions:


You can download Code (MPLAB X IDE and C30 compiler) and Proteus (v8) Simulation Click here

For all topics Click here.

That’s all for this post hope you will learn please comment if you have any questions.


All the text and graphics contained on this blog belongs to owner except otherwise mentioned. Other parties' trademarks and service marks that may be referred to herein are the property of their respective owners. Reproducing or distributing text and graphics on your own site is strictly not allowed without proper linking to original content and before publishing that you should ask for permission. 
© Copyright 2013 IbrahimLabs. All rights reserved.

Popular posts from this blog

Defining code regions in MPLAB X IDE

Digital AC voltmeter Schematic + Code + Proteus Simulation

Graphical LCD interfacing with PIC16F877 Code + Schematic + Proteus Simulation