SN8P1700
8-bit micro-controller build-in 12-bit ADC
PWM PROGRAM DESCRIPTION
ꢃExample: Setup PWM0 output from TC0 to PWM0OUT (P5.4). The external high-speed oscillator clock is
4MHz. The duty of PWM is 30/256. The PWM frequency is about 1KHz. The PWM clock source is
from external oscillator clock. TC0 rate is Fcpu/4. The TC0RATE2~TC0RATE1 = 110. TC0C = TC0R
= 30.
MOV
A,#01100000B
TC0M,A
TC0M,A
B0MOV
B0MOV
MOV
; Set the TC0 rate to Fcpu/4
; Set the TC0 rate to Fcpu/4
;First Time Initial TC0
A,#0x00
MOV
A,#30
; Set the PWM duty to 30/256
B0MOV
TC0R,A
B0BCLR
B0BSET
B0BSET
FTC0OUT
FPWM0OUT
FTC0ENB
; Disable TC0OUT function.
; Enable PWM0 output to P5.4 and disable P5.4 I/O function
; Enable TC0 timer
ꢂ
ꢂ
Note1: The TC0R and TC1R are write-only registers. Don’t process them using INCMS, DECMS
instructions.
Note2: Set TC0C at initial is to make first duty-cycle correct. After TC0 is enabled, don’t modify TC0R
value to avoid duty cycle error of PWM output.
ꢃExample: Modify TC0R/TC1R registers’ value.
MOV
B0MOV
A, #30H
TC0R, A
; Input a number using B0MOV instruction.
INCMS
B0MOV
B0MOV
BUF0
A, BUF0
TC0R, A
; Get the new TC0R value from the BUF0 buffer defined by
; programming.
ꢂ
Note3: That is better to set the TC0C and TC0R value together when PWM0 duty modified. It protects the
PWM0 signal no glitch as PWM0 duty changing. That is better to set the TC1C and TC1R value together
when PWM1 duty modified. It protects the PWM1 signal no glitch as PWM1 duty changing.
ꢂ
ꢂ
Note4: The TC0OUT function must be set “0” when PWM0 output enable. The TC1OUT function must be
set “0” when PWM1 output enable.
Note5: The PWM can work with interrupt request.
SONiX TECHNOLOGY CO., LTD
Page 89
Revision 1.94