@prefix vivo: . @prefix edm: . @prefix ns0: . @prefix dcterms: . @prefix skos: . vivo:departmentOrSchool "Applied Science, Faculty of"@en, "Electrical and Computer Engineering, Department of"@en ; edm:dataProvider "DSpace"@en ; ns0:degreeCampus "UBCV"@en ; dcterms:creator "Passmore, William A."@en ; dcterms:issued "2010-08-30T17:50:47Z"@en, "1989"@en ; vivo:relatedDegree "Master of Applied Science - MASc"@en ; ns0:degreeGrantor "University of British Columbia"@en ; dcterms:description """A photovoltaic powered pumping system offers an attractive means of supplying fresh water in remote areas not serviced by a utility grid. In order to extract the maximum amount of energy from the solar panels, it is necessary to match the characteristics of the photovoltaic array to the DC motor which drives a pump. A one quadrant DC-DC converter is capable of adjusting the effective load impedance for maximum power transfer under most lighting conditions. Three styles of DC-DC converters used to control the pumping system are described and compared. The voltage tracking style of converter fixes the array voltage at a level considered optimum. The power tracking converter measures, and attempts to maximize, the output power of the photovoltaic array. The microprocessor based power tracking, voltage tracking converter toggles between the two methods of control. Experimental results are included."""@en ; edm:aggregatedCHO "https://circle.library.ubc.ca/rest/handle/2429/27948?expand=metadata"@en ; skos:note "A D C - D C C O N V E R T E R S U I T A B L E F O R C O N T R O L L I N G A P H O T O V O L T A I C P O W E R E D P U M P I N G S Y S T E M William A . Passmore B.A . Sc . (Electrical Engineering) University of British Columbia A THESIS S U B M I T T E D IN PARTIAL F U L F I L L M E N T OF T H E REQUIREMENTS FOR T H E D E G R E E OF M A S T E R OF A P P L I E D S C I E N C E in T H E F A C U L T Y OF G R A D U A T E STUDIES D E P A R T M E N T OF E L E C T R I C A L E N G I N E E R I N G We accept this thesis as conforming to the required standard T H E UNIVERSITY OF BRITISH COLUMBIA March 1989 © William A . Passmore, 1989 In presenting this thesis in partial fulfilment of the requirements for an advanced degree at the University of British Columbia, 1 agree that the Library shall make it freely available for reference and study. I further agree that permission for extensive copying of this thesis for scholarly purposes may be granted by the head of my department or by his or her representatives. It is understood that copying or publication of this thesis for financial gain shall not be allowed without my written permission. Department The University of British Columbia Vancouver, Canada Date DE-6 (2/88) Abstract A photovoltaic powered pumping system offers an attractive means of supplying fresh water in remote areas not serviced by a utility grid. In order to extract the maximum amount of energy from the solar panels, it is necessary to match the characteristics of the photovoltaic array to the DC motor which drives a pump. A one quadrant DC-DC converter is capable of adjusting the effective load impedance for maximum power transfer under most lighting conditions. Three styles of DC-DC converters used to control the pumping system are de-scribed and compared. The voltage tracking style of converter fixes the array voltage at a level considered optimum. The power tracking converter measures, and attempts to maximize, the output power of the photovoltaic array. The microprocessor based power tracking, voltage tracking converter toggles between the two methods of control. Experimental results are included. ii Table of Contents Abstract ii List of Tables iv List of Figures v Acknowledgement vi 1 Introduction 1 1.1 System components 2 1.1.1 Photovoltaic Array 2 1.2 Thesis 6 2 Power Converter 7 2.1 Component Matching 7 2.2 Component Ratings 8 2.2.1 Filter Capacitor 9 2.2.2 Power Mosfets 11 2.2.3 Diode 14 2.2.4 Power Supply 15 2.2.5 Heatsink 16 3 Voltage Tracking Converter 18 3.1 Specifications 18 iii 3.2 Circuit Description 18 3.2.1 Basic Operation 20 3.2.2 Gate Drive 21 3.2.3 Overcurrent Protection 21 3.2.4 Thermal Protection '. 21 3.2.5 Protection 22 3.3 Testing and Results 23 3.3.1 Waveforms 23 3.3.2 Efficiency 29 4 Maximum Power Tracking Converter 31 4.1 The Logic Circuit 31 4.2 Results 34 4.3 Constant Voltage vs. Maximum Power Tracking 38 5 Microprocessor Based Hybrid Control 40 5.1 Logic Circuit 41 5.1.1 MC68HC11 Single Chip Microprocessor 41 5.1.2 Current Sensing 44 5.1.3 Overcurrent Protection 45 5.1.4 Voltage Sensing 46 5.1.5 Pulse Width Modulation 46 5.1.6 Gate Drive 50 5.2 Program 50 5.2.1 Maximum Power Tracking . 50 5.2.2 Voltage Tracking 51 5.2.3 Interrupts 55 iv 5.2.4 Changing the Duty Cycle 57 5.3 Results 57 5.3.1 Voltage Waveform 58 5.3.2 Current and Voltage Measurements 58 5.3.3 Maximum Power Point 65 6 C o n c l u s i o n s 72 A A s s e m b l y L a n g u a g e P r o g r a m 74 A . l Main Program 76 A.2 A /D Converter Set-Up 78 A.3 Timer Set-Up 79 A.4 Overcurrent Initialization 81 A.5 Read Input Data 82 A.6 Adjust the Pulse Width 84 A.7 Real Time Timer 90 A.7.1 Time of Day Interrupt Service 91 A.7.2 Increment The Time of Day . . 92 A.7.3 Add Time 93 A.7.4 Compare Time 94 A.8 Clear Timer Node 96 A.9 Maximum Power Tracking 97 A.9.1 Change Search Direction 104 A. 10 Current Adjustment 105 A.11 Voltage Tracking Routine 105 A. 11.1 Adjustment to the Duty Cycle 107 A.12 Read Open Circuit Voltage and Current 109 v A. 13 Calculate Load Voltage and Current 110 A. 14 Change the Duty Cycle in Small Increments 113 A.15 Overcurrent 116 A. 15.1 Overcurrent Interrupt 117 A.16 Output Compare One Interrupt 119 A. 17 Output Compare Two Interrupt 119 Bibliography 121 v i List of Tables 2.1 IRF730 Device Specifications: ,- 13 3.2 Voltage Tracking Converter Specifications 20 3.3 Converter Efficiency 30 5.4 Power Tracking Results 71 vi i List of Figures 1.1 Voltage vs Current Curves of a Photovoltaic Array 4 1.2 Current and Voltage vs Power at a Set Insolation Level 5 2.3 DC to DC Converter 9 2.4 Converter Voltage and Current Waveforms 10 3.5 Circuit Diagram of the Voltage Tracking Converter . 19 3.6 Drain-to-Source Voltage 24 3.7 Drain-to-Source Voltage at Turn-off 25 3.8 Gate-to-Source Voltage with the Drain-to-Source Voltage 26 3.9 Current Signal 28 3.10 Experimental Set-up 29 4.11 Block Diagram of Maximum Power Point Tracking Circuit 32 4.12 Array Power vs. Solar Radiation Level 35 4.13 Converter Efficiency 36 4.14 Motor Efficiency 37 5.15 External Logic Circuit 42 5.16 Pulse Width Modulated Waveforms 49 5.17 Simplified Power Circuit 53 5.18 Equivalent Power Circuit 53 5.19 Drain-to-Source Voltage Waveform 59 5.20 Drain-to-Source Voltage Waveform at Turn-off 60 viii 5.21 Drain-to-Source Voltage Waveform at Turn-on 61 5.22 HEXSense Current Waveform 62 5.23 Filtered HEXSense Current Waveform 63 5.24 Current Waveform with Active Overcurrent Protection 64 5.25 Microprocessor Current Measurements vs Metered Current Measure-ments 66 5.26 Microprocessor Voltage Measurements vs Metered Voltage Measurements 67 5.27 Calculated Power vs Metered Power 68 5.28 Power, Load Current, and Load Voltage vs Duty Cycle 69 ix Acknowledgement The author would like to express his appreciation to his supervisor, Dr. W. G. Dunford, for guidance and assistance during this project, and to Dr. M. D. Wvong, for assuming the role of acting supervisor during the final stages of this project. The author also wishes to express his gratitude to his father, Mr. C. E. Passmore, for his help and assistance, and to his wife, Carol, for her understanding and support. Gratitude is also expressed to colleagues Nick Jaeger, Ben Giudici, and C.E. Sudhakar for their help. Appreciation is also expressed to the staff of Electrical Engineering, UBC, for their helpful assistance, particularly to Alan Prince and Lloyd Welder. Appreciation is also expressed to Guang Liu for making available data on the photovoltaic array. x Chapter 1 Introduction A photovoltaic-powered pumping system offers an attractive means of supplying water from medium head wells in locations not serviced by a utility grid. The capital cost of a system is higher than a diesel-powered pumping station but the photovoltaic system utilizes a free and inexhaustible energy source, requires very little maintenance, and can be completely automated. Therefore the long term cost and reliability of the system compares favorably with that of a diesel powered station [l]. The regions that could benefit most from such a pumping system can generally least afford it. However, industrialized countries such as Canada are willing to fund such projects. They recognize the benefits that quantities of clean drinking water would allow in the areas serviced by these pumping stations. The Canadian International Development Agency, C I D A , is currently installing test pumping stations in Morroco and is considering many more sites in various locations throughout the world. Dry tropical countries offer particularly attractive sites because of their great need of water, consistently long hours of sunshine, and lack of alternate energy sources. However, there are areas within Canada, such as the prairies or the interior of B . C . which could benefit from such a pumping system. During dry spells, water is urgently needed to feed livestock. Where ground water is present and mains power is not, a photovoltaic-powered pumping system could supply the needed water. 1 Chapter 1. Introduction 2 1.1 System components The photovoltaic-powered pumping system consists of an array of solar panels, a power converter, a motor, and a pump. The photovoltaic array produces a DC voltage and current, therefore, a DC motor and a DC to DC converter are the logical component choices. Some systems do employ an AC motor requiring a DC to AC converter, but for a small or medium sized system the inherent extra complexity and reduced efficiency rule it out. A permanent-magnet DC motor is preferable to a separately-excited or compound-wound machine. The increased efficiency and reduced heating of the permanent mag-net machine will justify the higher cost. A l.lkW permanent-magnet BROT motor equipped with samarium cobalt magnets and interpole windings is used for many of the tests described in this report. This motor achieved measured efficiencies as high as 87% and has a long brush life to minimize maintenance. The Mono progressive cavity pump is the pump of choice for this application. It is efficient over a large range of speeds and well depths [2] and is well known at many of the target sites. The pump itself is submersed at the bottom of the well and driven by a shaft running up the length of the well and connected to a motor at the top. This gives the dual advantage of having a dry, easily accessible electric motor and a submersed pump, capable of efficiently delivering water from depths of up to 150m. 1.1.1 Photovoltaic Array The photovoltaic array is the most expensive system component. It is therefore wise to maximize its effectiveness by extracting the maximum amount of energy from its' panels. Chapter 1. Introduction 3 The voltage-current curves displayed in Figure 1.1 were obtained from measure-ments performed on the photovoltaic array located on the roof of the Hector MacLeod building at UBC. This array is made up of two parallel strings of five series panels rated at 16V and 35w each. The curves show that the current delivered by the panels increases significantly with the insolation level as compared to the open circuit volt-age which increases only a small amount. Consistent with theory [3], the open circuit voltage decreases as the temperature increases, creating intersecting curves. A curve displaying how the power output of the array varies with the array voltage at a particular insolation level is shown in Figure 1.2. Its jagged appearance is due to the limited eight-bit resolution of the measurement equipment. Nevertheless the general shape of the curve is clear. The peak of the power curve occurs on the knee of the corresponding voltage-current curve. The locus of maximum power points for different insolation levels is shown in Figure 1.1 and is approximately a constant voltage, variable current curve. It is apparent that a reasonable approximation to a maximum power tracking converter would be a voltage tracking converter. Such a converter would fix the array voltage at a level considered to be optimum. The voltage-current curve tends to flatten out as the panels age, shifting the opti-mum operating voltage. Add to this effect the shift in the open circuit voltage with temperature and a case could be made for using a converter which can adapt to chang-ing conditions. More practically, an adaptive converter would be able to automatically locate the best operating point regardless of the array configuration. The need for careful on-site measurements and adjustments would then be eliminated. Chapter 1. Introduction Array Current vs Array Voltage 4 . 0 Moderate temperature operat ion — — Higher temperature operat ion x x x x x Maximum power points 3.0 -CL E < 2.0 -c o 1.0 0 . 0 0 -I—I—I—I—I—I—I—I—I— I—I—1—I—I—I—I—I—I I I I 1 I I I 4 0 8 0 Voltage (Volts) Figure 1.1: Voltage vs Current Curves of a Photovoltaic Array Chapter 1. Introduction 5 Array Current and Power vs Array Voltage 2 0 4 0 6 0 8 0 1 0 0 Voltage (Volts) Figure 1.2: Current and Voltage vs Power at a Set Insolation Level Chapter 1. Introduction 6 1.2 Thesis This thesis covers the design and testing of three different styles of converters. The basic design of the power circuit is common to all three converters and is described in Chapter 2. The device specifications, thermal and RMS ripple current calculations, and heatsink sizing are presented in this chapter. The voltage tracking style of converter is described in Chapter 3. It was built as a prototype for Optima Design Ltd. to be considered for use in Morroco. The control is simple, yet it is a rugged reliable device. The array voltage is set on site by means of a potentiometer which is accessible through the front of the converter. Chapter 4 discusses an analogue maximum power tracking style of converter. It continuously searches for the maximum power point of the array and it does not require any field adjustments, however, the logic circuit is more complicated. A hybrid maximum power tracking, voltage tracking style of converter is presented in Chapter 5. In the maximum power tracking mode it searches for the optimum operating point. Once this point has been found the array voltage is maintained at its optimum level in the voltage tracking mode. Periodically the power tracking mode is reentered to make minor adjustments to the operating voltage. The MC68HC11 makes it possible to use this more sophisticated algorithm without increasing the circuit complexity. It is able to perform the A /D conversions, execute the control algorithms, keep track of timing, and output a series of pulse width modulated output waveforms. Only a few external chips are required to assist the MC68HC11 in controlling the converter. Chapter 2 Power Converter 2.1 Component Matching It is necessary to match the motor, pump, and photovoltaic array characteristics. Matching the D.C. motor to the Mono progressive cavity pump is relatively straight-forward. Their torque-speed characteristics must be matched with possibly the aid of a mechanical gearing system. Matching the photovoltaic array to the DC motor-pump combination is more challenging. A large starting current of at least twice the rated value of the machine may be necessary to overcome the static friction of the Mono pump. Once rotating, the motor will draw an almost constant current over most of its speed range for a fixed head. The DC-DC converter illustrated in Figure 2.3, is well suited to matching the pho-tovoltaic and motor characteristics. It is capable of increasing the impedance of the load as seen by the source so that it is possible to extract the maximum power from the source for most lighting conditions. This power conditioning is achieved by adjusting the ratio of the on-time to off-time, i.e. the duty cycle, of the power mosfets. During their on state the full source voltage, Vs, appears across the load while the load current, //,, is supplied by the source and the filter capacitor. During the off state the load voltage, VL, drops to zero while the current, maintained by the load inductance, flows through the freewheeling diode. The 7 Chapter 2. Power Converter 8 average load voltage, Vj,, is therefore: VL = t-f-.Vs = d.Vs (2.1) where tojv is the on time, T is the period and d is the duty cycle. If the chopping fre-quency and load inductance are high enough the load current remains almost constant with a small ripple component. Figure 2.4 displays the voltage and current waveforms of the load, source, and filter capacitor. In the steady state the average capacitor current is zero, which implies: Is = / L ~ = h-d (2.2) The resistance of the load as seen by the source is: Vs Vs R IN — Is h-d VL _ 1 w ( 2 - 3 ) The chopper is in effect a transformer with turns ratio equal to the duty cycle for the purpose of transforming the voltage, current and effective resistance from one side to another. The chopper can therefore increase the load resistance by the factor of d~2 to capture all maximum power points lying above the base load line. 2.2 Component Ratings The reliability and efficiency of the system will depend to a large degree upon the choice of suitable components. Reliability is essential, as in most practical applications the system will be located in remote areas. Efficiency is important, as the photovoltaic panels are expensive. A n increase in converter efficiency will usually result in an even greater increase in overall efficiency, as the pump and motor are generally more efficient at higher speeds. Chapter 2. Power Converter 9 A r r a y C o n n e c t i on Lo m m . Ro - h DC Mach i ne Figure 2.3: D C to DC Converter 2.2.1 Filter Capacitor The D C - D C input capacitor is essential to fix the array voltage. It accepts current from the array during the off state of the mosfets and delivers current to the load while the mosfets are switched on. The value of capacitance will be determined by the allowable input voltage ripple. Consider an example where a 0.5^ ripple is acceptable with the array delivering 5A of current. The worst case will occur when the switch is either open or closed for almost all of the switching period. If the switching frequency is 20kHz, then a capacitor of at least (2.4) „ q 50/zs x 5A c = 7 = = 5 0 0 * F ' would be required. The capacitor chosen must satisfy the R M S current requirements and withstand the peak open-circuit array voltage. From the current waveforms of Figure 2.4 and assuming a constant load current IL the capacitor R M S current can be Chapter 2. Power Converter 10 £ 200 -+-' \"o > o o 0 -ON T •L 5.0 Motor Current 0.0 Supply Current c CD L . D O o ' 'o o CL o o o 0.0 -5.0 \"i—i—i—i—i—i—i—i—i—i—i—i—i—i—r 0 50 -\\—i—i—i—i—i—i—i—i—i—i—i—i—i 100 150 T i m e (LLS) Figure 2.4: Converter Voltage and Current Waveforms Chapter 2. Power Converter 11 calculated: rms (2.5) Substituting equation 2.2 for the source current yields: — In*ON i _ * O N rms \\ L rp *• rp (2.6) Which has a maximum when: r toN — — (2.7) Therefore: Irms{max) h (2.8) 2 The maximum continuous load current is usually a known quantity, so that the maxi-mum continuous R M S capacitor current rating can be easily calculated. 2.2.2 Power Mosfets The logical choice of a switching device for the converter is the power mosfet. They are easily driven by either C M O S or T T L logic chips, switch rapidly, and do not require a commutation circuit. They are robust and are readily available at the current and voltage levels typically encountered in this application. They also can easily be driven at a high enough frequency to ensure a continuous motor current. Although the power mosfet is rugged, the designer must ensure that it is operated within its specified ratings. The ratings of concern are the maximum gate-to-source and drain-to-source voltage levels and the maximum junction operating temperature. In this application it is not difficult to adhere to the maximum voltage ratings. A zener diode inserted between the gate and source prevents the gate voltage from rising Chapter 2. Power Converter 12 beyond its limit. The drain-to-source voltage rating is maintained by choosing a device rated high enough to withstand the open-circuit voltage together with the voltage spike generated as the device is switched off. This spike is minimized by paying careful atten-tion to circuit layout and by the use of a free-wheeling diode. For further protection a zener diode may be inserted between the drain and source, or third generation devices used that have a built-in zener diode. The current ratings listed in the device specifications are misleading as they assume a junction operating temperature of 25°C which is impractical. Realistically current ratings of the device are derived from the maximum operating junction temperature of the mosfet. It is safe to force current through the device as long as the junction temperature remains below 150°C. If the device is operated above 150°C premature failure can occur. To arrive at an operating junction temperature for a specified current the on resis-tance must be known together with the junction to case, case to heatsink, and heatsink to ambient thermal resistances. As an example consider the IRF730 mosfet chosen for the voltage tracking converter described in Chapter 3. Six parallel devices are used and must be capable of supplying a continuous load current of 12A and a peak current of 22A. The maximum ambient temperature is assumed to be 55° C and a heatsink will be chosen to operate at a maximum of 30°C above ambient, under rated conditions. Table 2.1 summarizes the operating conditions and device ratings. Consider the mosfets turned fully on and delivering 12A of load current. Assume the heatsink temperature is 85°C and the junction temperature is 115°C. The calculated junction operating temperature is: ^ = TH + d*{^)2*RoN(t)*{Tjc + TCH) Chapter 2. Power Converter 13 Table 2.1: IRF730 Device Specifications: Description Symbol Value Ambient temperature TA 55° C Heatsink temperature TH 85°C Junction to case thermal resistance TJC 1.5° C/W Case to heatsink thermal resistance with an electrically insulating silica pad-TCH l.VCjW On resistance at a junction temperature, of 25° C RON{2S°) l.on On resistance at a junction temperature of 115°C RoN{n5°) i.9n = 85°C + (2.CL4)2 * 1.90 * [1.5°C/W + 1.7°C/W) - 109.3°C (2.9) where n is the number of parallel mosfets. This temperature is below the assumed value of 115°C used to determine the on resistance of the mosfets. It is also well within the safe operating temperature of 150°C. The power that must be dissipated by the heatsink due to losses within the mosfets for the above operating conditions is: Pics = 6 * (2.(L4)2 * 1.9f] = 45.6W (2.10) Consider now the converter providing peak load current, 24A, at a duty cycle of 25%. The same assumptions are made as above. The junction operating temperature would then be: = 85°C + 0.25 * (4.04)2 * 1.9H * (1.5°C/W + l.VC/W) = 109.3°C (2.11) Chapter 2. P o w e r C o n v e r t e r 14 with a loss of: P l o s s = 0.25 * 6 * (4.0.4)2 * 1.9H = 45.6W (2.12) The mosfets are operating at a safe temperature. The array current would be 6A for these conditions and it is unlikely the duty cycle would exceed 25% as most array configurations would not be able to deliver such a large current. The load current is prevented from exceeding 24A by the current limit. Note that for these conditions there are also losses in the diode to consider. 2.2.3 Diode A freewheeling diode is essential when switching inductive loads such as a DC motor. Even a resistive load will usually contain enough stray inductance to produce an exces-sive voltage spike as the mosfets are switched off if the freewheeling diode is removed from the circuit. A fast or ultra fast recovery diode is necessary to cope with the fast switching speed of the mosfets. If a slow diode is used a large reverse recovery current spike will be generated as the converter is switched on, which may damage the mosfets. This current spike also creates noise which may interfere with the operation of the logic circuits. Even when a fast recovery diode is used, it is often wise to slow down the mosfets turn-on time in order to reduce noise levels. The converter will need to supply maximum current at a low duty cycle when the DC machine is being turned on to overcome starting torque. The diode, therefore, must be able to handle the maximum current on a continuous basis. For example, for the converter described in Chapter 3, a current rating of 30A should be adequate. The diode should also be rated at 400V to be compatible with the mosfets. The MUR3040PT ultra fast recovery diode in a T0-218AC package is the device of choice. This device is Chapter 2. Power Converter 15 made up of two parallel 15A, 400V diodes in the same package, with a recovery time of 50ns. The diodes are matched and thermally coupled, enabling parallel operation of the two diodes. If the diode is operated under the same conditions used in equation (2.11) the power loss and operating junction temperature would be: P i 0 „ = {l-d)*IL* VON = 0.75 * 2AA * 0.75F = IZ.SW (2.13) m _ Ploss /rr, „, , Tj = TH + *{TCH + TjC) n 13 5W = 85°C + — * (1.7°C/W + l.5°C/W) = 106.6°C (2.14) 2.2.4 Power Supply The logic circuit requires its own power supply. The most practical way to derive this supply is directly from the photovoltaic array. The array voltage will vary at different installations and under different operating conditions while the logic voltage must remain constant. The current requirements of the logic supply are modest, approximately 100mA, so that a simple supply is adequate. The simplest supply would consist of a resistor charging an output filter capacitor whose voltage is set by a reference zener diode. At higher input voltages excess current would be drained through the zener diode. The power supply loss increases with the square of the input voltage over its operating range. This loss is high but may be acceptable for certain applications. The supply can be made more efficient by replacing the dropping resistor with a mosfet. The effective resistance of the mosfet is automatically adjusted to maintain a constant output voltage as the input voltage varies. The output voltage level is Chapter 2. Power Converter 16 maintained by the mosfet three volts below the value set by a reference zener diode attached to the gate. Only as much current as is necessary to maintain the source voltage is supplied resulting in a net loss which is directly proportional to the input voltage. This form of supply is used by the converter described in Chapter 3 and is shown in detail in Figure 3.5. The power loss in the logic supply when the array is operating at 250V is: P, 0 „ = 250V x lOOm.4 = 251V (2.15) A more sophisticated and efficient switched mode power supply could be used. However the extra circuit complexity would not justify the power savings achieved as only a small logic current is required. The added complexity would reduce the overall circuit reliability as well as increase costs. Once a steady output voltage is established a single, dual or triple supply can be derived. For example the analogue maximum power tracking circuit of Chapter 4 requires a 15V, 5V and —7V supply. A linear voltage regulator is used to provide the 15V and 5V supplies from the 18V supply. The negative supply is derived with the aid of a switching regulator and a few external components. 2.2.5 Heatsink Proper sizing of the heatsink is essential for reliable operation. The heatsink must be able to maintain the temperature of the active devices within their safe operating region over a large range of ambient temperatures. To calculate the heatsink size the power being dissipated must be known along with the temperature rise above ambient which can be tolerated. It is assumed the device is operated in the shade and with its fins positioned vertically. From the power losses calculated in equations (2.10) and (2.15) it is determined the Chapter 2. Power Converter 17 heatsink used in the sample converter may have to dissipate up to 70W under normal circumstances. From equations (2.11), (2.12) and (2.15) it can be seen that the losses under peak current conditions can reach as high as 84W. However, this is abnormal and peak current should only be delivered on a temporary basis. If peak current is supplied for a prolonged period, it could be expected the heatsink would warm up causing a thermal cutout to shut down the converter. It was decided while making thermal calculations that a 30°C temperature rise between the heatsink and the environment could be tolerated. This implies a heatsink with a thermal coefficient of 0.43°C/W is required. There are many shapes and sizes of heatsinks available. A suitable heatsink for this application is heatsink #2001 from AHAM TOR INC., California. Chapter 3 Voltage Tracking Converter 3.1 Specifications A DC-DC converter is to be designed for use with photovoltaic arrays of up to two kilowatts. The converter attempts to maximize the power output of the array by optimizing the operating voltage. The converter is built to be both efficient and reliable. The power mosfets are derated to ensure a long life and reduce overall losses. A high chopping frequency minimizes the ripple voltage, ripple current and harmonic motor losses. An over-temperature cut out is built into the converter to turn it off if the motor remains stalled for a prolonged period of time. Table 3.1 summarizes the device specifications. 3.2 Circuit Description The voltage tracking converter approximates a maximum power tracking converter by fixing the array voltage at a point considered optimum. This design is based on a circuit developed and tested by Dr. W.G. Dunford and Dr. P. Ward. The logic adjusts the duty cycle of the power mosfets according to the value of the array voltage. If the voltage is too high the duty cycle is increased to bring the voltage down and vice versa. The circuit diagram is detailed in Figure 3.5. 18 Chapter 3. Voltage Tracking Converter 19 CY LJ 'CY Lu L> 21 O O CJ o o CJ o i — CO z: o u (Y O l — O C y z: ! + A CS ISJ — CY CY Figure 3.5: Circuit Diagram of the Voltage Tracking Converter Chapter 3. Voltage Tracking Converter 20 Table 3.2: Voltage Tracking Converter Specifications. Electrical Specifications: Power Rating 2.0kW Efficiency @ 2kW 0.90 Input Operating Voltage 75V - 250V Input Current up to 12A Output Voltage 30V - 240V Continuous Output Current 14A Peak Output Current 24A Chopping Frequency 20kIIz Operating ambient temperature —10°C to +55°C Relative humidity 0 to 100% Automatic thermal shutdown External shutdown through a normally open switch contact 3.2.1 Basic Operation The logic senses the array voltage via an adjustable resistive voltage divider. This signal is inverted via an LM358 inverting operational amplifier which pivots around a 3.1V reference with a gain of minus one. The resultant signal is amplified by the internal opamp of the NE5561 PWM with a gain of minus 100 to form the reference voltage which determines the duty cycle. One volt corresponds to a 0% duty cycle while 5V corresponds to a 98% duty cycle. The chopping frequency is set by the RC oscillator of the NE5561 to approximately 20kIIz. The chopped output of the NE5561 PWM is buffered and then used as the gate drive signal. Chapter 3. Voltage Tracking Converter 21 3.2.2 Gate Drive A 4041 buffer is placed between the 5561 PWM chip and the gate drive. The comple-mentary NFET-PFET pair which forms the gate drive requires a little more switching current than the PWM can provide. Also the extra buffer helps to isolate the PWM from the power supply. A resistor is placed in series with the positive supply of the complementary NFET-PFET pair to limit the amount of gate current which can be supplied. This slows down the switching speed of the mosfets and limits the reverse recovery current through the devices. The series resistor should be between 290 and 470 to be effective. There is no problem switching the mosfets off as fast as possible, so it is not necessary to place resistance in the ground line of the complementary FET pair. 3.2.3 Overcurrent Protection Cycle by cycle overcurrent protection is provided by feeding a voltage signal propor-tional to the current through the mosfets to pin 6 of the NE5561. If this voltage rises above 0.6V the NE5561 output is forced high and turns off the mosfets for the remain-der of the cycle. This current signal is derived from the voltage across the mosfets. A resistive voltage divider feeds a portion of the mosfets on-state voltage to the NE5561. The high off-state voltage is ignored by switching on an NPN transistor, effectively shorting the segment of the voltage divider that provides the current signal. 3.2.4 Thermal Protection The internal temperature of the converter is monitored with the aid of a thermistor. If the temperature rises beyond the limit as indicated by the 6.2V reference zener diode the converter will be shut down. Hysteresis is built around the operational amplifier, Chapter 3. Voltage Tracking Converter 22 acting as a comparator, to give the converter time to cool down before the converter is restarted. Resistance values for the N T C l , R l l , R15, and R22 are chosen such that the converter is shut down at 85°C and restarted at 65°C. The sealed box which encloses the converter forms part of the heatsink so that in the steady state the internal temperature will approximately equal the temperature of the heatsinks. Also resistors and integrated circuits mounted on the printed circuit board itself produce heat that should raise the operating temperature slightly above the heatsink temperature. All electronic components must be rated to operate in an ambient temperature of up to 85°C. The mosfets, diode and capacitor are rated to operate at this high temperature. However, all the integrated circuits used in the prototype were not. The LM358 operational amplifier should be replaced with an LM258 opamp and the NE5561 P W M should be replaced with the SE5561 P W M . These devices are rated for use over a wider temperature range and are only moderately more expensive. 3.2.5 P r o t e c t i o n Some extra components have been added to the circuit to protect the power devices: • Two pairs of two zener diodes in series have been placed in parallel with the power mosfets to protect against overvoltages caused by any stray circuit inductance. Two pairs are used instead of one to maintain circuit symmetry. Two zeners are placed in series in each branch to form a high enough voltage rating. • A O.lf! resistor is placed between source and ground of each power mosfet. This small resistance enhances the current sharing capabilities of the mosfets during switching thereby minimizing the effects of varying device current gains. Chapter 3. Voltage Tracking Converter 23 • A 16V zener diode is placed across the power supply. If the resistors provide more logic current than required, then the excess current is is bled off by the zener diode. 3.3 Testing and Results To simulate a solar array source a variable DC source was used in series with a variable resistance. This would produce a linear voltage, current curve rather than the humped curve of Figure 1.1. This setup is however adequate to demonstrate the operation of the converter. 3.3.1 Waveforms The converter was first tested with a load made up of a 11.5mH inductor in series with a variable resistance. The converter was run at various input voltages ranging between 50V and 250V and with input currents between OA and 12A. Output voltages ranged between 0V to 200V and output currents between OA to 24A. The drain to source voltage waveform is displayed in Figure 3.6. A voltage spike is evident during turn off. This is due to stray circuit inductance which is impossible to completely eliminate. The magnitude of the spike is approximately 70V and can easily be tolerated as the mosfets are rated 150V higher than the maximum input voltage. A magnified view of this spike is shown in Figure 3.7. It is seen here as a damped sinusoid with a natural frequency of 40MHz. The mosfets are protected with zener diodes which should clamp the voltage appearing across them at 350V. Even at conditions of maximum input voltage and peak output current the voltage spike across the mosfets did not approach the 350V limit. The voltage across the mosfets drops very rapidly, even though the rise of the gate Chapter 3. Voltage Tracking Converter 24 Figure 3.6: Drain-to-Source Voltage \\ 1 N : 200V VOUT : 123V 50V/div. I ,„ : 7.7A lour • 12.1A 10.0/is/div. Chapter 3. Voltage Tracking Converter 25 VIN : 202V IiN : 7.52A YOVT • 125V I O U T : 11.95A 50V/div. 0.05/iis/div. Chapter 3. Voltage Tracking Converter 26 Figure 3.8: Gate-to-Source Voltage with the Drain-to-Source Voltage Top trace Gate to source voltage: 5V/div 2.0^s/div. Bottom trace.... Drain to source voltage: 50V/div 2.0/is/div. WIN • 200V WOVT : 35V I/* : 1.7A lour : 9.3A voltage is limited by a series resistor . The drain to source voltage together with the gate voltage is shown in Figure 3.8. The gate voltage takes approximately 0.5/xs to rise to near its' peak value, however the drain to source voltage falls so rapidly that it appears instantaneous. There is a delay of about 0.15/us from the instant that the gate voltage starts to rise and the drain to source voltage falls. This is because the drain to source voltage is constrained to remain high until the mosfets are conducting the full load current. The rate at which current through the F E T can rise is limited by the current gain of the device during switching. Limiting the gate current therefore limits the rate of rise of the current through the mosfet. This slows down the switching process and limits the peak recovery current through the device. Chapter 3. Voltage Tracking Converter 27 The signal used by the PWM to measure the current through the mosfets is shown in Figure 3.9. The displayed signal is turning off the mosfets on a cycle by cycle basis as the voltage exceeds the threshold level. The level at which the overcurrent protection engages is determined by the relative resistance values of R32, R33, and R34 in the voltage divider of Figure 3.5. The PWM only samples the current signal when the mosfets are turned on. The signal voltage during the mosfets off-state is ignored even though it may be higher than the cutoff threshold value. Also during the switching intervals a considerable amount of noise is present in the current signal. However, the operation of the overcurrent detector is not adversely effected. Figure 3.9 shows the current signal dipping down when the mosfets are first turned on. The signal grows as stray circuit capacitance is charged up through the resistive divider network. When the voltage builds up to the internal reference level of the NE5561, the mosfets are shut off creating the noise spikes visible on the waveform. The shorting transistor, Q2, is turned on when the mosfets are turned off preventing the current signal from going excessively high. The over-temperature protection was tested by operating the device with a peak load current for a prolonged period of time. The converter shut itself off when the internal temperature reached approximately 85DC and automatically restarted when the temperature cooled to 65\"C. The slow-start circuitry on the NE5561 and the overcurrent protection prevented excessive current from flowing through the converter as it was restarted. Chapter 3. Voltage Tracking Converter 28 Figure 3.9: Current Signal VJN : 223V VOVT • 84V 20mV/div. lIN : 7.1A lour • 18.5A lO^s/div. Chapter 3. Voltage Tracking Converter 29 Figure 3.10: Experimental Set-up 3.3.2 Efficiency The converter was also tested by driving a 2.5hp DC motor which in turn drove an induction machine operating as a generator. The generator supplied power to a resistive three-phase load. The generator load could be adjusted in order to vary the loading of the DC machine. Figure 3.10 shows the experimental set up. No problems were experienced by the converter driving the DC machine. The overcurrent protection operated successfully during machine start up and the starting torque was easily overcome. Measurements made to determine the converter efficiency are displayed in Table 3.3. The peak efficiency of the converter is about 96% which exceeds the design specifications. Chapter 3. Voltage Tracking Converter 30 Table 3.3: Converter Efficiency Duty Input Input Input Output Output Output Efficiency. Cycle Voltage Current Power Voltage Current Power n Resistive and inductive load: 0% 15mA 180V 2.7W OA 0V OW 0 14% 198.5V 1.4A 278W 30.0 V 6.8A 204 W 0.734 28% 199.8V 3.55A 709.3W 55V 12.2A 671W 0.946 40% 201.5V 7.3A 1471W 80V 18A 1440W 0.978 9.3% 200.2V 0.22A 44W 18.3V 1.9A 34.8W 0.789 25% 200.5V 1.3A 261W 49V 5.1A 250W 0.958 47% 201.5V 4.57 A 921W 93.5V 9.5A 888W 0.964 66% 204V 8.95A 1826W 133V 13.25A 1762W 0.965 71% 205V 10.0A 2050W 141V 14.0A 1974W 0.963 76% 206.5V 4.44A 917W 155V 5.7A 883W 0.963 90% 208V 6.4A 1331W 187V 6.97A 1303W 0.979 95% 209V 7.4A 1547W 202V 7.53A 1521W 0.983 Speed Input Input Input Output Output Output Efficiency r/min Voltage Current PoWer Voltage Current PoWer DC Motor load: 1000 141V 4.45A 627W 98.5V 6.1A 601W 0.958 1000 141V 5.18A 730W 99V 7.1A 703W 0.962 1000 141.5V 7.59A 1074W 98V 10.5A 1029W 0.958 1500 190.8V 2.14A 408W 137V 2.74A 375W 0.920 1500 191.2V 3.60 A 688W 138V 4.75A 655W 0.952 1500 192.1V 5.89 A 1131W 142V 7.68A 1090W 0.964 1500 200V 9.1A 1820W 145V 11.86A 1720W 0.945 2000 215.6V 2.45A 528W 188V 2.18A 410W 0.776 2000 216V 3.21A 693W 187V 3.6A 673W 0.971 2000 242.8V 4.1A 995 W 185V 5.0A 925W 0.929 2000 246V 6.85A 1685W 186 V 8.42A 1566W 0.929 2000 248.6V 9.46A 2352W 187V 12.1A 2262W 0.962 Chapter 4 Maximum Power Tracking Converter A true maximum power point controller that will automatically adjust to different input conditions is described in this chapter. This converter is designed to operate at power levels of up to one kilowatt and was tested using the facilities at B.C. Hydro-Research, Surrey, B.C. 4.1 The Logic Circuit The control circuit illustrated in the block diagram of Figure 4.11 provides true max-imum power point tracking. The controller adjusts the conversion ratio to maximize the array voltage and current product. The array voltage is sampled directly using a resistive voltage divider. The array current, however, is derived from the voltage across the mosfet. During its on state, the mosfet appears as a resistive element. The average on state voltage is proportional to the current through the device which is in turn proportional to the steady state array current. Changes in the mosfet resistance with temperature are unimportant as only relative changes in the current signal are of interest and not its absolute value. The average array current and voltage signals are multiplied using an analog mul-tiplier to produce an output power signal. A low frequency (3 Hz.) clock latches the power level into the sample and hold unit. The controller then changes the conversion ratio of the DC to DC converter. At the end of the cycle the instantaneous power level is compared with the sampled power level. 31 er 4. Maximum Power Tracking Converter Mosfet ««s Got i ng SIgnoI Pulse Vidth Modulo t or Ronp Generotor Flip Flop Mu11 i pIier Sonple ond Hold Conporotor Low Frequency Clock Figure 4.11: Block Diagram of Maximum Power Point Tracking Circuit Chapter 4. Maximum Power Tracking Converter 33 If the power level has increased, another change is made to the conversion ratio in the same direction. If the power level has decreased, the change in the conversion ratio is made in the opposite direction. When the converter is first switched on, the conversion ratio is set to its minimum value and climbs the hill to the value corresponding to the maximum power point. In the steady state, the duty cycle toggles around this optimum value. Two sets of low frequency timing pulses are required to synchronize the controller. Both pulses are very short, approximately 10/xs, with the second pulse immediately following the first. The first pulse is logically anded with the power level comparator output and then used as the clock input to a JK flip-flop. When the power level is decreasing, the comparator output goes high, allowing the timing pulse to propagate through to the flip-flop, causing its outputs to toggle. The complementary flip-flop outputs are each logically anded with the second timing pulse. One of the resulting signals has its polarity reversed. Once every cycle, there is either a positive or negative pulse generated, depending on the state of the flip flop outputs. These positive and negative pulses are then integrated and scaled to form the input of a pulse width modulator. As the pulses are narrow, the duty cycle is changed quickly at the beginning of each cycle. For the rest of the cycle the duty cycle is held constant while the motor and control circuit transients decay. The instantaneous power signal then represents a steady state value and a true comparison can be made with the last sampled power level. Some additional features include over-current protection which is provided on a cycle by cycle basis. If the measured current signal rises above a threshold level, a flip flop is set, turning off the power mosfet. The next gating signal resets the flip flop Chapter 4. Maximum Power Tracking Converter 34 allowing the power mosfet to be turned on again. The converter is also capable of being shut down if the motor overheats. The temperature signal provided by the DC motor can disable the gating signal as it switches from an open to a short circuit, or vice versa. 4.2 Results The hydraulic test equipment consisted of a 200-litre storage tank in which various Mono progressive cavity pumps could be inserted. The pump is discharged into a pressure tank regulated by a back pressure sustaining valve. By adjusting the pressure, well depths ranging between 10 to 65 meters can be simulated. Water from the pressure tank is discharged back into the storage tank. The power output of the pump is calculated by multiplying the water flow rate with the back pressure. The electrical system consisted of the panels, converter and motor. The photovoltaic array consisted of two parallel strings of 11 panels, producing a maximum power of 770 watts and nominal voltage of 165 V. The array was kindly supplied by British Columbia Hydro and Power Authority, Research and Development Division, which also provided laboratory space. Power from the array was routed through the DC - DC converter to a Brot 1.1 kW permanent magnet DC motor which directly coupled to the Mono pump. The system was tested at various insolation levels and well depths. The greatest system losses occur during the conversion of sunlight to electricity, which proceeds at an efficiency of 0.083. A large loss is inevitable due to the physics of the conversion process. The converter successfully altered the conversion ratio to track the maximum power point of the array for most light conditions. Figure 4.12 displays the power developed Chapter 4. Maximum Power Tracking Converter BOO 35 i i i i i i i i I i i i i i i i i i | i i i i i i i i i | i i i i i i i i i 300 500 700 900 1100 Solar radiat ion ( w a t t s / m 2 ) Figure 4.12: Array Power vs. Solar Radiation Level by the array for various levels of solar radiation. The converter was also able to deliver enough current to develop the required starting torque at all simulated well depths. The efficiency of the converter, as calculated by the output converter power divided by input array power (as shown in Figure 4.13), ranged from 0.75 to 0.91 with an average of 0.84. Losses were incurred in the power mosfets, the freewheeling diode and the logic power supply. The voltage tracking converter of Chapter 3 turned out to be slightly more efficient because it used six parallel power mosfets of a similar rating to the two used here. Also the voltage tracking converter used a more efficient power supply. The Brot permanent magnet DC motor operated with an average efficiency of 0.82. The efficiency ranged from 0.78 to 0.87 and tended to increase with motor speed as shown in Figure 4.14. Harmonic motor losses were small as the ripple current was kept Chapter 4. Maximum Power Tracking Converter 36 100 c O i_ d> Q. 90 • • o c |o c o o 80 L X H D 3 5 0 kPa head C O 0 0 O 4 5 0 kPa head HXMKK 545 kPa head 70 60 | i i i i i i i i i | i i i i i i i i i | i i—r 500 1000 1500 Motor speed (r/min) n—i—i—i—r 2000 Figure 4.13: Converter Efficiency Chapter 4. Maximum Power Tracking Converter 37 100 v_ O 90 c 0) o a o 80 c ' o 70 + i l I I I I 350 kPa head COD00 450 kPa head x x x x x 545 kPa head DE 60 I i i i i i i i i ' I ' ' 1 ' 1 1 ' ' 1 ' ' ' 500 1000 1500 Motor speed (r/min) i i i 2000 Figure 4.14: Motor Efficiency Chapter 4. Maximum Power Tracking Converter 38 below 0.1A at the 20kHz chopping frequency. The efficiency of the Mono pump also increased with speed up to approximately 1600 r/min as shown in Figure 4.14. Both the increased mechanical vibrations in the driveshaft and the increased hydraulic resistance at larger flow rates reduce the pump efficiency at higher speeds. 4.3 Constant Voltage vs. Maximum Power Tracking A simpler constant voltage tracking converter could perform many of the same func-tions as the maximum power tracking converter described in this chapter. It does not, however, provide the flexibility of the maximum power tracking system. The volt-age tracking converter must be carefully adjusted at each individual installation while the maximum power tracking circuit automatically determines the optimum operating point. It also tracks the changes to this optimum operating point as the ambient tem-perature and insolation levels change with the time of day and the seasons. A small increase in the power extracted from the array (possibly 5%) is multiplied to form an even greater overall efficiency as the power converter, motor and pump all operate with a greater efficiency at higher speeds and power levels. The maximum power tracking system may, however, have difficulty tracking fast changes in the insolation level. The converter assumes a constant or slowly varying insolation level. Changes in the observed power levels are assumed to be the result of a change to the conversion ratio, and not the result of a change in the insolation level. Normally, insolation levels change slowly and the converter is able to accurately track the maximum power point. However, occasionally weather conditions will cause rapid transitions in the light levels. It senses the changing power levels and attributes it to the last conversion ratio change. The conversion ratio then drifts away from the Chapter 4. Maximum Power Tracking Converter optimum value until the insolation level stabilizes. Chapter 5 Microprocessor Based Hybrid Control There are certain merits to using either a voltage tracking or a maximum power tracking control scheme. A voltage tracker has a simple control algorithm that is not affected by fast variations in insolation levels. A power tracker is self adjusting and can optimize the output of the array as the characteristics of the photovoltaic panels change with temperature and time. A hybrid power tracking, voltage tracking converter retains the advantages of both control schemes. When the converter is first turned on, it enters the power tracking mode. The voltage corresponding to the maximum power point is located and retained. The converter then switches to the voltage tracking mode where the array voltage is held constant. Periodically the power tracking mode is reentered to make fine adjustments to the optimum operating voltage. An analogue control circuit which could perform all of these functions would be quite complex. However, a digital implementation of this control scheme using a single chip microprocessor is feasible. Most of the logic functions can be implemented in software resulting in a low chip count. The system is flexible and additional functions can be incorporated to handle faults or special conditions as more sophisticated software is developed. 40 Chapter 5. Microprocessor Based Hybrid Control 41 5.1 Logic Circuit The majority of the control logic is handled by the Motorola MC68HC11 single chip microcomputer. It reads the photovoltaic array voltage and current signals, keeps track of timing, regulates the duty cycle and outputs a pulse-width-modulated waveform. Some external logic is required to support the MC68HC11 and to drive the power mosfets. Figure 5.15 displays the circuit diagram of the external logic and gate drive chips. 5.1.1 MC68HC11 Single Chip Microprocessor The MC68IIC11 incorporates the following features which make it possible to perform these multiple tasks: • An 8-bit central processing unit, CPU, containing two internal 16-bit index reg-isters, X and Y, one 16-bit stack pointer, S, a 16-bit program counter, two 8-bit accumulators,A and B, and a condition code register, CC. The two 8-bit accumu-lators can be concatenated into one 16-bit register, D. The CPU can be operated with a full 64K bytes of external memory or in the single chip mode. In this application the single chip mode of operation is selected. • There are 8K bytes of read only memory, ROM, available to store the resident program and also 512 bytes of EPROM and 256 bytes of RAM to store variables and constants. • A 16-bit free-running timer is available for use by the program. The external lines associated with the timer are attached to port A. Some timer features used in this application include: er 5. Microprocessor Based Hybrid Control VA cc A PA6 PBI 0C2 ON A A 0C3 0C4 PA5 PA4 of? NOS PBC C^C NCS A NCS ' 15V Vcc CLR2 D2 CIKZ PR2 OJ 05 7474 DUAL D nIP-FLOP CLR1 01 CLkl PR I 0) 5T I T PE2 A/D 0 luf SENSE PIN<-KELVIN G N 0 < -CAIE SIGNAL G Vcc = 5V PAO. PA6: MC68HC!1 I /O P o r t P i n s NQS: N o m a I 1 y Dpen S w i t c h PBO PB6: MC68HC11 I /D P o r t P i n s NCS: N o m a 1 1 y C l o s e d S w i t c h P E O . . P E 3 : MC68HC1I A / D Input P i n s Figure 5.15: External Logic Circuit er 5. Microprocessor Based Hybrid Control 43 — Five output compare registers attached to external pins PA3 through PA7. The voltage levels on these pins can be forced high or low, when the free-running timer count equals the number stored in the corresponding compare register. Interrupt requests can be optionally generated upon a successful output compare. — A periodic real time interrupt can be generated at various rates. This inter-rupt can be used to update a real time clock. — Some other features include a pulse accumulator, which can count external events or be used as the external timer clock, and an input capture register which can hold the timer count when a transition is sensed on an external pin. There are two eight-bit general purpose ports, B and C, available. Port C can be used for input or output while port B is strictly an output port. Ports A, D, and E, which are set aside for the timer, A/D converter, and communications interface can also be used as general purpose I/O ports when the special functions attached to these ports are not being used. A Serial Peripheral Interface, SPI, and Serial Communications Interface, SCI, are built into the chip and connected to port D. These interfaces are used to communicate with peripheral devices or external systems and have various modes of operation. An eight-bit analogue-to-digital, A /D, converter is included with four, or in some packages eight, input channels and connected to port E. The input channels can be individually selected or all four channels can be read consecutively. The conversions can take place continuously or under program control. Chapter 5. Microprocessor Based Hybrid Control 44 • Two non-maskable and fifteen maskable interrupt sources are possible. The inter-rupts obey a fixed hardware priority structure to resolve simultaneous requests. However, the priority of a maskable interrupt source can be raised under program control. Maskable interrupts are disabled by setting the Enable bit of the CC register. Internally generated interrupt requests also have a local mask. Each in-terrupt source has a corresponding interrupt vector containing the address of the interrupt routine. The CPU responds to an active request by saving the register state on the stack, setting the enable bit, and jumping to the address indicated by the interrupt vector. The power requirements of the MC68IIC11 are modest making it attractive for high efficiency, low power applications. It requires 20mA at 5V in the run mode, and even less in the special wait or stop modes. 5.1.2 Current Sensing A current signal is derived with the aid of a current sensing power mosfet. This device has identical characteristics to the regular power mosfets, except the source of a few transistor cells are isolated and connected to a separate external pin. Under ideal con-ditions, the current diverted to the current sense pin would be the ratio of the number of isolated cells to the total number of parallel cells in the power device. A separate Kelvin source pin is provided to increase the accuracy of the current measurement. This pin is internally connected to the source of the power device and does not share the metalization, bonding wire, and pin resistance with the external source pin. A virtual earth sensing circuit is used to amplify the current signal. This method is superior to a resistor sensing circuit in terms of speed, accuracy and noise immunity. However, the resultant signal is inverted and a second operational amplifier is required Chapter 5. Microprocessor Based Hybrid Control 45 to produce a signal of the correct sign. This current signal is suitable to be used as a reference for the cycle by cycle overcurrent protection. The current waveform is filtered to provide the A /D input pin, PE2, with a signal proportional to the average current through the power mosfets. In the steady state this signal is also proportional to the current provided by the supply. 5.1.3 Overcurrent Protection Cycle by cycle overcurrent protection is necessary when using a chopper to drive a variable impedance load such as a DC motor. During start up the motor may draw large currents to overcome static friction and inertia. The protection must respond quickly to be effective. The protection operates by comparing the instantaneous current signal to a refer-ence voltage level. If the current signal exceeds the reference, the LM311 comparator output toggles low, which in turn asynchronously latches the output of a D flip-flop low. When low, this flip-flop output turns off the power mosfets. At the start of the next cycle, the flip-flop clock input is strobed, resetting the output, which enables the power mosfets to be turned on once more. If the current signal again exceeds the reference, the power mosfets are switched off and the process is repeated. During an overcurrent fault the duty cycle of the chopper is governed by the over-current hardware and not the main logic program. The microprocessor therefore needs to be flagged when an overcurrent condition occurs. This is achieved with the aid of a second D flip-flop. The overcurrent signal is attached to the clear pin of this flip-flop to latch the output low. This output forces the STRA pin low, which in turn, is capable of generating an interrupt request. The output also forces bit 0 of port C low, which can be polled to determine if the overcurrent condition persists. The flip-flop clock line, bit 2 of port B, must be strobed to reset the flip-flop. Chapter 5. Microprocessor Based Hybrid Control 46 5.1.4 Voltage Sensing A portion of the input voltage to the chopper is sampled by the A /D converter via a resistive voltage divider. A potentiometer adjusts the sampled voltage to just be-low 5 V under open circuit conditions to utilize the full scale of the A /D converter. This manually adjusted potentiometer could be replaced with a digitally controlled potentiometer, such as the Xicor X9MME, for complete automation of the adjustment process. 5.1.5 Pulse Width Modulation The conventional means of creating a pulse-width-modulated waveform is with a PWM IC such as the NE5561. The frequency is fixed by an R,C oscillator while the pulse width is dependent on the input voltage level. When a digital controller is used, a D/A conversion is necessary to arrive at an analogue input voltage to the PWM. Yet the gating signal is basically a digital waveform. The D /A conversion is necessary because the digital processor is limited. It cannot toggle an output port bit fast or accurately enough to create a pulse-width-modulated waveform at a useful frequency. It may be possible, however, to create the waveform with the aid of external timers. The logic circuit would then become more complex and costly. What is gained by eliminating the D /A converter and PWM chip is offset by the additional timers. The MC68HC11 however has an on-board timer. A pulse-width-modulated wave-form can be created with the aid of only limited additional hardware in the following manner: The timer is free running and counts from 0 through to FFFF continuously. At-tached to the timer are five output compare registers O C l through OC5. Registers Chapter 5. Microprocessor Based Hybrid Control 47 0C2 through 0C5 are attached to the output port bits PA6 through PA3 respectively. Register OC1 can be attached to PA7 and it can also affect the output state of PA6 through PA 3. When a number loaded into one of the compare registers equals the timer count, a specified action will occur. For example, when the timer count equals the number contained in the OC2 register, PA6 can be forced high, or low, or be made to toggle, depending on the control register settings. An interrupt request can also be generated upon a successful compare. Compare register O C l is special. It can affect all output port bits associated with the compare registers simultaneously. The change called for by O C l will override a change called for by any other output compare register in the event of a conflict. A pulse-width-modulated waveform can be created at the output of pin PA6 by using O C l to set the pin high and by using OC2 to reset the pin low. The compare registers would be updated each cycle by responding to an interrupt request generated by an O C l successful compare. The processor would add a number representing the period to each compare register within the interrupt routine. The number contained in register OC2 would be offset from the number in O C l by the on time. In this scheme the on time must be long enough for the processor to respond to the interrupt request and update register OC2 ruling out the use of a small duty cycle. It is possible to use a full range of duty cycles by switching interrupt sources. When the duty cycle is greater than 50% O C l could generate interrupt requests as already explained. When the duty cycle is less than 50% interrupt requests could be generated by successful OC2 comparisons. Switching interrupt sources must be done with care to ensure a smooth transition. The maximum frequency of the generated waveform is limited by the speed of the CPU. Before it can respond to an interrupt request the CPU must complete the present Chapter 5. Microprocessor Based Hybrid Control 48 instruction, save the register state, and load the address of the interrupt routine into the program counter. Once in the interrupt routine, the CPU must update the next compare register before the timer count runs past it. These processes may take up to 37 machine cycles or 18.5/xs and must be completed within one half of a period of the pulse width modulated waveform. Updating the next compare register, clearing the interrupt request and returning to the interrupted task will take another 35 machine cycles. The maximum frequency is therefore limited to about 25kIIz. At an operating frequency of 25kIIz there would be very little free time for the CPU to service other procedures. Only one or two instructions could be executed between interrupt requests. Also the adjustment to the pulse width would be coarse. The minimum adjustment to the pulse width is a 0.5/LJS step, so at 25kHz there are only 80 steps between a 0% and 100% duty cycle. It is possible to free up CPU time and effectively decrease the step size by creating three output waveforms instead of one. These waveforms are combined in a set of external NAND gates to produce a single waveform at twice the frequency. A set of these waveforms are displayed in Figure 5.16. The waveforms produced at pins PA5 and PA4 are NANDED together. The output is then NANDED together with the waveform produced at pin PA6 to produce the resultant waveform shown in Figure 5.16. The waveform at pin PA5 remains at a 50% duty cycle while the waveforms at PA6 and PA4 are adjustable. By adjusting the waveforms at PA6 and PA4 separately the duty cycle resolution is effectively doubled. For example if the period is 50/xs and the on time of the first pulse stream is 18.0/us while the on time of the second pulse stream is 18.5/Lts the effective duty cycle is 36.5%. The duty cycle is adjustable in 0.5% steps instead of 1.0% steps, which would be the limit with a single pulse stream. With some additional NAND gates a full range of duty cycles from 0% to 100% is Chapter 5. Microprocessor Based Hybrid Control 5 . 0 -CN O O 0 . 0 5 . 0 -O O 0 . 0 H* 5 . 0 o o 0 . 0 5 . 0 Z ) Q_ I— ZD O 0C4 0C4 0 . 0 — i i i i i i i i i—i i i i i i i i i—i i i i i i i i i—i i i i i i i i i 0 5 0 1 0 0 Time (LIS) 1 5 0 2 0 0 Figure 5.16: Pulse Width Modulated Waveforms Chapter 5. Microprocessor Based Hybrid Control 50 possible, unlike conventional PWM chips, which are capable only of duty cycles between 0% and 98%. Bit one of port A is wired to the input of one NAND gate and dedicated to turning the converter fully off when low, while bit two is wired to the input of a second NAND gate and dedicated to turning the converter on. Figure 5.15 shows the detailed circuit diagram. Addition NAND gate inputs are used to externally switch the converter off. When turned fully off or on the pulse width modulation continues at a minimum or maximum duty cycle. This simplifies the restart process as timer synchronization within the program is never lost. 5.1.6 Gate Drive The gates of the three parallel power mosfets are driven by a DS0026 dual inverting buffer. This device can deliver a large peak current, 1.5A, to rapidly switch the power mosfets. A series resistance of 33fi is inserted between each power mosfet and the gate to limit the switching speed and prevent oscillations between parallel devices. 5.2 Program The main function of the logic program is to alternate between the maximum power and voltage tracking modes of operation. Various sub-tasks must be coordinated for the main program to successfully operate. 5.2.1 Maximum Power Tracking The program begins in the maximum power tracking mode and periodically reenters it. In this mode a search is made for the optimum operating point and the voltage corresponding to this point is recorded. Chapter 5. Microprocessor Based Hybrid Control 51 Initially the converter is turned fully off. The open circuit voltage is read together with the DC offset, if any, in the current measurement hardware. The duty cycle is then slowly increased in steps of approximately 5%. After each change to the duty cycle a delay of two seconds is introduced to allow system transients to decay. The voltage and current signals are sampled at each step and the operating power calculated. A record of the last three power and operating voltage levels are kept for future reference. The present power level is compared with previous power levels. If the measured power is increasing the duty cycle is again changed in the same direction. If, however, the power level has twice decreased, the direction of the search is reversed. The direc-tion of the search will also reverse if the converter reaches the limit of being turned either fully on or fully off. Each time the direction of the search is changed, the maxi-mum recorded operating power and corresponding voltage level of the latest sweep are recorded in an array. Also, the amount the on time is changed between samples is reduced for a finer gradient search. Once enough sweeps past the maximum power point have been made, presently 12, the power tracking mode is discontinued. A search is made for the highest recorded six power levels. The voltages corresponding to these power levels is then averaged and passed on to the voltage tracking routine. After a period of time, half an hour, the power tracking mode is reentered. The principle of sweeping past the maximum power point is maintained. This time, however, the search for the maximum power point originates at the present duty cycle rather than starting from a fully off position. 5.2.2 Voltage Tracking The controller enters the voltage tracking mode after the power tracking routine has de-termined the optimum operating voltage. The voltage is held constant by periodically, Chapter 5. Microprocessor Based Hybrid Control 52 ten times a second, comparing the operating voltage to the reference. An adjustment to the duty cycle is made to compensate for the difference between the optimum and measured voltage, AV. To calculate the magnitude of the change in the on time, AtoN, a simplified model will be used. The photovoltaic array will be modeled by a voltage source, Vs, with an internal resistance, Rs- The DC machine will be represented by a resistor and an inductor. The converter, by altering the duty cycle, adjusts the effective resistance of the load, REFF> as seen by the source. This system with a simple resistive and inductive load is shown in Figure 5.17 and Figure 5.18. The voltage at the terminals of the source, VA, is: VA = Vs - RSIS (5.16) where Is is the source current. Substituting Is = h • *-f (5.17) into Equation 5.16, where II is the load current and T is the period yields: VA = VS- Rsh— (5-18) Assume the converter is operating near the maximum power point. Then it can be shown for the simple resistive and inductive load modeled here that £.Iu = 0. Also if one considers the constant torque Mono pump as the load, then Ii is constant for most operating conditions. In any case, for the purpose of approximating the derivative of Equation 5.18 near the maximum power point, II shall be considered constant. Therefore: Chapter 5. Microprocessor Based Hybrid Control S o u r c e Res i s t once © I dea I Vo 1 t age S o u r c e -Q-Ar r a y C o n n e c t ion Lo J T T T I DC Mach i ne Figure 5.17: Simplified Power Circuit S o u r c e Res Is t a n c e © I dea I V o I t age S o u r c e E F F e c t i v e / L o a d / R Res i s t o n c e / EFF A r r a y C o n n e c t i on Figure 5.18: Equivalent Power Circuit Chapter 5. Microprocessor Based Hybrid Control 54 AVA = Rsh AtON T AVAT A W = ~-^r (5.19) From the maximum power transfer theorem, it is known that R$ = REFF a t the maximum power point. Therefore: Rs = REFF = ^r- (5.20) is Substituting Equations 5.20 and 5.17 into Equation 5.19 yields: AtON = - ^ O N . ( 5 . 2 1 ) All the quantities on the right hand side of Equation 5.21 are either known, can be measured, or can be easily calculated. The magnitude of the change in the on time, Alow, is therefore easily determined. Some of the assumptions made in the above equations may be either crude or do not hold true away from the maximum power point. The actual system contains a non-linear source impedance, and the usual equivalent circuit of a DC machine includes a back electromotive force, EMF, which is proportional to the machine speed. However, it is standard practice to linearize a non-linear system around an operating point. Also it is valid to lump the back EMF of the DC machine into an equivalent resistance, if the current through the machine is constant. In any case, there are no strict constraints on the performance of the control system. All that is necessary is that the operating voltage be held constant and that the system remain stable. These criteria are easily met by this control scheme. Chapter 5. Microprocessor Based Hybrid Control 55 5.2.3 Interrupts The hardware arbitrated priority structure of the MC68HC11 assists in coordinating the various tasks. At any time three interrupt requests are active. One to service the pulse width modulation routine, one to service the real time clock, and one to service the overcurrent routine. The main program receives the lowest priority and can be interrupted at any time. Timing within the main program is coarse, and not critical, so that interrupt requests can be easily serviced without interfering with the logical flow of the program. • Pulse Width Modulation The routine servicing the pulse width modulation interrupt receives the highest priority. This is achieved by appropriately setting the HPRIO, highest priority I interrupt register. It is critical that the output compare registers be updated before the timer count exceeds the updated compare register count. Otherwise gate voltage transitions will be lost and the power mosfets will be turned either, off or on for a prolonged period of time. An interrupt routine can only be serviced after the CPU has completed the present instruction. To reduce the maximum response time to an interrupt request, a wait instruction, WAI, is placed before each instruction which requires a long time to complete. The wait instruction saves the register state and halts the program execution until an interrupt request is received. In this way the longer instructions, such as divide, FDIV, and multiply, MUL, are executed just after the interrupt routine has been serviced and it is very unlikely that another interrupt request would be generated while these instructions are being executed. • Overcurrent Protection Chapter 5. Microprocessor Based Hybrid Control 56 The routine which services the overcurrent interrupt request receives the next highest priority. Response time to this routine is not critical as the hardware detector protects the power mosfets. This routine serves the purpose of clearing the fault and acknowledging its receipt. First the routine calls for a delay and then checks to see if the fault persists. If the fault persists the duty cycle is reduced, another delay is called for, and the overcurrent input line is read. This procedure continues until the fault is at last cleared. Before returning to the main program a flag bit is set to signal that an overcurrent fault has occurred. This flag bit is checked each time an increase in the duty cycle is called for. If the flag bit is set, an overcurrent counter is incremented before clearing the flag and increasing the duty cycle. If the overcurrent counter indicates a persistent fault, ie. more than six faults have occurred in a given period, then the converter is shut down for a period of half an hour. • Real Time Clock It is convenient to use a real time clock to synchronize events within the program. Delays ranging from a fraction of a second to several days can be handled with the aid of a real time clock. The clock is derived from the free running timer. As the timer overflows an interrupt request is generated. The interrupt service routine is then able to update the time of day node by a fraction of a second. The second, minute, hour and day counters are appropriately updated as required. More details as to the updating process are given in the program listing. To create a delay, the program must first access a timer node. The delay is added Chapter 5. Microprocessor Based Hybrid Control 57 to the time of day and the result is placed in the timer node. The timer node is periodically compared with the time of day until they match. The delayed procedure is then executed. Several delays can be handled simultaneously. Timer nodes may be sequentially tested until a match is found. The procedure associated with the matched node is then executed and the timer node released. This timer coordination is handled by the program. To handle a more complex coordination problem a special operating system could be written. However this is beyond the scope of this project. 5.2.4 Changing the Duty Cycle Although it is possible to make large, sudden changes to the duty cycle, it is more desirable to make changes slowly and smoothly. In this way large transient currents, due to the filter capacitor discharging, are avoided. In any case the motor together with the pump have a large inertia and cannot change speed quickly. The subroutine CHANGE ramps up or down the duty cycle in small steps. A minimal change, 0.5/tts, is made to one of the two sets of pulse streams in each step. The pulse width modulation process then continues for several cycles before the next small change is made. The pulse width is changed again until either the desired value is reached or the converter is turned fully on or off. 5.3 Results The program is able to handle the multiple simultaneous tasks well. The pulse width modulation process continues without interruption, the maximum power point is lo-cated within 1% of the optimum value, and the voltage tracking routine is both accurate and stable. Chapter 5. Microprocessor Based Hybrid Control 58 5.3.1 Voltage Waveform The drain-to-source voltage waveform is displayed in Figure 5.19. There is some ringing evident as the power mosfets switched off, but this is not important as the peak voltage is not very high. A magnified view of the drain-to-source voltage as the converter is switched off is displayed in Figure 5.20 while the drain-to-source voltage during turn-on is displayed in Figure 5.21. In both cases the switching is fast and the peak voltage is not significantly higher than the input terminal voltage. 5.3.2 Current and Voltage Measurements The accuracy of the power tracking routine is only as accurate as the voltage and current measurements made by the microprocessor, as the power level is calculated from this voltage-current product. The load current and voltage are also calculated from the supply current and voltage . The accuracy of the current, voltage and power measurements are verified by com-paring the values obtained by the microprocessor with actual measurements. Each measurement is taken with a fixed duty cycle, supply voltage, and load impedance. To obtain several data points the duty cycle is varied, while the other variables are held constant. Measurements made by the microprocessor are compared with the measure-ments obtained from the voltage and current meters. The signal read by the microprocessor is not calibrated, but in this application this is not important as only the relative current signal is of interest. All that is required is that an increase in the supply current be accompanied by a proportionate increase in the measured current. However, if it were required, it would not be difficult to calibrate the current and voltage signals. The instantaneous current signal through the power mosfets is shown in Figure 5.22. Chapter 5. Microprocessor Based Hybrid Control 59 Figure 5.19: Drain-to-Source Voltage Waveform V I N : 145V VOUT • H I V 20V/div. lIN : 4.9A IOVT • 6.1A lO.Oms/div. Apart from the ringing as the devices are first switched on the signal is an accurate representation of the current. The ringing, induced by the drain-to-source capacitance of the isolated current sensing cells, is removed by a low pass filter. The signal, shown in Figure 5.23, is then suitable to be used for the cycle-by-cycle overcurrent protection. Figure 5.24 displays the filtered current signal when the overcurrent protection is active. The supply current measured by the A/D converter is compared with the meter-measured current in Figure 5.25. The linear relationship between the two methods of measuring current is evident, even though the temperature of the power mosfets is changing as the current through the device increases. The load current is derived by the microprocessor by dividing the supply current by the duty cycle. The measured load current is compared with the derived load current Chapter 5. Microprocessor Based Hybrid Control 60 Figure 5.20: Drain-to-Source Voltage Waveform at Turn-off YIN • 145V Y O U T : 111V 20V/div. I/A, : 4.9A lOUT : 6.1A 0.02/its/div. Chapter 5. Microprocessor Based Hybrid Control 61 Figure 5.21: Drain-to-Source Voltage Waveform at Turn-on V / J V : 145V VOUT • H I V 20V/div. lIN : 4.9A IQVT • 6.1A 0.02/is/div. Chapter 5. Microprocessor Based Hybrid Control 62 Figure 5.22: HEXSense Current Waveform V/JV : 145V VQUT • 90.7V lV/div. I/JV : 6.37A I o t / r : 9.4A lO.Oms/div. Chapter 5. Microprocessor Based Hybrid Control 63 Figure 5.23: Filtered HEXSense Current Waveform VJJV : 145V VOVT • 90.7V lV/div. 1IN : 6.37A lour • 9.4A lO.Oms/div. Chapter 5. Microprocessor Based Hybrid Control 64 Figure 5.24: Current Waveform with Active Overcurrent Protection V/JV : 232V I/Tv : 2.6A V0UT : 52.9V lour • 10.4A l V / d i v . lO.Oms/div. Chapter 5. Microprocessor Based Hybrid Control 65 in Figure 5.25. The calculated load current is accurate within a few percent except when the duty cycle is very small. The point on the load current curve of Figure 5.25 with a significant error is calculated at a 2% duty cycle, where a quantization error in the supply current is magnified 50 times when the load is calculated. The supply voltage measured by the microprocessor is compared with the supply voltage read from a voltmeter in Figure 5.26. The calculated and measured load volt-ages are also displayed. It is evident that both the calculated load voltage and the supply voltage measurements obtained by the microprocessor are accurate. The bump that is observed in the region between the load and supply voltage measurements is due to losses in the converter which are unaccounted for in the computation of the load voltage. Other small discrepancies are due to fluctuations in the supply voltage. The power calculated by the microprocessor is compared with the measured input and output power in Figure 5.27. The measured power is the product of the measured voltage and current. There is a good correspondence between the two methods of measuring the power. There is a slight difference between the input power and the power delivered to the load. The difference between these two curves is the converter losses. There are also inaccuracies in the measurements due to the meters and variations in the supply voltage. 5.3.3 Maximum Power Point The controller attempts to maximize the power delivered to the load. To test the accu-racy of the power tracker the following test circuit was constructed: A stiff, adjustable DC source was derived from the rectified output of a three-phase variac. The source impedance of the photovoltaic array is simulated by an adjustable power resistor. The source resistance remains fixed for any given set of measurements. The load is made Chapter 5. Microprocessor Based Hybrid Control 66 M e a s u r e d C u r r e n t ( A m p s ) Figure 5.25: Microprocessor Current Measurements vs Metered Current Measurements Chapter 5. Microprocessor Based Hybrid Control •67 Figure 5.26: Microprocessor Voltage Measurements vs Metered Voltage Measurements Chapter 5. Microprocessor Based Hybrid Control 68 co 'E Z5 o c CD $ O Q_ X) CD i_ 13 CO D CD O CO CO CD U O Q_ O u 15000 10000 5000 0 Load power x x x x x Array power X » XX X * X X • » w x < X » X • X X X • X • X • X * X * X • X « X * X • X « x x . # ~i i i i i i i i i I i i i i | m i i i i i i i I r 0 100 200 300 400 500 M e a s u r e d P o w e r (Wa t t s ) Figure 5.27: Calculated Power vs Metered Power Chapter 5. Microprocessor Based Hybrid Control 69 600 -i 400 H 2 0 0 Input Power x x x x x Load Vol tage * * * * * Load Current 60 50 h-40 h 3 0 20 10 r 10 co > Cn O \"o > O O 0 | i i—i—i—i—i—i—i—i—|—i—i—i—i—i—i—i i i | r~i i 0 0 40 8 0 8 co Q . 6 E < h-4 c cu CJ \"a o o L 0 Duty Cycle (percent) Figure 5.28: Power, Load Current, and Load Voltage vs Duty Cycle Chapter 5. Microprocessor Based Hybrid Control 70 up of a 11.5mH inductor in series with an adjustable power resistor which also remains fixed for a given set of measurements. From the maximum power transfer theorem it is known that the load and source resistance should be equal at the maximum power point. Note that the effective load appears resistive to the source as both the voltage and current into the chopper are DC. The voltage at the terminals of the chopper will be half the source voltage when the effective load resistance equals the source resistance. The accuracy of the power tracking system is therefore tested by running the test circuit with various loads and open circuit voltages. These conditions are recorded and if the power tracker is accurate the voltage level at the terminals of the chopper will settle to one half the source voltage. The test results are summarized in Table 5.3.3. The maximum power point is located within 1.0% in all cases and within 0.5% in most cases. The operating voltage which the converter settles upon is located within a few volts of the optimum value. Near the maximum power point the power delivered to the load changes only slightly as the operating voltage is varied. Figure 5.28 displays how the input power, load voltage and load current change as the duty cycle is varied from 2% to 98%. The load current and load voltage curves are quite flat near the peak, which occurs at the same point as the peak on the power curve. As a final test the converter is set up to run a DC machine which in turn drives an induction generator. The same stiff DC source together with a series power resistor is used to simulate a photovoltaic array. The test results were encouraging. The starting torque is easily overcome, the maximum power point is located within 1.0% and the voltage tracking is stable and accurate. The converter meets all requirements. Chapter 5. Microprocessor Based Hybrid Control 71 Table 5.4: Power Tracking Results Open Maximum Power Circuit Operating Input Load Output Efficiency Input Tracking Voltage Voltage Power Voltage Power n Power Error 120 V 55.7V 202 W 42.3V 192W 95% 203 W 0.49% 120 V 57.8V 202 W 29.8V 186W 92.1% 202W 0.0 150V 71.4V 307W 52.3V 294 W 95.8% 310W 0.97% 151V 71.5V 309W 42.8V 290W 93.9% 311W 0.64% 175V 88.7V 257W 65.9V 247W 96.1% 258W 0.39% 175.8V 91V 406W 60.3 V 386W 95.1% 410W 0.98% 175.8V 88.1V 410W 49.3V 384W 93.6% 410W 0.0 201V 101V 530W 62.1V 500W 94.3% 530W 0.0 201V 98.6V 335W 75.4V 323W 96.4% 335W 0.0 201V 96V 532W 69.1V 505W 94.9% 532W 0.0 225V 109.7V 659W 76.4V 640W 97.1% 660W 0.15% 225.6V 104V 414W 60.6 V 386W 93.2% 415W 0.24% 225V 109.7V 659W 76.4V 640 W 97.1% 660W 0.15% 250V 117V 511W 93.5V 492W 96.3% 512W 0.20% 251V 123V 518W 72.7 V 492 W 95.0% 520W 0.38% 250.6V 125V 512W 66.0V 475W 92.8% 512W 0.0 300V 144V 731W 112.4V 710W 97.1% 735W 0.54% 304V 144V 940W 127.7V 910W 96.8% 942 W 0.21% 301V 146V 925W 90.9V 870W 94.0% 930W 0.54% Chapter 6 Conclusions The amount of water delivered by a photovoltaic powered pumping system can be maximized with the aid of a one quadrant DC to DC converter. The converter is capable of matching the combined motor-pump characteristics to the characteristics of the photovoltaic array for maximum power transfer under most lighting conditions. Three schemes of controlling the DC to DC converter are presented. The simplest control scheme involves fixing the photovoltaic array voltage at some manually set reference level. Close to maximum power is delivered to the load under most insolation levels and the control scheme is stable, even under fluctuating lighting conditions. Only a simple analogue circuit is required. A true power tracking control scheme can also be used to maximize the power output of the DC to DC converter. This controller finds and maintains the best operating point automatically at the expense of a more complex logic circuit. Maximum power output will be maintained, even if the photovoltaic array characteristics drift with temperature and age. Maximizing the output is important because the photovoltaic panels are expensive. A small increase in the power delivered to the load will result in an even greater increase in overall efficiency, as both the pump and DC motor operate more efficiently at higher speeds and power levels. One drawback is that the controller can temporarily drift away from the optimum operating point if the insolation levels are fluctuating. To maintain the advantages of both the power tracking and the voltage tracking 72 Chapter 6. Conclusions 73 control schemes a microprocessor based hybrid scheme is developed. A single chip mi-crocomputer provides most of the logic functions of the controller when used with only a few external chips. During the power tracking mode, the optimum operating point is automatically located and adjusted. Many data points are sampled and averaged to increase the accuracy of the search. The majority of the time is spent in the voltage tracking mode. In this mode the array voltage is held constant even as the insolation levels fluctuate. These basic functions have been implemented and tested. But perhaps the most important advantage of the microprocessor based control scheme is its flexibility. More sophisticated features can be added with little or no increase in the complexity of the hardware. For instance, it should be possible to identify a dry well and quickly shut down the converter preventing a catastrophic failure. This feature, although easily implemented, was not incorporated due to inadequate test facilities. Another possibility is that the microprocessor based system could act as a data logger, keeping a record of the power level, motor voltage and current, ambient tem-perature, etc., for future reference and study. This information, along with any fault alarms, could conceivably be transmitted to a central location to be recorded and speed the detection and repair of faulty equipment. The extra cost involved in developing and manufacturing the microprocessor based system would be justified by the extra flexibility and protection the system would provide. Appendix A Assembly Language Program ORG $00 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Hybrid Power Tracking, Voltage Tracking Controller * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This assembly language program i s targeted for the Motorola * MC68HC11A8 HCMOS single-chip microcomputer. J t^ 5 ^ SJ^ t^fi ^ l(C 5 ^ iff ^ 5^ )|c J^S 3J£ 3f* 5JC 5fc i k )|i *^ ^ 5k- *^ 3J< ^ #Jc J^C 5f< J^c 3 ^ )|c 5jc 3 ^ 3 ^ 5J< S^C 3 | C 5 | C - ^ 5 f c 5 | i s ( c 5 ^ ^ t 5 ^ 3 | i 5 ^ * This program controls the pulse width of the gating pulses applied to the gates of a set of p a r a l l e l power mosfets. The controller has two modes of operation. In the power tracking mode the duty cycle i s slowly increased from i t s minimum value in a search for the maximum power point. Once this point has been found the voltage tracking mode i s entered. In this mode the operating i s held steady at the value corresponding to the maximum power point. * * Label some memory locations to hold useful variables PERIOD RMB 2 0NCNT1 RMB 2 0FCNT1 RMB 2 0NCNT2 RMB 2 0FCNT2 RMB 2 STEP RMB 1 FLG RMB 1 MAXCUR RMB 1 OPEN RMB 1 Memory location to hold the period. Memory location to hold the ON count one. Memory location to hold the OFF count one. Memory location to hold the ON count two. Memory location to hold the OFF count two. Define a user f l a g register. Register to hold the short c i r c u i t current. Register to hold the open c i r c u i t voltage. 74 Appendix A. Assembly Language Program 75 CURR RMB 1 Reg i s t e r to hold the opera t i n g c u r r e n t . MOTCUR RMB 2 Reg i s t e r to hold the load c u r r e n t . VOLT RMB 1 Re g i s t e r to hold the operating v o l t a g e . MOTVLT RMB 1 Re g i s t e r t o hold the average l o a d v o l t a g e . POWER RMB 2 Reg i s t e r to hold the operating power. PWRMAX RMB 2 Reg i s t e r to hold the maximum op e r a t i n g power. OFFSET RMB 1 Re g i s t e r to hold the current o f f s e t . CORECT RMB 1 Reg i s t e r t o hold the current c o r r e c t i o n f a c t o r . MAXVLT RMB 1 Maximum power voltage. COUNT RMB 1 Reserve a space f o r a counter. TEMP RMB 2 Define a space f o r a temporary v a r i a b l e . TEMP 2 RMB 1 TMPVT1 RMB 1 TMPVT2 * RMB 1 * * Label memory l o c a t i o n s to h o l d the timer v a r i a b l e s . T-FRCSEC RMB 2 Holds the f r a c t i o n of a second count. SECOND RMB 1 The second counter. MINUTE RMB 1 The minute counter. HOUR RMB 1 The hour counter. DAY RMB 1 The day counter. TMENOD RMB 6 A 6 byte timer node. TMN0D2 RMB 6 A 6 byte timer node. * The l a s t item i s memory reserved f o r an array. * Although there i s only one byte reserved the array ARRAY RMB 1 can grow as f a r as the stack boundary. MSKOC1 EQU $80 Mask f o r the 0C1 f l a g and mask r e g i s t e r s . MSK0C2 EQU $40 Mask f o r the 0C2 f l a g and mask r e g i s t e r s . * Define the software f l a g r e g i s t e r b i t s . STRTUP EQU 1 ONGR EQU 2 UP EQU 4 DECRS EQU 8 FRST EQU $10 B i t one s i g n a l s pulse width modulation s t a r t - u p . When set , s i g n a l s the ON time i s gr e a t e r than the OFF time. When s e t , i n d i c a t e s an i n c r e a s i n g pulse width. When set , i n d i c a t e s a decreasing power l e v e l . B i t to i n d i c a t e the i n i t i a t i o n of the maximum power Appendix A. Assembly Language Program 76 * t r a c k i n g r o u t i n e . OVRCUR •J-EQU $20 Over-current f l a g b i t . Def ine some other u s e f u l constants. RDCURR EQU 1 RDVLT EQU 2 OFF EQU $01 ON EQU $02 RUN EQU $03 CLRCUR EQU $04 MIN EQU $2 DLAY EQU 1 One second delay. DELAY EQU $0600 F r a c t i o n of a second delay. * Define the I/O port l o c a t i o n s PORTA EQU $1000 I/O port A PORTB EQU $1004 I/O port B PORTC EQU $1003 I/O port C PRTCL EQU $1005 A l t e r n a t e l a t c h e d port C. DDRC EQU $1007 Data d i r e c t i o n f o r port C. PIOC EQU $1002 P a r a l l e l I/O Co n t r o l R e g i s t e r PORTD EQU $1008 I/O port D A . l M a i n P r o g r a m ORG $E000 BEGIN SEI LDS #$00FF * LDY #PORTB BCLR ,Y OFF BSET ,Y ON LDD #$0064 I n h i b i t i n t e r r u p t requests. Turn the power MOSFETS o f f . Load a number r e p r e s e n t i n g the per i o d . Appendix A. Assembly Language Program STD LSRD LSRD PERIOD Divide down the p e r i o d to form the i n i t i a l step s i z e t o perturb the pulse width. * * LOOP * L0P1 LSRD STAB STEP LSRD ADDB STEP STAB STEP Set up the overcurrent d e t e c t o r . JSR OCRSET CLRB STD PWRMAX I n i t i a l i z e the A/D converter. BSR ADSET I n i t i a l i z e the timer. BSR TIMER CLI Enable the i n t e r r u p t system. Determine the open c i r c u i t voltage and o f f s e t c u r r e n t . JSR ADJOPN Fi n d the maximum power p o i n t . JSR MAXPWR Place the converter i n the voltage t r a c k i n g mode. CLR COUNT Cl e a r the counter which records the number overcurrent i n c i d e n t s . LDX #TMEN0D Clear the timer node. JSR CLRTME LDAB #30 Add 30 minutes to the time. STAB JSR 3.X ADDTME Appendix A. Assembly Language Program 78 L0P2 * L0P2A L0P2B L0P3 JSR VLTRAK C a l l the voltage t r a c k i n g r o u t i n e . Test f o r overcurrent and branch i f c l e a r . BRCLR FLG OVRCUR L0P2B This s e c t i o n i s entered i f an overcurrent f a u l t has been detected LDAA COUNT INCA Increment the overcurrent counter. BCLR FLG OVRCUR C l e a r the overcurrent f l a g . CMPA #7 BNE L0P2A JMP OVRDLY E x i t i f the number of overcurrent occurrences STAA COUNT PSHX Save the timer node address. LDX #TMN0D2 JSR CLRTME Cl e a r the new timer node. LDD #DELAY Add a f r a c t i o n of a second to the time STD .X of day and place the r e s u l t i n the timer node JSR ADDTME JSR CMPTME Compare the timer node to the current time. TSTA BNE L0P3 Loop i f time i s not up. PULX Restore the f i r s t timer node address. JSR CMPTME Compare to the current time. TSTA BNE L0P2 Loop again i f time i s not up. Adjust the maximum power t r a c k i n g v o l t a g e . LDD PERIOD LSRD LSRD Redefine the step s i z e . LSRD STAB STEP BRA LOOP Fi n d the maximum power p o i n t again. = 7. A.2 A / D Converter Set-Up Appendix A. Assembly Language Program * *********************************************** * * SUBROUTINE ADSET * * Subroutine ADSET sets up the A/D converter t o read i n data * from a l l f o u r data l i n e s under program c o n t r o l . * * INPUT and OUTPUT: NONE * * REGISTERS EFFECTED: The CC and A r e g i s t e r . **************************************************************** * * * Define some memory l o c a t i o n s a s s o c i a t e d with the A/D * converter. * ADCTL EQU $1030 A/D Con t r o l / S t a t u s r e g i s t e r . OPTION EQU $1039 C o n f i g u r a t i o n options r e g i s t e r . ADR1 EQU $1031 A/D Result r e g i s t e r 1. ADR2 EQU $1032 A/D Result r e g i s t e r 2. ADR3 EQU $1033 A/D Result r e g i s t e r 3. ADR4 EQU $1034 A/D Result r e g i s t e r 4. ADDAT EQU $10 A data byte to conf i g u r e the ADCTL to read a l l * f o u r channels under program c o n t r o l . ADSET LDAA OPTION ORAA #$80 Set the A/D power up b i t i n the options reg. STAA OPTION LDAA #ADDAT Configure the A/D converter to read l i n e s one STAA ADCTL through f o u r under program c o n t r o l . RTS A.3 Timer Set-Up * * **************************************************************** * * SUBROUTINE TIMER * * Subroutine TIMER sets up the f r e e running timer. Appendix A. Assembly Language Program 80 * from a l l f o u r data l i n e s under program c o n t r o l . * * INPUT and OUTPUT: NONE * * REGISTERS EFFECTED: The CC and A r e g i s t e r . * Define some memory l o c a t i o n s a s s o c i a t e d with the timer. * TIME EQU $100E REG0C1 EQU $1016 REG0C2 EQU $1018 REG0C3 EQU $101A REG0C4 EQU $101C TMSK1 EQU $1022 TCTL1 EQU $1020 0C1M EQU $100C 0C1D EQU $100D CFORC EQU $100B TMSK2 EQU $1024 TFLG2 EQU $1025 TFLG1 EQU $1023 TIMER LDAA #$F8 STAA TCTL1 LDAA #$FF STAA 0C1M LDAA #$10 STAA 0C1D LDAA #$F8 STAA CFORC * * Set the timer r e g i s t e r s to zero. * LDX #FRCSEC JSR CLRTME LDAA TFLG2 C l e a r any pending overflow i n t e r r u p t s . STAA TFLG2 LDAA #$80 Enable the overflow i n t e r r u p t request by s e t t i n g STAA TMSK2 timer mask r e g i s t e r b i t . 16 b i t f r e e running timer address. Output compare r e g i s t e r one. Output compare r e g i s t e r two. Output compare r e g i s t e r three. Output compare r e g i s t e r f o u r . Main timer i n t e r r u p t mask r e g i s t e r 1. Timer c o n t r o l r e g i s t e r 1 address. Output compare 1 mask r e g i s t e r address. Output compare 1 data r e g i s t e r address. Timer compare f o r c e r e g i s t e r . Timer i n t e r r u p t mask r e g i s t e r 2. Timer i n t e r r u p t f l a g r e g i s t e r 2. Timer i n t e r r u p t f l a g r e g i s t e r 1. S p e c i f y the timers' mode of opera t i o n . Set the timer c o n t r o l r e g i s t e r to f o r c e 0C2 and 0C3 high, and 0C4 low a f t e r a s u c c e s s f u l compare S p e c i f y A3-A7 to be e f f e c t e d by a s u c c e s s f u l 0C1 compare i n the output compare mask r e g i s t e r . Set the compare 1 data r e g i s t e r to f o r c e 0C2.0C3 low and 0C4 high a f t e r a s u c c e s s f u l 0C1 compare. Set the timer compare f o r c e r e g i s t e r to f o r c e A3-A7 low. Appendix A. Assembly Language Program 81 LDAA #0 Set the FLG r e g i s t e r to i n d i c a t e a s t a r t up c o n d i t i o n . STAA FLG RTS A . 4 Overcurrent Initialization * * SUBROUTINE OCRSET * * * INPUT and OUTPUT: NONE * * REGISTERS EFFECTED: CC. Subroutine OCURST sets up the overcurrent d e t e c t o r . Both f l i p f l o p c l o c k s are strobed to place the d e t e c t o r i n a known s t a t e . Also i n t e r n a l r e g i s t e r s are set to r e c e i v e an overcurrent i n t e r r u p t request. OCRSET PSHX Strobe the output of PORTA to ensure overcurrent f l i p f l o p one l a t c h e s to a high value. PSHA LDAA PIOC LDAA PRTCL C l e a r any pending i n t e r r u p t f l a g s . LDX #P0RTA BCLR ,X $40 BSET .X $40 BCLR ,X $40 LDX #P0RTB BSET ,X 4 Strobe the c l o c k of overcurrent f l i p f l o p 2, BCLR ,X 4 BSET ,X 4 BCLR .X 4 Appendix A. Assembly Language Program LDAA #0 STAA DDRC LDX #PI0C BCLR ,X $2 BSET .X $40 PULA PULX RTS Set up port C as an input p o r t . A c t i v a t e an i n t e r r u p t request upon a f a l l i n g edge of STBA. Set the i n t e r r u p t enable mask. A . 5 Read Input Data ****************************************** * * SUBROUTINE READ * * Subroutine READ reads i n the data from a s i n g l e channel * of the A/D converter. The data i s read i n f o u r times and * averaged. * * INPUT: R e g i s t e r A i s input with the number of the * A/D l i n e to be read. * none * * OUTPUT: R e g i s t e r A i s returned with a value of: * 0: S u c c e s s f u l read. * -1: I l l e g a l input data. * * R e g i s t e r B i s returned with the average * of four A/D conversions. * * REGISTERS EFFECTED: A.B and CC r e g i s t e r s . **************************************************************** * READ PSHX CMPA #3 Test f o r i l l e g a l input data. BHI ERR1 PSHA LQ2 STAA ADCTL I n i t i a t e an A/D conversion process. Appendix A. Assembly Language Program LQ3 LQ3B Lq3C LQ3D Lq4 LQ5 LQ6 LQ7 LDX #ADR1 LDAA ADCTL BPL LQ3 Wait f o r v a l i d data. Test the data to ensure the four readings do not vary more than one b i t . LDAB ,X SUBB l.X BHS LQ3C NEGB CMPB #1 BLS LQ3D TSX LDAA .X BRA LQ2 INX CMPX #ADR4 BNE LQ3B Compare two readings. Form the absolute vale of the d i f f e r e n c e , If the readings vary more than one b i t . Fetch another set of readings. E l s e the two readings vary l e s s than one b i t . A l l f o r readings tested? If not, t e s t the next p a i r . Add the f o u r A/D conversion r e s u l t s and average them. Average the four readings. PULA CLRA STAA TEMP2 LDAB ADR1 ADDB ADR2 BCC LQ4 INCA ADDB ADR3 BCC LQ5 INCA ADDB ADR4 BCC LQ6 INCA LSRD BCC LQ7 INC TEMP2 LSRD BCC LQ8 INC TEMP2 Divi d e the r e s u l t by two. Divide by two again. Appendix A. Assembly Language Program 84 LQ8 LDAA #1 Check i f both d i s c a r d e d b i t s from the averag ing SUBA TEMP2 process were s e t . BCC LQ9 If so increment the r e s u l t . INCB LQ9 CLRA S i g n a l a s u c c e s s f u l A/D c o n v e r s i o n . PULX RTS ERR1 LDAA #$FF S i g n a l i l l e g a l input d a t a . CLRB PULX RTS A.6 Adjust the Pulse Width * SUBROUTINE ADJST * * Subrout ine ADJST a d j u s t s the pu l se width of the modulated * output v o l t a g e waveform. The waveform i s updated two pu l se s * at a time and the width of each of these two p u l s e s can be * s e p a r a t e l y a d j u s t e d . * * ASSUMPTION: * The ON times input f o r the two pu l se t r a i n s i s v a l i d and * s t r i c t l y l e s s than the p e r i o d . * * INPUT: * 1) The FLG r e g i s t e r i s set to i n d i c a t e which * compare l i n e a c t i v a t e s an i n t e r r u p t r e q u e s t . * a) FLG b i t 0 = zero i m p l i e s the waveform * has not yet been s t a r t e d . * b) FLG b i t 1 = 1 i m p l i e s the ON time i s * g r e a t e r than the OFF time and OCl i s c u r r e n t l y * g e n e r a t i n g i n t e r r u p t requests upon a s u c c e s s f u l * compare. * c) FLG b i t 1 = 0 i m p l i e s the OFF time i s * g r e a t e r than the ON time and 0C2 i s c u r r e n t l y * g e n e r a t i n g i n t e r r u p t reques t s upon a s u c c e s s f u l * compare. Appendix A. Assembly Language Program 85 * * 2) The ON time of the f i r s t pulse i s input v i a * the D r e g i s t e r . * 3) The ON time of the second pulse i s input v i a * the X r e g i s t e r . * 4) The p e r i o d of the waveform i s contained i n the * memory l o c a t i o n PERIOD. * * OUTPUT: * The pulse width s u i t a b l y modified and the FLG r e g i s t e r * s u i t a b l y s e t . * REGISTERS EFFECTED: CC * .J- si. sT. sL. si. vL- sl> sis si* *X* *ls st* \\l* \\t* sL> »X* st* sly >L> sL> xl* ^ ^ ^ ^ ^ ^ ^ ^ ^ & ^ \\L» \\1» J/ ^ ^ ^ ^ ^ ^ ^ ^ ^ Jtf ^ ^ it ^ ^ ^ ^ i Jtf J*Jtf^ ^^ fcJ*Jtfj£*kj£jtfJ^ ^ JfC Jfs J^ yx ^ •ji ^ ^ 7ft ^ •p. 'T' *T\" 'T* *T* 'T* \"T* *T\" *^ \"T* 'T' *T* *T* *T* *T* ^ *r\" -T\" 'Ts 'T* \"T* \"T^ *T* *T* 'T* 'T* 'T^ *T* 'T' 'T^ ^ ^ T1 \"T\" 'T* *T* 'T' *T* \"T\" *1* vr* *T* \"T* *T* \"T^ *T* *r* * * Define some constants. Highest p r i o r i t y I i n t e r r u p t r e g i s t e r address. Data byte used to set 0C1 as the highest p r i o r i t y . Data byte used t o set 0C2 as the highest p r i o r i t y . Save the ON time f o r pulse two. Save the ON time f o r pulse one. Branch i f the pulse t r a i n has not yet been s t a r t e d . BRCLR FLG 1 START Test b i t 2 of FLG to see i f the ON time i s gre a t e r * Branch i f OFF > ON. BRCLR FLG 2 OFFGR HPRIO EQU $103C HP0C1 EQU $8 HP0C2 EQU $9 ADJST PSHY PSHX PSHB PSHA This program s e c t i o n i s entered when the FLG r e g i s t e r i n d i c a t e s t h a t the ON time was p r e v i o u s l y g r e a t e r than the OFF time. Determine whether the new on or o f f time i s g r e a t e r . * I f the on time i s l a r g e r , there i s no need to change the i n t e r r u p t source. I f the o f f time i s now l a r g e r the i n t e r r u p t source * must be changed to 0C2. Appendix A. Assembly Language Program 86 XGDX Place the ON time for pulse two in D reg. TSX ADDD ,X Add the ON time for pulse one. SUBD PERIOD Branch i f the sum of the ON times is less than BCS 0C2SEL the period. LDD PERIOD SUBD ,X Calculate the new OFF time for pulse one. XGDY Save the OFF time in the Y register. LDD PERIOD Calculate the OFF time for pulse two. SUBD 2,X WAI SEI Disable interrupts while updating the ON and STY 0FCNT1 OFF registers. STD 0FCNT2 LDD ,X STD 0NCNT1 Save the ON time for pulse one. LDD 2.X STD 0NCNT2 Save the ON time for pulse two. CLI Enable interrupts PULA PULB Restore the register state. PULX PULY RTS * * This program section is entered i f the current ON time is greater * than the OFF time and the new OFF time is greater than the new * ON time. * LDD PERIOD SUBD .X Calculate the new OFF time for pulse one. XGDY Save the OFF time in the Y register. LDD PERIOD Calculate the OFF time for pulse two. SUBD 2.X PULX Load the ON time for pulse 1. WAI SEI Disable interrupts while updating the ON and STY 0FCNT1 OFF registers. STD 0FCNT2 STX 0NCNT1 Save the ON time for pulse one. PULX STX 0NCNT2 Save the ON time for pulse two. Appendix A. Assembly Language Program 87 LDD REG0C1 Prepare to change the 0C2 compare r e g i s t e r to account ADDD 0NCNT1 f o r the new pulse width. LDX #TFLG1 LQ10 BRCLR ,X MSK0C2 LQ10 Mark time u n t i l 0C2 changes. STD REG0C2 Set the 0C2 b i t of the timer i n t e r r u p t mask r e g i s t e r to s e l e c t an i n t e r r u p t request upon a successful 0C2 compare. Raise 0C2 to the highest p r i o r i t y i n t e r r u p t request. LDAA #MSK0C2 STAA TMSK1 LDAA #HP0C2 STAA HPRIO LDAA TFLG1 STAA TFLG1 CLI Clear any pending i n t e r r u p t requests Enable i n t e r r u p t s Set the FLG r e g i s t e r to show the OFF time i s BCLR FLG ONGR greater than the ON time. LDD LDX PULY RTS 0NCNT1 0NCNT2 Restore the r e g i s t e r state START BRA STRT This program section i s entered when the FLG r e g i s t e r i n d i c a t e s that the OFF time was previously greater than the ON time. Determine whether the new on or off time i s greater. If the off time i s l a r g e r , there i s no need to change the in t e r r u p t source. If the on time i s now larger the i n t e r r u p t source must be changed to OCl. XGDX Place the ON time f o r pulse two i n D reg. TSX ADDD ,x Add the ON time f o r pulse one. SUBD PERIOD Branch i f the sum of the ON times i s le s s than BCC 0C1SEL the period. LDD PERIOD SUBD .X Calculate the new OFF time f o r pulse one. XGDY Save the OFF time i n the Y r e g i s t e r . LDD PERIOD Calculate the OFF time f o r pulse two SUBD 2,X Appendix A. Assembly Language Program 88 WAI SEI Disable interrupts while updating STY 0FCNT1 OFF registers. STD 0FCNT2 LDD .X STD 0NCNT1 Save the ON time for pulse one. LDD 2,X STD 0NCNT2 Save the ON time for pulse two. CLI Enable interrupts PULA PULB Restore the register state. PULX PULY RTS * * 0C1SEL TSX LDD SUBD XGDY LDD This program section is entered i f the current OFF time is greater than the ON time and the new ON time is greater than the new OFF time. PERIOD .X PERIOD SUBD 2,X WAI SEI STY STD LDD STD LDD STD 0FCNT1 0FCNT2 .X 0NCNT1 2.X 0NCNT2 Calculate the new OFF time for pulse one, Save the OFF time in the Y register. Calculate the OFF time for pulse two. Disable interrupts while updating the ON and OFF registers. Save the ON time for pulse one. Save the ON time for pulse two. LDAA #MSK0C1 Set the 0C1 bit of the timer interrupt mask register STAA TMSK1 to select an interrupt request upon a successful 0C1 compare. LDAA TFLG1 Clear any pending interrupt requests. STAA TFLG1 LDAA #HP0C1 Raise 0C1 to the highest priority interrupt request. STAA HPRIO CLI Enable interrupts BSET FLG ONGR Set the FLG register to show the ON time is Appendix A. Assembly Language Program 89 PULA gre a t e r than the o f f time. PULB Restore the r e g i s t e r s t a t e . PULX PULY RTS * * T h i s next program s e c t i o n i s entered only during s t a r t up. STRT LDD PERIOD C a l c u l a t e and store the ON and OFF times. TSX SUBD .X STD 0FCNT1 LDD ,x STD 0NCNT1 INX INX LDD PERIOD SUBD .X STD 0FCNT2 LDD *x STD 0NCNT2 * * Determine whether the on or o f f time i s gr e a t e r . * If the on time i s l a r g e r s e l e c t 0C1 to generate i n t e r r u p t * requests and i n i t i a l i z e the compare r e g i s t e r s i n the appropriate * order. * Otherwise s e l e c t 0C2 s u c c e s s f u l comparisons to generate * i n t e r r u p t requests and choose the appropriate order to * i n i t i a l i z e the compare r e g i s t e r s . ADDD 0NCNT1 Add the two ON times together. SUBD PERIOD BCS SEL0C2 Branch i f the OFF time i s grea t e r than the ON time. LDAA #MSK0C1 Set the 0C1 b i t of the timer i n t e r r u p t mask r e g i s t e r STAA TMSK1 to s e l e c t an i n t e r r u p t request upon a s u c c e s s f u l * 0C1 compare. BSET FLG ONGR Set the FLG r e g i s t e r t o show the ON time i s * g r e a t e r than the OFF time. LDD 0NCNT1 STD REG0C2 Store the on time i n the output compare 2 r e g i s t e r . ADDD 0FCNT1 STD REG0C3 Store the r e s u l t i n the output compare 3 r e g i s t e r . Appendix A. Assembly Language Program 90 ADDD STD ADDD STD * LDAA STAA BRA SEL0C2 LDAA STAA 0NCNT2 REG0C4 0FCNT2 REG0C1 #HP0C1 HPRIO ENABLE #MSK0C2 TMSK1 Store the double p e r i o d i n the output compare 1 reg. Raise OCl to the highest p r i o r i t y i n t e r r u p t . Set the 0C2 b i t of the timer i n t e r r u p t mask r e g i s t e r to s e l e c t an i n t e r r u p t request upon a s u c c e s s f u l 0C2 compare. BCLR FLG ONGR Set the FLG r e g i s t e r to show the OFF time i s great e r than the ON time. S t a r t up the timer sequence. Store the number i n the compare r e g i s t e r 3. Store the r e s u l t i n the compare r e g i s t e r 4. Store the number used by the compare reg. 1. Store the number used by the compare reg. 2. Raise 0C2 to r e c e i v e the highest p r i o r i t y . LDD 0FCNT1 STD REG0C3 ADDD 0NCNT2 STD REG0C4 ADDD 0FCNT2 STD REG0C1 ADDD 0NCNT1 STD REG0C2 LDAA #HP0C2 STAA HPRIO ENABLE CLI BSET PULA PULB PULX PULY RTS Enable the i n t e r r u p t system. FLG STRTUP Set the FLG r e g i s t e r to show s t a r t u p has occurred. Restore the r e g i s t e r s t a t e . A.7 Real Time Timer ****************************************** * * REAL TIME TIMER * ************************************************************************* * Appendix A. Assembly Language Program 91 on The r e a l time timer w i l l monitor the time i n days, hours, minutes seconds, and f r a c t i o n s of a second. Tasks can then be scheduled accord i n g to the time of day or delayed f o r some s p e c i f i e d time p e r i o d as r e q u i r e d . The timer w i l l be d r i v e n by the \"overflow\" i n t e r r u p t request which i s assigned a lower p r i o r i t y than the \"output compare\" i n t e r r u p t request. An overflow occurs once every 2 to the power of 16 clock c y c l e s , the c l o c k r a t e being two megahertz. Each time the processor i s i n t e r r u p t e d the 16 b i t \" f r a c t i o n of a second\" r e g i s t e r i s updated. This r e g i s t e r i s then compared t o a number r e p r e s e n t i n g one second. If the f r a c t i o n of a second r e g i s t e r i s l a r g e enough The number re p r e s e n t i n g one second i s subtracted from i t and the \"second\" r e g i s t e r incremented. I f 60 seconds have elapsed the \"minute\" r e g i s t e r i s incremented and so In b i n a r y 2,000,000 i s 0001 1110 1000 0100 1000 000. This i s the number which should be subtracted from the f r a c t i o n of a second r e g i s t e r once i t i s l a r g e enough. I t i s however unnecessary t o keep a re c o r d of the l a s t seven zeros. S h i f t e d seven places the number becomes 0011 1101 0000 1001 and once every i n t e r r u p t p e r i o d 0000 0010 0000 0000 w i l l be added to t h i s 16 b i t f r a c t i o n of a second r e g i s t e r . Declare some constants MAXSM MAXHR CNTSEC INCFRC EQU 60 The maximum number of seconds or minutes. EQU 24 The maximum number of hours. EQU $3D09 The number r e p r e s e n t i n g one second. EQU $0200 The number added to the f r a c t i o n of a second r e g i s t e r each i n t e r r u p t p e r i o d . A.7.1 Time of Day Interrupt Service TIME OF DAY INTERRUPT SERVICE TMINTR LDAA TFLG2 Clea r the i n t e r r u p t request. Appendix A. Assembly Language Program 92 STAA TFLG2 CLI LDD FRCSEC ADDD #INCFRC CPD #CNTSEC BCC INCSEC STD FRCSEC RTI SUBD #CNTSEC STD FRCSEC BSR INCTME RTI Enable the i n t e r r u p t system. Increment the count by one time p e r i o d . Subtract the count r e p r e s e n t i n g one second. Save the f r a c t i o n of a second count. Add back the count r e p r e s e n t i n g one second. Save the f r a c t i o n of a second count. A.7.2 Increment The Time of Day ************************************************************************** * SUBROUTINE INCTME *************************************** * * Subroutine INCTME increments the time of day counter * by one second. * * The time of day i s d i v i d e d i n t o days, hours, minutes and seconds. * INCTME INC SECOND LDAA SECOND SUBA #MAXSM BEQ INCMIN RTS INCMIN STAA SECOND INC MINUTE LDAA MINUTE SUBA #MAXSM BEQ INCHR RTS INCHR STAA MINUTE INC HOUR LDAA HOUR Increment the hour counter. Appendix A. Assembly Language Program 93 SUBA #MAXHR Check i f the count has reached 24. BEQ INCDAY RTS INCDAY STAA HOUR Reset the hour counter to zero. INC DAY RTS A.7.3 A d d Time ****************************************** * * SUBROUTINE ADDTME ************************************************************************* * This subroutine adds a time increment t o the current time as s p e c i f i e d i n the time of day r e g i s t e r . INPUT: A p o i n t e r to the node c o n t a i n i n g the time increment OUTPUT: The time increment added to the time of day i n the time node pointed to by the X r e g i s t e r . REGISTERS EFFECTED: D.CC ************************************************************************ * D i s a b l e the time of day i n t e r r u p t . ADDTME CLRA STAA TMSK2 LDD ,X ADDD FRCSEC LP1 LP2 * Fetch the f r a c t i o n of a second increment. Add the f r a c t i o n of a second p o r t i o n of the time of day. SUBD #CNTSEC Determine i f there i s an overflow and the second counter needs to be updated. BCC LP1 If yes, branch. ADDD #CNTSEC Restore the f r a c t i o n of a second count. BRA LP2 Increment the second counter. Save the f r a c t i o n of a second p o r t i o n of the r e s u l t . Load the seconds p o r t i o n of the time increment, Add the seconds p o r t i o n of the time of day. INC 2.X STD .X LDAB 2.X ADDB SECOND Appendix A. Assembly Language Program 94 LP3 LP4 LP5 LP6 LP7 LP8 SUBB #MAXSM BCC LP3 ADDB #MAXSM BRA INC BRA INC BRA INC LP4 3.X STAB 2.X LDAB 3.X ADDB MINUTE SUBB #MAXSM BCC LP5 ADDB #MAXSM LP6 4.X STAB 3.X LDAB 4.X ADDB HOUR SUBB #MAXHR BCC LP7 ADDB #MAXHR LP8 5.X STAB 4.X LDAB 5.X ADDB DAY STAB 5.X LDAB #$80 STAB TMSK2 RTS Determine i f there i s an overflow and the minute counter needs to be updated. If yes. branch. Restore the second counter. Increment the minute counter. Save the second p o r t i o n of the r e s u l t . Load the minute p o r t i o n of the time increment. Add the minute p o r t i o n of the time of day. Determine i f there i s an overflow i n the minute counter. If yes, branch. Restore the minute counter. Increment the hour counter. Save the minute p o r t i o n of the r e s u l t . Load the hour p o r t i o n of the time increment. Add the hour p o r t i o n of the time of day. Determine i f there i s an overflow i n the hour counter. If yes, branch. Restore the hour counter. Increment the day counter. Save the hour p o r t i o n of the r e s u l t . Load the day p o r t i o n of the time increment. Add the day p o r t i o n of the time of day. Save the day p o r t i o n of the r e s u l t . An overflow i n the day counter i s not accounted f o r as t h i s counter c y c l e s back to zero when f u l l , Enable the time of day i n t e r r u p t . A.7.4 Compare Time * | c ifj J^C ^ ^ 3^C )fc ^* *|C ^ 3JC sfc -^C ^ j jc 3^ 3fc ^Jc * t * 5 J C * ^ 5 | * 4 * 4 C D | C 3 ^ * 3|C S^ C 5^ *^ ^ ^* ^ *^ ^ ' t * ' ^ ^ 3 k ^ 5 ^ ^ £ 3 f l 3 J C 2 | C 3 $ C 5 $ C * SUBROUTINE CMPTME ****************************************** * Appendix A. Assembly Language Program 95 * * * This subroutine compares the pending time contained in a timer node to the time of day. ASSUMPTION: This routine is called often enough so that that the day and hour registers of the pending time will equal the day and hour time of day registers for a successful match. INPUT: A pointer to the node containing the pending time. OUTPUT: Register A is returned with a value of: 0: The time of day is greater than or equal to the pending time. 1: The pending time is greater than the time of day. REGISTERS EFFECTED: D.CC time CLRA Disable the time of day interrupt. STAA TMSK2 LDAB DAY Load the current day. CMPB 5.X Compare the pending day. BNE RTN1 Return i f the day registers don't match. LDAB HOUR Load the current hour. CMPB 4.X Return i f the hour registers don't match. BNE RTN1 LDAB MINUTE Load the minute portion of the time. CMPB 3.X Compare to the pending time. BLO RTN1 Return i f the current time less than the pending BHI RTNO LDAB SECOND Load the second portion of the time. CMPB 2.X Compare to the pending time. BLO RTN1 Return i f the current time less than the pending time, BHI RTNO LDD FRCSEC CPD ,X BLO RTN1 Load the fraction of a second portion of the time Compare to the pending time. Return i f the current time less than the pending Appendix A. Assembly Language Program 96 time. RTNO RTN1 LDAA #$80 STAA TMSK2 CLRA RTS LDAA #$80 STAA TMSK2 LDAA #1 RTS Enable the time of day i n t e r r u p t s . The time of day i s gre a t e r than or equal to the pending time so r e t u r n with A set to zero. Enable the time of day i n t e r r u p t s . The time of day i s l e s s than the pending time so r e t u r n with r e g i s t e r A set to one. A.8 Clear Timer Node sfi s(c sfi 5(c s(c i(c 5|c s(c J4« sjc sfr !^ >(c sfj >(c jf; sft s|c 5}c sjc s(c sfi sjc sfc s(c s^c sfi 5(1 jc s(c s|c sfi sjc 3^c sfc )}c 3(t ijt s(Jc sf s^Jc s(c J(C s|c s|c sjc )(t 't- 'i- 4* 't' 'r' 4- 4^* 'f' ^ ^ ^ 5 ^ 5 ^ ^ ^ ^ ^ * SUBROUTINE CLRTME * This subroutine sets to zero the timer node p o i n t e d t o by the * address contained i n the X r e g i s t e r . * * INPUT: The address of the timer node i n the X r e g i s t e r . * OUTPUT: None. * * REGISTERS EFFECTED: D.CC * CLRTME LDD #0 STD ,X Clea r the f r a c t i o n of a second r e g i s t e r . STD 2,X C l e a r the second and minute r e g i s t e r s . STD 4,X Clea r the hour and day r e g i s t e r s . RTS Appendix A. Assembly Language Program A.9 Maximum Power Tracking 97 * SUBROUTINE MAXPWR * * This subroutine attempts to maximize the power d e l i v e r e d to the load * by a d j u s t i n g the duty c y c l e of the pulse width modulated output. * The ro u t i n e s t a r t s by c a l c u l a t i n g the power l e v e l at the present pulse * width s e t t i n g . The pulse width i s perturbed and the power l e v e l * r e c a l c u l a t e d . If the power l e v e l decreases twice the d i r e c t i o n of the * pulse width p e r t u r b a t i o n i s reversed. The peak power l e v e l and i t s ' * a s s o c i a t e d voltage l e v e l i s recorded f o r f u r t h e r r e f e r e n c e . * A number of peak power l e v e l s and t h e i r a s s o c i a t e d voltage l e v e l s * are recorded. The maximum power t r a c k i n g voltage i s then c a l c u l a t e d * by averaging the voltages corresponding to the top few of the peak * power l e v e l s . * * ASSUMPTIONS: * 1) The current s i g n a l i s t i e d to AN1 and the array voltage * s i g n a l to l i n e AN2. * 2) The load current i s approximately continuous throughout * the ON and OFF converter s t a t e s , i e . the load i s * i n d u c t i v e . * * INPUT: The i n i t i a l step s i z e by which the pulse width i s to * be i n i t i a l l y perturbed i n STEP. * * OUTPUT: * 1) The duty c y c l e i s adjusted f o r maximum power output. * 2) The voltage corresponding to the maximum power l e v e l * i s pl a c e d i n MAXVLT. * 3) The o f f s e t current i s returned i n OFFSET and the open * c i r c u i t voltage i n OPEN. * 4) The value of the maximum power l e v e l i s returned * i n MAXPWR and the maximum current reading i n MAXCUR. * * REGISTERS EFFECTED: CC * Appendix A. Assembly Language Program 98 **************************************************** * NMBR EQU 6 ARYMAX EQU 12*3+ARRAY MAXPWR PSHA PSHB PSHX PSHY CLR * LDD STD STD STD STAB LDY LDX BSET BSET * BCLR * * Enter * power * MAXLP1 PSHX * MLP1 Save the r e g i s t e r s t a t e . COUNT Clea r the counter which records the number of overcurrent i n c i d e n t s . #0 POWER Clear the v a r i a b l e s used. TEMP TMPVT1 MAXVLT #PORTB #ARRAY Load the base Array address. FLG FRST Set the b i t to i n d i c a t e the f i r s t pass. FLG UP Set the b i t to increase the pulse width. Cl e a r the b i t s i g n a l l i n g a decreasing power l e v e l . FLG DECRS the loop which perturbs the pulse width and records peak l e v e l s along with t h e i r operating voltage l e v e l s . Save the array address. C a l l f o r a delay. Load the address of a timer node. LDX #TMEN0D JSR CLRTME LDAB #DLAY STAB 2.X JSR ADDTME JSR CMPTME TSTA BNE MLP1 LDAA #RDVLT JSR READ STAB VOLT JSR CURNT STAB CURR LDAA VOLT Read i n the array v o l t a g e . Read i n the c o r r e c t e d current value C a l c u l a t e the power output. Appendix A. Assembly Language Program 99 WAI MUL PULX Retrieve the array address. * BRCLR FLG FRST MLP2 I f not the f i r s t power reading, branch. BCLR FLG FRST Clea r the f l a g b i t i n d i c a t i n g a f i r s t pass. STD POWER Save the power reading. LDAB VOLT STAB TMPVT1 Save the operating v o l t a g e . BRA MLP4 * MLP2 CPD POWER Check i f the power l e v e l i s i n c r e a s i n g . BLS MLP3 If NO, branch. * * This program s e c t i o n i s entered when the * power l e v e l i s i n c r e a s i n g . * * If the converter i s turned f u l l y ON, branch. BRCLR ,Y ON CHDIR1 * BCLR FLG DECRS Clear the decreasing power l e v e l f l a g . JSR PRUPD Update the power l e v e l s . BRSET ,Y OFF MLP4 * If the converter i s turned f u l l y o f f an e r r o r JMP BEGIN has been detected, so s t a r t again. * * T h i s program s e c t i o n i s entered when the power l e v e l * i s decreasing. * * If the power has twice decreased, branch. MLP3 BRSET FLG DECRS CHDIR2 BRCLR ,Y ON CHDIR3 I f converter turned f u l l y ON, branch. BRCLR ,Y OFF CHDIR3 If the converter i s turned f u l l y OFF, branch. BSET FLG DECRS Set the decrease f l a g . JSR PRUPD Update power l e v e l s . * * Change the pulse width * MLP4 LDAB STEP LDAA #1 Indicate an increase i n the pulse width. * Branch i f the pulse width i s to be Appendix A. Assembly Language Program 100 MLP4B BRSET FLG UP MLP4B CLRA JSR CHANGE increased. E l s e i n d i c a t e a negative change. Change the duty c y c l e . MLP4C * MLP4D CHDIR1 Test f o r overcurrent and branch i f c l e a r . BRCLR FLG OVRCUR MLP4D This s e c t i o n i s entered i f an overcurrent f a u l t has been detected. LDAA COUNT INCA Increment the overcurrent counter. BCLR FLG OVRCUR Cl e a r the overcurrent f l a g . CMPA #7 BNE MLP4C JMP OVRDLY E x i t i f the number of overcurrent occurrences = 7 STAA COUNT JMP MAXLP1 Enter the power t r a c k i n g loop again. CHDIR i s l o c a l to the maximum power r o u t i n e . CHDIR reverses the d i r e c t i o n of the maximum power search. I t a l s o p l a c e s the l a s t peak power value and i t s ' a s s o c i a t e d o p e r a t i n g voltage i n the array pointed to by the X r e g i s t e r . The array p o i n t e r i s updated and the power search i s ended a f t e r enough data p o i n t s have been c o l l e c t e d . CHDIR1 i s c a l l e d when the power l e v e l i s i n c r e a s i n g and the converter i s turned f u l l y ON. PSHA PSHB STD STD ,X POWER LDAB VOLT STAB 2.X Save the power reading i n the array. Save the a s s o c i a t e d voltage reading. BRA CHDIR4 * CHDIR2 i s c a l l e d when the power has decreased twice. CHDIR2 PSHA Appendix A. Assembly Language Program 101 PSHB LDD TEMP STD ,X Save the power reading i n the array. LDAB TMPVT2 STAB 2,X Save the a s s o c i a t e d voltage reading. BRA CHDIR4 * * CHDIR3 i s c a l l e d when the power l e v e l has decreased * once and the converter i s turned f u l l y ON. * CHDIR3 PSHA PSHB LDD POWER Save the l a s t power reading i n the STD ,X maxpower array. LDAB TMPVT1 STAB 2.X Save the a s s o c i a t e d voltage reading. * * This program s e c t i o n i s common to a l l three subroutines * which change the d i r e c t i o n of the maximum power search. * CHDIR4 PULB Retrieve the l a s t power reading. PULA STD POWER Save the l a s t power reading. LDAB VOLT STAB TMPVT1 Save the l a s t voltage reading. CLR TEMP CLR TEMP+1 CLR TMPVT2 INX Update the array p o i n t e r . INX INX CPX #ARYMAX IF enough data p o i n t s have been c o l l e c t e d . BHS EXITL1 EXIT the maximum power searching loop. Toggle the d i r e c t i o n of the maximum power search. LDAB FLG COMB ANDB #UP BEQ CHDIR5 BSET FLG UP Set the f l a g to increase the pulse width. BRA CHDIR6 Appendix A. Assembly Language Program 102 CHDIR5 CHDIR6 CHDIR7 EXITL1 MAXLP2 MAXLP3 MLP5 BCLR FLG UP Clear the f l a g so that the pulse width w i l l be decreased. BCLR FLG DECRS Clea r the f l a g which s i g n a l s one power decrease. Reduce the step s i z e . LDAB STEP LSRB Divide the step by two. CMPB #2 Compare the step to a minimum value. BHS CHDIR7 LDAB #2 STAB STEP Save the new step value. BRA MLP4 This program s e c t i o n i s entered when enough data p o i n t s have been c o l l e c t e d and i t i s time to e x i t the power search loop. CLRA CLRB PSHB Set a counter to zero. STD POWER Clear memory l o c a t i o n s . STD TEMP STD TMPVT1 LDX #ARRAY load the array base address. PSHX LDD .X Load the power l e v e l of array i t e m ( i ) . CPD POWER BLO MLP5 If power l e v e l i s the highest yet found, STD POWER Save the value of the power l e v e l and a p o i n t e r INS to i t s ' place i n the array. INS PSHX INX Update the array p o i n t e r . INX INX CPX #ARYMAX If the end of the array has not been found, BLO MAXLP3 loop again. The maximum power value has been l o c a t e d . Appendix A. Assembly Language Program 103 MLP6 MLP7 PULX LDD BNE LDD CPD BLS STD CLRA LDAB STD TMPVT1 MLP7 POWER PWRMAX MLP6 PWRMAX 2,X TMPVT1 PULB INCB PSHB CLRA LDAB 2.X ADDD TMPVT1 STD TMPVT1 LDD #0 STD POWER STD ,X PULB INCB PSHB CMPB #NMBR BLO MAXLP2 Load the p o i n t e r to the highest power l e v e l . If not the f i r s t value, branch. If t h i s i s the highest power l e v e l yet obtained, save i t . Load the a s s o c i a t e d voltage l e v e l . Save i t to add e x t r a weight to the voltage l e v e l a s s o c i a t e d with the highest power l e v e l . Increment the counter. Set the power l e v e l of the value j u s t processed to zero. Have the d e s i r e d number of data p o i n t s been processed? No, c o l l e c t another data p o i n t . D i v i d e the sum of the voltage l e v e l s by the number of samples PULB CLRA LDX TMPVT1 XGDX WAI IDIV LSLD SUBD #NMBR MLP8 BLO INX XGDX TSTA MLP8 Fetch the number of data samples. Fetch the accumulated voltage sum. Round o f f the r e s u l t Increment the quotient, Appendix A. Assembly Language Program 104 BEQ MLP9 * An e r r o r has been detected so r e s t a r t the program. * JMP BEGIN * MLP9 STAB MAXVLT Store the voltage l e v e l to tr a c k which corresponds PULY to the maximum power p o i n t . PULX PULB PULA RTS A.9.1 Change Search Direction ^ 3^ ) | c -t* ^ ^ ^ *^ 4* ^ ^ r^* ^ 1^* 4c*^^i5(l*^*^5|C5 (c 5JC 5|c T^C^fc^^^Sfc^^ 5^ 3^ * 3(/i 3JC 5JC *(c ^ }(c -^C S^CSjcsksf^I 'lc^.^?^^^?^ T h i s subroutine which can be considered l o c a l to the maximum power r o u t i n e updates the power l e v e l s . INPUT: 1) Current power l e v e l i n D r e g i s t e r . 2) Operating voltage l e v e l i n VOLT. OUTPUT: 1) Current power l e v e l i s pl a c e d i n POWER. 2) Last power l e v e l i s pl a c e d i n TEMP 3) Current voltage l e v e l i s placed i n TMPVT1 4) Last voltage l e v e l i s placed i n TMPVT2 * PRUPD PSHA Save the operating power l e v e l . PSHB LDD POWER Move the l a s t power l e v e l to TEMP. STD TEMP LDAB TMPVT1 Move the l a s t voltage reading to TMPVT2. STAB TMPVT2 LDAB VOLT Move the current voltage reading to TMPVT1 STAB TMPVT1 PULB PULA Store the current power l e v e l i n POWER. STD POWER RTS Appendix A. Assembly Language Program 105 A . 10 Current Adjustment ***************************************** * * SUBROUTINE CURNT ************************************************************************* * * * This subroutine reads and adjusts the value of the current being * read by the A/D converter. An adjustment may be necessary i f the current * s i g n a l has a DC o f f s e t . * * ASSUMPTIONS: 1) The cur r e n t has s e t t l e d to a steady s t a t e value. * 2) The o f f s e t current has been recorded. * * INPUT: None. * * OUTPUT: The adjusted current value i n the B r e g i s t e r . * * REGISTERS EFFECTED: B.CC. *• * CURNT PSHA LDAA #RDCURR Read i n the current from the A/D. JSR READ SUBB OFFSET Subtract the DC o f f s e t . BHS CUR1 Did the r e s u l t overflow? CLRB Yes? Set the r e s u l t t o zero. CUR1 PULA E l s e continue. RTS A . 1 1 Voltage Tracking Routine * * * SUBROUTINE VLTRAK * Appendix A. Assembly Language Program 106 * This subroutine maintains the array voltage at the l e v e l s p e c i f i e d * i n the memory l o c a t i o n MAXVLT. The array voltage i s adjusted by * v a r y i n g the duty c y c l e of the power MOSFETS. * * ASSUMPTIONS: * 1) The timers are i n i t i a l i z e d and running. * 2) The voltage corresponding to the maximum power p o i n t * has been determined. * * INPUT: The reference array voltage i n MAXVLT. * * OUTPUT: * 1) The duty c y c l e i s adjusted to t r a c k the reference * v o l t a g e . * 2) The opera t i n g array c u r r e n t , load c u r r e n t , array * voltage and power output l e v e l s are updated. * REGISTERS EFFECTED: CC * VLTRAK PSHA Save the s t a t e of the A and B r e g i s t e r s . PSHB JSR CURNT Read the cu r r e n t . STAB CURR LDAA #RDVLT Read i n the opera t i n g v o l t a g e . JSR READ PSHB * Take two sets of readings and average them. LDAA #RDVLT JSR READ PULA ABA Add the f i r s t and second readings. RORA Divide the r e s u l t by two. TAB Place the r e s u l t i n the B r e g i s t e r . STAB VOLT * * C a l c u l a t e the e r r o r v o l t a g e , d e l t a V. SUBB MAXVLT BEQ VLTRTN Appendix A. Assembly Language Program 107 BHI INCRSE INCRSE VLTRTN If t h i s program s e c t i o n i s entered the array i s opera t i n g at l e s s than i t s ' optimum voltage. Therefore decrease the MOSFETS' ON time. NEGB BSR LDAA JSR BRA DELTA #1 CHANGE VLTRTN Form the absolute value of the e r r o r voltage. C a l c u l a t e the change i n the ON time required. Delta ON w i l l be returned i n the B r e g i s t e r . I ndicate a decrease i n the pulse width. Ramp down the duty c y c l e . If t h i s program s e c t i o n i s entered the array voltage i s higher than i t s ' optimum value. Therefore increase the MOSFETS' ON time. BSR DELTA CLRA JSR JSR PULB PULA RTS CHANGE LOAD C a l c u l a t e the change i n the ON time r e q u i r e d . Delta ON w i l l be returned i n the B r e g i s t e r . I ndicate an increase i n the pulse width. Ramp up the duty c y c l e . Determine the load current and vol t a g e . Restore the A and B r e g i s t e r s . A.11.1 Adjustment to the Duty Cycle * * SUBROUTINE DELTA * * T h i s subroutine c a l c u l a t e s the change to the ON time of the pulse * width modulated waveform according to the formula: * * d e l t a ON = d e l t a V * ON / Varray * * Where ON i s the l a s t ON time, d e l t a V i s the e r r o r voltage and * Varray i s the opera t i n g array v o l t a g e . Appendix A. Assembly Language Program 108 d e l t a ON = d e l t a V * ON / Varray ASSUMPTION: The timers are i n i t i a l i z e d and running. INPUT: 1) The e r r o r voltage i n the B r e g i s t e r . 2) The operating voltage i n VOLT. 3) The current on time i n ON. OUTPUT: 1) The change i n the ON time i n the B r e g i s t e r . REGISTERS EFFECTED: B.CC sly *L» sly *1* *1* *L» sly *1* sly Jy »ly sL. sly sly sL- sL- sly si. si' si* sly sly si- d ' ^ ^ ^ X ^ s t ^ ' sly s^ s^ s^ sL> sL< ^ ^ «k s^ ^ ^ u ^ s ^ s L * L s V s U s ^ ^ ' s V s ^ s ^ >V ^ ^ *^ >k ^ >^ ^ *^ *^ *V *1* sUslysUslysLysksl»sL. y ^ y ^ y ^ y ^ y ^ y ^ y ^ y ^ y T . y ^ y ^ y T . y T ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ * DELTA PSHA Save the contents of the A and X r e g i s t e r s . PSHX LDAA 0NCNT1+1 M u l t i p l y the ON time by the e r r o r v o l t a g e . WAI MUL XGDX LDAB VOLT CLRA XGDX WAI IDIV Store the r e s u l t i n the X r e g i s t e r . Load the opera t i n g v o l t a g e . Wait f o r an i n t e r r u p t to complete as the next i n s t r u c t i o n takes 41 c y c l e s , ( d e l t a V * ON) / Varray. Check the remainder to see i f the r e s u l t should be incremented. LSLD M u l t i p l y the remainder by two. TSTA If the reminder s p i l l s i n t o the A r e g i s t e r BNE DLP1 the r e s u l t should be incremented. DLP1 DLP2 CMPB VOLT BLO DLP2 INX XGDX TSTA If 2 * remainder < VOLT do nothing E l s e increment the r e s u l t . Appendix A. Assembly Language Program 109 DLP3 DLP4 ERROR BNE ERROR TSTB BNE DLP3 INCB CMPB #1 BEQ DLP4 LSLB PULX PULA RTS JMP BEGIN If A i s not equal to zero an e r r o r has occurred. Set the change to one i f the r e s u l t was zero. M u l t i p l y the r e s u l t by two. Restore the X and A r e g i s t e r s Restart the whole process. A . 12 Read Open Circuit Voltage and Current * SUBROUTINE ADJOPN * This subroutine reads i n the open c i r c u i t voltage and current * o f f s e t upon s t a r t - u p . * * ASSUMPTION: Timers are i n i t i a l i z e d . * * INPUT: None. * * OUTPUT: 1) The open c i r c u i t voltage i n OPEN. * 2) The o f f s e t current i n OFFET. * 3) The p o r t i o n of the current s i g n a l c r e a t e d by noise i n CORECT * * REGISTERS EFFECTED: CC. ADJOPN PSHA Save r e g i s t e r s used by the r o u t i n e . Appendix A. Assembly Language Program 110 ADLP1 PSHB PSHX PSHY LDY #P0RTB Turn the converter o f f . BCLR ,Y ON BCLR FLG 1 S i g n a l the s t a r t up of the pulse width modulation process. LDX #TMENOD Load the address of a timer node. JSR CLRTME Clear the timer node. LDAA #DLAY C a l l f o r a delay. STAA 2.X JSR ADDTME JSR CMPTME Wait TSTA BNE ADLP1 LDAA #RDVLT Read i n the open c i r c u i t v o l t a g e . JSR READ STAB OPEN Save the value of the open c i r c u i t voltage LDAA #RDCURR Read i n the o f f s e t c u r r e n t . JSR READ STAB OFFSET Save the value of the o f f s e t c u r r e n t . S t a r t the pulse width modulation process LDD #1 LDX #1 JSR ADJST PULY PULX Restore the machine r e g i s t e r s . PULB PULA RTS A.13 Calculate Load Voltage and Current ****** ***************************************** * * SUBROUTINE LOAD ************************************************************************* Appendix A. Assembly Language Program 111 T h i s subroutine c a l c u l a t e s the average load voltage and current knowing the average supply voltage and current and the duty c y c l e . ASSUMPTIONS: 1) The count r e p r e s e n t i n g the p e r i o d i s l e s s than 256. INPUT: 1) The supply voltage i n VOLT. 2) The supply current i n CURR 3) A number re p r e s e n t i n g the on time i n ONCNT. 4) A number re p r e s e n t i n g the p e r i o d i n PERIOD. OUTPUT: 1) The load voltage i n MOTVLT. 2) The load current i n MOTCUR. REGISTER EFFECTED: CC. LOAD PSHA PSHB PSHX LDAA PORTB COMA ANDA #0FF BNE LDOFF LDAA PORTB COMA ANDA #0N BNE LDON Check i f the converter i s turned f u l l y OFF. Branch i f the converter i s turned o f f Check i f the converter i s turned f u l l y ON. Branch i f the converter i s turned f u l l y ON C a l c u l a t e the average load v o l t a g e . LDD 0NCNT1 ADDD 0NCNT2 LSRD LDAA VOLT WAI MUL LDX PERIOD WAI IDIV Average the two ON counts Load voltage = supply voltage * ONCNT / PERIOD. Appendix A. Assembly Language Program 112 LD1 LD2 LDON LSLD Round o f f the quotient by i n s p e c t i n g the CPD PERIOD remainder. BLO LD1 Increment the quotient i f 2 * remainder i s INX g r e a t e r than the d i v i s o r . XGDX TSTA If A .NE. 0 an e r r o r has occurred. BNE LDERR STAB MOTVLT Record the load voltage. C a l c u l a t e the average load c u r r e n t . 0NCNT1 0NCNT1 LD2 MOTCUR Fetch the current reading. Load current = supply current * PERIOD / ONCNT. Round o f f the quotient by i n s p e c t i n g the remainder. Increment the quotient i f 2 * remainder i s great e r than the d i v i s o r . Record the lo a d current as a 16 b i t data item. LDD PERIOD LDAA CURR WAI MUL LDX WAI IDIV LSLD CPD BLO INX XGDX STD PULX PULB PULA RTS This program s e c t i o n i s executed i f the converter i s turned f u l l y ON. LDAB CURR CLRA STD MOTCUR Load current = supply c u r r e n t . LDAB VOLT STAB MOTVLT Load voltage = supply v o l t a g e . PULX PULB PULA RTS Appendix A. Assembly Language Program 113 * T h i s program s e c t i o n i s executed i f the converter i s turned * f u l l y OFF. * LDOFF CLR MOTVLT Load voltage = 0 . CLR MOTCUR CLR MOTCUR+1 Load current = 0 . PULX PULB PULA RTS * LDERR JMP BEGIN An e r r o r has been detected so s t a r t again. A.14 Change the Duty Cycle in Small Increments 'i^- sfr* •'t^ 4^ 4^ 4^ sfc sf^ -5^ c S'fc sfc sfc 'f1* s|c s^ c sfc J^^- sfc {^c * SUBROUTINE CHANGE * Subroutine change ramps up or down the duty c y c l e from i t s present * value t o i t s ' d e s i r e d value i n one step increments. * * ASSUMPTIONS: 1) The count r e p r e s e n t i n g the p e r i o d i s l e s s than 256. * * INPUT: 1) An i n t e g e r which i n d i c a t e s the d i r e c t i o n of the * change i n the A r e g i s t e r . * 0: Increase the pulse width. * 1: Decrease the pulse width. * 2) An unsigned i n t e g e r r e p r e s e n t i n g the change i n the ON * count i n the B r e g i s t e r . * 3) The current on time i n 0NCNT1 and 0NCNT2. * 4) The p e r i o d i n PERIOD. * * OUTPUT: 1) The duty c y c l e i s ramped up or down. * REGISTERS EFFECTED: B.CC. Appendix A. Assembly Language Program 114 ******************************************** CHANGE PSHY PSHX PSHA PSHB LDY LDX * * * CHLP1 * * * CHNXT #PORTB 0NCNT2 CMPA #1 BHI CHERR BEQ TSTB BEQ NEGCHG CHRTN Check i f the duty c y c l e i s to be increased or decreased. Branch i f the parameter i s i l l e g a l . Branch i f the duty c y c l e i s to be decreased. If change = 0 r e t u r n . If an overcurrent c o n d i t i o n i s encountered, r e t u r n . BRSET FLG OVRCUR CHRTN Increase the duty c y c l e i n one count increments. PSHB LDD CPD BHI INCB CPD BHS CPX BNE 0NCNT1 0NCNT2 CHLP2 PERIOD CHON #0 CHNXT XGDX PULB DECB PSHB XGDX LDX INX JSR WAI BSET ,Y RUN PULB #0NCNT2 ADJST Branch i f 0NCNT2 < 0NCNT1 Increment the ON time. If ONCNT = PERIOD t u r n the converter f u l l y ON. Make sure 0NCNT2 does not equal zero. If 0NCNT2 = 0, increment i t . Decrement the step counter. Increment 0NCNT2 Adjust the duty c y c l e . Appendix A. Assembly Language Program 115 CHLP2 DECB BLS BRA INX CPX BEQ JSR WAI BSET PULB DECB BEQ BRA CHRTN CHLP1 PERIOD CHON ADJST ,Y RUN CHRTN CHLP1 Return i f the adjustment of the duty c y c l e i s complete. Adjust the duty c y c l e . Return i f the adjustment of the duty c y c l e i s complete. Decrease the duty c y c l e i n one step increments. NEGCHG PSHB LDD CPD BLO DECB BEQ JSR WAI BSET PULB DECB BEQ BRA CHLP3 DEX BEQ JSR PULB DECB BLS BRA CHRTN PULB PULA PULX PULY RTS 0NCNT1 0NCNT2 CHLP3 CHOFF ADJST ,Y RUN CHRTN NEGCHG CHOFF ADJST CHRTN NEGCHG Branch i f 0NCNT2 > 0NCNT1 Decrement the ON time. Adjust the duty c y c l e , Return i f the adjustment of the duty c y c l e i s complete. If the ON count = 0 tu r n the converter f u l l y OFF. Adjust the duty c y c l e . Return i f the adjustment of the duty c y c l e i s complete. Appendix A. Assembly Language Program 116 CHERR * CHON CHOFF S t a r t again i f an e r r o r i n the input parameter i n d i c a t i n g the sign of the change i s detected. JMP BEGIN Turn the converter f u l l y ON. BCLR ,Y ON BSET ,Y OFF INS PULB PULA PULX PULY RTS Turn the converter f u l l y OFF. BCLR .Y OFF BSET ,Y ON INS PULB PULA PULX PULY RTS Restore the r e g i s t e r state, Restore the r e g i s t e r s t a t e A.15 Overcurrent * OVRDLY * * C o n t r o l w i l l be passed to t h i s r o u t i n e i f the overcurrent * i n t e r r u p t has been repeatedly a c t i v a t e d . * * This r o u t i n e turns o f f the Mosfets, introduces a h a l f hour XSI * *ipeq.s eiiq. uo apou jerarq. e aq.eaJO * •sq.sanbaj q.dnjjaq.UT ajeduioo q.ndq.no exqeug n o •sq.dnaj8q.UT q .uajjnDJ8AO x^uoT^TPP18 9 I c l 1 S 8 T a 0fr$ X4 H109 ooid# xai yyoHAO * sl* sly sly si* sly si* sly sly si* si* sL* si* si* sly sly si* sly sly si* ij> sly sly sly si* sly sly sly sly si* sly sly sly sly si* sty sly si* si* sly sly sly sly sly sly sly si* sly sL* si* sly sly sly st* si* «A* sly sly >±» sL* sL- sly vL. sL* >X- *X\" »L* st* sL- -sL- \"sly *^ *^ *'J(y^ y](y^ y^ y|t*,|(yf*. yjt ^ Jfi y]t yfk y^ y^ yf( yf( J|k yj^ yf* JJ^ y^ y^ y^ y]tyfky|tj|s