SN8P2977
8-Bit Micro-Controller with Regulator, PGIA, 24-bit ADC
SONiX TECHNOLOGY CO., LTD
Page 84
Version 1.7
8.4.2
TC0IRQ AND PWM DUTY
In PWM mode, the frequency of TC0IRQ is depended on PWM duty range. From following diagram, the TC0IRQ
frequency is related with PWM duty.
8.4.3
PWM PROGRAM EXAMPLE
Example: Setup PWM0 output from TC0 to PWM0OUT (P1.1). The external high-speed oscillator clock is
8MHz. Fcpu = Fosc/8. 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
B0MOV
TC0M,A
; Set the TC0 rate to Fcpu/4
MOV
A,#30
; Set the PWM duty to 30/256
B0MOV
TC0C,A
B0MOV
TC0R,A
B0BSET
FPWM0OUT
; Enable PWM0 output to P1.1 and disable P1.1 I/O function
B0BSET
FTC0ENB
; Enable TC0 timer
Note: The TC0R is write-
only register. Don’t process them using INCMS, DECMS instructions.
Example: Modify TC0R 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
NOP
; programming.
B0MOV
A, BUF0
B0MOV
TC0R, A
Note: The PWM can work with interrupt request.
TC0 Overflow,
TC0IRQ = 1
0xFF
TC0C Value
0x00
PWM0 Output
(Duty Range 0~255)