13-01-2012, 02:10 PM
Pulse Width Modulation
[attachment=16063]
Introduction
The explanation of this issue is applied to the following conditions:
• Application MCU: 3803H Group (e.g. M38039FFHHP)
• Oscillation Frequency: 8 MHz
Description of module used
Figure 1 shows a block diagram of PWM module. In this sample task, the following features are used:
• Automatic generation of PWM output by hardware, without software intervention.
• Period and duty cycle of PWM output can be modified.
• If the PWM register or PWM prescaler is updated during PWM output, the pulses will change in the cycle
after the one in which the change was made.
The registers are described below:
• PWM control register (PWMCON)
PWMCON controls the PWM module. It contains two bits: PWMFE and PWMCS. PWMFE enables or
disables the module; PWMCS selects the count source of the PWM between f(XIN) and f(XIN)/2.
• PWM prescaler (PREPWM)
PREPWM is a 8-bit auto-reload prescaler. It counts the input from count source selected by the PWMCS bit.
The period of the PWM is determined by the value set to the PREPWM.
• PWM register (PWM)
PWM is a 8-bit down-count timer. It counts the output of the PREPWM underflow. Immediately after it
reaches 0016, FF16 is automatically reloaded. The output is kept at “H” level when the PWM counts between
FF16 and the value set by the user.