AN2839 Freescale Semiconductor / Motorola, AN2839 Datasheet - Page 10

no-image

AN2839

Manufacturer Part Number
AN2839
Description
Implementing a Lamp Dimmer with an HC908Q Family MCU
Manufacturer
Freescale Semiconductor / Motorola
Datasheet
Software Description
Figure 8. Switching Inductive Loads with HC908Q Family
Software Description
Two software codes were developed for this application note. The first one implements a lamp dimmer;
the second one was developed for an application where a lamp is turned on for a specific amount of time.
Lamp Dimmer Source Code
For the lamp dimmer source code, the MCU controls the lamp brightness by adjusting the conduction
angle with the timer modulus as illustrated in
Figure
9.
The code starts initializing configuration and timer registers, defining ports, and clearing variables and
accumulators. The initial timer value is set to have almost the maximum brightness adjusting the
constants InitTMODH and InitTMODL.
PTA0 senses the zero-crossing detection circuit. Each time a positive or negative edge is detected, the
timer starts to count until the timer module value (composed by TMODH:TMODL ) is reached.
When PTA0 recognizes a positive edge, the MCU verifies PTA5 and PTA4.
If PTA5 is in low level, the routine increments the timer modulus value if it is below the upper limit. PTA4
decrements the timer modulus value if it is above the lower limit when applied a low level . When a timer
overflow occurs, PTA1 generates a pulse train triggering the triac.
Implementing a Lamp Dimmer with an HC908Q Family MCU, Rev. 0
10
Freescale Semiconductor

Related parts for AN2839