using an st7ultralite microcontroller to drive a triac or...

21
September 2006 Rev 1 1/21 AN2425 Application note Using an ST7ULTRALITE microcontroller to drive a TRIAC or an AC switch for a Mains supply Introduction This document describes how to design a light dimmer or motor speed control device using an ST7ULTRALITE microcontroller as a driver for a TRIAC or AC switch on the mains supply. This electronic equipment is typically used in home appliances or in industrial applications for a variety of purposes such as motor regulation in washing machines, vacuum cleaner control, light dimming in a lamp, heating in a coffee machine, or motor regulation in a ventilator. The STEVAL-ILL004V2 evaluation board illustrates ST’s solution for these kinds of applications. This design is mainly based on the solution presented in Application Note AN2263: Universal motor speed control and light dimmer with TRIAC and ST7LITE microcontroller which provides a complete design description for the STEVAL-ILL004V1 evaluation board. The main difference between these two evaluation boards is the microcontroller; the STEVAL-ILL004V2 uses the smaller 8-pin ST7ULTRALITE microcontroller while the STEVAL-ILL004V1 uses a 16-pin ST7FLITE09 microcontroller. This document presents only new and important information concerning the STEVAL- ILL004V2 evaluation board in order to get quickly started with evaluation. Application Note AN2263 can be used as a reference for complete design solution and provides examples of capacitive power supply circuit design calculation, TRIAC power dissipation calculation, recommended TRIAC summary, ZCD (zero crossing detection) resistor calculation and gate-limiting resistor calculation. STEVAL-ILL004V2 evaluation board www.st.com

Upload: dobao

Post on 19-Mar-2018

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

September 2006 Rev 1 1/21

AN2425Application note

Using an ST7ULTRALITE microcontrollerto drive a TRIAC or an AC switch for a Mains supply

IntroductionThis document describes how to design a light dimmer or motor speed control device using an ST7ULTRALITE microcontroller as a driver for a TRIAC or AC switch on the mains supply. This electronic equipment is typically used in home appliances or in industrial applications for a variety of purposes such as motor regulation in washing machines, vacuum cleaner control, light dimming in a lamp, heating in a coffee machine, or motor regulation in a ventilator.

The STEVAL-ILL004V2 evaluation board illustrates ST’s solution for these kinds of applications. This design is mainly based on the solution presented in Application Note AN2263: Universal motor speed control and light dimmer with TRIAC and ST7LITE microcontroller which provides a complete design description for the STEVAL-ILL004V1 evaluation board.

The main difference between these two evaluation boards is the microcontroller; the STEVAL-ILL004V2 uses the smaller 8-pin ST7ULTRALITE microcontroller while the STEVAL-ILL004V1 uses a 16-pin ST7FLITE09 microcontroller.

This document presents only new and important information concerning the STEVAL-ILL004V2 evaluation board in order to get quickly started with evaluation. Application Note AN2263 can be used as a reference for complete design solution and provides examples of capacitive power supply circuit design calculation, TRIAC power dissipation calculation, recommended TRIAC summary, ZCD (zero crossing detection) resistor calculation and gate-limiting resistor calculation.

STEVAL-ILL004V2 evaluation board

www.st.com

Page 2: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

Contents AN2425

2/21

Contents

1 Basic principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Universal motor speed control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.1 Application schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 Light dimmer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3.1 2-load configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4 EMC testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4.1 EN 55015 for the light dimmer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4.2 EN 61000-3-2 class A for light dimmer . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

4.3 EN 55014 for motor speed control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

4.4 EN 61000-3-2 class A for motor speed control . . . . . . . . . . . . . . . . . . . . 12

5 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

5.1 Main.c module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

5.2 Ports.c module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

5.3 Pwm_ar_timer_12bit.c module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

6 References and related materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Appendix A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

Page 3: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

AN2425 Basic principle

3/21

1 Basic principle

Control techniques for monophase motors, light dimmers or any AC load are based on phase-angle adjusting. The block schematic of this principle is shown in Figure 1. The TRIAC is turned ON by the control signal coming from the microcontroller with a given delay after the zero crossing, and is automatically turned OFF when its current reaches a zero value. It is the same for positive and negative voltages. The total power delivered to the LOAD depends on the time, when the TRIAC is turned ON.

The “heart” of this application is the small, 8-pin ST7ULTRALITE microcontroller. The synchronization used to switch ON the TRIAC at the same time for each of the cycles is provided by zero crossing detection (ZCD). The MCU detects the zero crossing after each period of the input signal and sets the time to switch on the TRIAC in relation to the value of the voltage on the potentiometer or button. Due to the low power consumption, the evaluation board includes a low-cost capacitive power supply. As the TRIAC produces a noise when it is turned “ON” or “OFF,” an input EMI filter is connected on the board.

Figure 1. STEVAL-ILL004V2 board block schematic

Warning: The MCU is directly linked to the mains voltage supply. No insulation is ensured between the accessible parts and the high voltage. The STEVAL-ILL004V2 evaluation board must be used with care and only by persons qualified for working with electricity at mains voltage levels. Certain precautions have to be taken during emulation to avoid damaging development tools.

Page 4: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

Universal motor speed control AN2425

4/21

2 Universal motor speed control

The STEVAL-ILL004V2 evaluation board shows STMicroelectronics’ solution for driving a universal motor or any other AC load using a small, 8-pin microcontroller. The left side of the board includes two connectors; one is the mains connector for the input voltage supplied to the board and the other is the connector for the universal motor. Due to the universality of the board, the load can be controlled either by a button or a potentiometer. The way it is controlled is selected by Switch S2 (“Button” or “Potentiometer”) before the input voltage is connected. The button should not be used to control the motor speed, but only for adjusting the brightness of the light bulb when the lamp is connected as the load (light dimmer application). The potentiometer stands by on the board to control the speed of the motor. The tables on the board show how to connect the jumpers for the input EMI filter for the motor speed control and light dimmer.

The maximum power range of the evaluation board depends on the TRIAC and the size of its heatsink. For example, the board shown on page 1 was tested with a 1600W AC vacuum cleaner motor. For high power (higher than approximately 350W), it is necessary to use the heatsink on the TRIAC due to the power dissipation. The STEVAL-ILL004V2 evaluation board includes a TRIAC with an assembled heatsink for the maximum output power (approximately 1000W).

The application is independent of the input frequency because there is software frequency detection, and so 50 or 60Hz can be selected without any problems. The input voltage can be from 110 up to 240V AC with an ACST76S TRIAC connected on the board. If a BTB16 TRIAC is used in the application with the input voltage 110V, the capacitor C4 = 330nF must be replaced by C4 = 470nF in order to have enough energy to turn ON the TRIAC because the supply voltage is delivered from a capacitive source and depends on the input voltage.

2.1 Application schematic Figure 2 shows the application schematic diagram of the universal motor speed control. Appendix A lists the bill of materials for this application. Components L1, C9, C8 and R9 are not used for the motor speed control (jumpers J1 and J2 are connected and jumper J3 is disconnected).

Due to the universality of the evaluation board, the EMI filter (C7, L1, and C9) is designed as a CLC connection (p-element) to reduce the noise coming from the board to the mains. For motor control applications, it is enough to use only an input capacitor (for example, C7 = 470nF) to guarantee the requested specifications. Section 4: EMC testing describes EMC issues.

STMicroelectronics offers a family of TRIACs (snubberless TRIACs), with an integrated snubber, and so it is not necessary to use external components as overvoltage protection. If the standard TRIAC is used, the snubber circuit (C8 and R9) should be assembled to prevent the TRIAC from spurious turn-on.

The power supply circuit (R6, R7, R10, C4, ZD1, D1 and C5) is developed to supply the microcontroller. If both neutral and phase lines are available on the board, the maximum output current with the input voltage of 230V is 11.08mA. The total consumption of the microcontroller is approximately 3.26mA and consumption of the application is 3.97mA (measured value) and so 11.08mA is really enough to supply the MCU. If the microcontroller is in Halt mode, its consumption is only 6.09µA.

Page 5: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

AN2425 Universal motor speed control

5/21

The Zero Cross Detector (ZCD) is realized by R1, R2, and C2 and the signal is connected to the PA2 port of the microcontroller. A new software implementation can be easily done on the board, due to the ICC connector used to program the microcontroller. As stated above, Switch S2 selects the control method (button or potentiometer).

The TRIAC is driven by high-current capability port PA4 of the microcontroller with maximum current up to 20mA. If there is not enough power to switch ON the TRIAC, Jumper J5 can be connected to two ports in parallel configuration. In this case, the maximum current capability is 25mA. Jumper J4 must be disconnected in order to use the reset pin as the output. This action must be also supported by software modification, because the reset pin must be set as the output (port A3). To configure this pin as output, write 55h to MUXCRO and AAh to MUXCR1 registers. For more information, please refer to the ST7ULTRALITE datasheet.

Note: The STEVAL-ILL004V2 demonstrates both the light dimmer and motor speed control. It means the potentiometer and button is used. If one type of solution is requested, only the potentiometer or button can be used and therefore the next two high-sink ports of the microcontroller can be available (Switch S2 is also not used). It can increase current capability up to 60mA.

Page 6: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

Un

iversal mo

tor sp

eed co

ntro

lA

N2425

6/21

Fig

ure 2.

Ap

plicatio

n sch

ematic

VCC

VCC

VCC

VCC

VCC

L

N

5.6V

~275V AC X2

LOAD ORSHORTCONNECTION(IF LAMP ISIN SERIAL)

MAINS

~275V AC X2

Snubber

ACST67STR IAC

Use PIN4 as RESET or Port

LIGHT DIMMERSERIAL CONFIGURATION PRALLEL CONFIGURATION

JUMPER 1JUMPER 2JUMPER 3

JUMPER 1JUMPER 2JUMPER 3

JUMPER 1JUMPER 2JUMPER 3

MOTOR CONTROLPARALLEL CONFIGURATION

DIS.DIS.DIS.

DIS.DIS.

CON.

CON.

CON.CON.

USE PIN4 OF ST7ULTRALITE ASRESET OUTPUT

JUMPER 4JUMPER 5

JUMPER 4JUMPER 5

CON.CON.DIS.DIS.

C7C7470nF

C1

100nF

C1

12

34

56

78

910

ICC

R8

20K

R8

20K

R5

20K

R5

20K

R1

160K

R1

160K

C9100nFC9

100nF

Q1

BTB16 or

Q1

B16

F1

FUSE

F1

FUSE

J3J3

L1

0.1mH / 5A

L1

0.1mH / 5A

1 2

43

S1Bu tton

S1tto

~275

VAR

ISTO

R

~275

VAR

IS

J4J4

C61nFC61nF

1 2

43S3

Bu ttontto

VDD1PA

5 2PA4 3RESE T4

PA2 5

VSS8

PA1 6AIN07

IO1

ST 7ULT TE

1

RALI

R91kR91k

R10150R1150

12

J2J2

R6

150

R6

150

ZD11

C2100pFC2100pF

R134K7R14K

C4

330nF

C4

330nF

1 2JUMPER 2JUMPER 2

R31MR31M

R2

160K

R2

160K

D1

D4007

D1

D4007

124JUMPER 4

R4

47

R4

47

R7

150

R7

150

+C5470uF/16V

+C5470µF/16V

32

1P110K

P110K

12

J1J1

12 JU

MP

ER

11

12

JUM

PE

R 5

C310nF R11

4K7R1

R12

20K20K

12 JU

MP

ER

33

1 2

3

S2Switchitch

C8

2.2nF

C8

2.2nF

J5J5

AI12634

Page 7: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

AN2425 Light dimmer

7/21

3 Light dimmer

The STEVAL-ILL004V2 evaluation board is also used for light dimmer applications. This solution is based on the same design principle as the motor speed control; meaning that all information provided in Section 2: Universal motor speed control is also valid for light dimmers.

In regards to lighting specifications, a different type of input filter is selected compared with the motor speed control. A CLC filter (C7 = 470nF, C9 = 100nF and L1 = 0.1mH) is used.

In order to control the light (typical of dimmer applications), the use of Switch S2 must be taken into account when designing the application to enable certain features such as decreasing or increasing lamp brightness. If the switch is pressed twice quickly (between 0 and 40ms), nothing happens. If pressed between 40ms and 240ms, it means turn “ON” or “OFF” device. If the lamp is turned “OFF”, the brightness level is stored in the memory of the microcontroller. When pressed for longer than 240ms, the brightness “automatically” increases until it reaches its maximum value at which point the brightness starts decreasing and so on.

3.1 2-load configurationIn many lighting applications, the phase and neutral lines are not both available. A general example is the switch on the wall, where very often only the phase is connected as shown in Figure 3 - part 2. The lamp is connected in series with the evaluation board and the microcontroller is supplied from the voltage on the TRIAC when the TRIAC is turned “OFF”. So if the TRIAC is turned “ON” for a long time during half of the signal period, there is not enough time (voltage) to save the energy and the device will not work. This limitation means that it is not possible to switch “ON” the TRIAC for 100%. Using the power supply designed in this application, the maximum time for opening the TRIAC is approximately 80% (Figure 4). This value was measured using a 500W halogen lamp connected in series with the evaluation board.

Caution: If the load is connected in series with the evaluation board, the input filter must not be assembled (especially the input capacitors) because the input capacitors can produce a large di/dt on the TRIAC when the device is turned “ON” that may damage the TRIAC.

If the lamp is directly connected to the evaluation board (Figure 3 - part 1), the capacitive power supply is able to provide enough energy for the microcontroller because the phase and neutral lines are both available. In this case, the time for opening the TRIAC is unlimited, but, for example, it makes no sense to design software for more than 95% because there is almost no brightness difference between 95 and 100%.

Due to the universality of the evaluation board (motor speed control, lamp available on the board or lamp in series with the board), the software is designed to limit opening time for TRIAC at 80% in order to guarantee correct functioning for a lamp in series with the evaluation board. Of course, there is no problem to change this limit for applications where both the phase and neutral lines are available.

Page 8: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

Light dimmer AN2425

8/21

Figure 3. 2-load configuration

1. Both phase and neutral lines are available

2. Phase and neutral lines are not both available.

1.

2.

Page 9: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

AN2425 Light dimmer

9/21

Figure 4. Maximum time for switching ON the TRIAC with lamp in series

Page 10: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

EMC testing AN2425

10/21

4 EMC testing

Light dimmer applications are tested for compliance with EN55015 and motor speed control applications with EN55014-1 and EN61000-3-2 class A specifications.

EN55015 specifications describe the limits and methods of measurement of radio disturbance characteristics for electrical lighting and similar equipment.

EN55014-1 specifications describe electromagnetic compatibility - requirements for household appliances, electric tools, and similar devices - part 1: emission.

EN61000-3-2 specifications describe the limits for harmonic current emissions (equipment input current up to and including 16A per phase).

For more information, please refer to Application Note AN2263: Universal motor speed control and light dimmer with TRIAC and ST7LITE microcontroller.

The evaluation board was tested for compliance with these three specifications. Note that for any other design of these applications (light dimmer, motor control, etc.), the results will not be the same and the tests must therefore be repeated.

In conclusion, only a certification laboratory can provide and approve the compliance with specifications for the products to be sold on the market.

Warning: The MCU is directly linked to the mains voltage supply. No insulation is ensured between the accessible parts and the high voltage. The STEVAL-ILL004V2 evaluation board must be used with care and only by persons qualified for working with electricity at mains voltage levels. Certain precautions have to be taken during emulation to avoid damaging development tools.

4.1 EN 55015 for the light dimmerIn order to guarantee these specifications, a CLC input filter is selected. The value of the filtering capacitors is C7 = 470nF and C9 = 100nF (~275V AC X2) and the inductor L1 has the value of 0.1µH. A 150W bulb load is connected on the board, which means the phase and neutral lines are available for the power supply circuit. As the output power can be regulated by the switching time of the TRIAC, there are many states for testing, but the only the worst case (the highest noise) is measured. This happens if the TRIAC is turned ON in the maximum voltage of the sinusoidal waveform. Measuring the peak value shows that its real waveform is under the requested limit, proving that this type of EMI filter is suitable for light dimmer applications (Figure 5).

Page 11: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

AN2425 EMC testing

11/21

Figure 5. Peak measurement for the light dimmer

4.2 EN 61000-3-2 class A for light dimmerPhase-controlled dimmers up to 1kW do not need to be tested for harmonic current emissions because harmonic current limits are not specified in this specification for independent dimmers for incandescent lamps with a rated power less than or equal to 1kW. The STEVAL-ILL004V2 evaluation board includes a heatsink and is designed to deliver an output power up to 1kW and therefore does not require testing.

4.3 EN 55014 for motor speed controlOnly one input capacitor (C7 = 470nF) connected in parallel is able to obtain real measured waveforms below their limits, which means it is possible to guarantee compliance with these specifications using just this type of filter. In any case, when the AC motor is used as a load, the serial inductor is not needed in the application.

For testing purposes, a load of 1600W from a vacuum cleaner motor was used. The motor was connected to the board, so the both the phase and neutral lines were available for the power supply circuit. As stated above, the output power can be regulated by the switching time of the TRIAC. There are many states for testing, but the measurement is provided only for the worst case (the highest noise). This happens when the TRIAC is turned ON in the maximum voltage of the sinusoidal waveform. As above, two measurements are requested in these specifications. One is a quasi peak value and the second one is an average value. Both real waveforms are below the requested limits, which mean this type of EMI filter is suitable for an AC motor (Figure 6 and Figure 7).

Page 12: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

EMC testing AN2425

12/21

Figure 6. Quasi peak measurement for the motor speed control

Figure 7. Average value measurement for the motor speed control

4.4 EN 61000-3-2 class A for motor speed controlThe STEVAL-ILL004V2 evaluation board is almost the same as the STEVAL-ILL004V1; the only difference is the microcontroller. The EN61000-3-2 was already tested on the STEVAL-ILL004V1 and is described in Application Note AN2263: Universal motor speed control and light dimmer with TRIAC and ST7LITE microcontroller.

Therefore it was not tested to fulfill specification requirements for the STEVAL-ILL004V2. Generally the input capacitor C7 = 470nF is used on the board in order to guarantee compliance with these specifications.

Page 13: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

AN2425 Software

13/21

5 Software

The software is written in C language, structured, and well-commented. It contains several modules, but the main functions necessary for the proper operation of the evaluation board reside in the following:

Main.c

Ports.c

Pwm_ar_timer_12bit.c

Lite_timer_8bit.c

Adc_8bit.c

Note: The overall code is less than 1KB so that it will fit the ST7 ULTRALITE memory.

The working principle of using the TRIAC to drive either the incandescent lamp or one-phase AC motor is to switch ON the TRIAC at the exact time in both half-periods of the sine wave. The TRIAC is closed automatically upon zero crossing detection. The minimum and maximum opening time for the TRIAC is set as a constant value inside the software and it can be easily modified in order to guarantee the required power range for various applications.

The main idea of the software is to synchronize the internal timer inside the ST7 ULTRALITE microcontroller using the Zero Crossing (ZC) events of the mains sinusoidal waveform. The voltage from the mains is applied on Pin PA2 which is set up as an input interrupt in a pull-up configuration. In the case of an internal counter that is not synchronized with the ZC event, the user may have difficulty with the performance of the following interrupts:

1. Interrupt from the input pin

2. Interrupt from the timer (e.g. overflow interrupt)

Note: This can influence driver stability if in one period the TRIAC is switched ON at a different time compared to the second one.

The 12-bit Auto-reload Timer (AT timer) is used in Output Compare (OC) mode. The AT timer is over-flowed on address FFFh to the value set in the Auto-reload register (ATR, in this configuration, 000h).

At each ZC synchronized (sync) event interval (Figure 8), the DCR register is filled by the actual counter state from CNTR and the value corresponding to the 0.2ms interval (640 hrs). From that time, the ZC is synchronized on the mains. After that, an OC interrupt occurs every 0.2ms where DCR = DCR + the value corresponding to the 0.2ms interval (640 hrs). Each OC interrupt is incremented in the software counter (Figure 9).

The main advantage of this design is that the CNTR register is readable at any time and the new value can be written immediately to the DCR register without any delay. The 0.2ms interval is the smallest step required for firing the TRIAC.

The TRIAC is fired from PA4 pin, which can source the gate up to 20mA (max.). If the application requires more power (e.g. for a bigger TRIAC), change the RESET pin to output push-pull and use a jumper add it to PA4. To do this, modify the source code in the lib.h module to uncomment “#define RESETOUT” line and compile it again. This changes the port configuration and certain constants used for firing the TRIAC. The Watchdog is used in a hardware configuration set up using the option byte.

Page 14: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

Software AN2425

14/21

Figure 8. ZC events

Figure 9. Auto-reload timer principle

5.1 Main.c module After the MCU is turned ON, all active peripherals (e.g., ports, LITE Timer, and 12-bit Auto-reload), the ADC and Watchdog refresh (WDG) are set up in the “Main” program in this module. After this, all of the variables are set up and the MCU will enter Wait For Interrupt (WFI) mode. This leads to minimum power consumption because the program is performed only in interrupts (from ZC and the OC timer) as shown in Figure 10.

AI12629

ZC–sync.

ZC ZCZC–sync.

ZC–sync.

Period Period

AI12630

ZC sync.

OC int.

ZC sync.

ATR = 000

OC int. OC int. OC int. OC int. OC int. OC int. OC int. OC int. OC int. OC int.

FFF

000

DCR = CNTR+ 640 hrs DCR =

DCR + 640 hrs

DCR = DCR + 640 hrs

Page 15: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

AN2425 Software

15/21

Figure 10. Main programming flowchart

5.2 Ports.c module All timers are switched OFF until the first ZC event occurs. This interrupt is handled in the ports.c module using the PORTS_0_Interrupt routine (Figure 11) which checks the Port A pin 2 (PA2) on the falling edge. This pin is set up as the input interrupt that is in pull-up configuration. After catching the first interrupt, the AT timer is switched ON and the DRC is loaded with the 0.2ms value for the compare interrupt.

The timer is then synchronized with the ZC event. The ZC window is set up for 50Hz and the interrupt routine finishes. From this point, the AR_TIMER_OC_Interrupt routine is performed every 0.2ms (Figure 12).

After the 50/60Hz mains has been ON for a time period (approximately 20 to 16.7ms), the second ZC interrupt occurs. At this point, the interval between ZC events is measured and, based on this value, the corresponding flags are set (50 or 60Hz). If this event does not fit either the 50 or 60Hz parameters, all of the timer flags and the counter are re-initialized for another synchronization attempt. The ZC window interval is ±1.2ms. At the end of this interval, a new ZC event is set up.

After a successful synchronization phase, the next ZC event is monitored during the following ZC interrupt and monitored to see if the ZC interval passes synchronization parameters, or if the timer needs to be synchronized again.

The new value used to fire the TRIAC (via the 'Read from' button or potentiometer) is also measured here.

If the ZC interval is missed the first time, the program continues with the synchronization values measured from the previous ZC interrupt. If the next ZC interval is missed again, the microcontroller is reset by the WDG.

AI12631

MAIN

END

PORTS settingsTIMER settingsADC settingsWDG refresh

Set all variables

WFI

Page 16: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

Software AN2425

16/21

5.3 Pwm_ar_timer_12bit.c module The AT timer in OC mode is used as the main time counter. This interrupt is handled in the AR_TIMER_OC_Interrupt routine in the pwm_ar_timer_12bit.c module. This routine generates the 0.2ms time base used for push-button handling, TRIAC firing, WDG refresh, and software counter incrementing (Figure 12). The button checking and handling routine checks the state of the button driving pin every 0.2ms.

Figure 11. PORTS_0_Interrupt

AI12632

PORTS_0_ Interrupt

RETURN

SynchronizeTIMER

Set ZC window

SynchronizeTIMER

WDG on

Micro is alreadysynchronized

SynchronizeTIMER

Measure period

Set all flags + counterfor new synch.

Set 50Hz flag

Reset Microby WDG

Set 60Hz flag

Set ZC window for 50Hzor 60Hz

1stinterrupt?

1st ZCmissed?

Fit signal ZCwindow?

2ndinterrupt?

Set MISSED flag SynchronizeTIMER

Measure period

Set normal runflags

Use previousmeasured period

Set ZC window

Set ZC window

Prepare new valuefor triac firing

(read from buttonor potentiometer)

RETURN

50Hz, 60Hz or ?

Other Hz 60Hz

50Hz

1

NO NO

NO NO

YES YES

YES YES

1

Page 17: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

AN2425 Software

17/21

Figure 12. AR_TIMER_OC_Interrupt

AI12633

Recount edgesfor firing the triac

Reset the Micro

Button checking and

handling

Fire the triac

WDG refresh

RETURN

NO

NO

NO

YES

YES

YES

Set next 0.2msperiod

Dimmingdirectionhandling

Counter ++

2nd ZCmissed?

1st ZCmissed?

Is it the time to firethe triac?

AR_TIMER_0C_ Interrupt

Page 18: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

References and related materials AN2425

18/21

6 References and related materials

1. AN 2263: Universal motor speed control and light dimmer with TRIAC and ST7LITE micro

2. AN 1255: New circuital solution to efficiently drive an AC monophase motor or AC load

3. ACST6-7S Datasheet

4. BTB16 Datasheet

5. AN1512: ST FIVE control of an AC monophase motor without harmonic distortion

6. ST7ULTRALITE Datasheet

7. AN 392/1098: Using Microcontrollers and TRIACs on a 110/240V mains supply.

Page 19: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

AN2425

19/21

Appendix A

Table 1. Bill of material STEVAL - ILL004V2

Item Quantity Reference Part Ordering code

1 1 CONNECTOR2 ICC

2 1 C1 100nF/50V

3 1 C2 100pF/50V

4 1 C3 10nF/50V

5 1 C4 330nF/~275V AC X2

6 1 C5 470µF/16V

7 1 C6 1nF/50V

8 1 C7 470nF/~275V AC X2

9 1 C8 2.2nF (NC)

10 1 C9 100nF/~275V AC X2

11 1 D1 D4007

12 1 F1 FUSE- 10A

13 1 IO1 ST7ULTRALITE ST7FLITEUS5B6

14 5 J1, J2, J3, J4, J5 JUMPER

15 2 J6, J7 CON3

16 3 J8, J9, J10 CON1

17 1 L1 0.1mH/5A

18 1 P1 10KΩ

19 1 Q1 BTB16 BTB16-600CW

20 2 R1, R2 160KΩ

21 1 R3 1MΩ

22 1 R4 47Ω

23 3 R5, R8, R12 20KΩ

24 3 R6, R7, R10 150Ω

25 1 R9 1kΩ (NC)

26 2 R11, R13 4,7kΩ

27 2 S1, S3 Button

28 1 S2 Switch

29 1 ZD1 5,6V

30 1 ~275 VARISTOR

Page 20: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

Revision history AN2425

20/21

Revision history

Table 2. Document revision history

Date Revision Changes

7-Sept-2006 1 Initial release.

Page 21: Using an ST7ULTRALITE microcontroller to drive a TRIAC or ...application-notes.digchip.com/005/5-9758.pdf · 4 EMC testing ... TRIAC is turned ON by the control signal comi ng from

AN2425

21/21

Please Read Carefully:

Information in this document is provided solely in connection with ST products. STMicroelectronics NV and its subsidiaries (“ST”) reserve theright to make changes, corrections, modifications or improvements, to this document, and the products and services described herein at anytime, without notice.

All ST products are sold pursuant to ST’s terms and conditions of sale.

Purchasers are solely responsible for the choice, selection and use of the ST products and services described herein, and ST assumes noliability whatsoever relating to the choice, selection or use of the ST products and services described herein.

No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. If any part of thisdocument refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party productsor services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of suchthird party products or services or any intellectual property contained therein.

UNLESS OTHERWISE SET FORTH IN ST’S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIEDWARRANTY WITH RESPECT TO THE USE AND/OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIEDWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE (AND THEIR EQUIVALENTS UNDER THE LAWSOF ANY JURISDICTION), OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE, ST PRODUCTS ARE NOTRECOMMENDED, AUTHORIZED OR WARRANTED FOR USE IN MILITARY, AIR CRAFT, SPACE, LIFE SAVING, OR LIFE SUSTAININGAPPLICATIONS, NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY,DEATH, OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE. ST PRODUCTS WHICH ARE NOT SPECIFIED AS "AUTOMOTIVEGRADE" MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER’S OWN RISK.

Resale of ST products with provisions different from the statements and/or technical features set forth in this document shall immediately voidany warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever, anyliability of ST.

ST and the ST logo are trademarks or registered trademarks of ST in various countries.

Information in this document supersedes and replaces all information previously supplied.

The ST logo is a registered trademark of STMicroelectronics. All other names are the property of their respective owners.

© 2006 STMicroelectronics - All rights reserved

STMicroelectronics group of companies

Australia - Belgium - Brazil - Canada - China - Czech Republic - Finland - France - Germany - Hong Kong - India - Israel - Italy - Japan - Malaysia - Malta - Morocco - Singapore - Spain - Sweden - Switzerland - United Kingdom - United States of America

www.st.com