SyncMOS Technologies Inc. Specific Pulse Width Modulation(SPWM)

SyncMOS Technologies Inc.
Feb 2009
SyncMOS SPWM Application Note
For SM5964、SM8954A、SM8958A、SM89516A、SM59264、SM59128、SM79108
Specific Pulse Width Modulation(SPWM) Function Application Notes
适用产品:
1. SM5964、SM8954A、SM8958A、SM89516A(P1.3~P1.7)
2. SM59264、SM59128(P1.2~P1.5)
3. SM79108(P1.3)
功能说明:
每个 SPWM 波型是由一个 8bit 寄存器的组合而成,
其组合成份为 5bit 的 SPWM 及 3bit 的 BRM。
在 5bit SPWM
部份,其值将决定输出的脉冲宽度(“Hi")。3bit 的 BRM 将产生 1~7 个狭小的脉冲在一个 SPWM 周期结构
之间分别插入。
应用范围:1、背光版亮度控制 2、CCD Clock 输出
3、电压变化控制。
特殊寄存器说明:P1CON, SPWMC, SPWMD[4:0]
1、 P1CON(0x9BH):
(Example to define P1.3~P1.7 )
SPWME4 SPWME3 SPWME2 SPWME1 SPWME0 Unused Unused Unused
Read /Write
R/W
R/W
R/W
R/W
R/W
Reset Value
0
0
0
0
0
*
*
*
P1.7
P1.6
P1.5
P1.4
P1.3
SM5964
(Example to define P1.2~P1.5 )
TWSIDAE TWSICLE SPWME3 SPWME2 SPWME1 SPWME0 Unused Unused
Read /Write
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
0
0
0
0
0
0
*
*
P1.5
P1.4
P1.3
P1.2
SM59264
SPWME [4:0]:初始值为 0,当位设置为 1 时,对应 Port1 的脚位即设为 SPWM 的功能,当设置为 0 时 SPWM
的脚位即为一般的 I/O Pin。
2、SPWMC(0xA3H):
Unused Unused Unused Unused Unused Unused SPFS1 SPFS0
Read /Write
R/W R/W
Reset Value
*
*
*
*
*
*
0
0
SPFS[1:0] :是设置外部频率的被除数以决定 SPWM 时脉。
SPFS1 SPFS0 Divider
SPWM clock at Fosc=20MHz
SPWM clock at Fosc=40MHz
0
0
2
10MHz
20MHz
0
1
4
5MHz
10MHz
1
0
8
2.5MHz
5MHz
1
1
16
1.25MHz
2.5MHz
Specifications subject to change without notice, contact your sales representatives for the most recent information.
SPWMAPN_VerA_20090209
1
SyncMOS Technologies Inc.
SyncMOS SPWM Application Note
For SM5964、SM8954A、SM8958A、SM89516A、SM59264、SM59128、SM79108
Feb 2009
SPWM clock = 1/T = Fosc/Divider
SPWM 的输出频率 = SPWM clock/32 = (Fosc/ Divider)/32
3、SPWMD[4:0]( 0xAC、0xA7、0xA6、0xA5、0xA4):
SPWMD SPWMD SPWMD SPWMD SPWMD BRM
BRM
BRM
[4:0]4
[4:0]3
[4:0]2
[4:0]1
[4:0]0
[2:0]2 [2:0]1 [2:0]0
Read /Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Reset Value
0
0
0
0
0
0
0
0
SPWMD[4:0]: 为 SPWM 资料寄存器,决定 SPWM 输出波形,2 的 5 次方 = 32 =0~ 1FH
BRM[2:0]: 将要插入1~7个时脉在8个SPWM周期结构之间
N = BRM[2:0]
Number of SPWM cycles inserted in an 8-cycle frame
000
0
001
1
010
2
011
3
100
4
101
5
110
6
111
7
Example of SPWM timing diagram:
MOV SPWMD0 , #83H
MOV P1CON , #08H
; SPWMD0[4:0]=10h=16 (16T high, 16T low), BRM[2:0] = 3
; Enable P1.3 as SPWM output pin
范例:一组 SPWM 输出周期频率的计算方式 :
设 Fosc = 20MHz , SPWMC 的 SPFS [1:0] =0x03H (Divider=16)
SPWM clock =20MHz / 16 = 1.25MHz
SPWM output cycle frame frequency = 1.25MHz / 32 = 39.1KHz
SPWM 程序范例:
汇编语言:
X’tal = 20MHz
Specifications subject to change without notice, contact your sales representatives for the most recent information.
SPWMAPN_VerA_20090209
2
SyncMOS Technologies Inc.
Feb 2009
SyncMOS SPWM Application Note
For SM5964、SM8954A、SM8958A、SM89516A、SM59264、SM59128、SM79108
;******* SET DATA ****************************************
P1CON
EQU
09BH
;设置 SFR 内 P1CON 的地址
SPWMC
EQU
0A3H ;设置 SFR 内 SPWMC 的地址
SPWMD0
EQU
0A4H
;设置 SFR 内 SPWMD0 的地址
;******************* 定义程序的起始地址 ********************
ORG
0000H
;设置目前程序的起始地址
JMP
Start
;跳至 reset
ORG
100H
Start:
MOV
P1CON,#08H
;设置 P1.3 为 SPWM 输出
MOV
SPWMC,#03H
;设置 SPWM 的频率 (Divider=16)
MOV
SPWMD0,#083H ;设置输出波形(SPWMD0=10h=16,BRM=3h)
;输出波形周期为 16/32=1/2,在 8 个周期中插入 3 个脉冲
;************* 设置 LED 在 SPWMD0(即 P1.3 输出)的闪烁方式 ***************
;此段程序的 LED 显示是由暗至亮的表示方法
MOV
A,#0ffH
;此段为由 FF 至 00 的波形变化
LOOP1:
MOV
SPWMD0,A
MOV
R0,A
CALL Delay
DJNZ
R0,LOOP1
;********************* 呼叫 Delay **************************************
Delay:
MOV
20H,#02H
b3: MOV
21H,#0FFH
b2: MOV 22H,#0FFH
b1:
DJNZ
22H,b1
DJNZ
21H,b2
DJNZ 20H,b3
RET
END
C 语言:
sfr P1CON = 0x9B;
sfr SPWMC
= 0x0A3;
sfr SPWMD0 = 0x0A4;
sfr SPWMD1 = 0x0A5;
sfr SPWMD2 = 0x0A6;
sfr SPWMD3 = 0x0A7;
sfr SPWMD4 = 0x0AC;
void DelayX10ms(int);
unsigned char times;
//设置 SFR 内 P1CON 的地址
//设置 SFR 内 SPWMC 的地址
//设置 SFR 内 SPWMD0 的地址
//设置 SFR 内 SPWMD1 的地址
//设置 SFR 内 SPWMD2 的地址
//设置 SFR 内 SPWMD3 的地址
//设置 SFR 内 SPWMD4 的地址
Specifications subject to change without notice, contact your sales representatives for the most recent information.
SPWMAPN_VerA_20090209
3
SyncMOS Technologies Inc.
Feb 2009
SyncMOS SPWM Application Note
For SM5964、SM8954A、SM8958A、SM89516A、SM59264、SM59128、SM79108
void main(void)
{
//设置 SPWM 输出脚位//
//P1CON=0x04;
//set p1.2 out for 59264,59128
P1CON=0x08; //set p1.3 out for 5964,8954A,8958A,89516A,59264,59128,79108
//P1CON=0x10;
//set p1.4 out for 5964,8954A,8958A,89516A,59264,59128
//P1CON=0x20;
//set p1.5 out for 5964,8954A,8958A,89516A,59264,59128
//P1CON=0x40;
//set p1.6 out for 5964,8954A,8958A,89516A
//P1CON=0x80;
//set p1.7 out for 5964,8954A,8958A,89516A
//设置外部频率的被除数以决定 SPWM 时脉//
//外部频率:20MHz 设 Divider=16 其 SPWM 时脉为 1.25MHz
//SPWMC=0x00; //set SPWM frequency (Divider=2)
//SPWMC=0x01; //set SPWM frequency (Divider=4)
//SPWMC=0x02; //set SPWM frequency (Divider=8)
SPWMC=0x03; //set SPWM frequency (Divider=16)
//设置输出波形的比例(SPWMD0=10h=16,BRM=3h)//
SPWMD0=0x83; //输出波形周期为 16/32=1/2 ; 在 8 个周期中插入 3 个脉冲
//设置输出波形的比例(SPWMD0=18h=24,BRM=1h)//
SPWMD0=0xC3; //输出波形周期为 24/32=3/4 ; 在 8 个周期中插入 1 个脉冲
for(times=0xff;times<=0xff;times--)
{
SPWMD0 = times;
DelayX10ms(50);
}
}
void DelayX10ms(int count)
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<1500;j++);
}
Specifications subject to change without notice, contact your sales representatives for the most recent information.
SPWMAPN_VerA_20090209
4