可程序计数数组(PCA)功能使用方法

可程序计数数组功能使用方法
Application Note
可程序计数数组(PCA)功能使用方法
1 适用产品:SM59D04G2,SM59D03G2。
2 应用说明:
PCA 共有五组,每组皆可工作于以下七种模式:
3
z
捕获模式-正缘捕获模式(Positive edge capture mode)
z
捕获模式-负缘捕获模式(Negative edge capture mode)
z
z
捕获模式-正缘及负缘捕获模式(Both positive and negative edge capture mode)
计时模式(Timer mode)
z
高速频率输出模式(High Speed Output mode)
z
8 位脉宽调变模式(8-bit PWM mode)
z
16 位脉宽调变模式(16-bit PWM mode)
PCA Compare/Capture mode 应用说明
3.1 捕获模式-正缘捕获模式(Positive edge capture mode):
Capture mode 致能时,PCA 16-bit counter 计数缓存器(CCCH, CCCL)会不断的上数,当 CC0~CC4 pin
输入外部讯号,低电位转换成高电位的讯号将做为捕获条件,捕获时产生中断,并且由硬件将 PCA counter
存至捕获数据缓存器 CCnD[15:0](CCnDH, CCnDL)。
图: PCA capture mode with positive edge
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
1
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
3.2 捕获模式-负缘捕获模式(Negative edge capture mode):
Capture mode 致能时,PCA 16-bit counter 计数缓存器(CCCH, CCCL)会不断的上数,当 CC0~CC4 pin
输入外部讯号,高电位转换成低电位的讯号将做为捕获条件,捕获时产生中断,并且由硬件将 PCA counter
存至捕获数据缓存器 CCnD[15:0](CCnDH, CCnDL)。
图: PCA capture mode with negative edge
3.3 捕获模式-正缘及负缘捕获模式(Both positive and negative edge capture mode)
Capture mode 致能时,PCA 16-bit counter 计数缓存器(CCCH, CCCL)会不断的上数,当 CC0~CC4 pin
输入外部讯号,高电位转换成低电位,或由低电位转换成高电位的讯号将做为捕获条件,捕获时产生中断,
并且由硬件将 PCA counter 存至捕获数据缓存器 CCnD[15:0](CCnDH, CCnDL)。
图: PCA capture mode with both negative and positive edge
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
2
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
3.4 计时模式(Timer mode)
当该模式致能,PCA 16-bit counter计数缓存器(CCCH, CCCL)会上数,直到PCA counter溢位时,则会产
生中断.
图: PCA Timer mode
3.5 高速频率输出模式(High Speed Output mode)
当高速频率输出模式(比较模式)致能,每当PCA 16-bit counter计数缓存器(CCCH, CCCL)和数据缓存器
CCnD[15:0]相同时,CCn pin则会做反相讯号输出。
图: PCA high speed output
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
3
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
3.6 8-bit 脉宽调变模式(8-bit PWM mode)
3.6.1 8 位 PWM 仅使用数据缓存器 CCnDL[7:0],未使用 CCnDH[15:8]
3.6.2 8 位 PWM 讯号输出频率由 bit PCAC2^CCCLK 设定:
CCCLK
00
01
10
11
6T
Fosc/256
(Fosc/4)/256
(Fosc/12)/256
(CCCI pin frequency )/256
12T
(Fosc/2)/256
(Fosc/8)/256
(Fosc/24)/256
(CCCI pin frequency )/256
3.6.3 当使用 8 位 PCA 之 PWM 功能时需注意如下:
„
当 CCnDL=0x00 或 0xFF 时 CCn pin 输出皆为 low;
„
„
当 CCnDL=0x01 时 CCn pin 输出 low pulse 为 2 个 PWM Input clock;
当 CCnDL=0x02 时 CCn pin 输出 low pulse 为 3 个 PWM Input clock;
„
当 CCnDL=0xFE 时 CCn pin 输出 high pulse 为 1 个 PWM Input clock。
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
4
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
3.7 16-bit 脉宽调变模式(16-bit PWM mode)
3.7.1 16 位 PWM 使用数据缓存器 CCnDL[7:0]和 CCnDH[15:8]
3.7.2 16 位 PWM 讯号输出频率由 bit PCAC2^CCCLK 设定:
CCCLK
00
01
10
11
6T
Fosc/65536
(Fosc/4)/65536
(Fosc/12)/65536
(CCCI pin frequency )/65536
12T
(Fosc/2)/65536
(Fosc/8)/65536
(Fosc/24)/65536
(CCCI pin frequency )/65536
3.7.3 当使用 PCA 之 PWM 功能时需注意如下:
4
40L
PDI
P
Pin
#
„
当 CCnD = 0x0000 或 0xFFFF 时 CCn pin 输出皆为 low;
„
„
当 CCnD = 0x0001 时 CCn pin 输出 low pulse 为 2 个 PWM Input clock;
当 CCnD = 0x0002 时 CCn pin 输出 low pulse 为 3 个 PWM Input clock;
„
当 CCnD =0xFFFE 时 CCn pin 输出 high pulse 为 1 个 PWM Input clock。
Pin Description
44L
44L
PLC
QFP
C
Pin
Pin
#
#
3
42
4
4
5
6
7
8
43
44
1
2
3
5
6
7
8
9
Symbol
P12/CCCI/EEI2
/ICP_DATA
P13/CC0/EEI3
P14/CC1/EEI4
P15/CC2/EEI5
P16/CC3/EEI6
P17/CC4/EEI7
I/O
i/o
i/o
i/o
i/o
i/o
i/o
Names
Bit 2 of port 1 & PCA External clock input & EEI
interrupt 2 & ICP data/command IO
Bit 3 of port 1 & PCA Channel 0 & EEI interrupt 3
Bit 4 of port 1 & PCA Channel 1 & EEI interrupt 4
Bit 5 of port 1 & PCA Channel 2 & EEI interrupt 5
Bit 6 of port 1 & PCA Channel 3 & EEI interrupt 6
Bit 7 of port 1 & PCA Channel 4 & EEI interrupt 7
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
5
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
5
特殊功能缓存器说明:
Mnemonic
PCAC1
PCAC2
PCAH
PCAL
CC0CON
CC0DH
CC0DL
CC1CON
CC1DH
CC1DL
CC2CON
CC2DH
CC2DL
CC3CON
CC3DH
CC3DL
CC4CON
CC4DH
CC4DL
Description
PCA control
register 1
PCA control
register 2
PCA counter high
byte
PCA counter low
byte
CC0 control
register
CC0 data high
byte
CC0 data low
byte
CC1 control
register
CC1 data high
byte
CC1 data low
byte
CC2 control
register
CC2 data high
byte
CC2 data low
byte
CC3 control
register
CC3 data high
byte
CC3 data low
byte
CC4 control
register
CC4 data high
byte
CC4 data low
byte
Direct
Bit 7
Bit 6
A1h
CCR
CIDL
A2h
CCCLK[1:0]
Bit 5
PCA
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
RESET
-
CC4IE
CC3IE
CC2IE
CC1IE
CC0IE
00h
-
CC4IF
CC3IF
CC2IF
CC1IF
CC0IF
00h
9Ah
PCA[15:8]
00h
9Bh
PCA[7:0]
00h
A3h
-
-
-
TOG0
-
CC0MOD[2:0]
00h
9Ch
CC0D[15:8]
00h
9Dh
CC0D[7:0]
00h
A4h
-
-
-
TOG1
-
CC1MOD[2:0]
00h
9Eh
CC1D[15:8]
00h
9Fh
CC1D[7:0]
00h
A5h
-
-
-
TOG2
-
CC2MOD[2:0]
00h
91h
CC2D[15:8]
00h
92h
CC2D[7:0]
00h
A6h
-
-
-
TOG3
-
CC3MOD[2:0]
00h
93h
CC3D[15:8]
00h
94h
CC3D[7:0]
00h
A7h
-
-
-
TOG4
-
CC4MOD[2:0]
00h
95h
CC4D[15:8]
00h
96h
CC4D[7:0]
00h
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
6
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
5.1 PCA 控制缓存器 1(Control register 1)
Read/Write
Reset Value
Bit 7
CCR
R/W
0
CIDL
R/W
0
0
CC4IE
R/W
0
CC3IE
R/W
0
CC2IE
R/W
0
CC1IE
R/W
0
Bit 0
CC0IE
R/W
0
CCR: PCA Counter Run control bit:
CCR =1,启动PCA计数,由软件设定
CCR =0,停止PCA计数,由软件设定
CIDL: Counter Idle control:
CIDL =1,进入闲置模式,但必须要PCON[0] 同时也被致能为”1”
CIDL =0,离开闲置模式
CCnIE: CC0 ~ CC4 interrupt enable.
CCnIE = 1,中断致能
CCnIE = 0,中断禁能
5.2 PCA 控制缓存器 2(Control register 2)
Mnemonic: PCAC2
7
6
CCCLK[1:0]
R/W
5
-
4
CC4IF
R/W
3
CC3IF
R/W
2
CC2IF
R/W
1
CC1IF
R/W
Address: A2h
0
Reset
CC0IF
00h
R/W
CCCLK[1:0] 比较捕获频率来源选择(Compare/Capture clock source select)
CC0CLK[1:0] Clock source
00
Fosc
01
Fosc/4
10
Fosc/12
11
External clock input (CCCI pin)
CCCLK 会和 6T 或 12T 有关,详细请参考表一、图一及图二说明.相关名词定义如下:
System clock frequency(FSYS) = crystal(FCRY) or oscillator(FOSC) frequency in 6T, and
System clock frequency(FSYS)= crystal(FCRY) or oscillator(FOSC) frequency divided by 2 in 12T
CCnIF CC0 ~ CC4中断旗标 (CC0 ~ CC4 interrupt flag)
当发生中断时由硬件设置为”1”,必须由软件清除.
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
7
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
表一:计算取样周期,以使用 Crystal 16MHz 为范例
Machine
cycle
6T
Fcry
(MHz)
16
6T
CCCLK[1:0] PCA counter increment
Div
Sample period(us)
00
1 system clocks
1
0.0625
16
01
2 system clocks
4
0.25
6T
16
10
12 system clocks
12
0.75
12T
16
00
1 system clocks
2
0.125
12T
16
01
2 system clocks
8
0.5
12T
16
10
6T/12T
12 system clocks
24
1.5
External clock input
External clock input
16
11
/
(CCCI pin)
(CCCI pin)
注:CCCLK[1:0]=11 时,取样周期会依照外部的讯号输入而定;
其它模式取样周期(Sample period) = 1 / (Fcry / Div)
图. PCA clock selection at 6T mode
图二. PCA clock selection at 12T mode
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
8
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
5.3 PCA 计数缓存器 1(Counter register 1)
Mnemonic: PCAH
7
6
5
4
3
PCA[15:8]
R/W
2
1
Address: 9Ah
0
Reset
00h
Mnemonic: PCAL
7
6
5
4
3
PCA[7:0]
R/W
2
1
Address: 9Bh
0
Reset
00h
5.4 CC0CON (Compare/Capture channel 0 control register)
Mnemonic: CC0CON
7
6
5
-
4
TOG0
R/W
3
-
Address: A3h
2
1
0
Reset
CC0MOD[2:0]
00h
R/W
CC0MOD[2:0] 比较/捕获信道0模式选择(Compare/Capture channel 0 modes select)
CC0MOD[2:0]
000
001
010
011
100
101
110
111
TOG0: CC0 toggle register.
Function
Disable PCA channel 0
Positive edge capture mode
Negative edge capture mode
Both positive and negative edge capture mode
Timer mode
High Speed Output mode
8-bit PWM
16-bit PWM
5.5 CC0 Data register
Mnemonic: CC0DH
7
6
5
4
3
CC0D[15:8]
R/W
2
1
Address: 9Ch
0
Reset
00h
Mnemonic: CC0DL
7
6
5
4
3
CC0D[7:0]
2
1
Address: 9Dh
0
Reset
00h
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
9
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
R/W
5.6 CC1CON (Compare/Capture channel 1 control register)
Mnemonic: CC1CON
7
6
5
-
4
TOG1
R/W
3
-
Address: A4h
2
1
0
Reset
CC1MOD[2:0]
00h
R/W
CC1MOD[2:0] 比较/捕获信道1模式选择(Compare/Capture channel 1 modes select)
CC1MOD[2:0]
000
001
010
011
100
101
110
111
TOG1: CC1 toggle register.
Function
Disable PCA channel 1
Positive edge capture mode
Negative edge capture mode
Both positive and negative edge capture mode
Timer mode
High Speed Output mode
8-bit PWM
16-bit PWM
5.7 CC1 Data register
Mnemonic: CC1DH
7
6
Mnemonic: CC1DL
7
6
5
5
4
3
CC1D[15:8]
R/W
4
3
CC1D[7:0]
R/W
2
2
1
Address: 9Eh
0
Reset
00h
1
Address: 9Fh
0
Reset
00h
5.8 CC2CON (Compare/Capture channel 2 control register)
Mnemonic: CC2CON
7
6
5
-
4
TOG2
R/W
3
-
Address: A5h
2
1
0
Reset
CC2MOD[2:0]
00h
R/W
CC2MOD[2:0] 比较/捕获信道2模式选择(Compare/Capture channel 2 modes select)
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
10
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
CC2MOD[2:0]
000
001
010
011
100
101
110
111
TOG2: CC2 toggle register.
Function
Disable PCA channel 2
Positive edge capture mode
Negative edge capture mode
Both positive and negative edge capture mode
Timer mode
High Speed Output mode
8-bit PWM
16-bit PWM
5.9 CC2 Data register
Mnemonic: CC2DH
7
6
Mnemonic: CC2DL
7
6
5
5
4
3
CC2D[15:8]
R/W
4
3
CC2D[7:0]
R/W
2
2
1
Address: 91h
0
Reset
00h
1
Address: 92h
0
Reset
00h
5.10 CC3CON (Compare/Capture channel 3 control register)
Mnemonic: CC3CON
7
6
5
4
3
-
-
-
TOG3
R/W
-
Address: A6h
Res
2
1
0
et
CC3MOD[2:0]
00h
R/W
CC3MOD[2:0] 比较/捕获信道3模式选择(Compare/Capture channel 3 modes select)
CC3MOD[2:0]
000
001
010
011
100
101
110
Function
Disable PCA channel 3
Positive edge capture mode
Negative edge capture mode
Both positive and negative edge capture mode
Timer mode
High Speed Output mode
8-bit PWM
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
11
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
111
16-bit PWM
TOG3: CC3 toggle register.
5.11 CC3 Data register
Mnemonic: CC3DH
7
6
5
4
3
CC3D[15:8]
R/W
2
1
Address: 93h
0
Reset
00h
Mnemonic: CC3DL
7
6
5
4
3
CC3D[7:0]
R/W
2
1
Address: 94h
0
Reset
00h
5.12 CC4CON (Compare/Capture channel 4 control register)
Mnemonic: CC4CON
7
6
5
-
4
TOG4
R/W
3
-
2
Address: A7h
1
0
Reset
CC4MOD[2:0]
00h
R/W
CC4MOD[2:0] 比较/捕获信道4模式选择(Compare/Capture channel 4 modes select)
CC4MOD[2:0]
000
001
010
011
100
101
110
111
TOG4: CC4 toggle register.
Function
Disable PCA channel 4
Positive edge capture mode
Negative edge capture mode
Both positive and negative edge capture mode
Timer mode
High Speed Output mode
8-bit PWM
16-bit PWM
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
12
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
5.13 CC4 Data register
Mnemonic: CC4DH
7
6
5
4
3
CC4D[15:8]
R/W
2
1
Address: 95h
0
Reset
00h
Mnemonic: CC4DL
7
6
5
4
3
CC4D[7:0]
R/W
2
1
Address: 96h
0
Reset
00h
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
13
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
6
中断(Interrupt)
6.1 中断向量表(Interrupt Vector Table):
Interrupt Vector
External interrupt 0
Timer 0
External interrupt 1
Timer 1
Serial Port
Timer 2
EEI
PCA interrupt
0003h
000Bh
0013h
001Bh
0023h
002Bh
0033h
003Bh
Polling
sequence
Polling sequence
Interrupt Source
6.2 使用 Keil’ C 的中断设定范例程序:
unsigned char CPH,CPL;
void init(void)
{
IE = 0x80;
IE1= 0x02;
// PCAC1[7]=>PCA counter run bit
// PCAC1[4]~PCAC1[0] =enable all of CC4 ~ CC0 interrupt
PCAC1 = 0x9f;
// Clock source = Fosc
(note:12T=Fosc/2 ,6T=Fosc)
PCAC2 = 0x00;
}
void PCA_Capture(void) interrupt 7 //vector 003Bh
{
//user code===================
PCAL = 0x00;
PCAH = 0x00;
CPH=CC0DH;
CPL=CC0DL;
//============================
PCAC2 = PCAC2&0xC0;
//clear all flag
}
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
14
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
7
PCA 范例程序及说明:
7.1 PCA Capture mode 应用的范例程序:
Device:SM59D04G2C25
function generator: f=2KHz,T=500us
Description
Main program
Example:
P1.3 Negative edge capture mode
Crystal: 24MHz/12T, Clock source = Fosc/2, t= 0.0833333us, CC0D= 1743h
T*CC0D = 496.25us
Crystal: 24MHz/12T, Clock source = Fosc/8, t= 0.3333333us, CC0D= 05DFh
T*CC0D = 500.9us
Crystal: 24MHz/12T, Clock source = Fosc/24, t= 1us, CC0D= 01EEh
T*CC0D = 496us
//====================================================================
//
//
S Y N C M O S T E C H N O L O G Y
//
//====================================================================
#include "sfr.h"
//#include <reg51.h>
unsigned int j = 0;
unsigned char CPH,CPL;
void init(void)
{
P0 = 0xff;
P1 = 0xff;
P2 = 0xff;
P3 = 0xff;
//EA = 1;
IE = 0x80;
IE1= 0x02;
// PCAC1[7]=>PCA counter run bit
// PCAC1[4]~PCAC1[0] =enable all of CC4 ~ CC0 interrupt
PCAC1 = 0x9f;
//Clock source = Fosc
(note:12T=Fosc/2 ,6T=Fosc)
//PCAC2 = 0x00;
//Clock source = Fosc/4
(note:12T=Fosc/8 ,6T=Fosc/4)
//PCAC2 = 0x40;
//Clock source = Fosc/12
(note:12T=Fosc/24,6T=Fosc/12)
PCAC2 = 0x80;
//Clock source = External clockc (note:CCCI pin)
//PCAC2 = 0xc0;
PCAL = 0x00;
PCAH = 0x00;
}
/****************************************************/
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
15
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
// Select_channel_mode Set
/****************************************************/
// CCnCON.2 CCnCON.1 CCnC0N.0
Capture mode
// 0
0
1
postive edge
// 0
1
0
Negative edge
// 0
1
1
postive&Negative edge
// 1
0
0
Timer mode
void Select_channel_mode(void)
{
CC0CON = 0x02; //P1.3 Negative edge capture mode
CC1CON = 0x02; //P1.4 Negative edge capture mode
CC2CON = 0x01; //P1.5 Postive edge capture mode
CC3CON = 0x03; //P1.6 Postive & Negative capture mode
CC4CON = 0x03; //P1.7 Postive & Negative capture mode
}
void PCA_Capture(void) interrupt 7 //vector 003Bh
{
/****************************************************/
// PCA Capture interrupt
/****************************************************/
PCAL = 0x00;
PCAH = 0x00;
CPH=CC0DH;
CPL=CC0DL;
PCAC2 = PCAC2&0xC0;
}
void main(void)
{
unsigned int i=0, ii=0;
init();
Select_channel_mode();
P3 = 0xFF;
while(1)
{
for(i=0;i<1000; i++)
{
for(ii=0;ii<200; ii++)
{
}
}
P0 =CPH;
P2 =CPL;
}
}
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
16
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
7.2 PCA Timer mode 应用的范例程序:
Description
Main program
Device:SM59D04G2C25 Crystal:24MHz/12T
Clock source= Fosc/4
6T:T =1 / Clock source = 4/24MHz =0.1666666us
12T:T =2(1 / Clock source) =2*4/24MHz = 0.33333us
PCA = 65536 -300(decimal) =10000 -12C = 0xFED4
300T = 100us, will detect P3 toggles about 100us
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "sfr.h"
/****************************************************/
// enable interrupt and select clock source
/****************************************************/
void Initial()
{
IE=0x80;
//enable all interrupt
IE1=0x02;
//enable PCA interrupt
//PCAC1: CCR
//PCAC1=0x9f;
PCAC1=0x81;
CIDL -
CC4IE
CC3IE
CC2IE
//PCAC2.7,PCAC2.6
//
0
0
//
0
1
//
1
0
//
1
1
PCAC2=0x40;
PCAL =0xD4;
PCAH =0xFE;
Clock source
Fosc
Fosc/4
Fosc/12
External clock input(CCCI pin,P1.2)
//clock source from Fosc/4
//software reload value
//software reload value
CC1IE
CC0IE
}
/****************************************************/
// select_channel 0 ~ 4
/****************************************************/
void select_channel(void)
{
CC0CON=0x04;
//channel"0" timer mode
CC1CON=0;
//channel"1" timer mode disable
CC2CON=0;
//channel"2" timer mode disable
CC3CON=0;
//channel"3" timer mode disable
CC4CON=0;
//channel"4" timer mode disable
}
void PCA_Timer(void) interrupt 7 using 0//vector 003Bh
{
//if (PCAC2&0x01)
//{
//65536 -300(decimal) =10000 -12C = 0xFED4
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
17
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
PCAL =0xD4;
PCAH =0xFE;
//software reload value
//software reload value
//}
P3 = ~P3;
//12T@24MHz P3 toggle per 100us
PCAC2 &= 0x40;
//software clear all flag
}
void main(void)
{
select_channel();
Initial();
while(1)
{}
}
7.3 PCA High speed output mode 应用的范例程序:
Description
Main program
High speed pulse width
Device:SM59D04G2C25 Crystal:24MHz/12T
Clock source = Fosc/12
6T: T =1 /source clock = 1/(Fosc/12) = 12/24MHz =0.5us
12T: T =2(1 /source clock) = 2/(Fosc/12) =2*12/24MHz =1us
100T =100us, detect pin CC0(P1.3) toggles about 100us.
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
//********************************************************************
// high speed pulse width
// Device:SM59D04G2C25 Crystal:24MHz/12T
// 6T: 1 source clock = 1/(Fosc/12) = 12/24MHz =0.5us
// 12T: 1 source clock = 2/(Fosc/12) =2*12/24MHz =1us
// detect P1.3 toggle per 100us
//********************************************************************
#include"sfr.h"
void Initial()
{
IE=0x80;
IE1=0x02;
PCAC1=0x81;
//enable all interrupt
//enable PCA interrupt
//PCAC1.7=>PCA counter run bit
//PCAC1 enable CC0 interrupt
//PCAC2.7,PCAC2.6
Clock source
//
0
0
Fosc
//
0
1
Fosc/4
//
1
0
Fosc/12
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
18
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
//
1
1
PCAC2=0x80;
PCAH =0x00;
PCAL =0x00;
CC0DH=0x00;
CC0DL=0x64;;
External clock input(CCCI pin)
//clock source from Fosc/12
//software reload value
//software reload value
//detect P1.3 toggle per 100us
//
}
/****************************************************/
// only for select channel at CCnCON.
/****************************************************/
void Select_channel_mode()
{
CC0CON=0x05;
//high speed mode
CC1CON=0x00;
//high speed mode
CC2CON=0x00;
//high speed mode
CC3CON=0x00;
//high speed mode
CC4CON=0x00;
//high speed mode
}
=>P1.3 enable
=>P1.4 disable
=>P1.5 disable
=>P1.6 disable
=>P1.7 disable
/****************************************************/
// PCA High Speed interrupt
/****************************************************/
void PCA_High_Speed(void) interrupt 7//vector
3B
{
PCAL =0x00;
//software reload value
PCAH =0x00;
//software reload value
PCAC2=PCAC2&0xC0;
// PCAC2.7:6 (CCCLK is "11" representative
external clock input "p1.2")
}
void main()
{
Initial();
Select_channel_mode();
while(1)
{}
}
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
19
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
7.4 PCA PWM mode 应用的范例程序:
Description
Main program
Device:SM59D04G2C25 Crystal:24MHz/12T
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include"sfr.h"
void Select_channel();
void Initial();
void main()
{
Initial();
Select_channel();
while(1)
{
p3=~p3;
}
}
//*****************************************************************
//
initial set and select clock source mode0 ~ mode3
//*****************************************************************
void Initial()
{
p0=0xff;
p1=0xff;
p2=0xff;
p3=0xff;
PCAC1=0x9f; //PCAC1.7=>PCA counter run bit enable
//PCAC1.4 ~ PCAC1.0 enable CC4 ~ CC0 interrupt
//source clock = Fosc/12
PCAC2=0x80;
}
//*****************************************************************
//
select 8 bit or 16 bit PWM and select PWM output p1.3 ~ p1.7
//*****************************************************************
void Select_channel(void)
{
CC0CON=0x06;
//8bit PWM
CC0DL= 0x3F; //pulse width ,low:high =64us:192us =1:3
CC1CON=0x07;
//16bit PWM
CC1DH= 0x3F; //pulse width ,low:high =16.386ms:49.159ms =1:3
CC1DL= 0xFF;
/*
CC1CON=0x06;
//8bit PWM
CC1DL= 0x00; //pulse width ,always low
CC0CON=0x06;
//8bit PWM
CC0DL= 0x01; //pulse width ,low:high =2:254
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
20
Ver. A 2009/03
可程序计数数组功能使用方法
Application Note
CC2CON=0x06;
//8bit PWM
CC2DL= 0xfd; //pulse width ,low:high =254:2
CC3CON=0x06;
//8bit PWM
CC3DL= 0xfe; //pulse width ,low:high =255:1
CC4CON=0x06;
//8bit PWM
CC4DL= 0xff; //pulse width ,always low
*/
/*
CC0CON=0x07;
//16bit PWM
CC0DH= 0x00; //pulse width ,low:high =3:65533
CC0DL= 0x02;
CC1CON=0x07;
//16bit PWM
CC1DH= 0x00; //pulse width ,low:high =2:65534
CC1DL= 0x01;
CC2CON=0x07;
//16bit PWM
CC2DH= 0x00; //pulse width ,always low
CC2DL= 0x00;
CC3CON=0x07;
//16bit PWM
CC3DH= 0xFF; //pulse width ,low:high =65535:1
CC3DL= 0xFE;
CC4CON=0x07;
//16bit PWM
CC4DH= 0xFF; //pulse width ,always low
CC4DL= 0xFF;*/
}
Specifications subject to change without notice, contact your sales representatives for the most recent information.
IRFWX-A124
21
Ver. A 2009/03