Digital AC voltmeter Schematic + Code + Proteus Simulation
This post will provide a working example of how to measure AC peak voltage and RMS voltage. This is simplified Alternating current (AC) voltmeter.
I am using MPLAB X IDE, C30 Compiler and Proteus Simulation on v8.0. This code is written in C Language and will work on PIC24, DsPIC33 and DsPIC30 (16bit PIC microcontroller) by slightly changing the code. You may download code and Proteus simulation from the download section given at the bottom of this page.
In this post I supposed that you know following things if not then please go through following posts before proceeding with this.
· How to Blink an LED. (Click here)
· How to Interface LCD in 8bit (Click here)
· How to use ADC for 16Bit PIC microcontroller. (Click here)
· How to Implement DC voltmeter. (Click here)
In the following figure 1. Shows the basic schematic for the Digital AC voltmeter. As you have seen my previous post about how to implement DC voltmeter now the circuit is almost the same as in that an additional circuitry that I used in this schematic is simple peak detector circuit. As AC has frequency from 50-60Hz so we need to have a peak detector circuit which only has two components a diode and a capacitor. This circuit is really simple to understand. Diode only passes the current when AC has positive part. Capacitor is used to store that charge a large capacitor will store charge for long duration. So at this common point (Diode and capacitor) we have larger voltage about 300volts which is not measured by the controller ADC directly so a potential divider is used to divide that voltage into measureable range of 0-5volts for ADC. I used 10kΩ and 590kΩ. Now formula is
VO= (10kΩ/ (10kΩ + 590kΩ))*VCC
Whereas VCC in this case is common point of Diode and Capacitor (Peak detector output).
|Figure 1. Proteus Schematic.|
In the following figure 2. An animation shows how the change in AC voltage is measured and displayed by PIC microcontroller. The AC voltmeter measured the RMS value while DC volt meter is measuring the peak voltage at the output of peak detector circuit.
In the following figure 3. This is main function in which I first initialize LCD, then I configure the ADC module. I configure the Channel zero for input to ADC module. In while loop I called DisplayAC_Voltage() function which is responsible for displaying AC measurement on LCD.
|Figure 3. Main function.|
In the following figure 4. We have DisplayAC_Voltage() function which is responsible for displaying AC measured value On LCD. All this function is quite similar to my previous of DC voltmeter. But with a basic change in potential divider variable and RMS. You get potential divider value by solving the above mentioned formula with one unknown variable VCC. You get (VCC = V0 *60). Voltage output is the measured value from the ADC channel zero. Now variable named AcPeakVoltageMeasured has the value of Peak AC voltage measurement. Which is displayed on LCD via a function named WriteLongAsFloatUptoFiveFigures() by passing it as a parameter. Now for the RMS (root mean square) value we have to multiple the Peak voltage with 1/√2 = 0.707. This is done in Line no. 36 of the figure given below. The RMS value is in variable named AcRMSVoltageMeasured. Which is then again displayed on LCD via a function named WriteLongAsFloatUptoFiveFigures().
|Figure 4. Ac Voltage Display function.|
You can download Code (MPLAB X and C30 compiler) and Proteus (v8) Simulation. Clickhere
For all topics Click here:
That’s all for this post hope you will learn please comment if you have any questions for upcoming posts please subscribe or follow.
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.