AN2839 Freescale Semiconductor / Motorola, AN2839 Datasheet - Page 11
![no-image](/images/no-image-200.jpg)
AN2839
Manufacturer Part Number
AN2839
Description
Implementing a Lamp Dimmer with an HC908Q Family MCU
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
1.AN2839.pdf
(24 pages)
Lamp Timer Source Code
Figure 10
The code starts by initializing configuration and timer registers, defining ports, and clearing variables and
accumulators.
PTA0 senses the zero-crossing detection circuit. Each time a positive or negative edge is detected the
timer starts to count until the timer modulus value (composed by TMODH:TMODL ) is reached. When a
timer overflow occurs, PTA1 generates a pulse triggering the triac.
Freescale Semiconductor
shows the flowchart for a lamp timer.
Decrement Timer
Increment Timer
Implementing a Lamp Dimmer with an HC908Q Family MCU, Rev. 0
Figure 9. Flowchart for Lamp Dimmer Source Code
Y
Y
Timer Value
Timer Value
< Upper
> Lower
Limit?
Limit?
N
N
Y
Y
Initialize Timer Module
Maximum Brightness
Turns on Lamp with
MCU Initialization
Clear Variables
PTA5 = 0?
PTA4 = 0?
Start
N
Software Description
N
11