Programming of Pic Micro Controller For PDF
Programming of Pic Micro Controller For PDF
Programming of Pic Micro Controller For PDF
Submitted by
S. SENTHIL KUMAR 10504182
S. AMEEN 10504172
A. MOHAMMED ZACKRIYA 10504175
BACHELOR OF TECHNOLOGY
in
MAY 2008
BONAFIDE CERTIFICATE
SIGNATURE SIGNATURE
DATE:
i
ABSTRACT
In recent years, the power quality of the AC system has become a great concern
due to the rapidly increased numbers of inductive loads, electronic equipment, power
electronics and high voltage power system. In order to reduce line losses and improve
the transmission efficiency, power factor correction research became a hot topic.
Many control methods for the Power Factor Correction (PFC) were proposed. This
paper describes the design and development of a single-phase power factor correction
using PIC (Programmable Interface Circuit) micro-controlling chip. This involves
measuring the power factor value from the load using current transformer, potential
transformer, and zero crossing detector, then using proper algorithm to switching on
and switching off the capacitors in order to compensate excessive reactive power, thus
withdraw PF near to unity as a result acquires higher efficiency and better quality AC
output.
ii
TABLE OF CONTENTS
ACKNOWLEDGEMENT i
ABSTRACT ii
LIST OF FIGURE v
1 INTRODUCTION 1
1.1 OBJECTIVE 1
EQUIPMENT 4
1.6 DESCRIPTION 6
2 CIRCUIT DIAGRAM 7
OPERATION 8
3 HARDWARE IMPLEMENTATION 9
3.5 RELAY 14
3.6 CAPACITOR 15
FACTOR 16
3.8 LOAD 16
iii
4 PIC-MICRO CONTROLLER 19
4.3 DESCRIPTION 21
4.4 FEATURES 24
5.2 APPLICATION 28
6 CONCLUSION 28
7 REFERENCES 29
8 APPENDIX 30
iv
LIST OF FIGURE
v
1. INTRODUCTION
Power factor is the ratio between the KW and the KVA drawn by an electrical
load where the KW is the actual load power and the KVA is the apparent load power.
It is a measure of how effectively the current is being converted into useful work
output and more particularly is a good indicator of the effect of the load current on the
efficiency of the supply system. When an electric load has a PF. lower than 1, the
apparent power delivered to the load is greater than the real power that the load
consumes voltage. All currents will cause losses in the supply and distribution system.
A load with a power factor of 1.0 provides most efficient loading of the supply and a
load with a power factor of 0.5 will result in much higher losses in the supply system.
A poor power factor can be the result of a significant phase difference between the
voltage and current at the load terminals. Poor load current phase angle is generally
the result of an inductive load such as an induction motor, power transformer, lighting
ballasts, welder or induction furnace. An improved power factor AC output is the
main target of this paper. This paper focuses on the design and implementation of
power factor correction using PIC Micro-controller chip.
1.1 OBJECTIVE
The main objective of the proposed system is to maintain the power factor of
the induction motor near to unity by switching on and switching off the capacitor
through electromagnetic relay using pic-microcontroller chip.
vi
1.2 POWER FACTOR CORRECTION
The power factor of an AC electric power system is defined as the ratio of the
real power to the apparent power, and is a number between 0 and 1 (frequently
expressed as a percentage, e.g. 0.5 pf = 50% pf). Real power is the capacity of the
circuit for performing work in a particular time. Apparent power is the product of the
current and voltage of the circuit. Due to energy stored in the load and returned to the
source, or due to a non-linear load that distorts the wave shape of the current drawn
from the source, the apparent power can be greater than the real power. Low-power-
factor loads increase losses in a power distribution system and result in increased
energy costs. All Discharge Lamps, such as Fluorescent Lamps, High Pressure
Mercury Vapour Lamps, Sodium Lamps, Metal Halide Lamps, etc., require ballasts
(chokes) or transformers for their operation. These devices are inductive in nature.
When a Discharge Lamp is switched on, it draws Apparent Power from the mains.
This Apparent Power (VA) has two components, one is the Active Power (W)
actually being consumed by the lamp for illuminating it, and the other is the Reactive
Power (VAr) feeding the electromagnetic circuit of the control gear. Power factor is
the ratio of Active Power (W) to the Apparent Power (VA) .
Power factor is also denoted by p.f. or cos Ø . As mentioned above, the inductive
components, such as ballasts, draw Reactive Power (VAr) from the mains. It lags
behind the Active Power (W) by 90o. (A capacitor, if connected across the mains, will
also draw Reactive Power [VAr(c)], but it leads the Active Power (W) by 90o. The
direction of the capacitive Reactive Power [VAr(c)] is opposite to the direction of the
inductive Reactive Power (VAr). If a capacitor is connected in parallel with an
inductive load, it will draw capacitive Reactive Power [VAr(c)]. The effective
Reactive Power drawn by the circuit will reduce to the extent of the capacitive
Reactive Power [VAr(c)], Resulting in reduction of Apparent Power from VA to VA1.
vii
Fig: 1.1 Vector Diagram
The phase angle between the Active Power and the new Apparent Power VA1 will
also reduce from Ø to Ø1 . Thus the power factor will increase from cos Ø to cosØ1.
Real power (watts) produces real work; this is the energy transfer component
(example electricity-to-motor rpm). Reactive power is the power required to produce
the magnetic fields (lost power) to enable the real work to be done, where apparent
power is considered the total power that the power company supplies. This total
power is the power supplied through the power mains to produce the required amount
of real power. The previously-stated definition of power factor related to phase angle
is valid when considering ideal sinusoidal waveforms for both current and voltage;
however, most power supplies draw a non-sinusoidal current. When the current is not
sinusoidal and the voltage is sinusoidal, the power factor consists of two factors: 1)
the displacement factor related to phase angle and 2) the distortion factor related to
wave shape Irms is the current’s RMS value. Therefore, the purpose of the power
factor correction circuit is to minimize the input current distortion and make the
current in phase with the voltage when the power factor is not equal to 1, the current
waveform does not follow the voltage waveform. These results not only in power
losses, but may also cause harmonics that travel down the neutral line and disrupt
other devices connected to the line. The closer the power factor is to 1, the closer the
current harmonics will be to zero since all the power is contained in the fundamental
frequency.
viii
1.3 TYPICAL POWER FACTORS OF END USE EQUIPMENT
ix
1.4BLOCK DIAGRAM
x
1.6 DESCRIPTION
• 50 Hz Ac supply is connected to the lamp and capacitor start induction
motor.
current and voltage levels for zero crossing detector.
• The zero crossing detector is a device for detecting the point where the
voltage crosses zero in either direction.
• The measured voltage and current signal are given to RC0,RC1 pin of
pic‐microcontroller.
detector into digital signal.
depends upon error it will send signal to relay.
• Lcd display is used to display power factor value of the line
continuously.
parallel with load, when relay de energized it disconnect the capacitor
from the line.
xi
CIRCUIT DIAGRAM
TX1
K1
VDD 5
3 D1 1 VDD
4
1 JP2
2 2 - + 4 1 3
2 VIN VOUT
1 U2
RELAY SPDT
D 7805 R4
9 VAC C5 N C6 C7 220 ohm
G
470 uF 100 uF 0.1 uF
3 D2
V1 TX2 2
0V
1 LED
MG1
MOTOR AC
C1
6MFD/250V Bulb/200W
2 VPP
0.1 uF
SW2 R6 C10
R5
220 ohm
RESET 1k
1 2 2 1 DATA
1 3 1 3 CLK
D D S S
D D S S
V V V V
1 40 RB7
RA0 2 MCLR/Vpp RB7/PGD 39 RB6
RA1 3 RA0/AN0 RB6/PGC 38 RB5
R7 RA1/AN1 RB5
RA2 4 37 RB4
RA3 5 RA2/AN2/Vref - RB4 36 RB3
1 RA3/AN3/Vref + RB3/PGM
RA4 6 35 RB2
2 RA5 7 RA4/T0CKI PIC16F877 RB2 34 RB1
RE0 8 RA5/AN4/SS U3 RB1 33 RB0
D2 R3 RE1 9 RE0/AN5/RD RB0/INT
RE1/AN6/WR RB3
1 2 RE2 10
RE2/AN7/CS RB0
1N4007 10k
D1 3 13
14 OSC1/CLKIN 30 RD7
2 OSC2/CLKOUT RD7/PSP7 29 RD6
Q1 RD6/PSP6
R1 R2 Y1 RC0 15 28 RD5
4 - + 1 RC1 16 RC0/T1OSO/T1CKI RD5/PSP5 27 RD4
10k D3 RC2 17 RC1/T1OSI/CCP2 RD4/PSP4 22 RD3
RC2/CCP1 RD3/PSP3 Q1
10k BC547 4 Mhz RC3 18 21 RD2 R8
C2 5.1VZener RC4 23 RC3/SCK/SCL RD2/PSP2 20 RD1
BR805D C8 C9 RC5 24 RC4/SDI/SDA RD1/PSP1 19
100uF RC5/SDO RD0/PSP0 1k
27 pF 27 pF RC6 25 BC547
3 RC7 26 RC6/TX/CK
RC7/RX/DT
TX RX
D2 R3 J2
1 2
VDD 1
1N4007 10k 2
RE0 3
D1 4
2 RE1
RE2 5
Q1 6
R1 R2 RD0
4 - + 1 RD1 7
10k D3 RD2 8
10k 9
40235 RD3
C2 5.1VZener RD4 10
BR805D RD5 11
100uF RD6 12
3 RD7 13
14
15
16
LCD Module
xii
2.1 CIRCUIT DESCRIPTION AND PRINCIPLE OF OPERATION
The circuit diagram consists of mainly 3 units which constitute for the
perfect operation of the circuit.
1) Voltage & current measurement unit
2) Zero crossing detector unit
3) Pic ‐microcontroller unit
• When the inductive load is on the power factor decrease now the error will be
more in pic- microcontroller so pic energize the relay coil in order to
compensate the excessive reactive power.
• 16×2 LCD module is connected with port D of the pic-microcontroller
• We can get the output from LCD display.
xiii
3 HARDWARE IMPLEMENTATION
3.1 VOLTAGE & CURRENT MEASUREMENT UNIT
This unit contains components for measuring the line current and voltage
in order to calculate the power factor,
It consists of
1) Current transformer
2) Potential transformer
CURRENT TRANSFORMER
Fig: 3.1
current transformers measure power flow and provide electrical inputs to power
transformers and instruments. Current transformers produce either an alternating
current or alternating voltage that is proportional to the measured current. There are
two basic types of current transformers: wound and toroidal. Wound current
xiv
transformers consist of an integral primary winding that is inserted in series with the
conductor that carries the measured current. Toroidal or donut-shaped current
transformers do not contain a primary winding. Instead, the wire that carries the
current is threaded through a window in the toroidal transformer.
POTENTIAL TRANSFORMER
3.2 ZERO CROSSING DETECTING UNIT
As the name indicates the zero crossing detector is a device for detecting the
point where the voltage crosses zero in either direction. As shown in the circuit
diagram the first section is a bridge rectifier, which provides full wave rectified
output. This is applied to the base of the transistor through a base resistor, R2. The
capacitor charges to maximum of the bridge rectified output through the diode,D2.
This charge is available to the transistor as VCC. The capacitance value is kept large in
order to minimize ripple and get perfect dc. The transistor remains OFF until the Cut-
in voltage VBE is reached. During the OFF period of the transistor the output will be
high and approximately equal to VCC.
xv
From ct From pt
Once the transistor is ON and IB increases according to the input wave, the
transistor moves slowly towards saturation where the output reduces to the saturation
voltage of the transistor which is nearly equal to zero Initially VBE = Cut-in voltage of
diode, the capacitor will charge through the diode Vm where Vm is the maximum
amplitude of the rectified wave. Now the diode is reverse biased and hence does not
provide a discharging path for the capacitor, which in turn has two effects.
Variation in VCC. It will provide base current to the transistor in the region
where both diode and transistor are OFF.Thus an output square wave is produced
whenever the input voltage crosses zero thereby acting as a zero crossing detector.
xvi
Fig: 3.3 output waveform of zcd
Fig: 3.4 power supply circuit
The input 230v AC supply is converted into 9v DC supply with the help of a
bridge rectifier and it is filtered through a capacitor to get pure dc supply, and a
voltage regulator u2 7805 is placed in order to give a constant 5v dc, hence the
microcontroller works with 5v dc supply. And a LED is placed in parallel to the
microcontroller in order to know whether the microcontroller is given the input.
xvii
RESISTORS
A resistor is a two-terminal electrical or electronic component that opposes an
electric current by producing a voltage drop between its terminals in proportion to the
current, that is, in accordance with Ohm's law: V = IR. The electrical resistance R is
equal to the voltage drop V across the resistor divided by the current I through the
resistor. Resistors are used as part of electrical networks and electronic circuits.The
power dissipated by a resistor is the voltage across the resistor multiplied by the
current through the resistor
J2
VDD 1
2
RE0 3
RE1 4
RE2 5
RD0 6
RD1 7
RD2 8
RD3 9
RD4 10
RD5 11
RD6 12
RD7 13
14
15
16
LCD Module
The suggested circuit is quite simple. The display, data and control lines
are connected to the printer port lines. The read/write (RW) line is tied low to fix the
display in the write mode. The Enable (E) and the Register Select (RS) lines are tied
to two of the parallel port control lines. Liquid crystals solidify under low temperature
xviii
(below the storage temperature range) leading to defective orientation or the
generation of air bubbles (black or white). Air bubbles may also be generated if the
module is subject to a low temperature. If the LCD modules have been operating for a
long time showing the same display patterns, the display patterns may remain on the
screen as ghost images and a slight contrast irregularity may also appear. A normal
operating status can be regained by suspending use for some time. It should be noted
that this phenomenon does not adversely affect performance reliability. To minimize
the performance degradation of the LCD modules resulting from destruction caused
by static electricity etc., exercise care to avoid holding the following sections when
handling the modules Exposed area of the printed circuit board, Terminal electrode
sections.
3.5 RELAY
When a current flows through the coil, the resulting magnetic field attracts an
armature that is mechanically linked to a moving contact. The movement either makes
or breaks a connection with a fixed contact. When the current to the coil is switched
off, the armature is returned by a force approximately half as strong as the magnetic
force to its relaxed position. Usually this is a spring, but gravity is also used
commonly in industrial motor starters. Most relays are manufactured to operate
quickly. In a low voltage application, this is to reduce noise. In a high voltage or high
current application, this is to reduce arcing.
xix
If the coil is energized with DC, a diode is frequently installed across the coil,
to dissipate the energy from the collapsing magnetic field at deactivation, which
would otherwise generate a spike of voltage and might cause damage to circuit
components. Some automotive relays already include that diode inside the relay case.
Alternatively a contact protection network, consisting of a capacitor and resistor in
series, may absorb the surge. If the coil is designed to be energized with AC, a small
copper ring can be crimped to the end of the solenoid. This "shading ring" creates a
small out-of-phase current, which increases the minimum pull on the armature during
the AC
3.6 CAPACITOR
formula:
xx
3.7 RELATIONSHIP OF CAPACITOR WITH POWER FACTOR
3.8 LOAD
LINEAR LOADS
Electrical loads consuming alternating current power consume both real power,
which does useful work, and reactive power, which dissipates no energy in the load
and which returns to the source on each alternating current cycle. The vector sum of
real and reactive power is the apparent power. The ratio of real power to apparent
xxi
power is the power factor, a number between 0 and 1 inclusive. The presence of
reactive power causes the real power to be less than the apparent power, and so, the
electric load has a power factor of less than 1.
The reactive power increases the current flowing between the power source and the
load, which increases the power losses through transmission and distribution lines.
This results in additional costs for power companies. Therefore, power companies
require their customers, especially those with large loads, to maintain their power
factors above a specified amount (usually 0.90 or higher) or be subject to additional
charges. Electricity utilities measure reactive power used by high demand customers
and charge higher rates accordingly. Some consumers install power factor correction
schemes at their factories to cut down on these higher costs.
Power factor correction brings the power factor of an AC power circuit closer to 1 by
supplying reactive power of opposite sign, adding capacitors or inductors which act to
cancel the inductive or capacitive effects of the load, respectively. For example, the
inductive effect of motor loads may be offset by locally connected capacitors.
Sometimes, when the power factor is leading due to capacitive loading, inductors
(also known as reactors in this context) are used to correct the power factor. In the
electricity industry, inductors are said to consume reactive power and capacitors are
said to supply it, even though the reactive power is actually just moving back and
forth between each AC cycle.
xxii
factor at a specified level. The condenser’s installation and operation are identical to
large electric motors. Its principal advantage is the ease with which the amount of
correction can be adjusted it behaves like an electrically variable capacitor.
NON‐LINEAR LOADS
single-phase capacitor start induction motor It is suitable for any places where a
larger starting torque and the starting current to be limited are required, and is used as
driving motor of air compressors, refrigerators, medical apparatus and other small
machines in which full-load starting is demanded. These series motors have three
frame sizes, 09, 1and 2 of totally enclosed fan-cooled. The frames are made of cast
iron or cast aluminium according to the requests. A start capacitor is sometimes
connected in series with this winding. It is important to note, even for the same motor,
that this capacitor can be placed or removed, without disturbing the motor operation.
When C is placed in Position 2 (split-phase capacitor), it always sinks a current, even
when the PTC is hot or when the START triac is OFF. This allows power factor
improvement and power consumption reduction. In fact, the C capacitor will be added
if the refrigerator or freezer does not reach the required efficiency level
xxiii
4 PIC-MICRO CONTROLLER
xxiv
4.2 BLOCK DIAGRAM OF PIC16F877
xxv
4.3 DEVICE OVERVIEW
MEMORY ORGANIZATION
There are three memory blocks in each of these PICmicro MCUs. The
Program Memory and Data Memory have separate buses so that concurrent access
can occur and is detailed in this section.
The data memory is partitioned into multiple banks which contain the General
Purpose Registers and the Special Function Registers. Bits RP1(STATUS<6>) and
RP0 (STATUS<5>) are the bank select bits. Each bank extends up to 7Fh (128 bytes).
The lower locations of each bank are reserved for the Special Function Registers.
Above the Special Function Registers are General Purpose Registers, implemented as
static RAM. All implemented banks contain Special Function Registers. Some “high
use” Special Function Registers from one bank may be mirrored in another bank for
code reduction and quicker access.
xxvi
GENERAL PURPOSE REGISTER FILE
The register file can be accessed either directly or indirectly through the File
Select Register FSR.
The Special Function Registers are registers used by the CPU and peripheral
modules for controlling the desired operation of the device. These registers are
implemented as static RAM. The Special Function Registers can be classified into
two sets; core (CPU) and peripheral. Those registers associated with the core
functions are described in detail in this section. Those related to the operation of the
peripheral features are described in detail in the peripheral feature section.
I/O PORTS
Some pins for these I/O ports are multiplexed with an alternate function for the
peripheral features on the device. In general, when a peripheral is enabled, that pin
may not be used as a general purpose I/O pin. Additional information on I/O ports
may be found in the PICmicro™ Mid-Range Reference Manual, (DS33023).
xxvii
RA4 is multiplexed with the Timer0 module clock input to become the RA4/T0CKI
pin. The RA4/T0CKI pin is a Schmitt Trigger input and an open drain output. All
other PORTA pins have TTL input levels and full CMOS output drivers. Other
PORTA pins are multiplexed with analog inputs and analog VREF input. The
operation of each pin is selected by clearing/setting the control bits in the ADCON1
register (A/D Control Register1). The TRISA register controls the direction of the RA
pins, even when they are being used as analog inputs. The user must ensure the bits in
the TRISA register are maintained set when using them as analog inputs.
xxviii
4.4 MICROCONTROLLER CORE FEATURES
xxix
• Programmable code protection
• Low-power consumption:
xxx
ANALOG FEATURES
• Brown-Out Reset
• 2 analog comparators
PERIPHERAL FEATURES
xxxi
5 PROBLEM DUE TO LOW POWER FACTOR
• The electrical load on the Utility is reduced, thereby allowing the Utility to
supply the surplus power to other consumers, without increasing its generation
capacity.
• Most of the Utilities impose low power factor penalties. By correcting the
power factor, this penalty can be avoided.
• High power factor reduces the load currents. Therefore, a considerable saving
is made in the hardware cost, such as cables, switchgear, substation
transformers, etc.
5.2 APPLICATION
xxxii
6. CONCLUSION
The system design implementation and testing were The testing process did
not run test on power converter based systems or synchronous motor due to required
huge amount of expense may need to further enhance the system to such feature,
financial is a critical issue upon further enhancement. Besides systems that contain
serious harmonic current or ill non-sinusoidal current would mostly exist in systems
with huge amount of active elements.
xxxiii
7. REFERENCES
Source: http://www.st.com/stonline/products/literature/an/3727.htm
xxxiv
8. APPENDIX
xxxv
while(1)
{
for(i=0;i<5;i++)
{
CCP2IF=0;
while(CCP2IF==0);
TMR1ON=1;
CCP1IF=0;
while(CCP1IF==0);
TMR1ON=0;
time=CCPR1H;
time=(time<<8)+CCPR1L;
avg=avg+time;
}
avg=avg/5;
if(RB0==0)
{
if(avg<500)
{
RB1=0;
lcdcomd(0xC0);
printf("Power Factr:0.99");
DelayMs(100);
}
else if(avg<1000&&avg>500)
{
RB1=1;
lcdcomd(0xC0);
printf("Power Factr:0.91");
}
else if(avg<1000&&avg>1200)
{
RB1=1;
lcdcomd(0xC0);
xxxvi
printf("Power Factr:0.92");
}
}
else
{
if(avg<500)
{
RB1=0;
lcdcomd(0xC0);
printf("Power Factr:0.99");
DelayMs(100);
}
else if(avg<1000&&avg<800)
{
RB1=0;
lcdcomd(0xC0);
printf("Power Factr:0.67");
}
TMR1H=0;
TMR1L=0;
TMR1IF=0;avg=0;
}
void Capture_init()
{
CCP1CON=0x05;
CCP2CON=0x05;
T1CON=0x34;
TMR1H=0;
TMR1L=0;
}
void lcdinit()
{
int i;
unsigned char command[]={0x38,0x0c,0x06,0x01};
xxxvii
for(i=0;i<4;i++)
{
lcdcomd(command[i]);
DelayMs(2);
}
}
void lcdclr()
{
lcdcomd(0x01);
DelayMs(2);
}
void lcdcomd(unsigned char cmd)
{
RS=0;
RW=0;
EN=1;
DATA=cmd;
DelayMs(3);
EN=0;
}
void putch(unsigned char byte)
{
RS=1;
RW=0;
EN=1;
DATA=byte;
DelayMs(3);
EN=0;
}
xxxviii