EasyManua.ls Logo

SONIX SN8P2624 - 8.4.4 PWM Program Example

SONIX SN8P2624
94 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SN8P2624
8-Bit Micro-Controller
SONiX TECHNOLOGY CO., LTD Page 85 Version 0.3
8.4.4 PWM PROGRAM EXAMPLE
¾ Example: Setup PWM1 output from TC1 to PWM1OUT (P5.3). 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. TC1 rate is Fcpu/4. The TC1RATE2~TC1RATE1 = 110. TC1C =
TC1R = 30.
MOV A,#01100000B
B0MOV TC1M,A ; Set the TC1 rate to Fcpu/4
MOV A,#30 ; Set the PWM duty to 30/256
B0MOV TC1C,A
B0MOV TC1R,A
B0BCLR FTC1OUT ; Set duty range as 0/256~255/256.
B0BCLR FALOAD1
B0BSET FPWM1OUT ; Enable PWM1 output to P5.3 and disable P5.3 I/O function
B0BSET FTC1ENB ; Enable TC1 timer
Note: The TC1R is write-only register. Don’t process them using INCMS, DECMS instructions.
¾ Example: Modify TC1R registers’ value.
MOV A, #30H ; Input a number using B0MOV instruction.
B0MOV TC1R, A
INCMS BUF0 ; Get the new TC1R value from the BUF0 buffer defined by
NOP ; programming.
B0MOV A, BUF0
B0MOV TC1R, A
Note: The PWM can work with interrupt request.

Table of Contents

Related product manuals