AN1320 APPLICATION NOTE L6574 & MICROCONTROLLER IN BALLAST APPLICATIONS
by Francesca Sandrini and Luca Rodeschini
There is an increasing demand for flexibility in ballast applications. This means a request for having ballast that can be used for different tubes without changing the soldered components. The aim is to save money by using less parts (resistors, capacitors and so on) and less ballast models to be stored and managed. A way that is going to be investigated is the use of microcontroller which can "supervise" the application in such a way that the key parameters of the application can be modified according to the tube characteristics just by changing the micro-code. In this application note we will exploit a way to interface a microcontroller with our integrated ballast controller: the L6574.
1.0 INTRODUCTION Roughly speaking a HF-TL ballast converts the 50-60Hz input to a high frequency output, usually in the range of 25-125KHz. A rectifier block and a DC to high frequency inverter usually make up a ballast. The half bridge of the inverter can be driven in different ways with different ICs. We will focus on a specific driver: the L6574. We will see first how the L6574 can drive and control a ballast, then how it can communicate and be supervised by a C. The aim of this paper is to examine if there are advantages in having a C work with L6574, the feasibility of this "cooperation", and a practical example.
2.0 L6574 L6574 is a BCD off line 16 pin IC specifically designed for ballast applications [ref.1](see fig.1). It has both driver functions and controller functions on board. The most useful characteristics to control the lamp are: s Preheat and frequency shifting timing s Cmos shut down input s Sense op-amp for closed loop control or protection failures The parameters of the application are set by external components (resistors and capacitors) connected to the IC. L6574 allows the user to set all the parameters according to the lamp characteristics, and the ballast will be a high performance one. There is a specific application note on this IC (ref. [2]): here you find the description of 58W TL ballast with PFC section. Please refer to this application note and to the L6574 datasheet for the IC details. In the following paragraphs we will focus our attention on a way to interface the L6574 with the microcontroller rather than on "L6574 - stand alone" performances. The aim of this "supervision" is to control the three points mentioned above.
December 2000
1/20
AN1320 APPLICATION NOTE
Figure 1. L6574 Block Diagram
H.V. VS OP AMP 12 + UV DETECTION BOOTSTRAP DRIVER HVG DRIVER 16 VBOOT
OPOUT OPINOPIN+
5 6 7
15
HVG
CBOOT LOAD
14 Imin VREF DEAD TIME 4 RIGN Ifs Imax VREF + 2 RPRE CONTROL LOGIC 3 Cf Vthpre + VTHE 9 VTHE 8 Ipre LVG DRIVER 10 DRIVING LOGIC LEVEL SHIFTER VS 11
OUT
LVG
GND
+ -
EN1
+ -
VCO 1 CPRE
EN2
D97IN493B
3.0 L6574: HOW TO SET FREQUENCIES, TIMING, FAULT SIGNALS IN AN "ANALOG APPLICATION" In this paragraph we will have a snap shot of the L6574 working, just as far as the characteristics important for the micro interface are concerned. For further details please refer to [1] and [2]. The L6574 typical behavior is shown in fig. 2: there is a starting frequency (fMAX or fPRE) that is constant for a set preheat time TPRE, than there is a frequency shift towards fmin that last 0.1 of TPRE and is called TIGN or TSH. Figure 2. Frequency shift
preheating phase
ignition phase
freq fmax
normal operation Tpre Tsh time fmin
Leads 1, 2, 3, 4 are used to set frequencies and timing. The capacitor connected to pin 1[CPRE] sets the preheat time: TPRE = K1 · CPRE The ignition time, or better, the time to let frequency shift from preheat value to the min. value is one tenth of TPRE. The current that charges and discharges the capacitor connected to pin 3 (CF) sets the half bridge oscillating frequency. The current that charges C F is set by the current that flows out from pin 2 and 4 during preheat and from pin 4
2/20
AN1320 APPLICATION NOTE
alone during the on phase. As pin 2 and 4 are at 2V, the currents that flow out of them is inversely proportional to the resistance connected between gnd and pin 2 (RPRE) and between gnd and pin 4 (RIGN). There are some useful formula: 1.41 ( R p r e + R i g n ) m a x = -------------------------------------------------Rpre Rign C
1.41 m i n = ----------------------Rign C
Choosing properly the resistor and the capacitor values the designer can set the desired frequencies and timing. When the designer has to do another application for another lamp type, he has to change the resistors and capacitors in order to have another range of frequencies. For protection in case of lamp failure two logic input are provided: pin8 [EN1] and pin9 [EN2]. Both are active high, but they have different functions: when EN2 is activated it forces the IC to start again the preheat sequence. When EN1 is activated it shut down the IC until V CC is removed or until EN2 is pulled high. EN2 is usually used as "ignition fault": if the lamp is not ignited, the preheat sequence starts again. EN1 can be used to sense lamp removal / replacement or disconnection. Figure 3. EN1
VSUVP
VCC
LVG
HVG
EN1
D97IN490
3/20
AN1320 APPLICATION NOTE
Figure 4. EN2
VCC
VSUVP
fOUT
fPRE
fING
EN2
D97IN491B
tPRE
tSH
tPRE
tSH
L6574 has also a sense op-amp that can be used to have a closed loop control of the lamp. We can give a voltage reference to the non-inverting input, a signal proportional to the load current to the inverting input, and we can connect the op amp output pin to pin #4. In this way if the current in the load exceeds the reference the op amp will sink from pin 4 an additional amount of current that has to be added to the current that flows through RIGN. So the current charging CF will increase, that means a higher half bridge oscillation frequency, that means a lower current in the load. Changing the reference voltage on the non-inverting input of the op amp we change the frequency of the oscillator, that means we change the current in the load, and this allows lamp dimming. Figure 5. Closed Loop
Q3 STP4NB50/ STP6NB50 C9 8.2nF R33 9.1K R25 0.68
R18 100K D3 1N4148
R19 100K
6
5
7 +
RIGN 4
D98IN818A
4/20
Fuse D1 BYT11600
Bridge
T1 1.24mH (E25*13*7) 10 Turns 1.3mm gapped
C1 220nF 630V R16 47 D2 1N4148 C5 100nF C20 100nF R21 22 2 R17 9.1K 7 14 R22 22 6 R10 750K 4 1 R11 750K R14 4.7K 43 R18 100K C8 100nF R19 100K C13 470pF C14 1F R24 6.8K C15 330nF R25 0.68 RSENSE R8 0.68 R9 0.68 R12 9.53K R15 1.5K 1 D3 1N4148 5 C9 8.2nF 8 C7 22F 450V R13 100K 12 16 15 C6 4.7F 25V DZ1 14V C11 680pF 630V C12 100nF R20 47K
R1 1.5M
R5 68K
Figure 6. AN993 Demo Application Circuit
NTC
R3 120K
R4 120K
Q2 STP4NB50/ STP6NB50
5 R6 22 7 R7 47K
8
Q1 STP6NB50
6
L1 2.1mH C17 100nF 250V C18 100nF 250V
3
2
Q3 STP4NB50/ STP6NB50 11 R23 47K
C2 220nF 400V
L6561
L6574
R26 390K
R28 750K R29 750K 9 10 1N4148 D4 LAMP C19 8.2nF 1500V
C4 680nF
R2 10.1K
C3 10nF
R30 3.9K
R27 6.8K
R33 9.1K
D99IN1064
C16 1F
AN1320 APPLICATION NOTE
R32 20K
5/20
AN1320 APPLICATION NOTE
4.0 L6574: HOW TO SET FREQUENCIES, TIMING, FAULT SIGNALS IN A "MICROCONTROLLED APPLICATION" We have seen that the frequencies in L6574 are set by fixing the current that flows out from pin 2 and 4 and fixing the value of the CF capacitor. A microcontroller output pin can give us a high logic level (5V) a low logic one (0V) or a PWM output at fixed frequency and variable duty cycle. We can not use the PWM to act directly on CF pin, because the rising edge on CF is the low side mosfet "on time" and the falling edge is the high side mosfet one. The half bridge would oscillate in asymmetrical way at fixed frequency instead of at 50% duty cycle and variable frequency. So we have to interface the C with the pins that set the current that charges CF. A push pull output that gives us just 0V or 5V can not be used to interface pin 2 and 4 because they have a maximum voltage level up to 2V. We have to use the integrated value of a PWM signal to set a voltage level between 0V and 2V. We can use a PWM output also to give the op amp the voltage reference to change the load current (and so the lamp power to perform dimming) Acting on L6574 pin 4 and (or) on pin 7 (opamp+) we can control the inverter working frequency. If we want to control the preheat timing and frequency we have to act on pins 2 and 1. First we have to avoid that the L6574 fixes the preheat time by itself. If we connect to pin 1 a very small cap (e.g. 1nF), the L6574 "analog TPRE" will be so small to be "invisible" to the lamp (i.e. less than 2ms). During these 2 ms, the oscillating frequency has to be high enough to avoid lamp filaments preheat (> 150KHz). The resistor connected to pin 2 has to be sized properly. After these 2 ms L6574 is in "working mode": it means that pin 4 is no more involved in fixing the frequency. Only CF and RIGN (pin 3 and 4) set it. Now the effective preheat time can be decided by the C just acting on the PWM that gives the voltage reference to pin 4. For example, it can have a certain duty cycle (appropriate for the preheat freq.) for a fixed time, than it can change the duty cycle (i.e. the voltage reference) to set the ignition profile and the final working frequency. Now we are able to change all the frequencies and the timing involved in lamp turning on and dimming with two connections between L6574 and the C. The fault management can also be done by the C: all the fault signals will be brought to it, and then it will react according to the code. A connection that can be useful is the one to pin 8 (shut down pin) that can be direct because the ICs levels are compatible. In this way the C can react to a signal either by stopping the inverter or by changing the frequency (i.e. repeating a preheat sequence if there is the no-ignition alarm, or bringing the frequency to a very high value...). Just with these 3 connection between the L6574 and the C we can set nearly all the parameters of the application by software. The number of C inputs we need for fault signals depends only on what we want to control. We need another input pin to give the C the information about the dimming level: this is the interface between the ballast and the "final user". We can use either switches or an AD input. The first solution is more expensive in terms of number of pin, the AD input requires some attention for the code part but allows a much larger number of levels. 5.0 HOW TO APPLY THIS INTERFACE TO A BALLAST We started from AN993 demo board to build a C application with the same performances and some additional degrees of freedom. We will now apply all the concepts already discussed and put them into a working board.
6/20
AN1320 APPLICATION NOTE
The hardware and software development can not be separated: it is a very interactive process. Starting from the basic point there are different way to act on the L6574, depending on what we want to be software dependent and what we want to be hardware dependent in the final application. We will describe the two sections separately just for ease of understanding. 5.1 HARDW ARE CHOICES First we have to choose the C. We have chosen the ST62E62C, a 16 pin C belonging to the ST6 family. This device is able to perform all the functions we need with pins left over. In this microcontroller we have just an auto reload timer, this means that we have just one PWM available. We can call this PWM the HARDWARE PWM in the following pages, just to differentiate it from the second one we need and that is obtained by software from a standard output pin. We will call this second PWM the "SOFTWARE PWM" We have discussed in the previous chapters how to interface the C and the L6574; the remaining problem is how to supply the ICs. We have chosen a cheap way to supply the C: we use a L7805, which is a linear regulator (5V output). It has been connected to the L6574 supply. This choice (mainly based on economical reasons) has many consequences: s As L6574 supply is given by a charge pump connected to the middle point of the half bridge, the L6574 has to work (to oscillate) to give the supply to the micro s The ICs are not supplied at the same time, but as a sequence: the micro (the supervisor) has to be told when everything is OK to start the preheat sequence s If the L6574 is disabled (after a fault condition for example) the micro no longer has a voltage supply. When the circuit starts again the micro is reset and the program starts from the very beginning It can happen that the micro must always be supplied, even when L6574 is off. In this case another solution has to be used, e.g. a regulator connected to the rectified mains. The board start up sequence management takes into account the above mentioned point 1 and 2. Using the start up resistors we let the L6574 start, so its oscillation allows the charge pump work. Then the L6561 is supplied and the L7805 feeds the C. This sequence is an inheritance of L6561+L6574 demo board. The co-ordination between the L6574 and the L6561 is done by choosing the start up resistors and the charge pump components. The co-ordination between the micro and the analog part is a mix of hardware and software. By software we let the micro wait for a "power OK" signal from the L6574, that in the meanwhile keeps on oscillating at a very high frequency, so as to let the filament not to be preheated. The L6574 can provide this "power OK" signal for free. The internal sequence of the L6574 charges the preheat cap connected to pin 1 to 5V after the preheat and the ignition sweep has ended. We can deliver this 5V signal to a C input, and hereafter the C will start to set all the application parameters: in this way we are sure that everything is correctly supplied. Moreover by choosing properly CPRE value (i.e. very small ~1nF) this "waiting time" is around 2 ms, so it does not influence the overall timing: it is hundreds of time shorter than a typical preheat time. To be sure that the third condition does not happen and that there are no out of control situations in which we do not know which part of the code the micro is running we have added additional safety circuitry. After the alarm for open load or disconnection, the micro sets an output pin to the high logic level in order to activate an SCR to disconnect the VCC from all the ICs, PFC included. In this way the C can supervise not only the L6574 but also the L6561.
7/20
AN1320 APPLICATION NOTE
5.2 SOFTW ARE CHOICES We have already done some software choose choosing the microcontroller. When we chose a microcontroller with only one PWM output we have already decided to devote a certain amount of microcontroller resources to build the PWM software (see appendix for software details). A logic sequence of actions could be: 1) to check that everything is ok - i.e. all the ICs are supplied in the right way; 2) check the presence of the load 3) do the preheat sequence 4) check lamp ignition 5) set the current in the load according to the user input This is a basic set of functions typical of nearly any ballast application (see fig. 7) Figure 7. Flow Chart
N
L6574 OK?
ST6 start up
Y
open load?
Y
N
s et Fpre
N
wait for reset and/or power off t>Tpre?
Y
set IGN freq. profile L6574 and L6561 disable
N
lamp on?
N
Y
#fail
Y
set working freq. (freq.&loop ref.)
Y N
dimming?
Y
fault cd.?
N
8/20
PORTR IGH T-R R1 50
D1
IN L7805
6.0 BOARD
F1 2A 250V
D2
BR ID GE
C1
DIOD E
C2 D3 ST TA1 0 6 D4 D5 R4 14 V 68 K D6 1N 41 48 C3 10 0n F C4 10 uF 8 C6 VS Q1 10 0n F SW 2 RP RE U2 L6 57 4 7 OP IN+ C8 R11 22 Q3 ST P6 NB 5 0 C9 1.5 M C1 0 5 D7 8.2 nF R1 4 1N 41 48 1.5 M 4 RIGN R19 R22 9.1 K R2 4 R2 3 R28 0.6 8 3.9 K C16 R29 C13 1u F 20 0K 3 CF NC 13 R26 9.1 K 47 0p F 10 0n F SW D9 1N 41 48 PB 2 D1 0 R33 R35 1.2 K 2u F S6 PB 3 POWER OK C2 0 SW 3 2 1n F R3 7 1 2 10 K R39 20 K PB 7 3 R4 0 R43 20 K 2u F 2 VP P PC 3 NMI R4 5 POT 4.7K R 10 K 10 0n F R47 1.5 K RIF PIN 4 6 PB 7 PA 5 PA 4 D1 3 1N4 1 48 IN L7805 C29 10 uF GN D 3 C2 8 10 0n F 1 VIN VOUT U4 L7 80 5 C24 L6 57 4 POWER OK PF C DISABLE ST 62 E6 2 C RIF OP AMP (PIN 7) 3 4 5 PB 6 OS C_ IN 11 10 9 C26 20 pF PB 2 PB 3 RE SE T OS C_ OUT 15 14 13 12 Y1 8MH z C23 20 pF S7 SW DISCONNECTED LAMP 4.7 K 2.2 K R4 4 10 0K C22 DISA B L E L6574 1 PB 0 U3 PC 2 16 NOT IGNITED LAMP R4 1 R4 2 4.7 K NP N CBE C21 10 0n F 10 0K Q5 1 R38 1u F C1 9 SW SW 6.8 K 10 0 C17 S4 S5 1N4 1 48 R36 C1 8 33 0n F R3 2 10 K D11 5V PC 2 (NOT IGNITED LAMP) R3 1 20 K 1.2 K S3 C15 8.2 K R2 1A R2 5 51 0K CP1 E R G10D N 0.2 2 0.2 2 R2 1 R1 6 10 0K EN 2 SW R20 6.8 K 9 S2 65 0K 1IN V 47 uF C11 R1 5 OP OUT EN 1 8 8.2 n R13 10 0n F 250V 10 0n F 250V 39 0K C8 B1 R1 0 OU T 14 L1 2.1 mH 50 K R[*] HV G STP 6 NB 50 15 R9 81 .5K 7 GD R7 22 STP 6 NB 5 0 47 uF 25V R8 22 Q2 S1 12 C5 VC C VB OOT 16 1N 41 48 1.3 4n F 600V R2 36
+
22 0n F 630V T1 1.2 4m H (E25*13*7)1.3mm gapped
1
2
t
Figure 8. Schematic
NTC1 10
R3
PORTR IGH T-R
1.5 M
R5 12 0K
R6 12 0K
6
GN D
C7
ZCD
U1
L6 56 1
5
6 CS 65 0K 4 R12 OP INLV G
11
22 0n F 400V
3
MULT
C1 2
R17 1.2 K PC 3 (DISCONNECTED LAMP)
COMP 2
9.1 K R18
1u F
R27
10 .1K
C14
We have implemented the board whose schematic is shown in fig.8.
10 nF
PN P CBE Q4
DISA B L E PB0
C25
R46 1K
10 0n F
R4 8 10 0K C2 7
[*]: 4 resistors 200K 0.6W each PB 6 L6561 DIS
VD D 7 2
VS S 8
10 0n F
AN1320 APPLICATION NOTE
9/20
AN1320 APPLICATION NOTE
This is a "double board": it can be used with the micro or without it according to the position of six switches (S1 to S6) that are on board. The microcontroller, the L7805 and some parts related to the micro (the oscillator, the reset switch and so on) are mounted on a small separated board that can be connected with a 9 pin connector to the main board. As a result the board looks huge, but we have two different application on it. It is a "modular" board: the six switches and the small insertion PCB let the user choose between a "analog ballast" and a "microcontrolled one". The larger board includes the "analog ballast controller" (that is the L6561-L6574 demo board) and some additional parts that allows the use of the PCB with the microcontroller and the L7805 regulator. You can choose the control system setting by the proper position of 6 switches:
Analog version ### ### ### ### ### ### ### ### ### ### ### ### Sw nr. SW1 SW2 SW3 S W4 S W5 SW6 Pin 2 RPRE Pin 8 EN1- shut down Pin 7 op amp ref. PWM SW Pin 1 CPRE power OK Pin 9 EN2 Pin 4 RIGN- PWM HW Function vs. L6574
Changing all the switch positions the micro can take the control of the board (the control system cannot be changed while the application is running). The connector that allows the communication between the two boards has 9 signals:
Analog micro
Ref. # 0 1 2 3 4 5 6 7 8 9
function Void: there is the hole but it is not connected GND PB3 (L6574 power OK)
L7805 input voltage PB2 PB6 PB7 PC3 PC2 PB0 (ref. Op-amp) SW PWM PFC disable ref. Pin 4 = HW PWM disconnected lamp not ignited lamp disable L6574 - EN1
The two control system have the same performances, but the microcontrolled application can change its characteristics just changing the code of the micro. If we wish to have a counted number of re-strike of the lamp after ignition failure we can choose any number we want (2, 8 or 23), just changing a parameter of the software. The same can be done if we connect another lamp that needs a different TPRE or a different range of frequencies.
10/20
AN1320 APPLICATION NOTE
This is an added value of the micro. An important feature of the overall application is its modularity: we can have a board with the micro and a board without it changing very few parts, we can also put all the parts on the same PCB and then decide which connection to do. 7.0 COMMENTS: The lamp disconnection fault is managed as an interrupt not only for fast acting, but also for the characteristics of the application we have chosen. The ST62E62C has just a PWM output, while the application needs two PWM. We have solved the problem using the software PWM. This is something very "heavy" for the micro to perform, and it influences all the other choices: e.g. a polling sequence is to expensive as time consuming and it influences the SW PWM duty cycle dynamic. It consumes ~25%-30% of the cycle, and this, added to 20% due to the 4 instructions to do the PWM itself was too large. That is the main reason why the disconnection fault is managed as an interrupt. Of course there are different solutions. A feasible choice could be to use the hardware PWM to set the reference of the non inverting input and not to use the software PWM. But we should relay on the L6574 preheat and ignition sequence, where TPRE, fPRE and TIGN are set by capacitors and resistors. This means that the C has to supervise less items. A third choice might be to choose a C with two PWM output: in this way the application has the same characteristics and the C has an easier code to run. 8.0 REFERENCES: 1] L6574 datasheet 2] AN993: electronic ballast with PFC using L6574 and L6561 3] ST62E62C datasheet 9.0 APPENDIX: 1) Flow Chart 2) Vardef.inc 3) Ballast.asm
11/20
AN1320 APPLICATION NOTE
9.1 APPENDIX 1: Flow Chart Figure 9. Appendix 1: Flow Chart
N
PB3 H? ["check power"]
ST6 start up
Y
check PC3: H?
Y
N
["start up sequence"] set pwm on PB7=duty_pre
wait for reset and/or power off
N
t>Tpre? ["call tpre"]
Y
set IGN freq. profile ["load duty cycle values from look up table"] PB0 & PB5 high
N
check PC2: H?
Y
nr tent = max tent ?
Y
N
enable pwm1 on PB7 and pwm2[software] on PB2
Y
check PA4 voltage<> 5V
Y N
interrupts on PC3?
N
12/20
AN1320 APPLICATION NOTE
9.2 Appendix 2 - Vardef.inc
;* * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * *** ; ; MODULE Name: VarDef.Inc ; ;* * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * *** ; *** Default duty cycle value for preheating DUTY_PRE .EQU 0BEh ; *** Maximum start-up sequence retrials MAX_TENT .EQU 3h ; *** Default Sw PWM Duty Cycle DEF_SW_DUTY.EQU
0BCh
; *** Gen waiting timer parameters ; Gen Waiting = 2ms ; GenTick = 11 -> 11*192us = 2.112 ms ; GenRep = 1 GenTick .equ 0Bh GenRepeat .equ 01h ; *** Tpre waiting timer parameters ; Tpre [0.5 ./. 2 sec] = 1 sec ; TpreTick = 256 ; TpreRep = 21 TpreTick TpreRepeat
-> 256*192us = 49.152 ms -> 21*49.152ms = 1.032 s .equ 0FFh .equ 015h
; *** Tign waiting timer parameters ; Tign [(100 ./. 200)/64 msec] = 150/64 msec = 2.34 ms ; TignTick = 12 -> 12*192us = 2.3 ms ; TignRep = 1 TignTick .equ 0Ch TignRepeat .equ 01h ; *** Tad waiting timer parameters ; Tad = c.a 500 ms ; TadTick = 256 ; TadRep = 10 TadTick TadRepeat
-> 256*192us = 49.152 ms -> 10*49.152ms = 491 ms .equ 0FFh .equ 0Ah
.ORG 0F00H ; Look-up table for PWM ; *HW* *SW* .BYTE 0BCH,0B4H .BYTE 0C1H,0C8H .BYTE 0C2H,0CBH .BYTE 0C4H,0CEH .BYTE 0C6H,0D2H .BYTE 0CBH,0DBH .BYTE 0D0H,0E6H .BYTE 0D5H,0FEH
; Samp = 0
; Samp = 7
13/20
AN1320 APPLICATION NOTE
9.3 Appendix 3 - ballast.asm
;* * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * *** ; ; MODULE Name: Ballast.asm ; ;* * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * *** .romsize 4 .vers "st6262" .input "ST626x.INI"; ST626x data space & registers declaration .input "VarDef.inc" ;========================================================== ; Data Variables ;========================================================== Step Repeat NrTent Media Count Sample .DEF .DEF .DEF .DEF .DEF .DEF 084H,0FFH,0FFH,M 085H,0FFH,0FFH,M 086H,0FFH,0FFH,M 087H,0FFH,0FFH,M 088H,0FFH,0FFH,M 089H,0FFH,0FFH,M
;========================================================== ; Ignition Sweep PWM Parameters ;========================================================== .ORG 0F40H .BYTE 0BEH,0BEH,0BEH,0BFH,0BFH,0BFH,0C0H,0C0H .BYTE 0C0H,0C1H,0C1H,0C1H,0C2H,0C2H,0C2H,0C3H .BYTE 0C3H,0C3H,0C4H,0C4H,0C4H,0C5H,0C5H,0C5H .BYTE 0C6H,0C6H,0C6H,0C7H,0C7H,0C7H,0C8H,0C8H .BYTE 0C8H,0C9H,0C9H,0C9H,0CAH,0CAH,0CAH,0CBH .BYTE 0CBH,0CBH,0CCH,0CCH,0CCH,0CDH,0CDH,0CDH .BYTE 0CEH,0CEH,0CFH,0CFH,0D0H,0D0H,0D1H,0D1H .BYTE 0D1H,0D2H,0D2H,0D2H,0D3H,0D3H,0D3H,0D3H ;========================================================== ; Inizialisation ;========================================================== .org 880h Init reti clr IOR ; Disable Interrupts (Confirm Reset Value)
; *** Oscillator and internal Timer ldi OSCR,08h ldi TSCR,27h
; Set Prescaler ratio @ 1 ; Timer1 no int, presc 128, lock
; *** Por t configuration ; Port A: All Input, No Interrupt, Pulled up, except PA4 Analog - PA4 = A/D (in), PA5 = N/C ldi DRA,10h clr DDRA ldi OPRA,10h ; Port B: port 2,6 and 7 output 0, push pull, value 1; port 3 input ; PB0 = 6574 Disable PB2 = SW PWM (out), PB3 = POWER OK (in), ; PB6 = PFC Disable (out), PB7 = HW PWM - AutoReload Timer (out) clr DRB ldi DDRB,0C5H ldi OPRB,0C5H
14/20
AN1320 APPLICATION NOTE
; Port C: All Input, No Interrupt, Pulled up (PC2 = NO IGN(in), PC3 = DISC LAMP (in)) clr DRC clr DDRC clr OPRC ; Data Rom Window Configuration ldi DRWR,3DH ; Default Duty Cycle value on SwPWM ldi V,DEF_SW_DUTY set 2,DRB ; A/D Converter setup ldi
; = (0F40H >> 6)
; V = Duty Cycle ; SwPWM Port Set
ADCR,10h
; AD w/out Interrupt, Turned On
; AR-TIMER Configuration (HwPWM) ldi ARMC,20h ldi ARLR,00h ldi ARRC,80h ldi ARCP,DUTY_PRE set 7,ARMC res 7,ARMC ldi ARSC1,60h set 6,ARMC ;============================================== ; Star tup Sequences ;============================================== CheckPower ; "Power Ok" test twice jrr 3,DRB,CheckPower ldi a,GenTick ld x,a ldi a,GenRepeat ld y,a call Wait jrr 3,DRB,CheckPower LampOK jrr ldi ld ldi ld call jrr jp Star tHeat clr NrTent ; *** Test if Lamp is connected 3,DRC,Star tHeat a,GenTick x,a a,GenRepeat y,a Wait 3,DRC,Star tHeat StopIt
; Autoreload mode, enabled, stopped, no int enabled ; LOAD REGISTER ; RELOAD REGISTER ; COMPARE REGISTER ; Load ARRC and RESET ARSC1 ; STOP Load phase ; Fint, prescaler /8 Fpwm =7.8125KHz ; Start Timer
; wait for pin = 1 ; Load tick counter ; Load repetition time
; test for pin data steady
; if connected, go ahead ; Load tick counter ; Load repetition time ; Wait ; test twice for steady ; unconnected lamp: RIP
; Reset Tentative counter
PreHeat ; *** Preheating waiting time ldi A,DUTY_PRE ld ARCP,A ldi a,TpreTick ld x,a ldi a,TpreRepeat ld y,a call Wait
; Set preheating Duty-Cycle ; Load tick counter ; Load repetition time
15/20
AN1320 APPLICATION NOTE
IgnStar t ; *** Ignition sequence clr Ignition ldi add ld ld ld ldi ld ldi ld call inc ld cpi jrz nop nop jp Ignited inc ldi ld ldi ld call jrr ld cpi jrz jp GotoStop jp StopIt NrTent a,GenTick x,a a,GenRepeat y,a Wait 2,DRC,LampOn A,NrTent A,MAX_TENT GotoStop PreHeat ; Load tick counter ; Load repetition time
Step A,40H A,Step X,A A,(X) ARCP,A a,TignTick x,a a,TignRepeat y,a Wait Step A,Step A,40h Ignited
; Reset lookup table index ; Load Duty-Cycle value from look-up table
; on comparator value ; Load tick counter ; Load repetition time
; Update step counter ; if last value in table ; exit ; else next value
Ignition
; if lamp ignited (PC2=0) go ahead ; if trial number overflows, stop ; else retry
LampOn ; *** System working, set interrupt on PortC, pin 2 and 3 clr IOR clr DDRC ldi OPRC,08H clr DRC ldi IOR,30h ; *** Internal timer activation for A/D tracking res 3,TSCR set 6,TSCR ldi a,TadTick ld TCR,a ldi a,TadRepeat ld Repeat,a set 3,TSCR ; New Data Rom Window Configuration ldi DRWR,3CH
; PC3 (No Lamp) INT pull-up ; enable global int, rising edge
; Stop Timer 1 ; Enable interrupt ; Load tick counter ; Load repetition time ; Start Timer
; = (0F00H >> 6)
16/20
AN1320 APPLICATION NOTE
;============================================== ; Main loop ;============================================== res 0,ARSC0 nop Main jrr 0,ARSC0,Main res 0,ARSC0 set 2,DRB
; Set SwPWM output
SwPWMLoop ld cp jrc res jp A,ARLR A,V SwPWMLoop 2,DRB Main
; Reset SwPWM output
;============================================== ; Routines ;============================================== ;============================================== ; Stop all operations and disables chips ;============================================== StopIt set 0,DRB set 6,DRB RIP jp RIP ; ============================================= ; Wait: holds for a time:=x*y*192us ; x = 192us Ticks number to hold ; y = Repeat Times ; ============================================= Wait ld a ,y ld Repeat,a WaitRestar t ld a ,x ld TCR,a set 3,TSCR WaitTimerExp jrr 7,TSCR,WaitTimerExp res 7,TSCR dec Repeat ld a,Repeat jrnz WaitTimerExp res 3,TSCR ret
; Disable 6574 ; Disable PFC ; Do nothing
; Load repeat time nr.
; Load Counter Value ; Timer start
; Timer expired, reset flag
; WaitAgain ; Repetition Timer expired, reset
;========================================================== ; Setup A/D Converter ;========================================================== SADC clr Media; Reset Media register ldi Count,04h ; Init counter set 5,ADCR ; start a/d conversion nop nop set 7,ADCR ; Enable Interrupt ret
17/20
AN1320 APPLICATION NOTE
;========================================================== ; Interrupt routines ;========================================================== ; *** Port A IPA ; Unused reti ; *** Port C IPC ; Test if some signal went up ld jrs PC2End jrs PC3End ld reti PC2 nop nop jrr jp PC3 nop nop jrr jp A,W ; restore accumulator 3,DRC,PC3 ; Test port C, pin 3 W,A 2,DRC,PC2 ; save accumulator ; Test port C, pin 2
; PC2 issued
2,DRC,PC2End StopIt
; Confirm steady on pin ; Stop operations
3,DRC,PC3End StopIt
; Confirm steady on pin ; Stop operations
;========================================================== ; DispatchIRQ4: test if timer or AD interrupt ;========================================================== DispatchIRQ4 jrs jrs reti 7,TSCR,ITIM 6,ADCR,IADC ; Test for timer interrupt ; Test for AD interrupt
;========================================================== IADC res ld ld ld jrnz reti Conversion ld rlc rlc rlc rlc andi add ld dec ld jrz set nop a,Sample a a a a a,07h a,Media Media,a Count a,Count SetSamp 5,ADCR ; a = Sample ; a = a >> 4 7,ADCR a,ADR Sample,a a,Count Conversion ; Disable Interrupt ; Load Sample ; Test for maximum sample ; maximum reached
; 8 levels
; Enable A/D converter
18/20
AN1320 APPLICATION NOTE
nop set reti SetSamp ld andi rlc rlc rlc rlc rlc rlc rlc ld rlc addi ld ld ld inc ld ld reti a,Media a,01Ch a a a a a a a Sample,a a a,040h x,a a,(x) ARCP,a x a,(x) v,a ; Media=+last 4 conversion
7,ADCR
; Enable Interrupt ; Restart fo new sample
; sample=media/4 (media >> 2) ; offset for table look-up (@ 0x40)
; hw pwm
; sw pwm
;========================================================== ITIM ldi a,TadTick ; Load tick counter ld TCR,a res 7,TSCR ; Reset Tout Flag dec Repeat ld a,Repeat jrnz GetOut ; WaitAgain res 3,TSCR ; Repetition Timer expired, reset call SADC ldi a,TadRepeat ; Load repetition time ld Repeat,a set 3,TSCR ; Start Timer GetOut reti ;========================================================== ARTInt reti INMI .org 0FF0H ; Autoreload Timer interrupt RETI ; not used
irq4 jp irq3 jp irq2 jp irq1 jp .block 4 nmi jp vrst jp .END Init INMI IPA IPC ARTInt DispatchIRQ4
19/20
AN1320 APPLICATION NOTE
Information furnished is believed to be accurate and reliable. However, STMicroelectronics assumes no responsibility for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of STMicroelectronics. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all information previously supplied. STMicroelectronics products are not authorized for use as critical components in life support devices or systems without express written approval of STMicroelectronics. The ST logo is a registered trademark of STMicroelectronics 2000 STMicroelectronics - All Rights Reserved STMicroelectronics GROUP OF COMPANIES Australia - Brazil - China - Finland - France - Germany - Hong Kong - India - Italy - Japan - Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - U.S.A. http://www.st.com
20/20
|