I n' .3»3ti;w-»-«

78
"I n' ."3»3ti;w-»-"« UTILITY INTERFACE DESIGN FOR DISTRIBUTED RENEWABLE ENERGY SOURCES by GURUPRAKASH RADHAKRISHNAN, B.E. A THESIS IN ELECTRICAL ENGINEERING Submitted to the Graduate Faculty of Texas Tech University in Partial Fulfillment of the Requirements for the Degree of MASTER OF SCIENCE IN ELECTRICAL ENGINEERING Approved X) Accepted / 7 December, 2000

Transcript of I n' .3»3ti;w-»-«

Page 1: I n' .3»3ti;w-»-«

"I n' ."3»3ti;w-»-"«

UTILITY INTERFACE DESIGN FOR DISTRIBUTED

RENEWABLE ENERGY SOURCES

by

GURUPRAKASH RADHAKRISHNAN, B.E.

A THESIS

IN

ELECTRICAL ENGINEERING

Submitted to the Graduate Faculty of Texas Tech University in

Partial Fulfillment of the Requirements for

the Degree of

MASTER OF SCIENCE

IN

ELECTRICAL ENGINEERING

Approved

X) Accepted / 7

December, 2000

Page 2: I n' .3»3ti;w-»-«

iMMPmmmmiiiiiiiiiiiNiiiiiiiiimmnTre:^

7 3 ACKNOWLEDGEMENTS

â90 6

AloSVl

.o«

Leaming follows various roads, We note the start but not the end. For time and fate must rule the course, While we see not beyond the bend. The best of knowledge is a dream. The gainer holds steadfast uncowed. By ridicule, and moves serene. Despised and lowly in the crowd. "Present knowledge of the people Is a fog above the field; When the sun mounts the horizon To its ray the mist will yield".

"He who does not seek advice is a Fool. His folly blinds him to truth and makes

him evil, stubborn and a danger to his feilow men" - Khalil Gibran. The project was

approached; seeking inspiration from the advice rendered by the great philosopher Khalil

Gibran, seeking pearls of wisdom from a variety of sources. At the culmination of the

effort, the purpose fulfilled, it is time to pay my heartfelt acknowledgements to those

faces in the crowd.

No one person deserves it more than the Almighty and my Guru, who blessed me

with ample grit and perseverance, which were quintessential in my endeavor. FoUowing a

close second is Dr. Michael Giesselmann, my advisor and chairperson of my committee,

for having given me this opportunity. His valuable knowledge and lucid thinking brought

11

Page 3: I n' .3»3ti;w-»-«

I III II Il l l l l l llhl l l l llllllll l"1

to an end many a knotty problem. His constant interaction, encouragement, openness to

new ideas and infectious zeal were instrumental in the completion of the project.

Dr. James Dickens, for his technical support, whenever approached with a tough

situation on hand, needs a special note of appreciation. Daniel Garcia, Chris Hatfield,

Dino Castro and Marie Byrd and my lab-mates for their friendliness need a special

mention here.

I wouid ever be grateful to Dr. John Durrett, who not only trained me in Java, but

also was ever open for the implementation of new projects.

Also, I would like to thank my parents and grandparents, whose blessings have

enabled me in coming a long way in life's joumey, my sister for her constant

encouragement, my girlfriend for her love, and all my friends for their continued support.

111

Page 4: I n' .3»3ti;w-»-«

I" " I lllllllllll llirffnrT-Tn'ii'IW'•^-'-^"-^- •^^trrrf^rii1-r-='^---

TABLE OF CONTENTS

ABSTRACT v

LIST OF FIGURES vi

CHAPTER

I. INTRODUCTION I

n. FUNDAMENTALSOFTHEPOWERELECTRONICSUSED 4

III. IMPLEMENTATION OF THE PULSE-WIDTH MODULATION SCHEME 16

IV. OTHERELEMENTSUSEDESÍTHECIRCUIT 36

V. SCREEN CAPTURES AND THE EXPERIMENTAL SET-UP 41

VL MEASUREMENTS AND COMPARISON OF RESULTS 52

Vn. CONCLUSIONS 57

REFERENCES 58

APPENDIX 59

IV

Page 5: I n' .3»3ti;w-»-«

• ' T f ' i'i 'ii"'^iHr ,uii\\]Ar,i\Á {-Tm mr,

ABSTRACT

The basic idea of the project is to design and build single-phase inverters, and

use them to interface distributed renewable energy sources to the utility grid.

Photovoltaic elements can be used on rooftops to capture solar energy, which are used

to generate DC voltage. It is proposed to exploit this energy to create AC power,

which is then fed into the utility. Besides, this energy could also be used to

independently power some low-rated installations (a sixty-Watt light bulb is being

used in our case).

The project revolves around the design of the power electronics circuit

topology and the requisite controls. Metal Oxide Semiconductor Field Effect

Transistors (MOSFETs) are used in the form of an H-Bridge to form the single-phase

inverter, the output of which would be subject to Pulse Width Modulation (PWM) to

produce a sinusoidal wave, to be synchronized to the utility. A micro-controUer

(Motorola's HC12) is being used for the purpose. The magnitude and phase angle of

this synthetically generated voltage are adjusted with respect to the utility voltage,

thus achieving total control over the real and reactive power.

Page 6: I n' .3»3ti;w-»-«

j-^»mw^wftnri iiiiiiiUimiinninriii'i'' ^^—-^-^-

LIST OF FIGURES

1.1 Block diagram approach to the project 2

2.1 Schematic representation of a buck converter 4

2.2 The monolithic integrated chip in use (LM2574) 5

2.3 PSpice representation of LM 2574 6

2.4. Simulated output vohage and the load current 7

2.5. Zoomed-in version of2.4 8

2.6 Conventional single-phase inverter 8

2.7 Conventional single-phase H-Bridge inverter module 9

2.8 Definitions of variables used 11

2.9 Definitions of the functions used in generating the waveforms 11

2.10 The generated triangular and sinusoidal waveforms 12

2.11 Frequency spectmm of the PWM voltage as a factor of frequency 13

2.12 PWM and sinusoidal waveforms, as well as the average PWM voltage 13

2.13 Definition for moving average 14

3.1 An introduction to the program 16

3.2 Additional comment about the dipswitch 16

3.3 D-Bug 12 Callable routines and equivalent definitions 17

3.4 Definitions of all PWM equivalents 17

3.5 Timer register equivalent definitions 18

3.6 Analog-to-Digital Equivalent Definitions 19

3.7 Startofthecode 19

vi

Page 7: I n' .3»3ti;w-»-«

„-.Aji JMJ..»i-ji -" B lÆ g B ^ M i í i i i a ^ ^ S ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ p v i ^ ' * * ' ^ * ' " * " ^ ' " 'llflfflMlim'iir'^^'IF^ 'JillM-hrV^ri-f .-'H i'nl 'fniCTT

3.8 Initialization of the Analog-to-Digital Converter and the Timer Intermpt 19

3.9 Initialization of the PWM control and the 7-segment display 20

3.10 The main program 20

3.11 Generation of the sine wave 21

3.12 Display sub-routine 22

3.13 Sub-routine to calculate the sine of an argument 23

3.14 Allotment of memory for degree and phase count 23

3.15 Look-up table for the sine function 24

3.16 Symbol table for hex to decimal conversion 26

3.17 Processing of the number received from the Java program 26

3.18 Introduction to the program 27

3.19 Importing the required classes into the package thesis 27

3.20 The heart of the Graphical User Interface 29

3.21 Setting up of buttons for making it user-friendly 30

3.22 Details of the proj ect 31

3.23 Modified version of the code, using the PAC feature 35

4.1 Main circuit 36

4.2 Simulink representation of the zero cross-over detector 37

4.3 The zero cross-over detection, along with the sine wave, and zero reference 38

4.4 Schematic of inverting and non-inverting comparators 39

4.5 Simulated results of the schematic shown in Figure 4.4 39

vii

Page 8: I n' .3»3ti;w-»-«

,.,juLiiiiiiiii)HinM,]H|i|iimii.ii|jyffijji,. , i i i i i i . i^jui i- j i .m ^ .

4.6 Circuit for the zero cross-over detector 40

5.1 Borland'sJBuilder3.0 41

5.2 Java console window 42

5.3 Application prompting user input 43

5.4 Sample invalid user input 44

5.5 Program giving the options to the user 45

5.6 The example discussed above for 0.5 power factor 46

5.7 Calculated results being displayed for the user's convenience 47

5.8 The "Reset" option 48

5.9 Schematic of the daughter board 49

5.10 The schematic of the main circuit 49

5.11 Main circuit 50

5.12 The zero cross-over detector and the daughter board 50

5.13 The Tektronix Oscilloscope being used 51

5.14 The entire experimental set up 51

6.1 Screen capture at zero phase shift 53

6.2 Screen capture at a 60-degree phase shift 54

6.3 Captured waveform of the synthesized sine wave 55

6.4 Captured waveform of the PWM signal 55

6.5 Replica of Figure 6.3 done using Microsoft Excel 56

6.6 Replica of Figure 6.4 done using Microsoft Excel 56

Vlll

Page 9: I n' .3»3ti;w-»-«

i 3 | H ^ H H i ^ H ^ H I ^ ^ ^ ^ ^ ^ H H C ^ æ ^ r ø E S S

CHAPTERI

ESÍTRODUCTION

Photovoltaic systems can be used to supplement electric power from the

utility. Photovoltaic arrays are installed in small or large quantities, and closely

match the electricity needs of the user. Furthermore, photovoltaic arrays can be

installed and put into operation in a much lesser time frame than the time typically

associated with the setting up of conventional power plants. This flexibility

decreases utility costs, and provides superior service to the utility's customers.

In utility-connected systems, the role of the power-producing company is

more of a back-up power source than a primary source. If the home needs power in

excess of that produced by the solar panels, it uses the power generated by the

utility. In the case of the solar panels producing more power than the requirements

of the home, it could be sold to the utility.

Photovoltaics have several characteristics that make them attractive to

utilities, and not just those with interest in demand-side management.

The timing of the electricity produced by PV cells is often coincidental with

the demand for electricity from the utility. This is primarily due to the electrical

loads of commercial and industrial facilities.

The cost of transmitting and distributing power to a utility's customers is

often as high or higher than the cost of producing the power. When a utility has new

Page 10: I n' .3»3ti;w-»-«

demand (due to new customers or increased demand by existing customers), and

transmission and distribution lines are operating at their maximum capacity, the

utility would normally build additional lines, which could tum out to be very

expensive. An altemative is to use photovoltaic arrays at the customer's end of the

system to provide the additional power, removing the need to upgrade the

transmission and distribution lines. With these as the motivation, the project was

taken up.

The entire scheme of the project can be illustrated in the form of the block

diagram shown below (Figure 1.1).

BLOCK DIAGRAM APPROACH

SUPPLY 40 V H-BRIDGE VOLTAGE irrÆRTER

,py. MODULE

40 V OPTO-, COUPLER

BUCK ICONVERTER

5V

5V HC-12

STEP-UP TRANSFORMER UTILITY

Figure 1.1. Block diagram approach to the project.

The photo voltaic cell array is replaced with a dc power supply to simulate

test conditions in the laboratory. This supply is fed into a buck converter

(LM2574HV), to achieve a constant output of 5 Volts. This monolithic integrated

circuit is preferred to the traditional three-terminal linear regulator for greater

Page 11: I n' .3»3ti;w-»-«

fB ' \íUm \ u •^>mfi\h-r,-^^'Mi.\rf^ -^^

efficiency. The regulated output of the buck converter is used to power the

secondary of the opto-couplers. The opto-couplers are present to pass the PWM

control signals. The inverter is in the form of National Semiconductor's LMD

18200, which uses an H-Bridge topology. Using the micro controUer (Motorola's

68HC12), a sine wave is synthesized at the frequency of the utility. This synthesized

voltage is stepped up to match the voltage of the utility to be fed with additional

power. The amplitude of this generated voltage can be controlled, as well as the

phase, thus achieving a perfect utility interface.

Page 12: I n' .3»3ti;w-»-«

• ^ B " ™ ™ ^ ^ ^ ^ ^ ! 1 I "I H I ll4iPIMJ.JIMLimUJJlllUi,iJ1P^ ,„ . B U P - ^ ' ^ ^

CHAPTERII

FUNDAMENTALS OF THE POWER ELECTRONICS USED

This chapter deals with the representation, flinctions and simulations of each

building block used in the course of the project. It also deals with the corresponding

hardware used, and the expected results. These will iater be compared with the results

achieved.

2.1. Buck converter used as a regulator

The first block of the circuit scheme uses a buck converter in a dual role of a dc-

dc step-down transformer and a voltage regulator.

A buck converter is essentially a step-down converter, which produces an

average dc output voltage; lower than the dc input voltage.

Figure 2 I Schematic representation of a buck converter.

Page 13: I n' .3»3ti;w-»-«

^^^ss

Figure 2.1 depicts a schematic representation of a buck converter. Buck

converters are typically used in high efficiency power supplies. The output voltage

depends on the duty cycle of the switch, which is a ratio of the time the devices are on to

the total cycle time:

D= ton. Ts

In the current project, we make use of National semiconductor's LM2574 for the

dual purpose of a step-down converter and a regulator (Figure 2.2).

Block Diagram

lAnigu •twa 0CIBpjt~j7~

"

l.liv

iir:oe:

isv ^ - ti.a<

M -opM. iu-æi >irm- - f niirrwe M m n ^ -vpn Dt* p(in«3»

FKUREI.

Figure 2.2. The monolithic integrated chip in use (LM2574).

National semiconductor's LM2574 is a monolithic integrated chip that provides

excellent line and load regulation. It performs all the fiinctions of a step-dovm switching

regulator, driving a maximum load of 500mA.

For the sake of simplifying lab work, the solar panels were replaced

Page 14: I n' .3»3ti;w-»-«

f i_ ' ' " • ^ p g g gr""-- II i-i'.i^i'^'^-^

with a switched mode power supply to generate a dc input of 40-60 Volts, to be passed

through the LM2574 regulator. The chip consists of an intemal 52kHz fixed-frequency

oscillator. The capacitor Cl at the input is a bypass to provide stable operation.

However, the larger the value of the capacitor, the larger is the magnitude of the ripple

current. The capacitor provides the ripple current needed to drive continuous input

current from the primary source. The resistors Rl and R2, in combination with the

comparator and the digital circuit, help control the average output voltage to 5 Volts, by

providing the necessary feedback. The inductor and capacitor are designed to act as a

low-pass filter, considering a comer frequency much lesser than the switching frequency,

with an aim to eliminate the switching frequency ripple in the output voltage. It performs

all the flínctions of a step-down switching regulator, driving a maximum load of 500mA.

An equivalent circuit of the chip can be drawn as follows in Figure 2.3.

Buck (Step-Down) Converter Representation of LM 2574

M3

V_dc 40V

C1 0.5

-w;

In 7

.íí*

h

IRF15Û

D4"

a^ L1

330uH

/s .^, _ ^ Out , /

T

í

C2 J 220uF

RJoad

50

Figure 2.3. PSpice representation of LM 2574

Page 15: I n' .3»3ti;w-»-«

JII.L,.-. l i M — W B 8 ipWSH!fJCT««B*^5WB^^=VJ—^^j-.* —3r

Before carrying on with the actual testing of the device, simulations were

carried on to check the validity of using the chip. The circuit shown above was used for

simulation purposes, and the results were satisfying, and in keeping with the expected

waveforms. Following are the simulated output voltage and the load current (Figures 2.4

and 2.5). As seen from the simulations, the current stays well within the boundary limit

of 500mA. Also, the voltage settles down at a value close to the required 5 Volts, within

the permissible error of 5% (0.25 Volts for an output of 5 Volts).

c U(UUt)

i.afl-«i

b , l l 1 .

> y

M - -ús

c I(L1) l e i

^BOmA

. — 2Bns . nn-. otiri .111-. 8t)ns 90ns IBOns

Figure 2.4. Simulated output voltage and the load current (using Microsim's Pspice).

Page 16: I n' .3»3ti;w-»-«

*—^**—^^^r^mm^!f^'^ii,LMii \\'",v<' --

Figure 2.5. Zoomed-in version of 2.4.

2.2 Inverter topology

A conventional single-phase inverter can be depicted as shown below (Figure

2.6).

Figure 2.6. Conventional single-phase inverter.

8

Page 17: I n' .3»3ti;w-»-«

The topology consists of switches, with diodes in an anti-parallel fashion The

switches are usually Metal Oxide Semiconductor Field Effect Transistors (MOSFETs) or

Insulated Gate Bipolar Transistors (IGBTs), based on the application. The input voltage

Vj is reasonably assumed to be a constant. The other assumption is that the control

scheme would pulse-width modulate the inverter switches, so as to shape and control the

output voltage. This is taken care of by the micro controller (Motorola's 68HC12); the

control scheme wili be discussed in later chapters.

The output voltages with respect to the neutral point svsdtch between the input

voltage Vd and 0. For the sake of simplicity, the switches are assumed to be ideal for the

discussion of the generation of the control signals. The diodes are present to provide a

retum path for the current when the direction of the current is opposed to that of the

applied voltage (regenerative current).

In the current project, National Semiconductor's LMD 18200 has been used as an

H-bridge module. A conventional single-phase H-Bridge module can be depicted as

below (Figure 2.7).

M1 J l O 1 ^

IRF150

VDC 4^

t-

D1N4002

D1 M2 I

Dir44002

IRFIS'ôl

y D4

11 lOuH

LOAD

M4

IRF1

r 5ô\

l D2 M3

^- • L2

D1N4002

1

IRF15Ô1

lOuH

D3

D1N4002

Figure 2.7. Conventional single-phase H-Bridge inverter module

9

Page 18: I n' .3»3ti;w-»-«

I j .JI...JÍÍÍ ^XJUW. I , J»)U».-J . . . . 1 »• ' J " . ' ' '

2.3 Pulse-width modulation

The purpose of Pulse-Width Modulation (PWM) is to control the output voltage,

irrespective of fluctuations in the input voltage or the output load. Given a constant

switching frequency, by varying the time duration for which the switch is on, the average

output voltage can be controlled. This scheme (PWM) involves varying the duty cycle D,

which is defmed as the ratio of the on duration to the switching time period.

The PWM is generated by comparing a reference level, sinusoidal control voltage

with a repetitive triangular waveform, Vtri- The frequency of the repetitive triangular

waveform is the same as the switching frequency,;^. The reference level voltage, Vcontroi

is an amplified factor of the error between the output voltage and the desired voltage.

This adjusts the duty cycle of the generated PWM so as to maintain the output voltage at

a constant level.

The switching frequency is also called the carrier frequency. As discussed before,

the control signal Vcontroi modulates the duty ratio of the switch, and is at modulating

frequency. The modulation frequency is the fiindamental frequency of the inverter output

voltage.

The output voltage depends on the time periods for which the switches TA+ and

TA- are on. This is based on the comparison between the control voltage and that of the

triangular waveform. There are two cases:

( Í ) ^control<Vtri

(ÍÍ) Vcontrol>ytri.

10

Page 19: I n' .3»3ti;w-»-«

liii III i i i i i . jui i i . j .p.nn^,|y.. i j i^JifPi

In the case when Vcontroi<Vtri, the output of the comparator is high, and the switch

TA^ goes on. Consequently, the output voltage is the positive DC bus voltage. When

Vco/j/ro/ > "^tri, thc output of thc comparator is low, and the switch TA- goes on.

Consequently, the output voltage is the negative DC bus voltage. The resulting

waveform, along with the comparison of the control voltage with the triangular

waveform is shown in the form of a Mathcad document below (Figures 2.8 - 2.11):

Sinusoidal PWM Waveforms:

freq: = 60Hz ci) ^ :=2-7i freq

m^: = 0.8 mf:=45

N : = 4096 This number needs to be a

Sept-10-2000

Hs = 10 -sec ms=10 sec

T : = ' freq

powerof 2, as

T = 16.66>ms

it needs to be used for the FFT flinction

Figure 2.8. Defínitions of variables used.

Triangle function:

VTri(t) : = _-asin(sin(mf cû Q-X\\

Sinusoid:

^sin(0-="^aS^^(^ o'O

SPWM function:

VpwM(0:=if(V3Í^(t)>VTri(t),l,-

i:=0"N- 1

Tri. : = Vx-: i — ' ^"\ N/

Vsia-V^JiI

^Pwm--^PWMh' -i \'NÍ

. T \ î

Figure 2.9. Defmitions of the functions used in generating the waveforms

11

Page 20: I n' .3»3ti;w-»-«

Figure 2.10. The generated tríangular and sinusoidal waveforms

SPECTRUM:=FFT ( V p ^

AMPLITUDE^ :=| SPECTRUl^

last(SPECTRUM):=1024

FreQ) :=-û-sec

V-l.ii

AMPLITUDES:=2 SPECTRUM

Freqi : = -

AMPLITUDESo = 4.883-10

12

Page 21: I n' .3»3ti;w-»-«

'^ITWWimWIIILMIl-iA'.U-l"iHIJi'i-'iNiM.l^-' 'i "I = 3

0.8

0.6 AMPUTUDES. X

0.4

0.2

0

Ffequeney Spectram of PWM VolUfe:

• • - - -

1

*

• .^.f .....

1 ^ - - — 4 - • - • - -

1 . JIII 1. .111

For mf«45

2000 4000 «000 8000 Tnq.

fnqpmtey

MO 1.2-10

Figure 2.11. Frequency spectrum of the PWM voltage as a factor of frequency.

Pwnj;

Sm:

AVG V Pwiti'

PWM Vohage and Sinusoid:

IM

Figure 2.12. PWM and sinusoidal waveforms, as well as the average PWM voltage.

From Figures 2.12 and 2.13, we can predict that the generated PWM voltage

waveform will be sinusoidal, within the specified limits of error. The actual generation is

discussed in the next chapter.

13

Page 22: I n' .3»3ti;w-»-«

-_'!^^HiMni^^«9?i IÍIIIIMIIIUIIUJ18L ^I IJ IHI I I^f f l^JI IWI iy jB. .

Definition for moving Average: AVC3:x,n,i) = \ if i=0

0

k = i

i - n ^- 1

— • / \ otherwise

k = i

Figure 2.13. Definition for moving average.

The waveforms shovm in the figure above are for an amplitude modulafion ratio

of 0.8, and a frequency modulation ratio of 45, where amplitude modulation ratio can be

defíned as

nia A

V control

A

Vrrl

and / r / j

Frequency modulation ratio can be defined as

m/ / .

/ / ,

where// is the desired fiindamental frequency of the output voltage.

Table 2.1. Conducting states of the switches.

Condition

'^control > '^tri

'^control < ^tri

Switch in the ON state

TA^

TA-

Output voltage

•^Vd/2

-Vd/2

14

Page 23: I n' .3»3ti;w-»-«

.— EJ..JPÍW " il^"-^4W-,i,-,í,JJ,HW-^fiU7[^i

The next chapter discusses the implementation of the PWM using Motorola's

68HC12 micro-controller. Also, the Java program that was vmtten for possible user

interface is documented, along with the assembly language code associated with it.

15

Page 24: I n' .3»3ti;w-»-«

• ' ^^^mmivuEÅ^wiiw^^^ ^m

CHAPTER ni

IMPLEMENTATION OF THE PULSE-WIDTH MODULATION SCHEME

The pulse-width modulation scheme was implemented using Motorola's 68HC12

micro-controller. The code was initially written to generate a sinusoidal waveform and

phase-lock it in an abrupt manner. This code was tried out in association with the Java

code, which uses user-interface, allowing the user to decide the amount of power he or

she needs to be using at any point of time. This would permit the user to save the rest of

the power generated for future use. The assembly language code is as follows (Figures

3.1 -3.2). (The program is split up in blocks to describe the functional aspects of each.)

* Program for a Photovoltaic -> 120 V AC-Utility Interface * * Written for Motorola M68EVB912B32 Eval Board * * The Program uses the Ou^ut Compare 7 Function of the Timers * * All signals betvveen the Power Electronics and tíie HC12 are isolated * * A step-up transformer is connected at the Output of the LM 18200 * * PWM Channel 0, Port PO is always enabled * * Port P1 is the Direction Bit for the HBridge for Sign/Magnitude Mode * * To Produce AC Output Voltage, the PWM Signal is applied to Port Pl * * Port P2 is connected to the Brake Input the LM 18200 HBridge * * Port P3 is connected to the Overtemp Output of the LM 18200 H_Bridge * * Potentiometer is connected to PAD2. AD-Result = Amplitude of Sinewave * * Analog Current Oulput of HBridge is connected to PAD3 * * Input Capture 0/1 detect start of pos/neg Half-Cycle of Utiliy Volt. * * Written for AS12 Assembler, October 15,1999, by Michael Giesselmann *

Figure 3.1. An introduction to the program

Figure 3.1 provides a detailed introduction to the program, and its functions.

This makes the rest of the code easier to comprehend.

* DlP-Switch - Not required - program written such that * * the best results are obtained at a default position of zero, * * enabling the user to do away witíi the DlP-Switch *

Figure 3.2. Additional comment about the dipswitch

16

Page 25: I n' .3»3ti;w-»-«

•»JI ^"^-^'•'llMIA^^ll^iífn-n^^fir"-'- "V.-S -

Figure 3.2 gives a comment about doing away with the dipswitch, which was

initially used in different positions to get the best output. This was done because the

waveform generated had a continuous change of phase, to enable the zero crossover

detector to achieve perfect synchronism with the utility. The slower the rate of change

of phase, the better phase lock we could achieve. By trial and error, it was found that an

increment in steps of 2 degrees at a time to generate the PWM, and at a clock frequency

of 10.8 KHz yielded the best results even while the dipswitch was in the zero position.

* : t : * : ) c * : | c H c * * * * * * * * * * * * * * * * * * * * * 9 | c * * * * * *

* 68HC12 D-Bug 12 Callable Routines * HC12 Regs and other Equivalents

*

* ****:|c:|c:|c^3|c:|c*:ic:|c:jc4c4[:|cj|c;|c***4:3|c*:)c:|c:t:i|c:|::(c:(c*4e4c

PORTA EQU PORTB EQU DDRA EQU DDRB EQU PUCR EQU RTICTL EQU RTIFLG EQU COPCTL EQU

$0000 $0001 $0002 $0003 $000C $0014 $0015 $0016

;Port A Register of HCl 2 ;Port B Register of HC12 ;Data Direction Register Port A ;Data Direction Register Port B ;Pull Up Resistor Control Register ;Real Time Intemipt Control Register ;Real Time Interrupt Flag Register ;Watchdog Timer Control Register

Figure 3.3. D-Bug 12 Callable routines and equivalent definitions

Figure 3.3 defmes the routines and equivalents that will be used by the program.

* * * * * * * * * * *

PWCLK PWPOL PWEN PWSCALO PWSCALl PWPERO PWPERl PWPER2 PWPER3 PWDTYO PWDTYl PWDTY2 PWDTY3 PWCTL PORTP DDRP

PWM Control ************************************* EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU

$0040 ; $0041 ; $0042 $0044 $0046 $004C $004D $004E $004F $0050 $0051 $0052 $0053 $0054 $0056 $0057

PWM Clocks and Concatenate PWM Clock Select and Polarity PWMEnable Register PWM Scale Register 0, Channel 0/1 PWM Scale Register 1, Channel 2/3 PWMPeriod Register Channel 0 PWM Period Register Channel 1 PWM Period Register Channel 2 PWMPeriod Register Channel 3 PWM Duty Register Channel 0 PWM Duty Register Channel 1 ,PWM Duty Register Channel 2 ,PWM Duty Register Channel 3 ,PWM Control Register ,Port P Data Register ,Port P Data Direction Register

Figure 3.4 Defmitions of all PWM equivalents.

17

Page 26: I n' .3»3ti;w-»-«

•-^-'•••"'•.T-il^l-^flTUUWfl^ff',"-•- ••' — j g g g g ^

Figure 3.4 defmes the PWM equivalents that wiU be used by the program.

TIOS CFORC 0C7M 0C7D TCNT TSCR TCTLl TCTL2 TCTL3 TCTL4 TMSKl TMSK2 TFLGl TFLG2 TCO TCl TC2 TC3 TC4 TC5 TC6 TC7 PACTL PACNT PORTT DDRT SPOCRl SP0CR2 SPOBR SPOSR SPODR PORTS DDRS PURDS SCOSRl SCODRL Out2Hex Out4Hex PutChar INTSUP

EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU

$0080 ; $0081 ; $0082 ; $0083 ; $0084 ; $0086 ; $0088 ; $0089 ; $008A : $008B : $008C $008D $008E $008F $0090 $0092 $0094 $0096 $0098 $009A $009C $009E $00A0 $00A2 $OOAE $OOAF $00D0 $00D1 $00D2 $00D3 $00D5 $00D6 $00D7 $OODB $00C4 $00C7 $F696 $F698 $F684 $F69A

Timer Input Capture, Output Compare Select Timer Compare Force Register Ou^ut Con^are 7 Mask Register Ou^ut Compare 7 Data Register 16 Bit Free Running Counter Timer System Control Register Timer Control Register 1 Timer Control Register 2 Timer Control Register 3 Timer Control Register 4 Timer Mask 1 Timer Mask 2 Timer Interrupt Flag 1 Timer Intemipt Flag 1 Timer Input Capture / Output Compare Register 0 ,Timer Input Capture / Ou^ut Compare Register 1 ,Timer Input Capture / Output Compare Register 2 .Timer Input Capture / Oulput Compare Register 3 ,Timer Input Capture / Ou^ut Con^are Register 4 ,Timer Input Capture / Ou^ut Compare Register 5 ,Timer Input C^ture / Ou^ut Con^are Register 6 ,Timer Input Capture / Oulput Compare Register 7 ;Pulse Accumulator Control Register ;Pulse Accumulator Count Register ;Port T Data Register ;Data Direction Register for Timer Port ;SPI Control Register 1 ;SPI Control Register 2 ;SPI Baud Rate Register ;SPI Status Register ;SPI Data Register ;PortSRegisterofHC12 ;Data Direction Register for Port S ;PuU up and Reduced Drive for Port S ;SCI Status Register 1 ;SCI Data Register Low ;Output Byte as 2 Hex Characters ;Ou^ut Byte as 4 Hex Characters ;Put Character out on Serial Port ;Address forD-Bugl2 Interrupt Setup

Figure 3.5 Timer register equivalent definitions.

Figure 3.5 defmes the timer register equivalents that will be used by the program.

18

Page 27: I n' .3»3ti;w-»-«

'•a n 1 ^ ' ! -H ' - ! .U .J ;»^ .JgJ.LJ-JJH.JwJuj

ATDCTL2 ATDCTL5 PORTAD ADROH ADRIH ADR2H

EQU EQU EQU EQU EQU EQU

$0062 $0065 $006F $0070 $0072 $0074

;ATD Control Register 2 ;ATD Control Register 5 ;Port AD Input Register ;ATD Converter Result Register 0 ;ATD Converter Result Register 1 ;ATD Converter Result Register 2

Figure 3.6 Analog-to-Digital Equivalent Defmitions.

Figure 3.6 defmes the analog-to-digital equivalents that will be used by the

program. AU the above equivalents allot memory locations for each operation, and

enables systematic compilation and running of the code.

* : t : : | c * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

* Start (ORIGIN) of Code in Memory * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

ORG $0800 ;Origin= =Bottom of User RAM

Figure 3.7 Start of the code

The program starts at the memory location $0800, and will be $0D00 to place it in

the micro controller's EEPROM (Figure 3.7). Figure 3.8 shows initialization of the

analog-to-digital converter for amplitude control, and the timer interrupt.

++***********************++*************** * InitiaUze AD Converter for Amplitude Control * ++++*++++++++++++++*+*+*******++++****+++*

BSETATDCTL2,$80 BSET ATDCTL5,$22

;Tum AD-Converter on ;Tum on Scan Mode, Channel 2

++++*****************++++++++****+* * Initialization of Timer Interrupt * +++++++*+++******++++*+++********++

Start: MOVW #Timer7,$B00+(2*16) ;Setup Address for Timer Channel 7 Interrupt MOVW #DisPl, $B00+(2*24) ;Setup Address forReal Time Interrupt BSET PUCR, $02 BSET TCTL4,$05 MOVW #741 ,TC7

BSET TMSK2,$08 BSET TIOS ,$80 BSET TCTL1,$40 BSET TSCR ,$80 BSET TMSK1,$80

Enable Port B Pull-Up Resistors for DIP Switches Enable Rising Edge Captures on Channels 0/1 Load Channel 7 Output Compare Register for 10800 HzonPTZ Enable Timer Reset and set Prescaler=l Select C iannel 7 Ou^ut Compare Set Channel 7 to toggle Enable Timer System Enable Timer Channel 7 Interrupts

Figure 3.8 Initialization of the Analog-to-Digital Converter and the Timer Interrupt.

19

Page 28: I n' .3»3ti;w-»-«

I H mm'V'\ iii'Fiii'iTffP iiP' ri III" i', ym-m'vmwmT^Tm-*'^--^'*''"'^ -=~j>j>n->:taB^u,jgq>g?

+ + * + + + + + :|c+ + + + + + + + + + +:|c + + + + + + + + + + + + + + + + + + :|c:|c +

* InitiaUzation for 7 Seg Display * * + * + + + + * ++ + + + + :(£ + + +:|c + + + + :(! + :lc + + + + *:|c + + + :ic + + + :(::|e:|c

BSET DDRA, $FF BSET DDRP, $F0 BSET PORTP,$10 CLR PORTA CLI

;Make Port A all Outputs ;Make High Nibble of Port P all Outputs ;Tum Digit 1 on ;Tums all Segments off ;Clear Interrupt Masking Bit, Interrupts enabled

BSET DDRP ,$03 BSET PWCLK,$00 BSET PWPOL,$02 BSET PORTP,$01

+ + * + * * * * + + + + + + + + * * **********,|jS|(,|5,^5|tS^,|5,|j,|5^,^

******* Initialize the PWM Control ********* * + + + + * + + + + + + + + + + + + * * * * * * *****5|5, |J:J. 5^,|,,^,,t,|j,^,|,

PWMini:BCLR PORTP,$02 ;Clear Bit for Pin PWM-Channel 1 ;Make Pin PPO Output Pin PPl Output for SPWM ;Select clock A divider ratio of 1; P-Clock = 8MHz ;Select A clock and Positive Polarity for Channel 1 ;Tum H-Bridge on

BSET PWPER1,$FF ;Select $FF for Period of Channel 1, fs = 31.25 kHz BSET PWEN, $02 ;Enable PWM for Channel 1 MOVB #128,PWDTYl;Select 50% Duty Cycle for Channel 1 MOVW #0000, Deg ;Initialize the Degree count to zero

Figure 3.9 Initialization of the PWM control and the 7-segment display.

Figure 3.9 initializes the PWM control, with the channel 1 enabled for PWM. The

clock is set to 8 MHz, and the signal to H-bridge is turned ON. The duty cycle is

chosen as 50%.

Main: BRCLR PORTT,$02, Main MOVW Deg,Phase LDD Phase LDX Out4Hex JSR 0,X LDAB#$OD LDX PutChar JSR 0,X

;Loop until Signal on Bit 1 on Port T is High ;Copy Contents of Deg to Phase ;Load Phase Count into Accu D ;Load X with Vector to Out4Hex callable Routine ;Call Out4Hex Subroutine ;CR ;Load X with Vector to PutChar callable Routine ;Print CR Character

+******+*++++++++++*++++++****++*****++++++*******++++++++++++++++++++++ * The number on the followmg line corresponds to the phase difference, * which is calculated from a Java program, which prompts the user to

decide the power required. The Java program calculates the corresponding phase difference and attaches the number to this file. The number displayed on the screen is the hex equivalent of the phase difference

JSR CT; ******Also to be implemented - a feedback control to constantly monitor the power

Aux: BRSET PORTT,$02, Aux ;Loop until Signal on Bit 1 on Port T is Low BRA Main ; Wait for Intermpts

Figure 3.10. The main program.

20

Page 29: I n' .3»3ti;w-»-«

• v ^ l "rn" \--iriiM';'iM.n'^Tii-i'^Tii'iifiiir.fnhffinfffi;r" -"""^u r...:y.j~«.-^.-,-'. ,^ .-^-^

Figure 3.10 forms the main part of the program, deciding the phase locking

system. The statement "JSR CT" is the key to the phase at which the generated

waveform needs to be fed into the utility. This command jumps to the subroutine "CT",

which takes in the number from the Java program. This number, generated by the Java

program, is fed into the micro-controUer using the RS232C port. The Java program is

discussed later in this chapter.

+ * + + + + + + + + + + + + + + + + + * + :f!:(.:|c**:(c + :)c + + + + + + + c + + + + + + + + + ** + + + * + + + + + + + + + + + + * + + + +

* Timer Output 7 Compare Intermpt Service Routine Code starts here * * + + + + + + + + + + + + + + + + *:(!:|c + + *:(::|e + + :)c:|c:)c + :)::(::|c:|e*:|c + + *:lc* + + + + + + + + + + + + + + + + + + + + + + + + + + +

Timer7:

Cont:

LDD ADDD CPD BNE LDD STD JSR STAB

Deg #002 #360 Cont #$0000 Deg Sine PWDTYl

MOVW #740 TC7

BSET TFLG1,$80 RTI

;Load the Degree Count into Double Accumulator ;Add 2 degrees to the Count ;Compare Accu D with 360 deg ;Continue if not equal to 360 deg ;ClearAccuD ;Store Accu D to Memory Location Deg ;Calculate the Sine of the Angle ;Store Result in Duty Cycle Register 1 ;Load Channel 7 Output Compare Register ;forl0800HzonPT7 ;Clear Intermpt Flag ;Retum from Intermpt

Figure 3.11 Generation of the sine wave

This routine (Figure 3.11) generates the sine wave. However, the statement JSR

Sine jumps to a sub-routine below that calculates the actual value. The look-up table

stores the values of the sine of the angles from 0 to 90 degrees, corresponding to one

quarter of a fuU sine wave period. The values for the remaining three quadrants are

obtained by using trigonometric identities. These are defmed in Figure 3.13. The

display sub-routine is shown in Figure 3.12.

21

Page 30: I n' .3»3ti;w-»-«

•R'l At,\,Mn\\mmyimr< \u >mA'í'^} wiw" - " ^

* + + + * + + + + + + + *:|e + + :|c + + + + * * * : ) c + + + + :|c:|c + + + +

* Display Sub-Routine Code starts here DisPl:

Digit3:

Digit2:

Digitl:

Show:

LDAA PORTP BCLR PORTP,$F0 ANDA #$F0 LSRA CMPA #$10 BEQ Digitl CMPA #$20 BEQ Digia BSET PORTP,$40 LDD Deg-4b ANDA #$0F LDX #$0008 JSR ShiftR BRA Show BSET PORTP,$20 LDD Deg-4b ANDA #$00 ANDB #$F0 LDX #$0004 JSR ShiftR BRA Show BSET PORTP,$10 LDD Deg-4b ANDA #$00 ANDB #$0F

;Load Port P contents into Accu A ;Clear High Nibble of Port P ;Mask Out Higher Nibble ;Logical Shift Right Accu A, advance to next Digit ;Compare Accu A with $10 ;Branch to Digitl if equal ;Compare Accu A with $20 ;Branch to Digit2 if equal ;TumDigit3 on ;Load Accu D with Phase ;Mask out Digit 4, Accu B (Digit 1 & 2) will be shifted out ;Load X with decimal 08 (bits to shift) ;Jump to Right-Shift Sub-Routine ;Branch to Show Label ;TumDigit2 on ;Load Accu D with Phase ;Mask out Digit 4 & 3 ;Mask out Digit 1 ;Load X with decimal 04 (bits to shift) ;Jump to Right-Shift Sub-Routine ;Branch to Show Label ;Tum Digit 1 on ;Load Accu D with Phase ;Mask out Digit 4 & 3 ;Mask out Digit 2

LDX #SegCde;Load start of Code Lookup table into X LDAB B,X ;Load Character Code into Accu B, B,X=HC12 command STAB PORTA ;Put 7_seg Code to Port A RTS ;Retum from Display Subroutine

* Subroutine to shift Accu D (content of) X times * +++++++++++++++++++++++++++++******++++++++++++++++

ShiftR: LSRD DEX BNE RTS

SliiftR

Logical Shift Right Accu D Decrement X Branch back to ShiftR if X>0 Retum from ShiftR Subroutine

Figure 3.12. Display sub-routine.

22

Page 31: I n' .3»3ti;w-»-«

•H l •i' ^^^"- u'Uiuwwwmy^'fltv' u uW " BLÍ^"-,-'"•M ,..i-"T"r*~*' -iVrffl?"

* + * + + + + + + + :|e + * * + *:|e:|e :!«*:»: :j::|c:|e,|e,|e,|e:|,,,.,,e:,e + + + * + * + + **:,,:|e:„,|e,,e^,,e,,,^,|e^^e^^,,e,,e

* Subroutine to calculate the Sine of a Argument in * * Degrees, passed on in Accu D. Result is retumed in B * * X is used for Look-Up Táble addressing * * Y is used to mark negative values of the Sine Function * + * * * * * * * * * * * * * * * * * ^ „ e „ e * * * + + + + + * * * * * * „ e „ e * * * * * * * * * * * * : , e * * * * * * +

Sine: CPD #360 ;Compare Accu D with 360 degrees BLO LT360 ;Branch if lower than 360 SUBD #360 ;Subtract 360 degrees from Accu D BRA Sine ;Branch back to check for multiples of 3 60

* Assume Degrees < 180 (decimal) at first LT360: CPD #180 ;Compare AccuD with 180 degrees

BLS LS180 ;Branch if Lower or Same

* 180 < Degrees < 360 ; Sin(180+arg) = -Sin(180-arg) SUBD #180 ; Subtract 180 degrees from Accu D LDAA #180 ;LoadAccuAwithl80degrees SBA ;Subtract Accu B from Accu A TAB ;Transfer Accu A to Accu B LDY #0001 ;Load Y with 01 to indicate negative value

LS180: CMPB #90 ;Compare Accu B with 90 degrees BLS LS90 ;Branch if Lower or Same

90 < Degrees < 180; Sin(90+arg) = Sin(90-arg)

LS90:

End:

SUBB LDAA SBA TAB LDX LDAB SUBB LDAA MUL ADCA TAB CMPY BNE COMB

#90 #90

#Sin B,X #127 ADR2H

#127

#01 End

;Subtract 90 degrees from Accu B ;Load Ac|^ A with 90 degrees ;Subtract Accu B from Accu A ;Transfer Accu A to Accu B ;Load Start of Lookup Table into X ;Load Sine Code into Accu B ;Subtract Zero Level from Accu B ;Load AD-Result into Accu A ;Multiply the Cosine Value with the AD-ResuU ;Add Zero Level and Round Result to tlie MS_Byte ;Transfer Accu A to Accu B ;Check if 01 is in Y indicating negative value ;Go to End if no Inversion nescessary ;Invert Accu B ;Retum from Subroutine

Figure 3.13. Sub-routine to calculate the sine of an argument

Figure 3.13 is a sub-routine that calculates the sine of an argument passed from

the main routine, seen in Figure 3.10. Figure 3.14 allots memory for the variables.

* Place for Variables in Memory *

Deg: RMB 2 ;Reserve 2 Bytes of Memory for Degree count Phase: RMB 2 ;Reserve 2 Bytes of Memory for Phase in Degrees Figure 3.14 Allotment of memory for degree and phase count.

23

Page 32: I n' .3»3ti;w-»-«

J . L . . ^ U . i l J J J t ' ^ l - v . - I Æ i l ,

*+****+++++***************** **** Sine Lookup Table **** ** 000-090 deg, 1 deg inc** ** Zero Level is 127 dec** +++++++++++**********

Sin: FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB

$7F $81 $83 $86 $88 $8A $8C $8E $91 $93 $95 $97 $99 $9C $9E $A0 $A2 $A4 $A6 $A8 $AA $AD $AF $B1 $B3 $B5 $B7 $B9 $BB $BD $BF $C0 $C2 $C4 $C6 $C8 $CA $CB $CD $CF $D1 $D2 $D4 $D6 $D7 $D9

;00 deg

;05 deg

;10 deg

;15 deg

;20 deg

;25 deg

;30 deg

;35 deg

;40 deg

;45 deg

Figure 3.15. Look-up table for the sine flinction

24

Page 33: I n' .3»3ti;w-»-«

•'^,-L •', iHL'-'-"nr-^^ í f f j i M f i r t - ^ - - ^ a ~ i s 3 Zy^rSTn I K Ml I m I

FCB FCB FCB FCB FCB FCB FCB FCB FCB

$DA $DC $DD $DF $E0 $E2 $E3 $E4 $E6

;50 deg

FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB FCB

$DA $DC $DD $DF $E0 $E2 $E3 $E4 $E6 $E7 $E8 $EA $EB $EC $ED $EE $EF $F0 $F1 $F2 $F3 $F4 $F5 $F6 $F6 $F7 $F8 $F8 $F9 $FA $FA $FB $FB $FC $FC $FC $FD $FD $FD $FE $FE $FE $FE $FE $FE

;55 deg

;60 deg

;65 deg

;70 deg

;75 deg

;80 deg

;85 deg

;90 deg

Figure 3.15. (continued)

25

Page 34: I n' .3»3ti;w-»-«

-•'ffi^-iiPii'r-iti"irViTy-Miiffli "Tl i'i T l"n\mi,'mr^"rírf- •=^ ^•-í,.liKtJ^

*+++++++**+++++++******+++++*++

* Set iq) Symbol Table in Memory * +++++++++++********************

SegCde: FCB $3F ; FCB $06 ; FCB $5B ; FCB $4F ; FCB $66 ; FCB $6D FCB $7D FCB $07 FCB $7F FCB $6F FCB $77 FCB $7C FCB $39 FCB $5E FCB $79 FCB $71

$3F = Codefor0 $06 = Code for 1 $5B = Code for 2 $4F = Codefor3 $66 = Code for 4 $6D = Code for 5 $7D = Code for 6 $07 = Codefor7 $7F = Code for 8 ,$6F = Code for 9 ,$77 = CodeforA ,$7C = Code for B ,$39 = Code for C ,$5E = Code for D ,$79 = CodeforE ;$71 = CodeforF

Figure 3.16. Symbol table for hex to decimal conversion.

Figure 3.15 shows the Sine look-up table, while Figure 3.16 is the symbol table

for conversion of the hexadecimal numbers to decimal numbers. Figure 3.17 below

shows the data that will be captured from the Java program, using the RS232C port.

* Data from the Java program *

CT: MOVW #0137, Deg ; Phase difference of 60 degrees LDD Deg ; Load double accu D with degree count RTS ; Retum to subroutine.

Figure 3.17. Processing of the number received from the Java program.

As mentioned above, the number that was passed on to the micro controller

through the RS232C port was generated by the Java program shown below: The

foUowing figure is a documentation of the environment used, the problem defmition,

and the solution. The code is self-explanatory, with comments accompanying each

command or set of commands, explaining their function (Figure 3.18).

26

Page 35: I n' .3»3ti;w-»-«

•^<««He ^nw^ i.:-:iiiL'i',n^.^í.'^,^^±u^^^,^ji.jvm, iii i.iii i ^^-.^••^.f.^.-srrr^.

//Development Enviroimient: JBuilder 3.0 University version //WHAT:

Application that lets user choose from a variety of choices at a GUI (Graphical User Interface). Displays results

onto a text area.

II II II / / H O W : II II II II II II //API: II //NOTES: /*

Input: Program can be run desired number of times. User chooses desired base conversion through buttons. GUI design using buttons allows user to reset or to exit.

Output: The different results of the operations are ou^ut to a text area based upon what button has been cUcked.

Swing GUI is used here along with action listeners.

Self-explanatory GUI.

JAVA PROGRAM USED FOR THE INTERFACE DESIGN OF UTILITY - MEANT FOR SERIAL COMMUNICATION

WITO THE RS - 232C PORT.

PACKAGE : thesis CLASS : ta_extl FIRST WRITTEN ON : October 20, 1999 LAST MODIFIED ON: May 09, 2000 LAST MODIFIED BY: GURUPRAKASH RADHAKRISHNAN

Figure 3.18. Introduction to the program.

II package thesis;

// import required classes importjavax.swing.*; importjava.awt.*; in^ortjava.awt.event.*; importjava.text.DecimalFormat;

//import the package for serial communication importjava.io.*; importjava.util.*; importjavax.comm.*;

Figure 3.19. Importing the required classes into the package thesis.

Figure 3.19 shows all the classes imported to create the text area, as also the

packages to be imported for serial port communication. The package "javax.comm."

was released by Sun Microsystems, as a means to use the concept of Object Oriented

27

Page 36: I n' .3»3ti;w-»-«

-r—•w—^w •^-'^^^W^^-"^flF^- -- '

Programming (OOP), in order to achieve port communication. This package contains

inbuilt methods to be invoked, so as to avoid rewriting the entire code for the purpose.

However, the invoking of the method, as well as setting the class path correctly, is the

critical issues in this case. The class path was set in the options in the JBuilder

environment. Also, the MS DOS file "autoexec.bat" was modified to include the path in

a generic way, so that this package is imported, no matter what environment is used to

compile and run the program. Figures 3.20-3.22 contain the program written for the

purpose of user-interface. The comments accompanying them are self-explanatory.

However, it was decided that it would be more efficient to read in the frequency

of the utility and generating a sine wave at exactly that frequency, instead of an

assumed 60 Hertz. This would take into account the different geographic regions

(Europe and Asia at 50 Hz), as also the small variations in frequency due to noise. This

would be as generic a program as possible for utility interface anywhere in the world.

Hence the micro controller program was modified as foUows, using the Pulse

Accumulator Count function, present internally to the 68HC12. To achieve this, the

frequency of the utility is constantly measured by counting the clock cycles for a half

period, inside the pulse accumulator register. The entire program is similar to the one

discussed earlier in this chapter, except for the part where the PWM control is

initialized. That modified initialization of the PWM is documented in Figure 3.23.

28

Page 37: I n' .3»3ti;w-»-«

it i' '.1-11 iV.iv-.i hrty JVA 'H iiírtnwrrti u\ '^

II User defined class public class ta_extl extends JFrame implements ActionListener

// Defining variables for the power required, and the power factor double i_power, i_pf; intV=120,I=l ;

// declare a container that contains all GUI private Container c;

//Declare Panels to group GUI componenets together private JPanel textPanel, buttonPl;

// Declare an array of buttons private JButtonbutton[];

// Declare text area and scroller pubUc JTextArea outputArea = new JTextArea(18,30); pubUc JScroUPane scrollBar= new JScrollPane(outputArea);

//Declare String variables and an array pubUc String output = ""; pubUc StringbuttonName[] = {"Continue". "SerialPort", "Reset", "Exit"}; //For crossplatform look and feel static String hifName = new String("com.sunjava.swing.plaf.motif.MotifLookAndFeel"); static String InfName = new String ("javax.swing.plaf.metal.MetalLookAndFeel"); static String UifName = new String ("com.sun.java.swmg.plaf.windows.WindowsLookAndFeer');

//Variables for serial communication protected static Enumeration portList; protected static CommPortldentifier portJd; protected static SerialPort serialPort; protected static OutputStream oulputstream;

protected static String s_writeString; II //Constructor that creates the class and is used to initiaUze the requU-ed GUI

pubUc ta_extl()

//This try and catch block is used to check if the cross platform look and feel canbe loaded try

{ UIManager.setLookAndFeel(UifName);

} catch (Exception exc)

System.err.println("Could not load LookAndFeel:" + UiíName);

}

//Assign conten^ane m which aU GUI components wiU be placed c = getContentPaneQ;

Figure 3.20. The heart of the Graphical User Interface.

29

Page 38: I n' .3»3ti;w-»-«

i»kL^.i^llUJJL,.JIffV^.il.f•^X^JJH^,JJP•ILIIL JPW ..JUJ^ ='»'5'"^^^

// caU method to build up GUI buildGUIO;

//set the output area uneditable by the user outputAxea.setEditable (false);

outputArea.setFont(new Font("Times New Roman", Font.ITALIC + Font.BOLD, 16)); ou^utArea.setText("\n\n\n\n\n\n\n WAITING FOR INPUT FROM USER" +

"\n\n\n" + Please hit the CONTINUE button\n

requirement");

//Show the GUI show();

}// end of constructor for class ta extl

to input your power

II //Method to setup GUI called from constuctor

pubUc void buUdGUIO {

// Calls methods to set up the text area and the button panels setTextAreaO; setButtonsO;

>//endofbuildGUI

Figure 3.20. (continued).

II //Method to setup buttons and button panel caUed from constuctor

pubUc void setButtonsO {

//AUocate memory to the array of buttons button = new JButton[buttonName.length]; //Declare panels buttonPl = new JPanel(); //Set the layout for button panel as a grid layout buttonP 1. setLayout(new GridLayout( 1,3));

//initialize the buttons for(inti=0:i<=3;i++)

{ // Assign text to be written on the buttons button[i] = new JButton(buttonName[i]); //add action Usteners button[i] .addActionListener(this); // add buttons to respective panel buttonP 1 .add(button[i]);

}//endofforloop

// Add button panels to the container c. add(buttonP 1, BorderLayout. SOUTH); setSize(600,425);

} // end of set buttons

Figure 3.21. Setting up of buttons for making it user-friendly.

30

Page 39: I n' .3»3ti;w-»-«

"iV'"'-' iyr'^i^'i^^HM-mV^'-*^'^^'--'«*-'*-"'"^~ •*""•' r-^-Tmn-n--

II //Method to setup textarea and text panel called from constuctor public void setTextAreaO

{ //Assign a new panel textPanel = new JPanel();

textPanel.add(scrolIBar); textPanel. setBackgroimd(Color.red);

//Add panel to container c.add(textPanel,BorderLayout.CENTER);

} // end of settextArea II // Method to write individual conversions onto the text area, takes an mteger // argument that specifîes base to be converted to. public void mit ()

i String power;

// Getting the power requirement(input) from the user power = JOptionPane.showInputDialog("Enter the power reqd:");

// Transferring the input to the defmed integer variable i_power i_power = Double.parseDouble(power);

// Calculating the corresponding power factor i_pf = i_power/(V*I);

// CaUing method disp_change, which updates the information on the screen disp_change();

}

// Method which displays the data, based on the most recent calculations public void disp_change()

if (ijpower > 120 I i_power < 0)

outputArea.setFont(new Font("Ariel", Font.ITALIC + Font.BOLD, 18)); outputArea.setText("\n\n\n\n\n\n\tInvaUd entry!!! \n\n Power entered must be between 0 and

120 Watts\n\n\n\n Please hit the CONTINUE button to continue");

} else

outputArea.setFont(new Font("Ariel", Font.ITALIC + FontBOLD, 16)); DecimalFormatprecisionTwo = new DecimalFormat("0.00");

Figure 3.22. Details of the project.

31

Page 40: I n' .3»3ti;w-»-«

iM líii iirjnMm'i m-iViT'Ti"iiiiii.TTrr ™—^

The required power factor is :"+ " " +

precisionTwo .format(

if((((int)(Math.acos(i_pf)*180/Math.PI)^75)/100) >= 1) {

oulputArea.setText("Vn\n\n\n\n\n\n precisionTwo .foTmat(i_pf)+"\n"+

The correspondmg angle for phase-lock is :"+ Math.acos(i_pf)* 180/Math.PI)-^"\n"^

The number to be transferred to the port is :"+ "" + 0+((mt)(Math.acos(i_pí)* 180/Math.PI)+75)+" \n\n\n^n Please hit the CONTINUE button to continue");

else /

The required power factor is :"+ "" +

precisionTwo. format(

outputArea. setText("\n\n\n\n\n\n\n precisionTwo .format(i_pf)+"\n"+

The corresponding angle for phase-lock is :"+ Math.acos(i_pf)* 180/Math.PI)+"\n"+ " The number to be transferred to the port is :"+ " " + 0^0^((mt)(Math.acos(i_pf)*180/Math.PI)-75)-" \n\n\n\n Please hit the CONTINUE button to continue"):

} }

//Show the GUI showO;

}// end of method disp_change

//Method to perfbrm SerialCommunication, and transfer calculated data to the COM port pubUc void SerialCommunication (int i_sendData) {

//Convert data to be sent in string format swriteString = Integer.toString (i_sendData);

//Get Ust of the avaUable ports portList = CommPortldentifier.getPortldentifiers 0;

while (portList.hasMoreElements 0 ) {

portld = ( CommPortldentifier) portListnextElementO; if (portld.getPortType 0 = CommPortldentifier.PORTSERIAL ) {

if (portld.getName Oequals ("COMl")) {

/ i

serialPort = ( SerialPort) portld.open ("UtiUt\ App". 3000 ): } catch (PortlnUseException e) {

System.out.printIn ("Choose another COM port, this port is in use/vaUd.");

} Figure 3.22. (continued).

32

Page 41: I n' .3»3ti;w-»-«

' • '^^'-^'• '4i iJ llilMIII LIHm-Uwmi -^i L^jm^

try

//write the output data

{ //Get the handle to the output stream, which wUl be used to

outputstream = serialPort.getOu^utStream 0; } catch (lOException e) { System.out.println ("I/O error: COM port does not support

sending data");

tiy

/*Set the initialization parameters for the COM port. Parameters are: Baudrate = 9600. Databits = 8, Stopbits = 1, Paritybits = none

*/

seriaU^ort.setSeriaPortParams ( 9600, SeriaPort.DATABITS_8, SeriaU^ort.STOPBITS_l, SeriaU>ort.PARITY_NONE);

} catch (UnsupportedCommOperationException e )

{ System.out.println ("IiútiaUzation is fa ed: COMport parameters are not supported");

} try

//Write the output stream outputstream.write ( s_writeString.getBytes ());

catch (lOException e) {

System.out.println ("I/O error: data can'tbe send"); }

II .11 public void actionPerformed(ActionEvent e)

// if binary button is cUcked call method to compute & write binary conversion if (e.getActionCommand().equals("Continue"))

initO; }

Figure 3.22. (continued).

33

= ^ t a

Page 42: I n' .3»3ti;w-»-«

•^BBP^H 'iJvi,..m,.,umAmm:JÁmi^^E!ssmai^\\^i»>^v,.í.''^isiii:^±s.i-' - •^•^

}

//If serial button is cUcked serial conununication is performed if (e.getA.ctionCommand0.equaIs("Serial Port"))

//Call the SerialCommunication Method with the specified parameters SerialCommunication (5) ;

// if Reset button is clicked clear screen if (e.getActionCommand().equals("Reset"))

outputArea.setFont(new Font("Ariel", FontlTALIC + Font.BOLD, 16)); outputArea.setText( "\n\n\n\n\n\n TO CHANGE THE POWER

REQUIREMENT" + "\n\n\n Please hit the CONTINUE button \n"+ "\n\n\n\n\n\n\n The required power factor is :\n"+

The corresponding angle for phase-lock is :\n"+ " The number to be transferred to the port is :\n\n");

show(); }

// if Exit button is clicked exit the system if (e.getActionCommand(). equals("Exit"))

{ System.exit(0);

} }// end of action performed

//Main method public static void main(String[ ] args)

/ i

// declare variables and call method to display a baimer String Name = "GURUPRAKASH RADHAKRISHNAN"; String Subject = "THESIS"; banner(Name, Subject); // Instantiate an object of class taextl ta_extl app = new ta_extl();

}// end of main //

// Method to output baimer onto console public static void banner(String Name,String Subject) {

Svstem out println("**********************\n*\n*\n*")' System.out.printhi("*\tTHESIS PROJECT : UTILITY INTCRFACE DESIGN"); System.out.printhi("*\t "); System.out.printhi("*\n*\n*"); System.out.printhi("*\t ADVISOR : DR.MICHAEL GIESSELMANN \n*\n*"); System.out.printhi("*\t PROGRAM BY : "+ Name +" \n*\n*"); System.out.printhi("*\t SUBJECT : " + Subject +" \n*\n*"); Svstem outDrintf ***************************************************

} // end of method banner } ^ ^ H e * * * * * * * * * * * * * * * * 4 : * * * * * * * * * * * * * * * * * * * * * * * 4 : * * * * * * * * * * * * * * * * * * * * * * * ! | c * * * *

Figure3.22. (continued).

34

Page 43: I n' .3»3ti;w-»-«

"^^-^-miMf.B/JW.^fl'1 I I I IIIIIIIIIIIIIIIIIH III ^^ J^i ^

******* UiitiaUze the PWM Control *********

PWMmi:BCLR PORTP,$02 BSET DDRP ,$03 BSET PWCLK,$00 BSET PWPOL,$02 BSET PORTP,$01 BSETPWPER1,$FF BSET PWEN, $02 MOVB #128,PWDTY1 MOVW #0000, Deg

Main: BRCLR PORTT,$02, Mam JSR DISPLAY MOVW Deg,Phase

Con:

WaitL:

LDD CPD BNE CLR

Deg #0000 Con Deg

MOVB PORTB,Deg+l LDD LDD LDX JSR

#$0000 Phase Out4Hex 0,X

LDAB#$OD LDX JSR

PutChar o,x

BRSET PORTT,$02, WaitL LDD PACNT MOVW #$0000,PACNT LDY #14222 EMUL LDX EDIV INY STY JSR BRA

#10000

$09FE DISPLAY Main

;Clear Bit for Pin PWM-Channel 1 ;Make Pm PPO Output Pm PPl Output for SPWM ;Select clock A divider ratio of 1; P-Clock = 8MHz ;Select A clock and Positive Polarity for Channel 1 ;Tum H-Bridge on ;Select $FF for Period of Channel 1. fs = 31.25 kHz ;Enable PWM for Channel 1 ;Select 50% Dut>- Cycle for Channel 1 ;IiiitiaUze the Degree count to zero

;Loop until Signal on Bit 1 on Port T is High ;Call Display Scan Subroutine ;Copy Contents of Deg to Phase

Load the Degree Count into Double Accumulator Compare Accu D with 360 deg Continue if not equal to 360 deg Clear High Byte of Deg Count Move Dip Switch Setting to Deg low Byte Clear Accu D Load Phase Count into Accu D Load X with Vector to Out4Hex callable Routine Call Out4Hex Subroutine CR Load X with Vector to PutChar callable Routine Print CR Character Loop until Signal on Bit 1 on Port T is Low Load PAC Count mto Accu D Clear Pulse Accumulator Load X with 14222 dec (D) X (Y) => Y : D Load X with 10000 dec (Y : D) / (X) => Y. Remamder => D

;Store Result to Display Location ;CaU Display Scan Subroutine ; Wait for Interrupts

Figure 3.23. Modified version of the code, using the PAC feature.

The results achieved, followed by the conclusions will be dealt with in the

foUowing chapters.

35

Page 44: I n' .3»3ti;w-»-«

nap " ' ' • / - ' • • i ^ I tiVirfti"ynr I-1 •6^'^'^'' ,.,^'J^^A.AS^

CHAPTERIV

OTHER ELEMENTS USED IN THE CIRCUIT

The schematic of the main circuit is as shown below in Figure 4.1,

Figure 4.1. Main circuit.

Figure 4.1 is the schematic representation of the entire circuit used. The individual

components of the circuit have been discussed in Chapter II, and in Chapter I in the

form of a block diagram.The pin connections are the ones that go into the HC12

daughter board, which is depicted in Chapter V, alongside the screen captures.

One of the main circuit elements not discussed is the zero cross-over detector.

This element helps in the phase locking of the synthesized waveform with the utility.

As discussed in the last chapter, the sine wave is generated using the timer interrupts in

36

Page 45: I n' .3»3ti;w-»-«

mmmmm^i •huinpimiiMxM' i r'.ii n-^fAHí'!in ?cir^^^^^^='^^''^«i'^^^»'^'^^^

the HC12 program. The generated waveform is to be phase-locked with the utility. For

this purpose, we use a zero cross-over detector, which would detect the positive zero-

crossing of the utility, and feed the generated power at that point. This would make sure

that the feeding of the power does not take place abruptly. Figure 4.2 shows a Simulink

simlulation of the zero crossing over.

°3 Sine Wave Zero cross-over

Multiplexer Scope

Zero reference

Figure 4.2. Simulink representation of the zero-cross over detector.

The following figure gives the scope reading of the simulated waveform. This

wiU be seen in the chapter in which the measurements will be compared with the

theoretical and simulated expectations (Figure 4.3).

37

Page 46: I n' .3»3ti;w-»-«

-' U l ' l n a B B B u iW^TT -^i-i'i'T^^-i-ri-lr-" "

Figure 4.3. The zero crossover detection, along with the sine wave, and zero reference.

National Semiconductor's LM 339 is used for the purpose. LM 339 basicaily

comprises a set of four comparators, designed to operate over a wide range of voltages.

The main features are:

• High precision,

• Low drift over temperatures,

• Low power drain.

One of the applications of this chip is that of a comparator. The schematic and the

simulated results for the inverting and non-inverting comparators are shown in the

follov^ng figures (Figures 4.4-4.5).

38

Page 47: I n' .3»3ti;w-»-«

i uL_ snmmBOí LIIHIf.^JJJff-^i

^•ew.S«»«cheMic< -1 tMDauMrt n h n l feMtMí i

h t*' l'S t"-^ l i ' - V * ' i r * 2i-'-3': i-.'V. ; 1 » * S.J:ii=í JifMfctr a^t; 5; X

iai

*1B]^ • .|sjc<N!q.| ^ iojs j |ôi; r lí—ÍÉjgMJI^ 2J > i ^í Ití I »Jafv)r?/er*« CfviûêraîGf y * : H<«!w?aã

S.

'^'íril

1VE<5

nl -VA-

< r?3

I L*132a > - ^ ^

lrTrBrSir;a Camcj rs i iM Í ^ - S r te íerEE

Om'I 'ri _•_

'Jia 1-

^ R5

1g

Ví=T2

Cas:

Figure 4.4. Schematic of inverting and non-inverting comparators

W>tMSmFw*t. ICMnM«l.«Ml

IJî-'^ í" * • ' - ^ ' ' i - ' '«"- •a:"**^ t *

Mi^#J Ultelej SEMSJ MM^m E i ^ i ^ ^^;íJiilMí±lM^id ^

iaí . 'TJ-t

5 t L » ;

- uí î r tn Î . W T

5 , » T

• Í - + r - — - i f t es i ) -!íBnU

L sacit

Figure 4.5. Simulated results of the schematic shown in Figure 4.4.

39

Page 48: I n' .3»3ti;w-»-«

B.^maíáajuflmwwtimftv.^T'r.;i vjj>u.i"' '!m\-ÅmiiLUjmiiÆmuL.^n-^ ^^.

One major application of the LM339, which is of use in case of the current project,

is that of a zero crossover detector. This compares the input from the utility with a

reference zero voltage. The output is a square wave, with the signal remaining high (5

Volts) when the sine wave is in the first two quadrants (has a positive value), and low

(0 Volts) when the sine wave is negative. This enables efficient feeding back of power

to the utility. The circuit used for this purpose is depicted below in Figure 4.6.

AC120* 120V.60HZ l .SV.GOOmA o - ™1

AC120.

« t5HC12

<HC12PT1

«GndHC12

Figure 4.6. Circuit for the zero-crossover detector.

As discussed in Chapter III, the HC12 program was written so that the phase shift

takes place slow enough for it to receive a signal from the zero crossover detector to

phase lock it with the utility. The output of the zero crossover detector is discussed in

Chapter VI, along with the measurements.

40

.. :3m

Page 49: I n' .3»3ti;w-»-«

innriiiBnrnrnir — ^ '

CHAPTERV

SCREEN CAPTURES AND THE EXPERIMENTAL SET-UP

This chapter depicts the experimental set-up and the screen captures of the Ja\ a

application, created to enable a user-fiiendly power monitoring system. Figure 5.1

shows the environment, Boriand's JBuiider 3.0, in which the program was executed

j> JBuildei

t ^ l i w i i ' 1 ' 1 I I i I i i I i Piocets to Rirv'Debiø ^.extl.jaM

mLWH C:USuMlf3V«yp(fl|erHNtett\tk « « 1 lAva

! ! • •

|7 \^\gí - J l test pi

. ^ t^*Ht1 .Í«V«

. ^ loíthtml

- •Jn_e>«1 ^ JFfâme

»P, ActnriLstenei A act mPertomwdlActionEvent A bemeffStrng. Stmgl

* buldGUI A di<p_change(]

* r i t n «1 m«r(StnngO) 4ki SenaConvnmcatiorimt)

4Ê se<eutton$0 A tetTextAíeaO

« la.exlin • button

• buttonName • buttonPI

• c * 1

' LP» .» LPOwer • kifNwne

.1 • U

pdckage thesis;

î i / / i»port cequired claases i ivort javax.svlng.*; i ivort java.awc.*; uiiort ]ava.awt.event.»; mport ^ava.text.Deciaalí°oE>at;

•'•lEport thf package for serial communication u ^ r t ^ava.io.*; ii«M)rt java.ut l l .*; isport ^avax.cou.*;

/ / Ussr defined class p A l i c c l a n ca_extl exte ds Jrcame iJvlewBt* iccionListenec (

/ / Defimng variabies £or the power retjuiced, and the pouer factor dotrtile Ijpovec, i j ) I ; imt V » 120, I - 1 ;

—3

J

l i

/ / declare a container that contams aJ.1 WJl private Containec c;

//reciare ?ai.e-s :o JI.ÛUÍ' J-Cl componenets together private J?anel cexcPanel, buttonfl;

/ / Declare an array o£ buttona I

.31 Proiecl I j Opened | Ji 0<i*ctoiy | S««ce | Doe < I&110

Figure 5.1 Borland's JBuilder 3.0

Figure 5.2 shows the Java console window that pops up even as a program runs

This was also programmed to display the details of the project, instead of the blank

screen it normaily displays.

41

Page 50: I n' .3»3ti;w-»-«

"-•• r"-', iiSftvi v J I M - ' i I iV IT liii iWiHi-Vr iftnril Wl ni II tfl '

^^ -d Í::II Ifel sj gfg AJ

Figure 5.2. Java console window.

The following figure is the application that comes up on the screen after the

console window. This application is created in the form of a text area, which has been

created to make things as simple as possible for the user. Figure 5.3 is the first step in

the input needed fi"om the user.

42

Page 51: I n' .3»3ti;w-»-«

W M< I h JMíi.iMÍSSSSirW-;^-,: »• „ t / i ;-.-i3: :sgnMW«iHiM'<i kiwf^'"tii"-'Tr-TTíwrníasea^

Figure 5.3. Application prompting user input.

The next two fígures represent a situation where the user does not have an idea

of the power that he or she may be handling. The program prompts the user, giving him

or her the message, shown in Figure 5.5. Figure 5.4 below shows a sample invalid user

input.

43

Page 52: I n' .3»3ti;w-»-«

if rfnrgr-—--

ConUmw i SerlalPort

Figure 5.4. Sample invalid user input.

44

Page 53: I n' .3»3ti;w-»-«

M r n í i iMTlTFtfli rgiTfr —rmrTgnM nrr-

tnvattd entrylil

PowwentondmustbebøtW9enOand120Watís

Pfease hlt the CONTINUE t)utton to conOnue

ConlinMB 1 SMWPWt j| ItaMt Eidl

Figure 5.5. Program giving the options to the user

The following is a real example, chosen for a power of 60 Watts, which wouid

mean a power factor of 0.5 (Figures 5.6 and 5.7). The program carries out the

calculations, including that of the 4-digit number that can be read by the HC12 program

for the phase lock.

45

Page 54: I n' .3»3ti;w-»-«

"•Mwm.aRÆ.'F • « ;mnWtim vlMM.:,gi'-c- "TT , ^ ^ ^ . ^ - ^ ,

Figure 5.6. The example discussed above for 0.5 power factor.

46

Page 55: I n' .3»3ti;w-»-«

K7KE.!:.::— ^^:_: .\-' •••• J ? M C . Í _ ifitH^i hrt r •TT'^ymlTf^^

Condnue SwWP t | RBMI Eidi

Figure 5.7. Calculated results being displayed for the user's convenience

The last figure in this series depicts the possibility where the user makes a

mistake, and wants to make a change in his or her selection. All that needs to be done is

hit the "Reset" button. Consequently the screen that pops up is shown in Figure 5 8

47

Page 56: I n' .3»3ti;w-»-«

-- iiíFiixMyiii I i i i i i w — • — • . ^— -..J.-r.m . a '."h-- 't -Ui ' .a Z^^^SUBJl

ConUnuB SarMPart

Figure 5.8. The "Reset" option.

The next section of this chapter concentrates on the schematic of the main circuit,

as well as some pictures of the experimental set-up (Figures 5.9-5.14).

48

Page 57: I n' .3»3ti;w-»-«

Figure 5.9. Schematic of the daughter board.

cm «C>URT » a n iTit.*M iM«wk >«»«BMU

C ^ »-=»%(»• •• i »• ^ ^ ^ d

11 o '

: r-:rtí r '-' • o ue W -v>Ca

pg^o IJ

m 0—S ** . p-

s=8:

2 - 0 TM .•iQ-^^p Cl

. 1 » -

1» at

*ijo.^ i</ja^

"=^—r • • L - ^ í -

v n

, > ^ - ^

tí—)• i «

.L2_

Ci OT^M II

> r. 0 Ai.aaw

íeww

m t n w w t i «••»«*»• ..^»> m n

-1^3=—r-

Figure 5.10. The schematic of the main circuit.

49

Page 58: I n' .3»3ti;w-»-«

"» » " ' " ^ ^ ^ ^ I B - - J : \ A i--.'^.^^iíÁJåm\\i\m Mtird i»íT

Figure 5.11. Main circuit.

Figure 5.12. The zero-cross over detector and the daughter board

50

Page 59: I n' .3»3ti;w-»-«

l:VH;MiViiW<UíiiH"iimir t

Figure 5 13 The Tektronix Oscilloscope being used

Figure 5.14. The entire experimental set-up

51

Page 60: I n' .3»3ti;w-»-«

—._ . .. >.!se^m^. i i B ^ ^ ^ — ^ ^ — ^ ^ i ^ — ^ — • i i i i i i i i i ' i i i iiiiiitiiiib|i|i) iiifiiiiiiiiinwmínMii/'- iin°^nf—-nn^—-"•"-^-' -—-

CHAPTER VI

MEASUREMENTS AND COMPARISON OF RESULTS

This chapter deals with the measurements taken using the varíous scopes

available for the purpose. Most of the measurements were done on the Tektronix TLS

216 scope, which is a digital scope. However, for measurements over 5 Volts, the

Tektronix PS 222 was used. To capture the signals of the waveforms to be measured, a

special executable program called CAT.exe was used. To screen capture the

waveforms, an environment using a Visual Basic program, PS222.exe, wrítten by Dr.

Giesselmann was used. (Program available in the Appendix.) The measurements tally

with the expected results, as can be seen below:

Figure 6.1 features a capture of the waveforms corresponding to the fírst

program discussed in Chapter III, with an abrupt phase-lock. The screen capture was

done for 60 degrees phase shift to the utility, corresponding to half power. Figure 6.2

features a capture of the waveforms corresponding to the modified program, which uses

the pulse accumulator count of the micro controller to measure the frequency of the

utility, and generate a waveform at the same frequency. This capture was done at a zero

phase shift to the utility, corresponding to zero power.

52

Page 61: I n' .3»3ti;w-»-«

Mw^m^'^mm^t . " " ' W M M I ^ ._lL-il l' a iL v'J *Sf!MMaiiswe-fe.''.--:T»r-'---»^« •-'-:'

Tek Run: 50.0kS/s Average [ T

I • i ' T ' J 1 I t t I I I I I I 1 I I I 1

C3 Freq 127.305 Hz Low signal amplitude

C2 Freq 60.024 Hz Unstable

hlstogram

Cl Freq 59.978 Hz

n - r j "i: V [MÍGE4 :4 j loomv GRP3[3 :3 ] 1.00

Figure 6.1. Screen capture at zero phase shift.

14Sep 2000 17:20:07

In the above figure, output C1 corresponds to the output of the zero crossover

detector. This output is a logic high when the utility voltage is positive, and low when

the utility voltage is negative. Thus this also becomes a measure of the fi^equency, used

to synthesize the sine wave. Output C2 corresponds to the output current, which goes

into the load. For experimental purposes, a 60-Watt incandescent bulb was used, which

acts as a resistive load. Output C4 corresponds to the output current, before stepping up

the voltage to the required 120 Volts. This is essential, as a variation in the synthesized

voltage and the utility voltage would result in modifying the reactive power. However,

our concem is to control the phase, which controls the real power. The scales have been

53

Page 62: I n' .3»3ti;w-»-«

••i, **«tî.tl .--•: •uro.-.«ri:~«9£5fi—Jé-BSHS*-?! J-JÍSÍ

so chosen that the waveforms C2 and C4 can overlap, for the sake of comparison. The

slight phase difference in these two is due to the leakage reactance of the transformer

used. Output C3 corresponds to the output of the H-bridge.

Tek Run: SO.OkS/s Average [ - T ]

T . A .

i

I I I I I I ! I I I 1

á R M l 1 : r i 1.6ÔV cWfíirJ :2 ]Sd.ÔmvM4.Ûdms Edge G R P 3 [ 3 : 3 ] l.OOV aEBfil[4 :4 ] lOOmV

Figure 6.2. Screen capture at a 60-degree phase shift.

C3 Freq 126.988 HZ Low signal amplitude

C2 Freq 60.071 HZ

Cl Freq 59.998 Hz

C4- C1 Pha 59.45 °

14Sep 2000 17:04:12

Figure 6.3 and Figure 6.4 show screen captures done using the environment

created using the Visual Basic file. The waveform in the environment gives an accurate

measure of the required waveform. Also, the same waveforms have been generated

using Microsoft Excel, and data of the waveforms fi"om the ".pm" files, as shown in

Figure 6.5 and Figure 6.6.

54

Page 63: I n' .3»3ti;w-»-«

•T-ftHiTBnWiiyiii

PS ???_Scope £ie QefLevd ^boU

mÁm\ Otf l l ' W i l DC ^ ChTI taAIVI |0C0e0F21DO

2By;Divi I otf M Crftf i 1 oc Ch zT] | 5i2 I gi 1 ] [ CUBVCHI

AHoTr.Mí I [RÔZÔ?n R f P g XY_0» I p l I Vwt NonMl

0 Voftase

O 1 Ayv

10 A/V O

100A/V O

Sloie.OII I f X 0_O» I I Ai*o_L¥l | rBgcLWo | |VolSLYc»| |r»cOtil_lio

Figure 6.3. Captured waveform of the synthesized sine wave.

PS 2P? Scope £le BeiLevd ^oU

SOV/MV Oíf C4ra 1 DC Chl:

TWJON OfF 1 C M 1 DC Cti 2: 512 Ch2 CURVCH2

AuioTr.Og I |RO_On| [ ] ] | PMI

Wofinal I I XY_Og j |W| [ V l t

0 Vt

O 1 A/V

10 A/V

100 A ^

O O

Stoie_OII [ rXI0_O« I Arito_L»i | \ncdíJÊo \ fVdSrYeil |Ti»eOKI_M

Figure 6.4. Captured waveform of the PWM signal.

55

Page 64: I n' .3»3ti;w-»-«

. . . . •tr'-.lM^.~K'.t^Jb^'fi

VBiliMiiim e(ttM QinanMd ww««orn

1M

100 *•

-100 -^

-150

r i M

Figure 6.5. Replica of Figure 6.3 done using Microsoft Excel

V v i t M M n of » » gøwaiM »aw*«arm

4.00E*01

)0OE*O1

ZOOE'OI

I 1 00E«O1

0 00E«O0 - ^ OOOE^W

-1 0OE*O1 -*fl

-2 OOE-'OI

-J0OE«O1 ••

3 00E.02: j i|

« ' ' r

V v V ^ j It

IMK4S

JW**s»

TMM

•JDE-c:

Figure 6.6. Replica of Figure 6.4 done using Microsoft Excel

56

Page 65: I n' .3»3ti;w-»-«

T-rtTrniTíriTiI I II i i i i i i i i imi i 11

CHAPTERVn

CONCLUSIONS

As anticipated, a sinusoidal waveform was generated using the pulse-width

modulation scheme. Sixty Watts of power was generated, and a synchronized utility

interface was achieved, thereby transferring power to the utility. A signal was generated

to control the phase manually instead of the voltage; so as to have a control over the

real power transferred. The Java program was used for user interface. Finally, the

generated power was fed into the grid for to achieve the goal of utility interface.

57

Page 66: I n' .3»3ti;w-»-«

rn'T rwriTiiiii I II iiiiiiiiiriinrr n rrTi~~ —

REFERENCES

[1] K.Oguchi, G.Maeda, N.Hoshi, T.Kubota, Ibaraki University, Hitachi, Japan,A New Maximum Photovoltaic Power Tracking Control Scheme based on Power Equilibrium at DC link, 1999 lEEE Industry Applications Conference, 34^ Annual Meeting, vol. 1, pp. 804-809.

[2] Mikihiko Matsui, Tatsuya Kitano, Tokyo Institute of Polytechnics, Kanagawa, Japan, DC Ripple Current Reduction on a Single-Phase PWM Voltage Source Rectifier, 1999 lEEE Industry Applications Conference, 34 ^ Annual Meeting, vol. l,pp. 810-817.

[3] http://www.tracetec.com

[4] Mohan, Ned, Tore M. Underland, and William P. Robbins, Power Electronics, Converters, Applications, and Design, John Wiley and Sons, Inc, New York, New York, 1989.

[5] http://www.mcu.motsps.com/documentation/hcl2/hcl2nn.html, Motorola Inc, "68HC12 Reference Manual".

[6] "Programming 68HC12", http://www.seattlerobotics.org/encoder/oct97/68hcl2.html, Encoder, News letter of Seattle Robotics Society.

[7] "68HC12 Timer Module," http://www.seattlerobotics.org/encoder/nov97/68hcl2.html, Encoder, News letter of Seattle Robotics Society.

58

Page 67: I n' .3»3ti;w-»-«

APPENDDC

Following is the Visual Basic 5.0 program to read the waveform from the 222PS scope, for the purpose of screen capture.

'**** Programto read 222PS Scope .WFM **** ***** andgenerate ASCII.PRN Files **** ***** VB5.0 VersionAugust-23-97 **** ***** (C)1996byDr.M. Giesselmann **** ***** EEDepartment,MS3102 **** ***** TEXAS TECH UNIVERSITY **** ***** LUBBOCK, TEXAS 79409 **** ***** Ph.: (806) 742-3462 **** ***** FAX: (806) 742-1281 ****

***** Defme Global Variables **** l * * * * * * * * * * * * * * * : ( c * : | c * : | c :(.:((* + :(. 5(c* + : ) c * * * * * * * * * * * * *

Option Explicit *A11 Variables must be declared before use GlobalDrive As String *Drive letter for .WFM file Global SelectedFileName As String 'File name with full path for .WFM file Global X_Curve(511) As Integer *Array for X Values of Scope Trace Global Y_Curve(511) As Integer *Array for Y Values of Scope Trace Global Elements As Integer 'Number of data points in curve (normally 512, 1024 for X-Y) Global Max As Integer *Maximum of curve values Global Min As Integer *Mimmum of curve values Global Avg As Single 'Average of curve values Global Lvl As Integer 'Zero level of Trace from Slide Control Global Channel As Integer 'lnput Source Channel 1 or 2 Global Couphng(2) As String 'Coupling of Channel 1 and 2, AC, DC, GND, OFF Global Curve_Header As String 'First part of file e.g. (Curv Chl:) Global Settings As String '10 Char String contaiidng Scope Settings Global ScopeMode As String '02 Char String holding Scope Operational Modes, x-t, x-y etc. Global Y_Ch_Sett(15) As String *Text Description of Y Volts_Div Setting Global Y_V_Div( 15) As Single 'Numerical Constant of Y Volts_Div Setting Global X_Ch_Sett(26) As String 'Text Description of X Time_Div Setting Global X_T_Div(26) As Single 'Numerical Constant of X Time_Div Setting 'lndex Definitions Global V_Div_Index_l As Integer *Index for V/DIV for Channel 1 Global V_Div_Index_2 As Integer *Index for V/DIV for Channel 2 Global X_Div_Index_l As Integer *Index for Time/DIV - High Char Global X_Div_Index_2 As Integer *Index for Time/DIV - Lov ^ Char 'Define constants for Error handling Global Const ERR_DISKNOTREADY = 71 Global Const ERR_DEVICEUNAVAILABLE = 68 'Define constants for Message box Global Const MB_RETRY_CANCEL = 5 'Retry and Cancel buttons Global Const MBEXCLAIM = 48 'Exclaimation Mark Global Const MB_STOP = 16 Global Const MB_OK_CANCEL = 1 Global Const BUTTON OK = 1

59

Page 68: I n' .3»3ti;w-»-«

W î f í n l î r^ r' • ' - ""

Global Const 'Colors Global Const Global Const Global Const Global Const Global Const Global Const Global Const Global Const

BUTTON_RETRY = 4

BLACK = &H0& RED = &HFF& GREEN = &HFFOO& YELLOW = &HFFFF& BLUE = &HFFOOOO MAGENTA = &HFFOOFF CYAN = &HFFFFOO WHITE = &HFFFFFF

Sub ClearSettingsDisplayO 'Clear Curve Array

Dim I As Integer ForI = 0To511

Y_Curve(I) = 0 Nextl

Elements = 0 *Reset Level frmMain.VScroUl.Value = 255 Lvl = 255 *Assume *'Voltage" Trace as Default

frmMain.Optionl(0).Value = True 'Clear Labels for Scope Settings

frmMain.Settingsl.Caption = frmMain.Settings2.Caption = frmMain. S ettings3. Caption = frmMain.Settings4.Caption = frmMain.Settings5.Caption = fimMain.Settingsô.Caption = fmiMain.Settings7.Caption = frmMain.Settings8.Caption = frmMain.Settings9.Caption = frmMain. S ettings 10. Caption = frmMain.Settingsl l.Caption = frmMain.Settingsl2.Caption = frmMain. Settings 13. Caption = frmMain.Settingsl4.Caption = frmMain. Settings 15. Caption = frmMain.Settingsl6.Caption = frmMain.Settingsl7.Caption = frmMain. Settings 18. Caption = frmMain. S ettings 19. Caption = frmMain.Settings20.Caption = frmMain. S ettings21. Caption = frmMain.Settings22.Caption = frmMain.Settings23.Caption = frmMain.Settings24.Caption = fnnMain.Settings25.Caption = fnnMain.Settings26.Caption = frmMain.Settings27.Caption =

End Sub

60

Page 69: I n' .3»3ti;w-»-«

ii' Tinia íri mTiTrTrnmr " '' -

'Function to convert a Hex number (HEX_Char As String) to *a binary string with **Bits** bits. The binary String is 'formatted to have "Bits" characters including leading zeros 'Date: June-21-1996 Function Conv_2_Bin(HEX_Char As Stiing, Bits As Integer) As Stiing *Declare local Variables used in Routine

Dim I As Integer, Num As Single Dim BmSti- As Stiing ReDim Number(Bits) As String

'Check if enough Bits are declared to convert HEX_Char Conv_2_Bin="" If 4 * Len(HEX_Char) > Bits Then Exit Function

*Initialize Variables Num = Val(**&H" + HEX_Char)

*Start Conversion For I = 1 To Bits

Number(I) = Hex$(Num Mod 2) Num = Int(Num / 2)

Next I *Construct Binarv String by reversing Order

BinStr=**" ForI = BitsTo 1 Step-1

BinSti = BinSti + Number(I) Nextl Conv_2_Bin = BinStr

End Function

'Sub_Routine to Decode Scope Settings 'Date: July-07-1996 *<Settings> is a Global 10 Char String containing Scope Settings *Bit and Chr Count is from left to right; Bit 1 = MSB *Char#l stands for 16 different Y Settings for Channel 1 *Char#2 stands for 16 different VDiv Settings for Channel 1 'Char#3 stands for 16 different Y Settings for Channel 2 *Char#4 stands for 16 different V_Div Settings for Channel 2 Sub DecodeSettingsO *Declare local Variables used in Routine DimSett_l_HEX As String 'Char#l of Settíngs Stiing in HEX Dim Sett_l_Bin As String 'Char^l of Settings String in Binary DimSett_3_HEX As Stiing 'Chan^3 of Settings Stiing in HEX Dim Sett_3_Bin As String 'Char#3 of Settings String in Binary DimSett_5_HEX As Stting 'Char#5 of Settings Stiing in HEX Dim Sett_5_Bin As String 'Chai^5 of Settings String in Binary Dim Sett_7_HEX As Stiing *Char#7 of Settings Stiing in HEX DimSett_7_Bin As Stiing *Char#7 of Settings Stiing in Binary Dim Sett_8_HEX As Stiing 'Char#8 of Settings Stiing in HEX Dim Sett_8_Bin As Stiing *Char#8 of Settings Stiing in Binary Dim Sett_9_HEX As Stiing 'Char#9 of Settings Stiing in HEX DimSett_9_Bin As Stting 'Char#9 of Settings Stiing in Binary Dim Sett_10_HEX As Stiing 'Char#10 of Settings Stiing in HEX Dim Sett_10_Bin As Stiing *Char#10 of Settings Stiing in Binar>' Dim Byte_4_HEX As Stiing 'Byte#4 of Settings Stiing in HEX Dim Byte_4_Bin As String *Byte#4 of Settings Stiing in Binary 'Calculate Index Numbers for Setting Sûings

61

Page 70: I n' .3»3ti;w-»-«

'The following Index Variables are declared Global V_Div_Index_l = Val("&H" + Mid$(Settings, 2, 1))' **** Ch.l V/DIV **** V_Div_Index_2 = Val("&H" + Mid$(Settíngs, 4, 1))' **** Ch.2 V/DIV **** X_Div_Index_l = Val("&H" + Mid$(Settings, 5,1))' **** Time / DIV High Char **** X_Div_Index_2 = Val("&H" + Mid$(Settings, 6,1))' **** Time /DIVLow Char ****

'Obtain Binary Representations for Settings Characters and Bytes Sett_l_HEX = Mid$(Settings, 1,1) 'Char#l of Settings Stiing in HEX Sett_l_Bin = Conv_2_Bin(Sett_l_HEX, 4) *Char#l of Settings Stting in Binarv Sett_3_HEX = Mid$(Settings, 3,1) *Char#3 of Settings String in HEX Sett_3_Bin = Conv_2_Bm(Sett_3_HEX, 4) *Char#3 of Settings Stting in Binary Sett_5_HEX = Mid$(Settings, 5,1) *Char#5 of Settings Stiing in HEX Sett_5_Bin = Conv_2_Bin(Sett_5_HEX, 4) *Char#5 of Settings String in Binary Sett_7_HEX = Mid$(Settings, 7, 1) 'Char#7 of Settings Stting in HEX Sett_7_Bin = Conv_2_Bm(Sett_7_HEX, 4) 'Char#7 of Settings String in Binary Sett_8_HEX = Mid$(Settings, 8, 1) 'Char#8 of Settings Stting in HEX Sett_8_Bin = Conv_2_Bin(Sett_8_HEX, 4) 'Char#8 of Settings String in Binary Sett_9_HEX = Mid$(Settings, 9, 1) 'Char#9 of Settings Stiing in HEX Sett_9_Bin = Conv_2_Bin(Sett_9_HEX, 4) 'Char#9 of Settings String in Binair Sett_10_HEX = Mid$(Settings, 10, 1) 'Char#10 of Settings String in HEX Sett_10_Bin = Conv_2_Bin(Sett_10_HEX, 4) 'Char#10 of Settmgs String in Binary

I

Byte_4_HEX = Mid$(Settings, 7, 2) 'Byte#4 of Settings Stiing in HEX Byte_4_Bin = Conv_2_Bin(Byte_4_HEX, 8) 'Byte#4 of Settings Stiing in Binary

'Decode single Bits and Groups of Bits of Binary Strings of Settings Characters 'Decode Bit 1 of Settings Char#l to determine Channel 1 inverted On/Off

If Mid$(Sett_l_Bin, 1, 1) = "0" ThenfrmMain.Settings3.Caption= "Off' If Mid$(Sett_l_Bin, 1, 1) = "1" ThenfrmMain.Settings3.Caption = "On"

'Decode Bit 2 of Settings Char#l to determine Channel 1 Cal'd/Uncal If Mid$(Sett_l_Bin, 2, 1) = "0" ThenfrmMain.Settings5.Caption= "Cal'd** If Mid$(Sett_l_Bin, 2, 1) = "1" Then frmMain.Settings5.Caption = "UnCal" If fnnMain.Settings5.Captíon = "UnCal" Then

frmMain.Settings5.ForeColor = RED Else

frmMain.Settings5.ForeColor = BLACK Endlf

'Decode Bits 3,4 of Settíngs Char#l to determine Coupling of Channel 1 If Mid$(Sett_l_Bin, 3, 2) = "00" Then Coupling(l) = **DC" If Mid$(Sett_l_Bin, 3, 2) = "01" Then CoupUng(l) = "AC" If Mid$(Sett_l_Bin, 3, 2) = "10" Then CoupUng(l) = "Gnd" If Mid$(Sett_l_Bin, 3, 2) = "11" Then CoupUng(l) = *'Off*

*Decode Bit 1 of Settings Char#3 to determine Channel 2 inverted On/Off If Mid$(Sett_3_Bin, 1, 1) = "0" ThenfiinMain.Settings4.Caption = "Off* If Mid$(Sett_3_Bin, 1,1) = "l'* ThenfrmMain.Settíngs4.Captíon = "On"

'Decode Bit 2 of Settings Char#3 to determine Channel 1 Cal'd/Uncal If Mid$(Sett_3_Bin, 2, 1) = *'0" Then firmMain.Settings6.Caption = *'Cal'd" If Mid$(Sett_3_Bin, 2, 1) = "1" Then frmMain.Settings6.Caption = "UnCal" If frmMain.Settings6.Caption = "UnCal" Then

fnnMain.Settings6.ForeColor = RED Else

fnnMain.Settings6.ForeColor = BLACK Endlf

62

Page 71: I n' .3»3ti;w-»-«

feap tir saiaíiu^^sgg

'Decode Bits 3,4 of Settíngs Char#3 to determine Coupling of Channel 2 If Mid$(Sett_3_Bin, 3, 2) = "00" Then Coupling(2) = "DC" If Mid$(Sett_3_Bin, 3, 2) = "OV Then Coupling(2) = "AC'* If Mid$(Sett_3_Bin, 3, 2) = "10" Then Coupling(2) = "Gnd" If Mid$(Sett_3_Bin, 3, 2) = '* 11" Then Coupling(2) = "C«r'

•Decode Bit 1 of Settíngs Char#5 to determine ReadOut On/Off Setting If Mid$(Sett_5_Bin, 1, 1) = "0" ThenfrmMain.Settingsl4.Caption= "RO_On" IfMid$(Sett_5_Bin, 1, 1) = "1" ThenfimMain.Settingsl4.Caption = "RO_Off '

•Decode Btt 2 of Settings Char#5 to determine XY Mode On/Off Setting If Mid$(Sett_5_Bin, 2, 1) = **0** Then frmMain.Settingsl7.Caption = "XY_Off* If Mid$(Sett_5_Bin, 2, 1) = *'l" ThenfimMain.Settingsl7.Caption = "XY_On"

'Decode Bit 3 of Settings Char#5 to determine XIO Magnificatíon On/Off Setting If Mid$(Sett_5_Bin, 3, 1) = "0" ThenfrmMain.Settings20.Caption = "X10_Off' If Mid$(Sett_5_Bin, 3, 1) = "1" Then fiinMain.Settings20.Caption = "X10_On"

*Decode Bit 4 of Settings Char#5 to determine Time/Div Setting If Mid$(Sett_5_Bin, 4, 1) = **1** Then X_Div_Index_2 = X_Div_Index_2 + 16

*Decode Bit 4-5 of Settings Byte#4 to determine Trigger Source If Mid$(Byte_4_Bin, 4, 2) = *'00" Then frmMain.Settingsl9.Caption = "Vert" If Mid$(Byte_4_Bin, 4, 2) = "01" Then frmMain.Settingsl9.Caption = "Ch_l" If Mid$(Byte_4_Bin, 4, 2) = "10" ThenfrmMain.Settingsl9.Caption= "Ch_2" If Mid$(Byte_4_Bin, 4, 2) = "11" Then frmMain.Settingsl9.Caption = "Ext"

*Decode Bit 1-3 of Settings Chai#7 to determine Trigger Setting If Mid$(Sett_5_Bin, 1, 2) = "00" ThenfrmMain.Settingsl6.Caption = "Post" If Mid$(Sett_5_Bin, 1, 2) = "01" ThenfnnMain.Settingsl6.Caption = "Mid" If Mid$(Sett_5_Bin, 1, 2) = "10" ThenfrmMain.Settingsl6.Caption = "Pre" If Mid$(Sett_5_Bin, 3, 1) = "1" ThenfrmMain.Settingsl5.Caption = "+" If Mid$(Sett_5_Bin, 3, 1) = "0" ThenfrmMain.Settingsl5.Caption= "-"

'Decode Bit 2-4 of Settings Char#8 to determine Trigger Settíng If Mid$(Sett_8_Bin, 2, 3) = "000" Then frmMain.Settings21.Caption = "Norm" If Mid$(Sett_8_Bin, 2, 3) = "001" ThenfrmMain.Settings21.Caption= "Auto_Lvl" If Mid$(Sett_8_Bin, 2, 3) = "010" ThenfrmMain.Settings21.Caption= "Auto_Bl" If Mid$(Sett_8_Bin, 2, 3) = "011" ThenfrmMain.Settings21.Caption= "S_Seq*'

'Decode Bit 1 of Settings Char#9 to determine TimeOut Condition If Mid$(Sett_9_Bin, 1, 1) = "0" ThenfiinMain.Settings27.Caption= **TimeOut_Yes" If Mid$(Sett_9_Bin, 1, 1) = "1" ThenfrmMain.Settings27.Caption= "TimeOut_No"

'Decode Bit 2 of Settings Char#9 to determine Input channel If Mid$(Sett_9_Bin, 2, 1) = "1" Then Channel = 1: frinMain.Settingsll.Caption = "Ch 1" If Mid$(Sett_9_Bin, 2, 1) = "0" Then Channel = 2: fimMain.Settingsll.Caption = "Ch 2"

'Decode Bit 3 of Settings Char#9 to determine recalled Waveform If Mid$(Sett_9_Bin, 3, 1) = "0" ThenfrmMain.Settings22.Caption = "Recl_No" If Mid$(Sett_9_Bin, 3, 1) = "1" ThenfrmMain.Settings22.Caption = "Recl_Yes"

'Decode Bit 4 of Settings Char#9 to determine Valid Store If Mid$(Sett_9_Bin, 4, 1) = "0" ThenfrmMain.Settings23.C:aption = "ValSt_No" If Mid$(Sett_9_Bin, 4, 1) = "1" ThenfiinMain.Settings23.Caption= "ValSt_Yes"

'Decode Bit 1-2 of Settings Char#10 to determine aquisition mode If Mid$(Sett_10_Bin, 1, 2) = "00" ThenfrmMain.Settings25.Caption= "Normal" If Mid$(Sett_10_Bin, 1, 2) = "01" ThenfrmMain.Settings25.Caption = "Envelope" If Mid$(Sett_10_Bin, 1, 2) = '*10" ThenfimMain.Settings25.Caption = **Average" If Mid$(Sett_10_Bm, 1, 2) = "11" ThenfinmMain.Settings25.Caption= "Cont_Env"

'Decode Bit 3 of Settings Char#10 to determine aquisition mode If Mid$(Sett_10_Bin, 3, 1) = "0" -nienfrraMain.Settings^^.Caption = *'Store_Off' If Mid$(Sett_10_Bin, 3,1) = "1" Then frmMain.Settings26.Caption = "Store_On"

63

Page 72: I n' .3»3ti;w-»-«

'Decode Bit 4 of Settings Char#10 to determine aquisition mode

If Mid$(Sett_10_Bin, 4, 1) = "0" ThenfrmMain.Settnigs24.Caption = "AutoTr_Ofr* If Mid$(Sett_10_Bin, 4, 1) = "1" Then frmMain.Settings24.Caption = "AutoTr_On"

• * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * : ( : * * * : ( : :(c:(c

** Post Setting Stiings to Main Form * ' * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

'Print CurveHeader in Lábel Field frmMain.Settíngsl8.Caption = Scope_Mode frmMain.Settíngsl3.Caption = Curve_Header frmMain.Settingsl .Caption = Y_Ch_Sett(V_Div_Index_l) firmMain.Settíngs2.Caption = Y_Ch_Sett(V_Div_Index_2) frmMain.Settings7.Caption = Coupling(l) frmMain.Settings8.Caption = Coupling(2) frmMain.Settíngs9.Caption = X_Ch_Sett(X_Div_Index_2)

'Print Settíngs in Label Field frmMain.Settingsl2.Caption = Settúigs

'Print # of Elements in Label Field frmMain.SettingslO.Caption = Elements KElements<512Then

frmMain.SettingslO.ForeColor = RED Else

frmMain.SettingslO.ForeColor = BLACK Endlf

End Sub

****** Print Ascii Values to *.PRN File *****

*Global Airay X_Curve(511) is Integer 'Global Array Y_Curve(511) is Integer 'Coordinate Transformation to actual measured 'Values is performed inside this Routine I

*Date: July-14-1996, revised August-23-1997 Sub Print_XY(PrintFileName As Stting) 'Declare local Variables used in Routine Diml Aslnteger 'Generic Count Variable Dim X As Single *X Value for Scope Trace Point Dim Y As Single *Y Value for Scope Trace Point DimTStart As Single 'Start ValueforTime DimT_Stop AsSingle 'Stop ValueforTime DimV_Div_X AsSingle *Volts/Div for X-Scope Trace Dim V_Div_Y As Single 'Volts/Div for Y-Scope Trace Dim Scale_Factor As Integer 'Scale Factor for Current Probe Measurements 'Exit right away if nothing to print If Elements = 0 Then Exit Sub 'Read Option Buttons If frmMain.Optionl(0).Value = True Then Scale_Factor = 1 If fnnMain.C)ptionl(l).Value = True Then Scale_Factor = 1 If frmMain.Optionl(2).Value = True Then Scale_Factor = 10 If frmMain.C)ptionl(3).Value = True Then Scale_Factor = 100 'Disable FileOpen and Print_File Menus

64

Page 73: I n' .3»3ti;w-»-«

-- - l — f i - n •TTiii l i î r f r í 'iirmnTnOT nr

frmMain.mnuOpen.Enabled = False frmMain.nmuPrint.Enabled = False 'Open Print File Open PrintFileName For Output As #2 V_Div_X = Y_V_Div(V_Div_Index_l) V_Div_Y = Y_V_Div(V_Div_Index_2)

ForI = 0To511 X = Scale_Factor * X_Curve(I) * 10 * V_Div_X / 256

Print #2, Format$(X, "+O.0000E+00;-0.0000E+00**);","; Y = Scale_Factor * Y_Curve(I) * 10 * V D i v Y / 256 If I > (Elements / 2) -1 Then Y = 0 'Zero Padding

Print #2, Fonnat$(Y, "+O.0O00E+00;-0.0000E+OO") Nextl

Print#2, Close #2

'Enable File^Open and Print_File Menus frmMain.mnuOpen.Enabled = True frmMain.mnuPrint.Enabled = True End Sub

• * * * * * * * * * * * * * * * + : (c* + + : (c* + + *:(c + + :(c* + + :(c:(c* + + :(c* + : ( c * * * +

****** Print Ascii Values to *.PRN File ***** l * * * * * * * * * * * * * : ( c * * * * + : ( c : ( c * * * * * : ( ! : ( c * * : ( : + : ( c * * * : ( c * * * : ( : + : ( c * *

'Global Array Y_Curve(511) is Integer *Coordinate Transformation to actual measured *Values is performed inside this Routine I

'Date: October-03-1996, revised August-23-1997 Sub Print_Yt(Printf^ileName As Stting) 'Declare local Variables used in Routine Dim I As Integer 'Generic Count Variable Dim T As Single 'Time Value for Scope Trace Point DimY AsSingle *Y Value for Scope Trace Point Dim T_Start As Single *Start Value for Time Dim T_Stop As Single *Stop Value for Time Dim V_Div As Single 'Volts/Div for Scope Trace Dim Scale_Factor As Integer 'Scale Factor for Current Probe Measurements 'Exit right away if nothing to print If Elements = 0 Then Exit Sub 'Read Option Buttons If frmMain.Optionl(0).Value = True Then Scale_Factor = 1 Lf frmMain.Optionl(l).Value = True Then Scale_Factor = 1 If frmMain.C^tionl(2).Value = Tme Then Scale_Factor = 10 If frmMain.C^tionl(3).Value = True Then Scale_Factor = 100 'Disable File_Open and Print_File Menus fnnMain.nmuOpen.Enabled = False frmMain.mnuPrint.Enabled = False 'Open Print File Open PrintFileName For Output As #2 If Channel = 1 Then V_Div = Y_V_Div(V_Div_Index_l) If Channel = 2 Then V_Div = Y_V_Div(V_Div_Index_2) T_Start = 0 T_Stop = 10* X_T_Div(X_Div_Index_2) * 10 Divisions for Time

ForI = 0To511

65

Page 74: I n' .3»3ti;w-»-«

iiiiij II í II iii iniiiíiii 1II I[!• ii7 iiimTMirr- u

T = T_Start + (I * (T_Stop - T_Start) /511) Print#2, Format$(T, "+0.0000E-K)0"); \ ";

Y = Scale_Factor * (Y_Curve(I) - Lvl) * V_Div * (10 / 256) If I > Elements -1 Then Y = 0 'Zero Padding

Print #2, Format^O", "+O.0000E+00;-O.0000E+00") Nextl

Print#2, Close #2

'Enable File_Open and Print_File Menus frmMain.mnuOpen.Enabled = True frmMain.mnuPrint.Enábled = True End Sub

Sub Read_XYO ' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + :(c

******* Reading X-Y Trace Values ****** ' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

*Declare local Variables used in Routine Dim I As Integer *Generic Count Variable Dim EndCnt As Integer *End Count for Loop

EndCnt = Int(Elements / 2) -1 For I = 0 To EndCnt

X_Curve(I) = Val(**&H** + Inpuî$(2, 1)) Y_Curve(I) = Val("&H" + Input$(2, 1))

Nextl Close #1 frmMain.VScroUl.Enabled = False End Sub

Sub Read_YtO I * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

'****** Reading Trace Values ****** I * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

******* Date: July-13-1996 ****** 'Declare local Variables used in Routine Dim I As Integer 'Generic Count Variable Dim Sum As Single 'Sum of Values Max = 0: Min = 255: Sum = 0

For I = 0 To Elements - 1 Y_Curve(I) = Val("&H" + Input$(2, 1)) Sum = Sum + Y_Curve(I) If Y_Curve(I) > Max Then Max = Y_Curve(I) If Y_Curve(I) < Min Then Min = Y_Curve(I)

Nextl Close #1 Avg = Int((Sum / Elements) + 0.5) frmMain.VScroUl.Enabled = True ********* Determine Reference Level ********** If fnnMain.mnuAuto.Checked = Tme Then

If Coupling(Channel) = "AC" ThenfrmMain.VScroUl.Value = Avg If Coupling(Channel) = "DC** ThenfrmMain.VScroUl.Value = Min

Endlf

66

Page 75: I n' .3»3ti;w-»-«

If firmMain.mnuAvg.Checked = Tme Then frmMain.VScroUl. Value = Avg If fnnMain.mnuMin.Checked = Tme Then finmMain.VScroUl.Value = Min If frinMain.mnuMax.Checked = Tme Then fimMain. VScrolU.Value = Max End Sub

*Sub_Routine to Read Ascii values from File for Y-t mode 'Date: July-06-1996 Sub ReadFileHeader(SelectedFileName As Stting) 'Declare local Variables used in Routine Diml Aslnteger *Generic Count Variable Dim In_String As String *Generic Input Stting Dim DataCount As String *Stting that contains tiie number of data points in trace (normally 512) Dim Msg As String *Error Message ! * * * * * * * * * * * * * * * * : ( : : ( t : (c: ,c: , : : (c:C: ,c******** + + + :(c:(c

********** OpenDataFile ************ l * * * * * * * * * * * * : ( c : , : ^ c * * * * * * * * * * * + * + :(c**:,.4::(c:(c:jc

Open SelectedFileName For Input As #1 l * * * * * * * * * * * * * * * * * : , : + + :(c + :(c + :(c + :(c* + + * : ( c : , : : | c * * + : ( c * * : ( c * * +

**** READ SCOPE SETTING STRINGS FROM FILE *** I * * * * * * * * * * * * * * * * * * : ( c * * * : ( c * : ( c * : ( c * * * * * * * * * * * * * * * * *

CurveHeader = Input$(9, 1) If Right$(Curve_Header. 1) o ":" Then

In_Stting = Input$(l, 1) Curve_Header = CurveHeader + InString

Endlf Settings = Input$(10, 1) Scope_Mode = Input$(2, 1) Data_Count = "&H'* + Input$(4, 1) Elements = Val(Data_Count) I * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

***** Call Sub to Decode and Postthe Scope Settings ****

DecodeSettings *Exit the Sub here End Sub

Sub ReadSettingsDataO I * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

***** DATA FOR FRONT PANEL ENCODING **** I * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

I * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

****** Y-Channel SETTINGS ***** I * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Y_Ch_Sett(0) = ** SmVIDW" Y_Ch_Sett(l) =" lOmV/DIV'* Y_Ch_Sett(2) = ** 20mV/DIV" Y_Ch_Sett(3) = " 50mV/DIV** Y_Ch_Sett(4) = ** O.IV/DIV** Y_Ch_Sett(5) = ** 0.2V/DIV" Y_Ch_Sett(6) =" 0.5V/DIV" Y_Ch_Sett(7) =" IV/DIV" Y_Ch_Sett(8) =" 2V/DIV" Y Ch Sett(9) = " 5V/DIV"

67

Page 76: I n' .3»3ti;w-»-«

^.---•.i^Li^j^^^ijSS

Y_Ch_Sett(10) =" lOV/DIV" Y_Ch_Sett(ll) = " 20V/DIV" Y_Ch_Sett(12) =" 50V/DIV*' Y_Ch_Sett(13) = ** lOOV/DIV** Y_Ch_Sett(14) =" 200V/DIV** Y_Ch_Sett(15) = *' 500V/DIV" ' * * * * * * * * * * * * * * * * * * * * : ( c * * + : ( c * * * * * * *

Y_V_Div(0) = 0.005 Y_V_Div(l) = 0.01 Y_V_Div(2) = 0.02 Y_V_Div(3) = 0.05 Y_V_Div(4) = 0.1 Y_V_Div(5) = 0.2 Y_V_Div(6) = 0.5 Y_V_Div(7) = 1 Y_V_Div(8) = 2 Y_V_Div(9) = 5 Y_V_Div(10) = 10 Y_V_Div(ll) = 20 Y_V_Div(12) = 50 Y_V_Div(13) = 100 Y_V_Div(14) = 200 Y_V_Div(15) = 500 ' * * * * * * * * * * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

'***** X-Channel SETTINGS *****

X_Ch_Sett(0) = ** 50ns/DIV" X_Ch_Sett(l) = "O.lus/DIV" X_Ch_Sett(2) = "0.2US/DIV" X_Ch_Sett(3) = "0.5US/DIV" X_Ch_Sett(4) = " lus/DIV" X_Ch_Sett(5) = ** 2US/DIV** X_Ch_Sett(6) = " 5US/DIV" X_Ch_Sett(7) = " lOus/DIV'* X_Ch_Sett(8) = *' 20US/DIV" X_Ch_Sett(9) = " 50US/DIV" X_Ch_Sett(10) = "O.lms/DIV" X_Ch_Sett(ll) = "0.2ms/DIV" X_Ch_Sett(12) = "0.5ms/DIV" X_Ch_Sett(13) = " Ims/DIV" X_Ch_Sett(14) = " 2ms/DIV" X_Ch_Sett(15) = " 5ms/DIV" X_Ch_Sett(16) = " lOms/DIV'* X_Ch_Sett(17) = " 20ms/DIV'* X_Ch_Sett(18) = " 50ms/DIV" X_Ch_Sett(19) = *'0.1 s/DIV" X_Ch_Sett(20) = "0.2 s/DIV" X_Ch_Sett(21) = "0.5 s/DIV" X_Ch_Sett(22) = " 1 s/DIV** X_Ch_Sett(23) = " 2 s/DIV" X_Ch_Sett(24) = *' 5 s/DIV" X_Ch_Sett(25) = " 10 s/DIV" X_Ch_Sett(26) = ** 20 s/DIV* 1 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

68

Page 77: I n' .3»3ti;w-»-«

X_T_Div(0) = 0.00000005 X_T_Div(l) = 0.0000001 X_T_Div(2) = 0.0000002 X_T_Div(3) = 0.0000005 X_T_Div(4) = 0.000001 X_T_Div(5) = 0.000002 X_T_Div(6) = 0.000005 X_T_Div(7) = 0.00001 X_T_Div(8) = 0.00002 X_T_Div(9) = 0.00005 X_T_Div(10) = 0.0001 X_T_Div(ll) = 0.0002 X_T_Div(12) = 0.0005 X_T_Div(13) = 0.001 X_T_Div(14) = 0.002 X_T_Div(15) = 0.005 X_T_Div(16) = 0.01 X_T_Div(17) = 0.02 X_T_Div(18) = 0.05 X_T_Div(19)=0.1 X_T_Div(20) = 0.2 X_T_Div(21) = 0.5 X_T_Div(22) = 1# X_T_Div(23) = 2# X_T_Div(24) = 5# X_T_Div(25) = 10# X_T_Div(26) = 20# I * * * * * * * * * * * * * * * *

End Sub

69

_ áÊ^ : .. . 1—^—^—^^^^—^^^^_^_^.->.^-.^w.--^«.t>—- . ^ ^ ^ y ^ w r •»<•••••>»;

Page 78: I n' .3»3ti;w-»-«

r ' * - * fc''5l:ít;í3eiî»;i*5iei»"-^> ' ^ : - ^ - * • "

PERMISSION TO COPY

In presenting this thesis in partial fulf llment of the requuements for a master's

degree at Texas Tech University or Texas Tech University Health Sciences Center, I

agree that the Library and my major department shall make it fi-eely available for

research purposes. Permission to copy this thesis for scholarly purposes may be

granted by the Director of the Library or my major professor. It is understood that

any copying or publication of this thesis for financial gam shall not be allowed

without my flirther written permission and that any user may be liable for copyright

infrmgement.

Agjee (Permission is granted.)

Student Signature Date

Disagree (Permission is not granted.)

Student Signature Date