Professional Documents
Culture Documents
Golam Mostafa
Department of Electrical and Electronic Engineering, Ahsanullah University of Science and Technology (AUST)
e-mail: mostafagb@yahoo.com
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
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
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. 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
+5V
Fig. 6 Schematic Diagram for the 89S52 MCU based Power Factor Meter
CC7SDD
U n it
M u lt ip le x e d ccF
cc0 cc1 ccE
C C -c o d e
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