
ML66517 Family User’s Manual
Chapter 11
PWM Function
11 – 7
11.3.2 Example of PWM-related Register Settings
8-bit PWM settings
(1) Port 7 mode register (P7IO)
If PWM0OUT is to be used, set bit 6 (P7IO6) to “1” to configure the port as an output. If PWM1OUT is to
be used, set bit 7 (P7IO7) to “1” to configure the port as an output.
(2) Port 8 mode register (P8IO)
If PWM2OUT is to be used, set bit 6 (P8IO6) to “1” to configure the port as an output. If PWM3OUT is to
be used, set bit 7 (P8IO7) to “1” to configure the port as an output.
(3) Port 7 secondary function control register (P7SF)
If PWM0OUT is to be used, set bit 6 (P7SF6) to “1” to configure the port as a secondary function output. If
PWM1OUT is to be used, set bit 7 (P7SF7) to “1” to configure the port as a secondary function output.
When PWM is halted, the port is fixed to “1”.
(4) Port 8 secondary function control register (P8SF)
If PWM2OUT is to be used, set bit 6 (P8SF6) to “1” to configure the port as a secondary function output. If
PWM3OUT is to be used, set bit 7 (P8SF7) to “1” to configure the port as a secondary function output.
When PWM is halted, the port is fixed to “1”.
(5) PWM counters (PWC0, PWC1)
Set these counters with the value at which to start counting. Writing to PWC0 and PWC1 causes the same
value to be simultaneously and automatically written to PWCY0 and PWCY1.
(6) PWM cycle registers (PWCY0, PWCY1)
If PWM0OUT and PWM2OUT are to be used, set the PWM cycle in PWCY0. If PWM1OUT and
PWM3OUT are to be used, set the PWM cycle in PWCY1.
(7) PWM registers (PWR0 to PWR3)
If PWMnOUT are to be used, set the desired output duty value in PWRn (where n = 0 to 3). Set a value for
PWR0 and PWR2 that is larger than the value of PWCY0. Set a value for PWR1 and PWR3 that is larger
than the value of PWCY1.
(8) PWM control register 0 (PWCON0)
If PWM0OUT and PWM2OUT are to be used, set the count clock for PWM counter 0 (PWC0) with bits 1
and 2 (PWCK00, PWCK01), and specify the interrupt factor that will initiate a PWINT0 interrupt request
with bit 3 (PWC0OV). If bit 0 (PW0RUN) is set to “1”, the PWM counter 0 (PWC0) begins counting.
If
reset to “0” the counting is halted.
If PWM1OUT and PWM3OUT are to be used, set the count clock for PWM counter 1 (PWC1) with bits 5
and 6 (PWCK10, PWCK11), and specify the interrupt factor that will initiate a PWINT1 interrupt request
with bit 7 (PWC1OV). If bit 4 (PW1RUN) is set to “1”, the PWM counter 1 (PWC1) begins counting.
If
reset to “0” the counting is halted.
[Equation to Calculate 8-Bit PWM Cycle]
f(PWM8) = PWCLK / (256 – PWCYn)
f(PWM8)
: PWM cycle [Hz]
PWCLK
: PWM input clock frequency [Hz]
PWCYn
: Value of PWCY0 or PWCY1 (8 bits)