SN8P2740 Series
ADC, OP-amp, Comparator 8-Bit Micro-Controller
8.3.3 PULSE WIDTH MODULATION (PWM)
TC0 timer builds in PWM function controlled by PWM0OUT bit. PWM output pin is shared with GPIO. When
PWM0OUT=1, the PWM function is enabled and GPIO pin is switched from GPIO to PWM output status. When
PWM0OUT=0, PWM output pin returns to GPIO last status. PWM signal is generated from the result of TC0C, TC0R
and TC0D comparison. When PWM0OUT=1 or TC0C counts from 0xFF to 0x00 (overflow), the PWM outputs high
status which is the PWM initial status. TC0C is loaded new data from TC0R register to decide PWM cycle and
resolution. TC0C keeps counting, and the system compares TC0C and TC0D. When TC0C=TC0D, the PWM output
status exchanges to low. TC0C keeps counting. When TC0 timer overflow occurs, and one cycle of PWM signal
finishes. TC0C is reloaded from TC0R automatically, and PWM output status exchanges to high for next cycle. TC0D
decides the high duty duration, and TC0R decides the resolution and cycle of PWM. TC0R can‟t be larger than TC0D,
or the PWM signal is error. The PWM output phase can be selected through TC0DIR bit. When TC0DIR = 0, PWM‟s
phase is high pulse and low idle status. When TC0DIR = 1, PWM‟s phase is low pulse and high idle status.
Enable TC0 and PWM.
TC0C is loaded from TC0R.
PWM outputs high status.
TC0C overflows from 0xFF to 0x00.
TC0C is loaded from TC0R.
PWM exchanges to high status.
TC0C = TC0D.
PWM exchanges to low status.
TC0R
TC0R
+2
TC0D
-2
TC0D
-1
TC0R
+1
TC0R
+2
TC0R
+1
...
TC0D
...
0xFD
0xFE
0xFF
TC0R
...
TC0C
PWM Output
TC0DIR=0
One complete cycle of PWM.
One complete cycle of PWM.
Next cycle.
Next cycle.
PWM Output
TC0DIR=1
The resolution of PWM is decided by TC0R. TC0R range is from 0x00~0xFF. If TC0R = 0x00, PWM‟s resolution is
1/256. If TC0R = 0x80, PWM‟s resolution is 1/128. TC0D controls the high pulse width of PWM for PWM‟s duty. When
TC0C = TC0D, PWM output exchanges to low status. TC0D must be greater than TC0R, or the PWM signal keeps low
status. When PWM outputs, TC0IRQ still actives as TC0 overflows, and TC0 interrupt function actives as TC0IEN = 1.
But strongly recommend be careful to use PWM and TC0 timer together, and make sure both functions work well.
The PWM output pin is shared with GPIO and switch to output PWM signal as PWM0OUT=1 automatically. If
PWM0OUT bit is cleared to disable PWM, the output pin exchanges to last GPIO mode automatically. It easily to
implement carry signal on/off operation, not to control TC0ENB bit.
PWM Output
TC0DIR=0
PWM0OUT=0.
PWM0OUT=0.
PWM0OUT=0.
PWM0OUT=0.
PWM0OUT=0.
PWM0OUT=0.
PWM0OUT=1.
PWM0OUT=1.
PWM0OUT=1.
PWM0OUT=1.
PWM0OUT=1.
PWM0OUT=1.
PWM0OUT=1. The pin exchanges to output
mode and outputs PWM signal automatically.
PWM0OUT=0. The pin exchanges
to last GPIO mode (output low).
PWM Output
TC0DIR=0
PWM0OUT=1. The pin exchanges to output
mode and outputs PWM signal automatically.
PWM0OUT=0. The pin exchanges
to last GPIO mode (output high).
High impendence (floating)
PWM Output
TC0DIR=0
PWM0OUT=1. The pin exchanges to output
mode and outputs PWM signal automatically.
PWM0OUT=0. The pin exchanges
to last GPIO mode (input).
PWM Output
TC0DIR=1
PWM0OUT=1. The pin exchanges to output
mode and outputs PWM signal automatically.
PWM0OUT=0. The pin exchanges
to last GPIO mode (output low).
PWM Output
TC0DIR=1
PWM0OUT=1. The pin exchanges to output
mode and outputs PWM signal automatically.
PWM0OUT=0. The pin exchanges
to last GPIO mode (output high).
High impendence (floating)
PWM Output
TC0DIR=1
PWM0OUT=1. The pin exchanges to output
mode and outputs PWM signal automatically.
PWM0OUT=0. The pin exchanges
to last GPIO mode (input).
SONiX TECHNOLOGY CO., LTD
Page 82
Version 2.0