Home / Home made Projects / Microcontroller Projects / Power Factor measurement using Microcontroller

Power Factor measurement using Microcontroller

The article will help the readers to use microcontroller for power factor measurement using a very simple external circuitry. The article will cover the design calculation, explanation of connection diagram and program to be embedded in microcontroller. In the end, the simulation results of designed power factor meter are presented with brief description.

Introduction

One of the important quantities in the power system is the power factor. It is defined as

Ratio of active power to the total power in the system

Cosine of angle between voltage and current.

It is always expressed either in percentage or in decimal less than 1. It shows the part of total power consumed as by the load. It is kept near to unity or 100%.

Block diagram

The following figure shows the block diagram.  For power factor measurement, two quantities are required to be monitored. One is current and second is voltage. High current and voltage can damage electronics component. Therefore they are step down by using their respective transformers.

The detail description and function of each block is given separately.

 

Power factor meter block diagram

CT & PT

CT stands for current transformer. It is an electrical device which steps down the high current to low current with a certain ratio so that it can be used for measurement. Further details about working of CT can be found in the following link

https://electricalnotes.wordpress.com/2011/04/16/current-transformer/

VT stands for Voltage transformer. It also serves the same purpose as that of CT. It reduces the voltage level so that it can be used by delicate meters and other electronic devices. The detail description of VT can be found in my article

All about voltage transformer

Active filter

The current and voltage in power lines contain harmonics or noise which can lead to incorrect measurement of power factor. Therefore it is necessary to remove noise and harmonics from voltage and current signal before they are given to microcontroller. Active filters employ op-amps for this purpose. Connections of active filters can be seen in schematic diagram (later in article).

Zero crossing detectors.

As it is already been mentioned that power factor is the phase difference between voltage and current. These signals are sine waves having no sharp edges. However, to measure precise phase difference between two signals they must have sharp edges. So they are converted into square waves of the same frequency and time priod. It is achieved by using zero crossing detectors based on operational amplifier. Zero crossing detectors used in this circuit are shown in the schematic.  Zero crossing detectors are op-amp comparators which compares the input signal with reference voltage which is zero in this case. So if the input signal is greater than 0, output is +5 and if input signal is less than 0, output signal is -5V.

Schematic

Components which are required for power factor measurement are

  • Capacitors (2.5uF, 1.25 uF)
  • Resistors (1k, 2K) etc.
  • Op-Amps (741)
  • CT
  • PT
  • Microcontroller 16F877
  • LCD (16×2)

Following figure shows the connection diagram

Circuit for power factor measurement using microcontroller

It can be seen from above figure that there are two input terminals. One is for current and second is for voltage. The signal applied to these input terminals must come from CT and PT.

Active filter is constructed using op-amp 741 along with resistors and capacitors. The values of resistors and capacitors define the cutoff frequency which is given by following equation.

Where R, R2, C1 and C2 are capacitors in the low pass filter.

Two Zener diodes are connected at the output of each zero crossing detector. Their function is to keep the output voltage at 5V maximum. Voltage above 5V can damage the microcontroller therefore Zener diode keep it under limit of 5V.

Results

In order to verify our circuit, it is simulated in ISIS Proteus. For different values of phase difference, the results are displayed.

In the first case, Current lags the voltage by 30ᵒ.

Result 2

LCD shows two results. First line shows the phase difference while the second line shows the power factor. Both the results shown by LCD are correct.

Now consider current is leading voltage by 30ᵒ

Result 1

Now LCD shows phase difference of 330 (334 exactly)  which means current is leading. Also power factor displayed by LCD is 0.8 which is correct.

Program

The program for the power factor measurement using microcontroller is written in C language and compiled in MIKRO C.

    // 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;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
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
unsigned int cnt_pf=0;
unsigned int sample[10];
unsigned int avg_pf;
unsigned int final_pf_cnt;
unsigned int i;
 void Interrupt()
 {
     if (TMR0IF_bit)
     {
       TMR0IF_bit = 0;
       TMR0L = 0xCD;
       cnt_pf++;
     }//  Timer0
     else if(INT1IF_bit) //first zerocrossing found
     {
       TMR0IE_bit = 1;   // enables timer0
       TMR0IF_bit = 0;  // clear flag
       cnt_pf = 0;
       INT1IF_bit = 0;  // clear flag for INT1
     }
     else if (INT0IF_bit)   // second zerocrossing found
     {
        TMR0IE_bit = 0;    //disable timer0
        TMR0IF_bit = 0;     // clear flag
        INT0IF_bit = 0;   //clear flag for INT0
        i++;
        sample[i] = cnt_pf;
        avg_pf+=sample[i];
        if(i==5)
        {
         i = 0;
         avg_pf/=5;
         final_pf_cnt = avg_pf;
        }
     }
 }
 char message1[] = “pf:        %”;

char message2[] = “powerfactor:       “;

 char ch;
void main()
{
  TRISA = 0XFF;// All input
  TRISB0_bit = 1;//set as input
  TRISB1_bit = 1;//set as input
    // ADC initialization…
  ADCON0 = 0x00;// all digital inputs
  ADCON1 = 0xFF;
  // Initialize LCD configuration…
  Lcd_Init();
  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);           // Cursor off
    // interrupt enable settings…
    //Timer0 settings for 10us timer
  T0CON             = 0xC8;
  TMR0L             = 0xCD;
  GIE_bit    = 1;   //global interrupt enable
  TMR0IE_bit = 1;   //enable timer0
  TMR0IF_bit = 0;   //cler flag
  // Int0 settings…
  INT0IE_bit = 1;   //enable INT1
  INTEDG0_bit = 0;   //interrupt on falling edge
  INT0IF_bit = 0;   //clear flag
    // INT1 settings…
  INT1IE_bit = 1;   //enable INT1
  INTEDG1_bit = 0;   //interrupt on falling edge
  INT1IF_bit = 0;   //clear flag
  while(1)
  {
      message1[3] = final_pf_cnt/1000+48;
      message1[4] = (final_pf_cnt/100)%10 +48;
      message1[5] = (final_pf_cnt/10)%10 +48;
      message1[6] = final_pf_cnt%10 +48;
      Lcd_Out(1,1,message1);
    angle = cosE3(final_pf_cnt);

    tlong = ((angle));

      message2[13] = (tlong/1000)%10 +48;
      message2[14] = ‘.’;
      message2[15] = (tlong/100)%10 +48;
      message2[16] = (tlong/10)%10 + 48;
      message2[17] = (tlong) + 48;
      Lcd_Out(2,1,message2);
      Delay_ms(100);
}
}

If you have any questions please ask in comments.

About Harris Fayyaz

Muhammed Harris Fayyaz, electrical engineer from NUST, EME, has 2.5 yrs industrial experience. He does research work in control systems, micro controllers and their applications.

Check Also

Digital Frequency meter for sine waves

This article describes the design and construction of microcontroller based digital frequency meter. The circuit …

4 comments

  1. is there a program may use bascom avr?

  2. can i have power factor code for atmel studio plz?

Leave a Reply

Your email address will not be published. Required fields are marked *

*