Академический Документы
Профессиональный Документы
Культура Документы
AC voltage measurement using pic microcontroller and op-amp. You have come across
many online tutorials on various websites about voltage measurement using different
microcontrollers. But all these tutorials are about measurement of low DC voltage. In this
project, you will learn how to measure high AC voltage using PIC16f877A microcontroller.
There are two methods to step down 220 alternating voltage into low alternating voltage which
peak value should not be greater than 5 volt.
Potential Transformer ( All Electrical Engineering students must know about P.T and its
use)
Difference amplifier (I will discuss difference amplifier method in this project.)
1
Potential Transformer can also be used to step down 220 Alternation voltage. But why you want
to spend more money? When you can do this with the help of cheap operational amplifiers and
few resistors. Difference amplifier method is more economical than potential Transformer when
you want to step down voltage less than 400 volt AC.
NOTE: Difference amplifier method is economical for voltage measurement less than 400
volt. Because above 400 volt, this method become expensive than potential Transformer.
There are reasons behind it. I am not going to discuss reasons here.This method is suitable
for final year students who want to measure Alternating voltage and current.
Difference Amplifier:
Difference amplifier is used to amplify voltage from two voltage levels. In case of Alternating
voltage we have two voltage level one is positive with respect to neutral and other is negative with
respect to neutral. I will recommend you to Google about difference amplifier and its use. You can
adjust the gain of difference amplifier according to our requirement by selecting proper values of
resistors. In this project gain is equal to:
In Alternating voltage case second voltage level is zero. Because during positive cycle and
negative cycle other side is considered zero or neutral. So output voltage will be
2
Difference amplifier to step down voltage
In Above picture resistor R1, R2, R3 R4, and R5 have high values which do not allow high
voltage to appear across op-amp. Because high input resistors are used thats why micro ampere
current will low and this way power loss will be in mili watts. According to difference amplifier
gain formula our gain will be:
NOTE: you must make calculation according to peak value of sine wave. Because peak voltage
is the maximum voltage input to microcontroller analog pin. So with a .0091 gain, with respect to
peak voltage of sine wave output voltage from op-amp is :
As you see above figure we have connected other terminal of R7 to 5 volt instead of ground as we
do while using difference amplifier in many applications. R7 resistor is used to increase DC voltage
level op-amp output. Sine wave have zero DC voltage level and negative voltage cycle.
Microcontroller cannot read negative voltage. So we increase the DC level of sine wave by 5
volt.In this way negative voltage will not appear across micron roller. Now output peak voltage
3
from op-amp is 5 + 2.8301 = 7.8301 volt. But as I have mentioned, microcontrollers cannot
measure voltage greater than 5 volt.So as shown in above figure we have used voltage divider to
divide voltage by 2.Hence output voltage is:
Capacitors C1, C2, and C3 are used to filter harmonics from input voltage and to provide protection
to microcontroller from harmonics. Now AN pin can be connected to microcontroller analog pin
to measure voltage easily.
To know about how to measure analog voltage using analog module of PIC16F877A
microcontroller go through PIC microcontrollers tutorials..
4
PIC MICROCONTROLLERS TUTORIALS
COMPLETE CIRCUIT DIAGRAM:
To know about LCD interfacing with PIC micronctrollers, go through pic
microcontrollers tutorials
5
AC voltage measurement code
Code for this project is written using Mikro C. To download code for AC voltage measurement
click on link below: [sociallocker]
float v;
char txt[5];
char txt1[5];
void voltage_READ(void)
float max;
int i;
int t[40];
6
ADCON0.ADON=1;
v =v*(10.0/1023.0);
v=(v-5.0);
t[i]=v*110.1909091;
ADCON0.ADON=0;
max=t[0];
if(max<t[i])
max=t[i];
max=max*.707106781;
intToStr(max, txt);
Lcd_out(1,9,txt);
delay_ms(1000);
void main()
7
{
ADCON0.ADCS1=1;
ADCON0.ADCS1=0;
ADCON0.ADON=0;
while(1)
Lcd_out(1,1, "Voltage:");
voltage_READ();
After sending payment, send me email, I will send you code and simulation in your email.
Thanks
8
SECOND METHOD TO MEASURE AC VOLTAGE.
In that article I have discussed each and everything you need to know to make ac voltage
measurement project. In that article, I have used operational amplifier as a difference amplifier to
step down ac voltage level from 220 volt ac to less than 5 volt ac. But I have seen many people
struggling with that method. So I have decided to write a article on how to measure ac voltage
using potential transformer and pic microcontroller with digital lcd display.
As I have already discussed in this project, I will be using potential transformer to step down
220volt ac voltage to less than 5 volt ac. I will discuss it later why we need to step down ac voltage
to measure it with the help of pic microcontroller.
Followings are the main components of ac voltage measurement project. Brief descriptions of all
components are also given below:
Potential transformer
Bridge rectifier
voltage divider circuit
Liquid crystal display
PIC16F877A pic microcontroller
What is potential transformer (PT):
Potential transformer is a type of transformer which is used to step down ac voltage. It is used to
measure ac voltage by stepping down AC voltage. For example in this project, potential
transformer is used to step down 220volt ac voltage to 12 volt ac. Potential transformer secondary
winding have less turn than primary windings. So according to below mentioned turns ratio
formula, it step down ac voltage.
9
Ns/Np = Vs/Vp
Bridge rectifier is electronics circuit used to convert ac voltage into pulsating dc voltage. In other
words it converts, negative cycle of AC voltage into positive cycle. Now the question is why we
need bridge rectifier in this project? Because microcontrollers cant reads negative
voltage. Therefore we need to convert negative half cycle of AC voltage into positive cycle. Bridge
rectifier is made using rectifier diodes connected in a form to form a bridge. 1N4007 rectifier
diodes are used to make H Bridge.
10
LCD INTERFACING WITH pic16f877a MICROCONTROLLER
PIC16F877A microcontroller:
PIC16F877A microcontroller is used in this project. PIC16F877A microcontroller is belongs to
16F family of pic microcontrollers. It have built in analog to digital converters module. Some of
basic features of PIC16F877A microcontroller is given below:
11
Input to circuit is 220 volt AC voltage. Potential transformer step downs 220 volt AC voltage in
12 volt AC. After that bridge rectifier converts step down AC into pulsating dc voltage. Voltage
divider further divides the voltage into two parts. Voltage less than 5 volt appear across analog to
digital converter pin of pic16f877a microcontroller. Microcontrollers are basically small
microcomputers which understand only digital values. Built in analog to digital converter module
of pic16f877a microcontroller converts analog values of AC voltage into digital values. These
digital values are used in processing of data with in microcontroller. Pieces of instructions written
in the form of coding told microcontroller what to do. Microcontroller itself do not do anything.
You tell him to do whatever you want him to perform by writing pieces of information called
program.
Diagram below shows simulation results of ac voltage measurement project. LCD displays 220
volt AC which is measured with the help of microcontroller and necessary components
connected with the microcontroller and potential transformer.
12
List of components:
List of required components for how to measure ac voltage is given below:
Capacitors,"C1",22pF,
Capacitors,"C2",22pF,
Integrated Circuits,"U1",PIC16F877A,
Diodes,"D1",1N4007,
Diodes,"D2",1N4007,
Diodes,"D3",1N4007,
Diodes,"D4",1N4007,
Miscellaneous,"TR1",TRAN-2P2S PT,
Miscellaneous,"X1",CRYSTAL 8MHZ,
CODE
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
13
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
float maxpoint = 0;
int i;
unsigned int temp=0;
char ch[5];
void main()
{
while(1)
{
Lcd_Out(1,1,AC voltage);
for(i=0;i<500;i++)
{
if(temp = ADC_Read(0),temp>maxpoint)
{
maxpoint = temp;
14
}
}
maxpoint = ( maxpoint * 5 )/ (1023) ;
maxpoint = maxpoint * 4;
maxpoint = maxpoint + 1.4;
maxpoint = maxpoint * 18;
maxpoint = maxpoint * ( 1 / sqrt(2) );
intToStr(maxpoint, ch);
lcd_out(2,1, Ltrim(ch));
maxpoint = 0;
}// while
}// void main
I have made necessary comments in code for your understanding. If you still have any issue in
understanding of code, let me know. If you have no issue after reading this article your
comments are welcome. Kindly share it with others.
15