# 3 Phase Voltage Measurement using Atmel AVR Microcontrollers

3 Phase voltage measurement is a little bit tricky task. I will start from the basics and give you details step by step. Let’s start with the basics of 3 – Phase voltage.

Specification of this Project:

• Measure voltage of each phase
• Measure angle of each phase
• Gives Line to Line voltage as well
• All results display on 16x2 LCD
• Less components needed
• Cheap system

## Difference between 3 Phase voltage and 1 Phase:

In 1-Phase voltage you have to take care about only one phase. So during measurement you don’t have to worry about voltage angle. But in 3-phase system you have to take care of all three phases and their present angle as well. Angle of voltage is very important factor in 3-phase systems, it tells that which phase are we dealing with. At a identical time all three phases have different angles. So we have to measure it as well. Look at the figure below:

There are two diagrams present in the figure above. 3 overlapped voltage waveforms are showing the real version of 3 phase voltage through oscilloscope. 2 phases are 120 degrees apart to each other and 3rd phase is 240 degree apart to first phase. You can take these phase angles as -120,0,120 degrees as well.  It depends on the reference phase you take. So during measurement of 3 phase voltage, we have to measure these angles as well.

## Hardware Part:

In hardware part we will study about the circuit diagram and components of the system. I used a 16x2 LCD to display our results. To save us from extra wiring I used 4 bit interfacing of LCD with Atmega8.

## Components Needed:

• 3 x 1 phase transformers 220V/6V volt (1amp or less) or 110V/6V (1amp or less)
• 3 x 1N4001 (Diodes)
• 3 x 10uF Capacitors
• 3 x 4.7V Zener
• 2 x LM358
• 1 x Atmega8
• 1 x 16x2 LCD
• 1 x 10 K Variable Resistor
• Other components like PCB etc

Now look at the complete circuit diagram:

Three voltage sources present at the right side of the diagram is basically star connection of 3 phase voltage source.  It is output of 3 phase transformer.

## How to step down the 3 Phase Voltage?

3 Phase step down transformer at such small level is hard to get. So there is an easy way to step down the 3 phase voltage using 3 single phase 220V/6V or 110V/6V transformers. Connect primary side of three transformers with each phase of source and neutral will be common.  Take a look on the figure below to understand the connections.

This connection is basically star to star(Y-Y) connection.

Note: In circuit diagram I did not use voltage dividers while giving voltage to IC and ATmega8 microcontrollers for simplicity. Before giving the voltage to the IC and ATmega8 microcontroller, check the output voltage first. If peak of the voltage is more than 5 Volts then use voltage dividers to further step down the voltage.

## 3 Phase Voltage Source in Proteus:

To make a 3-phase voltage source in proteus, the setting of each source should be as shown is figures below:

I set frequency of 50Hz to the each source and give time delays to second and third source. When you will convert this time delays into angle you will get 120 and 240 degrees respectively. I will explain this time delay formula in coding part.

I have divided remaining discussion into two parts.

1. Voltage measurement part
2. Angle Measurement part

## Voltage Part:

Let’s start with the voltage measurement. We will measure the all 3 phases of voltage by first converting it into DC then fed it to the microcontroller Atmega8 which is from the family of Atmel AVR microcontrollers.

As you see in the figure, a diode is present to rectify the voltage and the capacitor will remove the ripples.  Zener is here just to protect the Atmega8 microcontroller. In case of any surge voltage it will remove that surge.

## Angle Measurement Part:

To measure the angle I used the zero detection technique which is implemented through 3 amplifiers. These amplifiers are working as comparators here. In zero detection technique the comparators wait for the zero point. Whenever a zero point came, they give a high signal at the output. Let’s understand this technique through the circuit diagram.

I connected ground (zero level) to the non-inverting (+) pin of comparator. A sine wave is coming on the inverting (-) pin of comparator. In sine wave, zero points came in each cycle. So whenever these points came a High signal is generated on the output of comparator which will read by microcontroller.

Every comparator will give high signals to the microcontroller. Time consumed between one high signal to other high signal is basically our required angle. Let’s have a look on coding part to understand this technique clearly.

## Coding Part:

If you have knowledge of ADC and 4 bit LCD interfacing then the remaining tricky part in the coding is only angle measuring part of 3 phase voltage. I am not going to explain the voltage measuring part because it is exactly same as single phase AC voltage measurement. Let’s just stick with the only demanding part here.

Take a look on this figure again. Three white circles are basically neutral or zero points of three phases. We just have to measure the t1 and t2 which are time differences of three phases.  If we get these t1 and t2 then we can easily get the above angles as well. Understand the coding below and you will understand the whole scenario here. Don’t worry you can get whole code and simulation at the end of article.

```void loops1(){
while(1){
if ( (PINC &(1<<4)) != 0  ){
TCNT1=0;
TCCR1B = 0x01; // Start timer1 at Fcpu/1
break;
}
else{
continue;
}
}
while(1){
if ( (PINC &(1<<5)) != 0  ){
TCCR1B = 0x00;//stop timer1
g=TCNT1;//getting number of counts
break;
}
else
{
continue;
}
}```

At PINC.4 of Atmega8 Microcontroller, output of the comparator of phase B is connected and at PINC.5 output of the comparator of phase C is connected. So when zero crossing of phase B will occur, a high value will be generated and loop will break and at the same time timer1 will start counting. After when zero crossing of phase C occur, a high value will be generated and timer1 will stop counting. The TCNT1 value (which is counter register) of Timer1 will be stored in ‘g’ variable.

Now, what will happen after getting this counter value? We have to convert this counter value to angle. Look at the code below to learn how to convert the counter value to angle.

```int calculatioins(){
unsigned int k=0;
//To complete number of counts
g=g+1;
//To convert  into seconds
float pf=(float)g/1000000;
//To convert seconds into degrees
pf=pf*50*360;//here frequency = 50hz
k = pf;
return k;
}

```

I hope you got the answer. If you have any query comment below. We are looking forward for your feedback and Don’t forget to like our facebook page. 🙂

#### Ismail

Electrical engineering is my profession, my hobby and my passion. I completed bachelors of electrical engineering in 2015. Currently I am working with a utility company which provides electricity to its consumers. Power Electronics, Embedded Systems and Energy Metering are my fields of specialization. In free time I listen music and watch movies.

## 17 thoughts on “3 Phase Voltage Measurement using Atmel AVR Microcontrollers”

1. Dafi Yondra says:

What compiler to be used for sorce code above ? Do you use AVR Studio ? If yes what version

1. Ismail says:

Its Atmel Studio 6

2. Ismail says:

It is one of the good method for the capture of zero crossing and hence for the measurement of phases. Your circuit must have some problem. Check your circuit, specially the comparators and their connections.

1. no, it is not the circuit problem, because I also tested from a function generators directly. If I change the code to find the maximum value from the loop, than the result is accurate, but I am just trying to figure it out why....really strange.

1. Ismail says:

There is a mistake I just found out in my code.
Voltage 3 routine reading from same ADC channel as Voltage 2. Voltage 3 must read channel 2 not 1

3. I have so many problems using this method to read the phase. How can you be sure when PINC(1<<4) !=0 happens exactly at the beginning of each signals. because the whole time period of the high level signals can be recognized as PINC(1<<4). and When I test the code on my zerocrossing circuit, the result are 0,0,0,0,0,0,120,0,0,0,120..... , which means it does not always detect the time difference.I think i basically use the same code, Can you think of why?

4. SKT says:

But I am not getting Correct Voltage of R Phase . Why ?

1. What do you mean ? In simulation or on real device. What is the correct value and what is the displayed value ? Maybe there are some defective components or the zenner is mounted upside down or the input port of the Atmega is defective. I am still working on simulator, trying to use 16x4 display and showing the line frequency of the Line 1. So far I succede to modify the source code so all the parameters are shown on the 16x4 display. I hope that Ismail Sarwar will guide ( help ) me to display the Line 1 ( V1 ) frequency.

1. Ismail says:

You have to make some changes of circuit in simulation as well.

2. Ismail says:

Check your connections first. And calibration is the most important part while implementing the circuit in hardware. So take care of it as well.

1. Yes you can measure in actual through the above circuit diagram as well. Be careful while handling the 3 phase voltage.

5. Hi, instead "Line" voltage can it show Line frequency something like 50.2 ? Thank you.

1. Yes you can use it for the measurement of frequency as well. Some changes will be required in the code and circuit. Only one comparator will be used in the circuit. Code will be set in such a way that time of two zero crossing will be calculated. This time will be then finally converted into frequency.

1. Kelciov Bartolomeu says:

Hi,
After many days and testing, I have succede made some modifications to your schematic and code but not happy with the results. I have use the second AO from U3, and inserted few lines and modify other lines. I know only electronics. My programming skils are verry poor.

The problem is that I don't know how to display the frequency with one decimal after the value, something like 50.2 or 50.6.
I din't post the entire code here because is too large.
The display looks like this:

V1=224V A1=0*
V2=224V A2=120*
V3=225V A3=240*
Line=387V 50Hz