R01UH0092EJ0110 Rev.1.10
Page 400 of 807
Jul 31, 2012
M16C/64C Group
21. Pulse Width Modulator
21.3
Operations
21.3.1
Setting Procedure
Follow the procedure below to set individual registers in order to start PWMi (i = 0, 1) output. (All SFRs
are assumed to be reset. Refer the register descriptions to access registers or bits.)
(1) Write output data of the port corresponding to the pin for PWMi output to the P9 or P4 register.
Then, set the direction bit for the corresponding port to 1 (output mode).
(2) Set the PWMSELi bit in the PWMCON0 register to select a pin for PWMi output. Set the PWMCLKi
bit to select the count source.
(3) Set registers PWMPREi and PWMREGi to set the PWM cycle and high-level pulse width.
(4) Set the PWMPORTi bit in the PWMCON1 register to 1 (PWMi function) and the PWMENi bit to 1
(PWM output enabled).
21.3.2
Operation Example
The values written to registers PWMPREi and PWMREGi during PWMi (i = 0, 1) output are not
reflected until the next cycle of PWMi output begins.
The PWM output signal is low immediately after the MCU is reset. Then, the associated waveform
output starts.
The PWMi output level remains unchanged even if the PWMENi bit in the PWMCON1 register is
changed from 1 (PWMi output enabled) to 0 (PWMi output disabled) during PWMi output. Registers
PWMPREi and PWMREGi retain the value before the PWMi output is disabled. When setting the
PWMENi bit to 1 after registers PWMPREi and PWMREGi are rewritten while PWMi output is disabled,
the values of registers PWMPREi and PWMREGi prior to the change are reflected for the first cycle of
PWM output. The rewritten register values are reflected in the following PWMi cycle.
Figure 21.2
to Figure 21.4 shows PWMi output examples.
Figure 21.2
PWMi Output Example (After Reset and During PWM Output)
PWMENi bit in the
PWMCON1
register
PWMi prescaler
prelatch
PWMi output
PWMi register
prelatch
PWMi prescaler
latch
PWMi
register latch
The above diagram assumes the PWMPORTi bit in the PWMCON1 register is 1 (PWMi output).
Set to 1 (PWM output enabled) by a program
Rewritten reset value but before
PWMi output enabled is reflected in
the second cycle of PWMi output
m1
00h
m1
00h
m2
n1
00h
n2
Reset value
Value rewritten during PWM output is reflected
in the next cycle
n1
00h
n2
m2
i: 0, 1
fj: PWM count source frequency
Reset value
(2
8
-1)
×
(m1+1)
fj
Low-level output
(m1+1)
×
n1
fj
(m2+1)
×
n2
fj
(2
8
-1)
×
(0+1)
fj
(2
8
-1)
×
(m2+1)
fj
This length of low-level signal is output for first cycle after reset.
Set registers PWMPREi and PWMREGi by a program
Содержание M16C Series
Страница 846: ...M16C 64C Group R01UH0092EJ0110...