SN8P1600
8-bit micro-controller
PWM PROGRAM DESCRIPTION
ꢃ
Example: Setup PWM1 output from TC1 to PWM1OUT (P5.3). 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. TC1 rate is Fcpu/4. The TC1RATE2~TC1RATE1 = 110. TC1C = TC1R = 30.
MOV
B0MOV
MOV
A,#01100000B
TC1M,A
A,#0x00
; Set the TC1 rate to Fcpu/4
;First Time Initial TC0
B0MOV
TC1C,A
MOV
A,#30
; Set the PWM duty to 30/256
B0MOV
TC1R,A
B0BCLR
B0BSET
B0BSET
FTC1OUT
FPWM1OUT
FTC1ENB
; Disable TC1OUT function.
; Enable PWM1 output to P5.3 and disable P5.3 I/O function
; Enable TC1 timer
ꢂ
ꢂ
Note1: The TC1R is write-only register. Don’t process them using INCMS, DECMS instructions.
Note2: Set TC1C at initial is to make first duty-cycle correct. After TC1 is enabled, don’t modify TC1R
value to avoid duty cycle error of PWM output.
ꢃ
Example: Modify TC1R registers’ value.
MOV
B0MOV
A, #30H
TC1R, A
; Input a number using B0MOV instruction.
INCMS
B0MOV
B0MOV
BUF1
A, BUF1
TC1R, A
; Get the new TC1R value from the BUF1 buffer defined by
; programming.
ꢂ
Note3: 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 TC1OUT function must be set “0” when PWM1 output enable.
Note5: The PWM can work with interrupt request.
SONiX TECHNOLOGY CO., LTD
Page 64
Revision 1.94