19
ZiLOG Worldwide Headquarters • 532 Race Street • San Jose, CA 95126 Telephone: 408.558.8500 • Fax: 408.558.8300 • www.zilog.com Application Note Dimmer Application Using Z8 Encore! XP ® 8-Pin Microcontroller AN025101-1106

Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

Embed Size (px)

Citation preview

Page 1: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

ZiLOG Worldwide Headquarters • 532 Race Street • San Jose, CA 95126Telephone: 408.558.8500 • Fax: 408.558.8300 • www.zilog.com

Application Note

Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

AN025101-1106

Page 2: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

AN025101-1106

This publication is subject to replacement by a later edition. To determine whether a later edition exists, or to request copies of publications, contact:

ZiLOG Worldwide Headquarters532 Race StreetSan Jose, CA 95126Telephone: 408.558.8500Fax: 408.558.8300www.zilog.com

ZiLOG is a registered trademark of ZiLOG Inc. in the United States and in other countries. All other products and/or service names mentioned herein may be trademarks of the companies with which they are associated.

Information IntegrityThe information contained within this document has been verified according to the general principles of electrical and mechanical engineering. Any applicable source code illustrated in the document was either written by an authorized ZiLOG employee or licensed consultant. Permission to use these codes in any form, besides the intended application, must be approved through a license agreement between both parties. ZiLOG will not be responsible for any code(s) used beyond the intended application. Contact the local ZiLOG Sales Office to obtain necessary license agreements.

Document Disclaimer©2006 by ZiLOG, Inc. All rights reserved. Information in this publication concerning the devices, applications, or technology described is intended to suggest possible uses and may be superseded. ZiLOG, INC. DOES NOT ASSUME LIABILITY FOR OR PROVIDE A REPRESENTATION OF ACCURACY OF THE INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED IN THIS DOCUMENT. ZiLOG ALSO DOES NOT ASSUME LIABILITY FOR INTELLECTUAL PROPERTY INFRINGEMENT RELATED IN ANY MANNER TO USE OF INFORMATION, DEVICES, OR TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE. Except with the express written approval ZiLOG, use of information, devices, or technology as critical components of life support systems is not authorized. No licenses or other rights are conveyed, implicitly or otherwise, by this document under any intellectual property rights.

Application Notes are tested with the version of ZDS II available at the time of release. Subsequent releases of ZDS II may require you to modify Application Note code to restore its function.

Page 3: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

AN025101-1106 Revision History

iii

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

Revision HistoryEach instance below reflects a change to this document from its previous revision. For more details, refer to the corresponding pages and appropriate links in the table given below.

Date Revision Level Description Page No

November 2006 01 Original issue All

Page 4: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

AN025101-1106

iv

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

Table of ContentsAbstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Z8 Encore! XP® Flash Microcontrollers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Theory of Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Hardware Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2Software Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Test Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Equipment Used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Test Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Test Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Page 5: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

AN025101-1106

v

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

List of FiguresFigure 1. Phase Control on Full Wave Rectified Line Voltage . . . . . . . . . . . . . . 2

Figure 2. Hardware Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Figure 3. Software Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Figure 4. Z8 Encore! XP® Dimmer Application Reference Design . . . . . . . . . . 11

Figure 5. Flowchart of main Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

Figure 6. Flowchart of Comparator ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Figure 7. Flowchart of Timer0 ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

Figure 8. Flowchart of ADC ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

List of TablesTable 1. List of References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Table 2. Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Page 6: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

1

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

AbstractThis Application Note describes an implementation of a dimmer based on ZiLOG’s Z8 Encore! XP® 8-pin microcontroller. The dimmer functions effectively for 230V/50Hz and 110V/60Hz AC power source. An incandescent lamp is used as the load in this dimmer and the intensity of this lamp is controlled using a potentiometer. An optical isolation is provided between control and power circuits to create an electrical isolation and to protect the control circuits.

On-chip peripherals such as Comparator, Analog-to-Digital Converter (ADC), Oscillator, and Timer in the Z8 Encore! XP MCU combined with its 8-pin foot print make the MCU a best choice for dimmer application.The source code associated with this Application Note is available in Z8 Encore! XP Applications Library under Application Sample Libraries on www.zilog.com.

Z8 Encore! XP® Flash MicrocontrollersZ8 Encore! XP 4K Series products expand upon ZiLOG's extensive line of 8-bit microcontrollers. Flash memory in-circuit programming capability allows faster development time and program changes in the field. The high-performance register-to-register based architecture of the ZiLOG's eZ8 core maintains backward compatibility with ZiLOG's popular Z8 MCU. Featuring eZ8 CPU, the new Z8 Encore! XP microcontrollers combine a 20 MHz core with Flash memory, linear-register SRAM, and an extensive array of on-chip peripherals. These peripherals make the Z8 Encore! XP MCU suitable for a variety of applications including motor control, security systems, home appliances, personal electronic devices, and sensors.

DiscussionDimmer is used in theatres, industries, and also in house-hold lighting applications. The concept used in the design of dimmer is also applied to control motor speeds in fans and heaters. Different loads (lamp, motors, heating coil, etc.) respond to different controlled parameters such as root mean square (rms) voltage, average voltage, and peak voltage. That is, the intensity of the lamp, speed of the motor, and amount of heat in the heating coil can be varied by controlling the parameters.

AN025101-1106 Abstract

Page 7: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

2

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

Theory of OperationIn this dimmer, the alternating current (AC) phase control method is used to control the intensity of an incandescent lamp, which is connected as a load. The rms value of the voltage supplied to the lamp is varied by controlling the firing angle of a Triac. The firing angle is the delay from the zero crossing of the AC to the time the Triac is fired. The firing angle is determined by the position of a potentiometer, which is interfaced to the Z8 Encore! XP MCU.

Figure 1 displays the effective voltage applied to a load by controlling the firing angle, α. When the AC changes its direction, that is, at a point when AC voltage is zero, the Triac is turned OFF. This makes the load current zero at every AC half cycle. Therefore, to keep the lamp glowing continuously at the set intensity, the Triac needs to be fired during both halves of the AC sine wave, which ensures that the average load current is not zero. In ON condition, the voltage across Triac drops to zero and in OFF condition the line voltage appears across the Triac.

Figure 1. Phase Control on Full Wave Rectified Line Voltage

By controlling the firing angle, the rms voltage supplied to the load changes and according to the voltage light intensity of the bulb varies.

Hardware ArchitectureFigure 2 on page 3 provides an overview of the hardware architecture for the dimmer.

Voltage Applied to Load

Firing Angle ( )

AN025101-1106 Discussion

Page 8: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

3

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

Figure 2. Hardware Block Diagram

The hardware sections are described below:

Power Supply SectionThe power supply section consists of a RC voltage dropper and zener diode followed by a bridge rectifier. The break down voltage of the zener diode is 12 V. A capacitor across the zener diodes provides smoother waveform to the rectifier. The rectifier output is tapped across two diodes as displayed in schematic (see Appendix C). Therefore, the rectified voltage varies between 0 V and 1.4 V. This signal is used for zero crossing detection. Further, the rectified output is filtered and is provided as input to a 3.3 V regulator to power the MCU.

The value of C2 (see Schematic Diagrams) must be 0.6 µF for working with 110V/60Hz AC and 0.47 µF for 230V/50Hz power source.

Optoisolator Triac Drive SectionAn optoisolator Triac drive (MOC3021) is used for isolated Triac triggering. The Triac drive is connected to a General-Purpose Input/Output (GPIO) pin of Z8 Encore! XP MCU through a current limiting resistor. A snubber circuit is also

Line

(AC Voltage

230V /50Hz

or110V /60Hz)

Voltage Step Down

(12 V)

and

Bridge Rectifier

Voltage Regulator

(3.3 V)VCC

Load / Incandescent

Lamp

Z8 Encore!XP®

Power Supply

Neutral

Opto-isolator Triac Drive

GPIO

Comparator

Dimming Control

Potentiometer

Switch to put

CPU in STOP mode

ADC

GPIO

For Zero Crossing Detector

Note:

AN025101-1106 Discussion

Page 9: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

4

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

provided to avoid false triggering of the Triac due to rate of voltage change (dv/dt) exceeding the rating.

Dimming Control SectionUser control of the dimmer is through a potentiometer and a switch. The potentiometer is used to control the intensity. The potentiometer is tied to the internal reference voltage of the ADC available on the Vref pin of the Z8 Encore! XP MCU. The internal ADC reference is made available on Vref pin by setting REFOUT bit in ADCCTL0 register and enabling alternate function for the associated GPIO. The switch is used to put the system in STOP mode and also to recover from STOP mode and restart on subsequent press.

The voltage across the potentiometer is read in ADC Interrupt Service Routine (ISR). The ADC output is used to find the table offset needed to load timer reload values. The timer reload value determines the firing angle of the Triac and the intensity of the lamp. The timer reload value is loaded in Comparator ISR.

Software ImplementationThe following sequences of events constitute the dimmer application:

1. Initializes Comparator, Timer0, ADC, and GPIO (see Initialization section on page 5).

2. Measures AC line frequency (50Hz/60Hz).

3. Potentiometer position is read in ADC continuously and table offset for timer reload is determined.

4. Timer0 reload register is updated and the timer is started in Comparator ISR, that is, at the start of each half cycle of AC.

5. When the timer expires, an interrupt is generated and the Triac is fired in the Timer0 ISR.

6. The program monitors the state of Switch SW1 tied to PA3 (Port A Pin 3) continuously and on a valid switch press the CPU is put in STOP mode. PA3 is configured to generate an interrupt on falling edge.

7. CPU recovers from STOP mode on subsequent switch press and resets and the sequence repeats.

The block diagram displayed in Figure 3 on page 5 provides an overview of the software architecture for the dimmer application. Description of each block follows the figure.

AN025101-1106 Discussion

Page 10: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

5

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

Figure 3. Software Architecture

InitializationThe initial state of the system is set to detect AC line frequency apart from initializing the on-chip peripherals. The following APIs are called from the main function to initialize the peripherals Timer0, GPIO, Comparator, and ADC

• Init_Timer0()–Initialize Timer0 for CONTINUOUS mode 0.5 ms timeout.

• Init_GPIO()–Initialize GPIO for comparator input (CINP\PA5), switch input (PA3), ADC input (ANA1\PA4), Triac drive (PA2), internal Vref buffering to PA1.

• Init_Comparator()–Initialize comparator to accept non inverting input through GPIO (PA5) and for inverting input internal reference of 0.4 V is used.

• Init_ADC()–Initialize ADC for continuous conversion to read potentiometer input through ANA1 (PA4). ADC internal reference voltage source is chosen as 2 V.

Line Frequency Detection The line voltage is stepped down, rectified, and fed to the non-inverting input (CINP pin on MCU) of the comparator on Z8 Encore! XP MCU. The comparator is configured to generate interrupt when its non-inverting input voltage is greater than the set internal reference voltage (0.4 V). The internal reference forms the comparator inverting input (CINN). The timer is started in comparator ISR. At every 0.5 ms, a counter is incremented in Timer0 ISR. The line frequency is determined by capturing the value of this counter between two zero crossing points.

Determine

AC Line

Frequency

Read Switch

State

Put system in STOP

mode

Phase Control

Read Potentiometer position.

Determine Triac firing instant.

Fire triac at the derived time.

Switch State=0

SwitchState=1

Frequency50 Hz/

60 HzIntialization

Stop mode recovery from SW1 press

AN025101-1106 Discussion

Page 11: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

6

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

The comparator is configured to generate an interrupt when its positive input goes above a threshold voltage of 0.4 V. This is done in order to eliminate any spurious signal near the zero crossing to cause undesirable interrupts. The threshold voltage (comparator negative input) is set by the internal reference voltage generator in the MCU through CMP0 register.

On successful frequency detection, the system state is changed to phase control and Timer0 is reconfigured to operate in SINGLE SHOT mode.

Phase ControlAt the zero crossing point (Comparator ISR) the timer is started with the new reload value and when the timer expires, the Triac is fired. Therefore, higher the intensity required lower will be the timer reload value, providing a larger conduction angle.

The timer reload value proportional to the voltage across the potentiometer is updated in Comparator ISR, which varies the lamp intensity.

The voltage across potentiometer that controls the lamp intensity is read by the ADC. For every change in 0.24 V at the ADC, input firing angle is changed by loading a corresponding timer reload value. The timer reload value is stored in a look-up table. A 0.24 V change is reflected as bit change in the higher three most significant bits that correspond to seven incremental changes in timer reload value and therefore, the look-up table has seven values.

The timer reload value look-up table is a two dimensional array with values for T0RH and T0RL registers. The values range from 30% to 90% of the reload value corresponding to the period of the rectified sine wave.

Example:Period of full wave rectified signal for 50 Hz line frequency = 1/100 Hz = 10 ms

Timer Reload value for this period with prescale value 32 and Internal Precision Oscillator (IPO) as system clock = (0.01 x 5529600)/32

= 1728 = 0x06C0

The array is filled with 90% to 30% of this maximum reload.

ADC value read for a particular potentiometer position = 0x199

= 0110011001 (binary)

Table index (3 most significant bits) = 011 (binary)

Table index = 3 (decimal)

AN025101-1106 Discussion

Page 12: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

7

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

Stop ModeWhen switch SW1 is pressed, the controller is put in STOP mode and is configured for stop mode recovery from PA3. On stop mode recovery the CPU resets and the program execution starts.

For more details on the software flow, see flowcharts in Appendix D.

TestingThis section provides details of the test setup, equipments used, and the procedure for testing dimmer application.

Test SetupConnect the circuit as displayed in schematic (see Appendix C).

Equipment UsedThe test setup consists of the following:

• ZiLOG Developer Studio II (ZDS II) for Z8 Encore!.

• Oscilloscope for capturing waveform.

• PC with USB port to download dimmer application software to target board.

Test ProcedureFollow the steps below to test the Z8 Encore! XP-based dimmer application:

1. Install the Z8 Encore! XP Applications Library available under Application Sample Libraries on www.zilog.com.

2. Launch ZDSII for Z8 Encore!, and open the XP_Dimmer.zdsproj file located in the source folder.

3. Switch ON the AC power supply.

4. Build the code and download to the development board.

5. Reset the CPU to execute the code.

6. Vary the potentiometer position and note the change in lamp intensity.

AN025101-1106 Testing

Page 13: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

8

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

7. Press switch SW1 and observe that the lamp is turned OFF, since CPU enters into the STOP mode.

8. Press switch SW1 again to turn ON the lamp.

Test ResultsThe lamp intensity is observed to vary in accordance with the potentiometer position. The CPU enters the STOP mode on SW1 press and a subsequent press of SW1 causes stop mode recovery and the system to restart, with the lamp intensity corresponding to current potentiometer position.

SummaryZ8 Encore! XP® 8-pin offers greater flexibility for dimmer application than any other conventional methods with all the necessary on-chip peripherals such as comparator, timers with PWM capability, and ADC. The low pin count offers small footprint solution, saving PCB area. This application is designed for ohmic loads only. For inductive loads or any other loads, hardware changes are needed with minimum or no software changes. Thus, dimmer application can be designed for different loads quickly and accurately.

This dimmer application can be easily integrated into a bigger control system and additional features can also be incorporated in the application with minimal software changes.

AN025101-1106 Summary

Page 14: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

AN025101-1106 Appendix A—References

9

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

Appendix A — ReferencesFurther details on Z8 Encore! XP® family of products and Triac used is available in the list below.

Table 1. List of References

Topic Document Name and Document Number Source

Product Specification Z8 Encore! Microcontrollers with Flash Memory and 10-bit ADC

Z8 Encore! XP 8K and 4K Series Product Specification (PS0228)

www.zilog.com

eZ8 CPU eZ8 CPU User Manual (UM0130) www.zilog.comBTA12, Logic level Triac BTA12 Datasheet (BTA12) www.st.comMOC3021, Optoisolator Triac Driver Output

MOC3021 Datasheet (MOC3021-m) www.fairchildsemi.com

Page 15: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

10

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

AN025101-1106 Appendix B—Glossary

Appendix B — GlossaryThis application note uses the following abbreviations.

Table 2. Glossary

Term/Abbreviation Definition

MCU Microcontroller Unit

IPO Internal Precision Oscillator

ISR Interrupt Service Routine

API Application Programming Interface

GPIO General-Purpose Input/Output

ADC Analog-to-Digital Converter

Page 16: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

Application NoteDimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

11

AN025101-1106 Appendix C—Schematic Diagrams

Appendix C — Schematic Diagrams

Figure 4. Z8 Encore! XP® Dimmer Application Reference Design

5

5

4

4

3

3

2

2

1

1

D D

C C

B B

A A

Line

Line

Neu

tral

Neutral

VCC_3V

VCC_3V

VCC_3V

VCC_3V

Title

Size Document Number Rev

Date: Sheet of

<Doc> 0

Z8 Encore! XP 8 Pin Dimmer

A

1 1Friday, October 13, 2006

Title

Size Document Number Rev

Date: Sheet of

<Doc> 0

Z8 Encore! XP 8 Pin Dimmer

A

1 1Friday, October 13, 2006

Title

Size Document Number Rev

Date: Sheet of

<Doc> 0

Z8 Encore! XP 8 Pin Dimmer

A

1 1Friday, October 13, 2006

Note: All Resistors are 0.25W unless specified

ZiLOG Confidential Property

R810KR810K

C30.1uF/250V

C30.1uF/250V

U2 Z8F042ASB020SCU2 Z8F042ASB020SC

VDD1

PA0/T0IN/T0OUT/XIN/DBG2

PA1/T0OUT/XOUT/ANA3/VREF/CLKIN3

PA2/RESET/DE0/T1OUT4PA3/CTS0/ANA2/COUT/AMPINP/T1IN 5

PA4/RXD0/ANA1/CINN/AMPNN 6

PA5/TXD0/T1OUT/ANA0/CINP/AMPOUT 7GND 8

D5

1N4007

D5

1N4007

Q2BTA12Q2BTA12

U1

C78L03/SO

U1

C78L03/SO

VOUT 1VIN2

VIN3

VIN6

VIN7

R91ER91E

R3100R3100

R739/1WR739/1W

- +

D1

DB107

- +

D1

DB107

1

2

3

4

L1

Ferrite Bead 600ohm

L1

Ferrite Bead 600ohm

R410kR410k

C6470uFC6470uF

C50.1uFC50.1uF

C1MOV 275V

C1MOV 275V

DS1LAMP 230VDS1LAMP 230V

1 2

L2

Ferrite Bead 600ohm

L2

Ferrite Bead 600ohm

C710uFC710uF

R5 330R5 330

D212VD212V

R1470/1W

R1470/1W

J3

230V, 50Hz

J3

230V, 50Hz

12

C20.47uF/250VC20.47uF/250V

SW1ON/OFF

SW1ON/OFF

U3

MOC3021

U3

MOC3021

1

2

64

D4 1N4007D4 1N4007

R6 470R6 470

R21KR21K

D312VD312V

C90.01uFC90.01uF

Page 17: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

12

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

Appendix D—FlowchartsThis Appendix displays the flowcharts of main function and interrupt service routines (ISRs) of the dimmer application.

Figure 5. Flowchart of main Function

Start

Initialize GPIO for comparator input and for

firing Triac.

Initialize Timer0 for SINGLE SHOT mode.

Initialize ADC for reading voltage across

potentiometer.

Initialize Comparator.

Detect the line

frequency

50/60 Hz

Scan switch

SW1

PA3=0

PA3 =1

Put CPU in Stop

mode

Sto

pM

od

eR

eco

ve

ryth

rou

gh

PA

3

Start Timer0

Enable Interrupts

Start ADC to read

potentiometer

ANN025101-1106

Page 18: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

13

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

Figure 6. Flowchart of Comparator ISR

Figure 7. Flowchart of Timer0 ISR

Start

Skip 10

samples

initially

System State

is Phase Control?

No

(State is Frequency Detection)

Yes

Timer captured

value corresponds

to 50 Hz?

End

Frequency

detected is

50 Hz

No

Load timer reload register

with reload value from

table.

The offset determined in

ADC ISR is used as table

index

Reset timer

counter

Start Timer

Frequency

detected is

60 Hz

Yes

Start

Turn ON Triacgate signal

End

System State

is Phase Control?

No

Yes

Incrementhalf millisecond

counter

(State is Frequency Detection)

ANN025101-1106

Page 19: Application Note Dimmer Application Using Z8 Encore! …read.pudn.com/downloads109/ebook/450259/AN0251[1].pdf · Application Note Dimmer Application Using ... Hardware Block Diagram

14

Application Note Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller

Figure 8. Flowchart of ADC ISR

Read potentiometer

position through ADC

Determine offset

for timer reload

value table

Start

End

ANN025101-1106