You are on page 1of 6

Dynamic Computation of Load Power Factor through the Evaluation of

Maclaurin cos x Function using 8051 Microcontroller Architecture

Golam Mostafa
Department of Electrical and Electronic Engineering, Ahsanullah University of Science and Technology (AUST)
e-mail: mostafagb@yahoo.com

ABSTRACT waves, which are available for most of the industrial


Power factor is an index of the utilization efficiency loads. Our method is simple, low-cost, accurate and
of electric energy at the load side. Linear inductive dynamic owing to its motivation for computing the
loads of the industries operate at low power factor power factor through the evaluation of the Maclaurin
and thus reduce the utilization factor of electric cos x (Section-4, Eqn. 2) function using 8051
energy. To counteract it, the industry owners install microcontroller architecture.
PFI plant, which measures the load power factor and
then switches capacitor banks as needed to raise the It is hard to find reports on the internet literature
power factor. This paper presents a method [Eqn. 2], about the application of Maclaurin cos x Function for
which finds the phase shift () between v-i waves by the determination of power factor. The authors
detecting their zero crossing points, transform it into motivation for using this function to measure power
equivalent counts (N) and then pass it into the factor came from his experience of writing Low
Maclaurin cos x Series for dynamic computation of Level Program [Appendix-C] for converting n-bit
power factor by 8051 microcontroller. The method Binary number into equivalent BCD number using
has been tested using 8051 microcontroller (Fig. High Speed Horner Rule (Appendix-C). This is the
1[2]) and the results are found in good agreement BINary-to-BCD (BIN2BCD) conversion subroutine
with the theoretically computed results (Table 1). that inspired the author transforming the Maclaurin
cos x function into Eqn. 3, which is in 40-bit binary
KEYWORDS: Zero Crossing Points, PFI Plant, domain and requires the use of BIN2BCD subroutine
Power Factor, Maclaurin Series, Inductive Load. for getting transformed back into decimal domain.

1. INTRODUCTION 2. WORKS DONE


Linear inductive loads such as induction motors of In this paper, we have primarily focused on the real
the industries draw reactive energy from the utility time verification of the correctness of the power
supply. As a result, the transmission lines are forced factor computing expression gpf (1012pf) = 1012
to carry more currents than expected and incur power 49348 * N2 [Eqn. 2], which we have approximately
losses. To avoid this abnormal operation of the synthesized from the Maclaurin cos x series for
transmission lines, the utility authority asks the dynamic computation of the power factor. The works
industry owners to improve their load power factor, are:
which in turn reduces the transmission line losses. Use of RC network (Fig. 5) to create voltage and
current waves with varying phase shifts by
Power factor is improved by installing PFI plant at changing the circuit component C1.
the industry yard. The PFI plant measures the power Detection of the positive zero crossing points of
factor and then switches over capacitor banks across the voltage and current waves using
the load lines. The local capacitors supply the discriminators (Fig. 5).
demanded reactive energy of the load. The Derivation of a single power factor pulse width
transmission line is relieved from supplying the (PW) using the zero crossing points and SR flip-
reactive energy and enjoys its healthy operating flop (Fig. 5). The PW-width is directly
condition. proportional to the phase shift (the power factor,
pf ) between the voltage and the current waves.
There are various ways of measuring power factor Precision measurement of the PW-width in terms
[1], [3] with relative merits and demerits and have of counts (N) using 1-MHz crystal clock and 16-
been devised for both linear and non-linear loads. bit Timer-1 of the 8051 microcontroller (Fig. 4).
Some of these methods have used low-cost but less- Algebraic manipulation to transform the counts
accurate zero-crossing detection techniques and (N) into equivalent phase shift () [Eqn. 1].
some have used expensive but highly-accurate Algebraic simplification of the Maclaurin cos x
sampling techniques. The method presented in this series to derive the power factor expression in the
paper is for linear load and works on the detection of form of : gpf (1012pf) = 1012 49348 N2 [Eqn. 2].
the zero crossing points of the voltage and current
Algebraic manipulation to transform the gpf pf = 1 21! ( 10
N 2
4 ) ; x is replaced by N4 , Eqn. 1
10
expression from Decimal-domain into BINary-
domain [Eqn. 3]. 10 pf = 10 2
8 8 2N 2

Algebraic verification through value substitution


10 8 pf = 10 8 4.9348 N 2
that the gpf expression does provide expected
value of power factor (pf), which is, for example:
cos = cos 300 = 00.86.
1012 pf = 10 12 49348 N 2
Formulating Software Control Structure to gpf = 1012 49348 N 2 .(Eqn. 2)
implement Eqn. 3 using the instruction set of the
8051 microcontroller. 5. TRANSFORMATION OF gpf EXPRESSION
Experimental verification, using 8051 FROM DECIMAL DOMAIN TO BINARY
Microcontroller Trainer Kit (CMCKIT) (Fig. 3) DOMAIN
[2], of the software routines and subroutines that In order evaluate Eqn. 2 using a binary computer
are involved for the evaluation of gpf expression. such as an 8051 microcontroller, we need to
Complete listing of the Control Program in the transform it into binary-domain and then formulate
form of Data Structure (Fig. 1, 7), Flow Chart the algorithm. The transformation simply involves
(Fig. 2), Schematic Diagram (Fig. 6). the replacement of the decimal factors with their
binary (hex) equivalents. The count (N) is already in
3. TRANSFORM COUNTS (N) into PHASE binary format being the content of the T1-register of
SHIFT the MCU. Now, the required binary-domain of the
Refer to pulse width measurement circuit of Fig. 4, gpf is:
we state that the internal 16-bit Timer-1 (TH1, Tl1)
of the 8051 microcontroller is configured to work as gpf = E8D4A51000H C0C4H * N2 ...... (Eqn. 3)
a binary up counter with a preset value of 0000H. An
internal 1MHz clock derived from a 12MHz crystal 6. VERIFICATION OF gpf EXPRESSION BY
oscillator drives the Timer-1, T1 [Fig. 4]. SUBSTITUTIONS
Let us verify the correctness of the gpf expression of
The T1 starts counting the 1s pulses of 1MHz Eqn. 3 by substituting the value of N for a given
source, when the switch SW2 is closed at the arrival simulated phase shift of 300. We need to abide by the
of rising edge of PW-pulse at INT1-pin. The T1 following steps:
keeps counting for the whole duration of the PW- Find binary value of N for the phase shift of 300.
pulse and stops counting at the arrival of falling edge For an 1800 phase shift between the voltage and
of the PW-pulse. The falling edge opens the switch, current waves, the equivalent time shift is 10ms
SW2. It also sets the IE1-bit (Fig. 4), which the MCU (10*10-3 sec). Therefore, for the given phase shift
polls to understand that the T1 has finished counting. of 300 between v-i waves, the time shift is
If desired, the arrival of the falling edge of the PW- approximately 1666*10-6 sec. This indicates that
pulse could also be detected through INT1 interrupt. the PW-pulses width is 1666 s.

The MCU reads the counts (N) from the T1 and The above result further indicates that the T1of
relates it with phase shift () in the following ways: MCU of Fig. 4 counted pulses for 1666 s. Since,
N counts were accumulated over Nx1s = N s. the period of a driving clocking pulse of T1 is
10 ms (Half cycle) of the 50Hz line frequency is 1s, the T1 counted 1666 pulses. Therefore, the
equivalent to radians value of N is 1666 (0682H).
Therefore, N s is equivalent to: Evaluate Eqn. 3 with the value of 0682H for N.
gpf = E8D4A51000HC0C4H * 0682H*0682H
3 ) = (
6
( 10* Nx10
*10 N c
10 4
) Radians ... (Eqn. 1)
gpf = E8D4A51000H C0C4H * 2A5A04H
4. POWER FACTOR EXPRESSION FROM gpf = E8D4A51000H 1FE3EFEB10H
MACLAURIN cos x FUNCTION gpf = C8F0B524F0H
The Maclaurin series for the expansion of cos x gpf = 863031862512d [ d for decimal system]
function is given by:
1012 * pf = 863031862512
cos x =
n=0
( 1)n x 2 n
( 2 n )! pf = (863031862512) /1012

pf = .863031862512
cos x = 1 x2
2! + x4
4! x6
6! + ........
pf 00.86 = cos 300 ; verified
cos x 1 x2
2!
7. FORMULATING CONTROL STRUCTURE into the program memory of the target 89S52
TO IMPLEMENT gpf EXPRESSION microcontroller.
In Section-6, we have validated our power factor PFM.asm: The complete ASM program
computing formula, Eqn. 3 through substitution. We downloadable from [2], which when fused in the
intend to test it through the hardware intelligence of target MCU of the CMCKIT, measures the PW-
the 8051 microcontroller. Therefore, we need to width, performs all calculations and then puts the
submit this formula to the 8051 in the form of a power factor on 7-segment display devices.
program, which can be easily coded into executable
binary bits using the instruction set of the 8051. 9. CONCLUSIONS
L1: Initialize everything as needed In this paper, we have wished to document our field
L2: Design subroutine (SUR) to perform works on the applications of 89S52 MCU and
Binary multiplication (BMULT). BIN2BCD subroutine through the evaluation of
L3: Design SUR to perform multi-byte Maclaurin cos x function for measuring power factor
binary subtraction (MSUB). of linear loads; for the readers who wish to acquire
L4: Design SUR to perform 40-bit Binary- microcontroller technology through the reproduction
to-BCD conversion using high speed of results of working projects. To meet this purpose,
Horner Rule (BIN2BCD). we have provided complete setup, procedures,
L5: Design SUR to convert multi-byte BCD circuits and program codes.
data into CC-codes data (BCD2CC).
L6: Design SUR to transfer CC-coded data The results of Table 1 are accumulated through
onto CC-type 7-segment display devices. actual measurements by varying the component C1
of Fig. 5. The results are correct and could be
The above text codes may be coded as follows by the validated by putting the measured value of N in Eqn.
assembly syntax of the 8051 microcontroller. 2. The errors are found to be within 3% tolerance.

L1: LCALL INIT ; initialize as needed However, as we see in Table 1, the %error increases
L2: LCALL BMULT ; to perform N*N N as the phase shift between v-i increases but this
L2A: LCALL BMULT ; to perform N*C0C4H happens when the power factor falls below 0.7. This
L3: LCALL MSUB ; multi-byte subtraction is not a problem for us as we maintain the power
L4: LCALL BIN2BCD ; using Horner Rule factor between 0.85 0.95.
L5: LCALL BCD2CC ; data formatting
L6: LCALL CCX7SD ; data xfer to display 10. FUTURE SCOPE OF WORKS
The works presented in this paper is a self-contained
8. EXPERIMENTAL VERIFICATION OF THE
project and might help the academicians, researchers
CONTROL STRUCTURE OF SECTION-6
and engineers to find more and more interesting
All the principles that we have so far accumulated for
projects on electrical power theory to implement
computing power factor based on zero crossing
using microcontroller hardware.
detection of the voltage and current waves have
strong mathematical support. Now, we wish to test
Additional circuits could be inserted to detect the
these principles using actual hardware of the 8051
leading/lagging status of the current wave with
microcontroller. We have chosen the CMCKIT [2]
respect to voltage wave. The techniques of this works
(Fig. 3) for this purpose. It is an 89S52 (a family
could be applied to design Power Factor
member of 8051) microcontroller based Trainer and
Improvement Plant for smooth regulation of the load
Writer Kit. The set up under the CMCKIT requires
power factor.
the following resources[2]:
The CMCKIT REFERENCES
It is equipped with breadboards for placing the 7- [1]. http://www.freepatentsonline.com/6756771.html;
segment display devices and the circuitry of Fig. For Power factor correction method with zero
5. The Kit contains an 89S52 MCU to drive crossing detection & adjustable stored ref voltage
peripheral devices through jumper connections. [2]. www.krdcbd.com for CMCKIT an 89S52
IBMPC with WINXP operating system, Microcontroller Trainer/Write Kit and PFM.asm
WINASM5: It is a window-based assembler for [3]. A.R. Al-Ali. M/M.Nagm; A PLC Based Power
8051 microcontrollers. Factor Controller, IEEE, 2000; p1065.
USBRS232 Converter Cable: This cable allows [4]. G. Mostafa, 8086 Microprocessor Interfacing
the IBMPC to communicate with the CMCKIT and System Design, Karighar R&D Center,
over USB port. 2009, p354, p407.
CMCKTVCOM3: This is a GUI interface that [5]. J.B. Peatman, Microcomputer Based Design,
allows the IBMPC to download and burn codes McGraw-Hill Book Company, 1988, p402.
APPENDIX-A: Data Structure for the Control Introduction:
Program PFM.asm In 1711, Isaac Newton presented the polynomial
7F
Stack Growth
A(x) = an-1xn-1+an-2xn-2+..+a2x2+a1x1+a0x0,
Stack RAM T7 which later on in 1819, was modified by W.G.Horner
70 Stack TOP
for algebraic simplification and became to be known
6F as Horner Rule. At the advent of digital computers,
Scratch Pad
RAM for Rough
T6 engineers have applied this rule for BINary-to-BCD
58 and BCD-to-BINary conversions in connection with
57 To store BCD Byte for digits: DPEDPF
HEX/BCD
the design of instruments. But, unfortunately, very
T5 little information about the implementation
Data Table
50 To store BCD Byte for digits: DP0DP1 mechanism of this rule has been recorded in the
4F To hold 8-bit cc-code data for digit-F
literature except [5]. The author had the opportunity
LUT
to do extensive work on Horner Rule while designing
Lookup Table T4
Digit Vs CC-code Digital Weighing Machine in 1998[4].
41 To hold 8-bit cc-code data for digit-1
40 To hold 8-bit cc-code data for digit-0
3F To store cc-code data of DPF Position Derivation of Horner Rule for 40-bit Input Binary
CC-code BIN = b39b38b37,,b2b1b0
Data for 7-segment T3 BCD = b39x239+b38x238+b37x237+..+b2x22+b1x21+b0x20
31 To store cc-code data of DP1 Position
Display Devices BCD = (b39x238+b38x237+b37x236+..+b2x21)2+b0
30 To store cc-code data of DP0 Position
2F BAR BCD = ((((b39)2+b38)2+b37)2+.+b2)2+b1)2+b0
21 0F 08 Bit Addressable T2 BCD=(((.(IPBCDx2+b39)+ b38)2++b2)2+b1)2+b0
20 07 01 00 RAM Locations
1F R7 Where: IPBCD stands for Initial Partial BCD and is 00.
18 R0
17 R7 Control Structure for Computation:
GPR for (x=39 to 0)
R0
10
0F R7
General Purpose T1 IPBCDx2+bx IPBCD
Registers
08 R0
07 R7
8051 Data Structure for Computation
00 R0 534p Input BINary Output BCD
57 01 MSByte
Fig. 1 Data Structure for Control Program PFM.asm 56 09
5E FF MSByte 54 95
5D FF BIN2BCD 53 11
APPENDIX-B: Control Program Flow Chart for 5C FF 52 62
5B FF 51 77
Program PFM.asm 5A FF LSByte 50 75 LSByte
0
R

1
@

R
@

517

R ST : N O P

ST A R T :
8051 Assembly Codes for BIN2BCD Subroutine:
;==========================================
In itia liz e BIN2BCD:
E v e ry th in g a s n e e d e d MOV R2, #32H ; bits in input BINary
LX1: ;-- catch bit-39,38,37,,2,1,0 ------------
L1: MOV R3, #05H ; input bytes
MOV R0, #59H ; points Input Table
K eep ;-------
R e fr e s h D is p la y NXTB: INC R0
L2: MOV A, @R0 ; getting 1st BIN Byte
RLC A
N 5 -s e c e la p s e d MOV @R0, A
? DJNZ R3, NXTB ; Rotate next byte
Y
;--evaluate : IPBCDx2+bx (39-0) IPBCD-----
L3: LCALL EVBCDHR
A c q u ire P h a s e DJNZ R2, LX2 ; catch next MS-bit
S h ift a s C o u n ts , N RET
LX2: MOV R3, #05H
L4: MOV R0, #59H
LJMP LX1
1. C o m p u te p f in B IN ;------------------------------------------------
2. C o n v e rt B IN P F to B C D P F
3. C o n v e rt B C D P F to C C P F
EVBCDHR:;Evaluate to BCD using Horner Rule
4. T ra n sfe r C C P F to D isp la y MOV R4, #07H ; 7-byte to update
MOV R1, #4FH ; points BCD Table
;------
UPDNB: INC R1
753xy MOV A, @R1
ADDC A, A ; perform: IPBCDx2+bx
Fig. 2 Flow Chart for Control Program PFM.asm DA A ; adjust to correct BCD
MOV @R1, A
;------
APPENDIX-C: Horner Rule for Converting 40-bit DJNZ R4, UPDNB ; update next byte
;-------
(range: 0000000000h - FFFFFFFFFFh) Binary into RET
BCD (range:00000000000000 01099511627755) ;=================================================
Table 1

Theoretical Calculations of Electrical Quantities Practical Measurements of Electrical Quantities

From Circuit of Fig. 3 Using CMCKIT

A B C D E F

Capacitor Phase Shift [Eqn. 4] pf Power Factor Counts (Hex) %Error (C-D)

C1 (F)
= tan ( 1 0.184
C1 *10 6
) cos pf N pf

0.6x10-6 17.050 0.95 0.94 043B -1%

0.5x10-6 20.020 0.93 0.92 050D -1.1%

0.4x10-6 24.700 0.90 0.88 0616 -2.2%

0.3x10-6 35.020 0.85 0.83 0756 -2.3%

0.2x10-6 42.610 0.73 0.74 08FA +2.7%

Fig. 3 Power Factor Meter Set up using CMCKIT Atmel 89S52 CISC Microcontroller Trainer and Writer Kit

Timer-1
18 XT2 Registers Marked by
TMOD B7 B6 B5 B4 B0 Asterisk (* ) are both
1 uS Pulse (89H) GATE1 C1-T1/ M1 M0 Byte and Bit
OSC 1/12
0 1 Addressable
19 XT1
ET1=0
Y1 SW2
C1-T1/=0 SW1 TL1 TH1 NO
12MHz
TF1
(8AH) (8CH) IRQ
15 C1/ (P35) SW5
PW 16-Bit
H
Mode-1
13 INT1/(P33) H
B7 B3 B2 B1 B0
IE *(A8) EA ET1 EX1 ET0 EX0
PW
TCON*
TF1 TR1 IE1 IT1
B7 B6 B3 B2 B0 (88H) EA=1
EX1=1
IT1=1
IE1 IRQ
SW3 SW4 0013H
SW6
534 GM : 2011

Fig. 4 Internal Structure of Timer-1 of the 89S52 Microcontroller


V o lta g e W a v e
LS 123 based L S 7 4 B a se d
+5V
150uS O ne Shot S R F lip flo p
PW
W 12V
L W R2 3 7
9V +
6 1
R1 T1
2
5k1 R2 - pf
220V 4 10 9
0V 1 2k 2 4 U1 Q1 SET Q1
50H z C 1 = 6 x0 .1 u F 741
-5 V
N 0V
9V
2
-
T1
3
+
6 10 T2
Q2
12 13
CLR
U2
S im u la te d P h a se S h ifte d 741
U3 U4
534p C u rre n t W a v e

Fig. 5 Generating phase shifted voltage and current waves for creating artificial Power Factor Pulse (PW)

The phase shift between the simulated voltage and current waves of the above circuit is:
3
Impedance, Z = 17.3 * 10 j = 17.3 *10 3 j 3.18C*110
3 1
2 *50*C1

tan 1 ( 3.18C*110 * 17.31*103 ) = tan 1 C0.*184


3
Phase shift, | | = [C1 is in F].(Eqn. 4)
106 1

+5V

RN1 Power Factor (pf) Counts(N) in Hex


89S52 MCU 8x1k
Y1 = 12MHz
DP0 DP1 DP2 DP3 DP4 DP5 DP6 DP7
+5V P2
X2
P2.7 5 p p
RST P2.6 10 g g
P2.5 9 f f
C1 X1
P2.4 1 e e
100uF
P2.3 2 d d
RST
P2.2 4 c c
P2.1 6 b b
R1
P2.0 7 a a
4k7
ccE cc1 cc2 cc3 cc4 cc5 cc6 cc7
3 3 3 3 3 3 3 3
0V
GND P0
+5V
Vcc
PW
EA/ P00
P01
INT1 P02
P03
0V
P10 P04
R2 P05
LEDR2
1k5 P06
P07
1602x : GM : 15-2011

Fig. 6 Schematic Diagram for the 89S52 MCU based Power Factor Meter

DP0 DP1 DPE DPF

CC7SDD
U n it
M u lt ip le x e d ccF
cc0 cc1 ccE
C C -c o d e

S0/ S1/ CCX7SDD SE/ SF/


DPE
P2 DP0 DP1
D P 0 -D P F D P 0 -D P F DPF

D P 0 -D P F

C C -C o d e
DP0 DP1 DPE DPF
T a b le
(C C C T )
In t e r n a l R A M 30H 31H 3EH 3FH
In t e r n a l R A M
C C -C o d e
LUT
40 C C -0
D ig it
H EX 2C C Vs
C Ccode
4F C C -F

H ex
DP0DP1 DP2DP3 DP4DP5 DP6DP7 DP8DP9 DPADPB DPCDPD DPEDPF T a b le
In p u t
(H E X T )
In t e r n a l R A M 50H 51H 52H 53H 54H 55H 56H 57H
52x : G M : 2011

Fig. 7 Data Structure for the Data Display Mechanism of Power Factor Meter

You might also like