Professional Documents
Culture Documents
AN025102-0608
zero. In ON condition, the voltage across Triac By controlling the firing angle, the rms voltage
drops to zero and in OFF condition the line voltage supplied to the load changes and according to the
appears across the Triac. voltage light intensity of the bulb varies.
Line
(AC Voltage Opto-isolator Triac Drive
230 V/50 Hz
or110 V/60 Hz)
Z8 Encore!XP®
Neutral GPIO
Load / Incandescent
Lamp
Dimming Control
ADC Potentiometer
Voltage Regulator V CC
Voltage Step Down (3.3 V)
(12 V) Switch to put
GPIO
and CPU in STOP mode
Bridge Rectifier For Zero Crossing Detector
Comparator
Power Supply
AN025102-0608 Page 2 of 12
Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller
Note: The value of C2 (see Appendix B— 1. Initializes the Comparator, Timer0, ADC, and
Schematic Diagrams on page 8) GPIO (see Initialization on page 4).
must be 0.6 µF for working with 2. Measures AC line frequency (50 Hz/60 Hz).
110 V/60 Hz AC and 0.47 µF for
230 V/50 Hz power source. 3. Potentiometer position is read in ADC
continuously and table offset for timer reload is
Optoisolator Triac Drive Section determined.
An optoisolator Triac drive (MOC3021) is used for 4. Timer0 reload register is updated and the timer
isolated Triac triggering. The Triac drive is con- is started in Comparator ISR, that is, at the start
nected to a General-Purpose Input/Output (GPIO) of each half cycle of AC.
pin of Z8 Encore! XP ® MCU through a current 5. When the Timer expires, an interrupt is
limiting resistor. A snubber circuit is also provided generated and the Triac is fired in the Timer0
to avoid false triggering of the Triac due to rate of ISR.
voltage change (dv/dt) exceeding the rating.
6. The program monitors the state of Switch SW1
tied to PA3 (Port A Pin 3) continuously and on
Dimming Control Section
a valid Switch press the CPU is put in STOP
you can control the dimmer through a potentiome- mode. PA3 is configured to generate an
ter and a Switch. The potentiometer is used to interrupt on falling edge.
control the intensity. The potentiometer is tied to
7. CPU recovers from STOP mode on subsequent
the internal reference voltage of the ADC available
Switch press and resets and the sequence
on the Vref pin of the Z8 Encore! XP MCU. The
repeats.
internal ADC reference is made available on Vref
pin by setting REFOUT bit in ADCCTL0 register The block diagram displayed in Figure 3 on page 4
and enabling alternate function for the associated provides an overview of the software architecture
GPIO. The Switch is used to put the system in for the dimmer application. The description of each
STOP mode and also to recover from STOP mode block is provided in the following sections:
and restart on subsequent press.
• Initialization
The voltage across the potentiometer is read in • Line Frequency Detection
ADC Interrupt Service Routine (ISR). The ADC
output is used to find the table offset required to • Phase Control
load timer reload values. The timer reload value • STOP Mode
determines the firing angle of the Triac and the
intensity of the lamp. The timer reload value is
loaded in Comparator ISR.
AN025102-0608 Page 3 of 12
Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller
AN025102-0608 Page 4 of 12
Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller
The timer reload value proportional to the voltage Recovery from PA3. On Stop Mode Recovery, the
across the potentiometer is updated in Comparator CPU resets and the program execution starts. For
ISR, which varies the lamp intensity. more details on the software flow, see Appendix
C—Flowcharts on page 9.
The voltage across potentiometer that controls the
lamp intensity is read by the ADC. For every Testing
change in 0.24 V at the ADC, input firing angle is
changed by loading a corresponding timer reload This section provides details of the test setup,
value. The timer reload value is stored in a look-up equipments used, and the procedure for testing the
table. A 0.24 V change is reflected as bit change in dimmer application.
the higher three most significant bits that corre-
spond to seven incremental changes in timer reload Test Setup
value and therefore, the look-up table has seven
values. Connect the circuit as displayed in the schematic
(see Appendix B—Schematic Diagrams on page
The timer reload value look-up table is a two 9).
dimensional array with values for T0RH and T0RL
registers. The values range from 30% to 90% of the Equipment Used
reload value corresponding to the period of the
The test setup consists of the following:
rectified sine wave.
• Zilog Developer Studio II (ZDS II) for
Example:
Z8 Encore! MCU.
The period of full wave rectified signal for 50 Hz
• Oscilloscope for capturing waveform.
line frequency = 1/100 Hz = 10 ms.
• PC with USB port to download dimmer
The Timer Reload value for this period with pres- application software to target board.
cale value 32 and Internal Precision Oscillator
(IPO) as system clock = (0.01 x 5529600)/32 = Test Procedure
1728 = 0x06C0.
Follow the steps below to test the Z8 Encore! XP®-
based dimmer application:
The array is filled with 90% to 30% of this
maximum reload.
1. Install the Z8 Encore! XP Applications Library
available under Application Sample Libraries
The ADC value read for a particular potentiometer at www.zilog.com.
position = 0x199 = 0110011001 (binary).
2. Launch ZDS II for Z8 Encore!, and open the
Table index (3 most significant bits) = 011 XP_Dimmer.zdsproj file located in the
(binary). source folder.
3. Switch ON the AC power supply.
Table index = 3 (decimal). 4. Build the code and download to the
development board.
STOP Mode
5. Reset the CPU to execute the code.
When Switch SW1 is pressed, the controller is set
to STOP mode and is configured for Stop Mode 6. Vary the potentiometer position and note the
change in lamp intensity.
AN025102-0608 Page 5 of 12
Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller
AN025102-0608 Page 6 of 12
Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller
Appendix A—Glossary
Table 1 lists the definitions for terms and abbreviations used in this Application Note.
Table 1. Glossary
Term/Abbreviation Definition
AN025102-0608 Page 7 of 12
Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller
5 4 3 2 1
L1
R1 D1
1
D D
Line
470/1W
J3
D4 1N4007 U1
1 VCC_3V
2 C1 4 - + 2 2 1
MOV 275V VIN VOUT
3 VIN
D3 R4 6
230V, 50Hz 10k VIN C7 C5
12V 7 VIN
Neutral
3
470uF C78L03/SO
D2 D5
L2 12V
1N4007
DS1
C Ferrite Bead 600ohm LAMP 230V C
Neutral
Line
1
2
VCC_3V
U2 Z8F042ASB020SC
1 VDD GND 8 R5 R6
7 330 470
PA5/TXD0/T1OUT/ANA0/CINP/AMPOUT
2 R7
PA0/T0IN/T0OUT/XIN/DBG 39/1W
PA4/RXD0/ANA1/CINN/AMPNN 6
R3
4
3 100 0.1uF/250V
PA1/T0OUT/XOUT/ANA3/VREF/CLKIN C3 Q2
PA3/CTS0/ANA2/COUT/AMPINP/T1IN 5 2
4 BTA12
PA2/RESET/DE0/T1OUT
B VCC_3V 1 B
C9
0.01uF
6
MOC3021
VCC_3V
R9 U3
1E
R8
10K
R2 Note: All Resistors are 0.25W unless specified
1K
SW1
ON/OFF
A A
ZiLOG Confidential Property
Title
Z8 Encore! XP 8 Pin Dimmer
Size Document Number Rev
A <Doc> 0
AN025102-0608 Page 8 of 12
Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller
Appendix C—Flowcharts
This Appendix displays the following flowcharts for the dimmer application:
Start
Start Timer0
Enable Interrupts
PA3=0
Scan switch Put CPU in Stop
SW1 mode
PA3 =1
AN025102-0608 Page 9 of 12
Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller
Start
No
Timer captured
value corresponds
to 50 Hz?
Yes
Frequency Frequency
detected is detected is
60 Hz 50 Hz
End
Start
No
(State is Frequency Detection)
Increment
half millisecond
counter
End
AN025102-0608 Page 10 of 12
Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller
Start
Read potentiometer
position through ADC
Determine offset
for tim er reload
value table
End
AN025102-0608 Page 11 of 12
Dimmer Application Using Z8 Encore! XP® 8-Pin Microcontroller
As used herein
Life support devices or systems are devices which (a) are intended for surgical implant into the body, or (b)
support or sustain life and whose failure to perform when properly used in accordance with instructions for
use provided in the labeling can be reasonably expected to result in a significant injury to the user. A
critical component is any component in a life support device or system whose failure to perform can be
reasonably expected to cause the failure of the life support device or system or to affect its safety or
effectiveness.
Document Disclaimer
©2008 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.
Z I L O G A L S O D O E S N O T A S S U M E L I A B I L I T Y F O R I N T E L L E C T U A L P R O P E RT Y
INFRINGEMENT RELATED IN ANY MANNER TO USE OF INFORMATION, DEVICES, OR
TECHNOLOGY DESCRIBED HEREIN OR OTHERWISE. The information contained within this
document has been verified according to the general principles of electrical and mechanical engineering.
Z8, Z8 Encore!, and Z8 Encore! XP are registered trademarks of Zilog, Inc. eZ8 is a trademark of Zilog,
Inc. All other product or service names are the property of their respective owners
AN025102-0608 Page 12 of 12
12