SN8P1829
8-Bit MCU build-in 12-bit ADC + PGIA + Charge-pump Reg 128 dots LCD driver
SONiX TECHNOLOGY CO., LTD
Page 79
Version 1.0
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, TC0X8
=0, TC0_Counter=8-bit
B0BCLR
FTC0X8
;
MOV
A,#01100000B
B0MOV
TC0M,A
; Set the TC0 rate to Fcpu/4
MOV
A,#0x00
;First Time Initial TC0
B0MOV
TC0C,A
MOV
A,#30
; Set the PWM duty to 30/256
B0MOV
TC0R,A
B0BCLR
FTC0OUT
;
Disable TC0OUT function.
B0BSET
FPWM0OUT
; Enable PWM0 output to P5.4 and disable P5.4 I/O function
B0BSET
FTC0ENB
; 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
A, #30H
; Input a number using B0MOV instruction.
B0MOV
TC0R,
A
INCMS
BUF0
; Get the new TC0R value from the BUF0 buffer defined by
B0MOV
A, BUF0
; programming.
B0MOV
TC0R,
A
Note2: 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.
Note3: The TC0OUT function must be set “0” when PWM0 output enable. The TC1OUT function must be
set “0” when PWM1 output enable.
Note4: The PWM can work with interrupt request.