English
Language : 

SN8P2501A Datasheet, PDF (63/69 Pages) SONiX Technology Company – SONiX 8-Bit Micro-Controller
SN8P2501A
8-Bit Micro-Controller
8.5.2 PWM PROGRAM DESCRIPTION
Example: Setup PWM0 output from TC0 to PWM0OUT (P5.4). The external high-speed oscillator clock is
4MHz. Fcpu = Fosc/4. 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
B0MOV
A,#01100000B
TC0M,A
; Set the TC0 rate to Fcpu/4
MOV
B0MOV
B0MOV
A,#30
TC0C,A
TC0R,A
; Set the PWM duty to 30/256
B0BCLR
B0BCLR
B0BSET
B0BSET
FTC0OUT
FALOAD0
FPWM0OUT
FTC0ENB
; Set duty range as 0/256~255/256.
; Enable PWM0 output to P5.4 and disable P5.4 I/O function
; Enable TC0 timer
Note: The TC0R is write-only registers. Don’t process them using INCMS, DECMS instructions.
Example: Modify TC0R registers’ value.
MOV
B0MOV
A, #30H
TC0R, A
; Input a number using B0MOV instruction.
INCMS
B0MOV
B0MOV
BUF0
A, BUF0
TC0R, BUF0
; Get the new TC0R value from the BUF0 buffer defined by
; programming.
Note: 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.
Note: The PWM can work with interrupt request.
SONiX TECHNOLOGY CO., LTD
Page 62
Preliminary Version 0.2