Technical Application Notes

SyncMOS Technologies International, Inc.
ADC
Technical
Application Notes
1.
2.
3.
Index
简述 .......................................................................................................................................................2
适用产品 ...............................................................................................................................................2
应用说明 ...............................................................................................................................................3
3.1
ADC 规格概述 ..............................................................................................................................3
3.2
SM59A16U1 ..................................................................................................................................4
3.3
SM59R04A2、SM59R05A5、SM59R09A5、SM59R16A5 ....................................................12
3.4
SM39A16M1、SM39R16A6 ......................................................................................................16
3.5
SM39R08A2、SM39R16A2 .......................................................................................................23
3.6
SM39R08A3、SM39R16A3 .......................................................................................................27
3.7
SM39R08A5 ................................................................................................................................33
4. 最佳 ADC 取样频率选择说明 ...........................................................................................................37
5. 注意事项 .............................................................................................................................................39
Application Notes
1.
简述
本应用指南提供了该系列产品的一些功能应用及所需要注意的讯息或问题的解决对策,以作为改善客户所碰到的疑难
问题,不过相关的功能应用及电器特性等,客户还是需要请参考 Datasheet. 可於新茂網站 www.syncmos.com.tw 下
載。
2.
适用产品
零
件
号
码
SM59A16U1、SM59R04A2、SM59R05A5、SM59R09A5、SM59R16A5、SM39A16M1、SM39R16A6、
SM39R08A2、SM39R16A2、SM39R08A3、SM39R16A3、SM39R08A5
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
-2-
Application Notes
3.
应用说明
3.1
ADC规格概述
(1). 10-bit 的 ADC 可提供最大的通道数及转换率如表 3-1。
* 请看 Keil C 有关 C51 用户指南中的描述中断功能。
表 3-1: ADC 通道數及轉換率
9
ADC 时钟
最大频率(MHz)
12.5
最高轉換率
(KHz)
961
8
12.5
500
SM59R04A2、 SM59R05A5、SM59R09A5、
SM59R16A5
8
12.5
961
SM39A16M1、
8
12.5
500
SM39R08A2、SM39R16A2
7
12.5
961
SM39R08A3、SM39R16A3
8
11.0592
851
SM39R08A5
通道數
零
件
号
码
SM59A16U1
(2). ADC 为 SAR 架构。
(3). ADC 时钟,提供 32 组预除设定(请
SFR ADCCS 设定)。
參考
(4). ADC 中断向量为 0x53H,中断号码为 10,如表 3-2。
表 3-2: ADC 相对应的中断向量表
IE0 – External interrupt 0
0003h
Interrupt Number
*(use Keil C Tool)
0
TF0 – Timer 0 interrupt
000Bh
1
IE1 – External interrupt 1
0013h
2
.
.
.
.
.
.
.
.
.
.
.
.
0053h
10
.
.
.
.
.
.
IICIF – IIC interrupt
006Bh
13
RI1/TI1 – Serial channel 1 interrupt
0083h
16
Interrupt Request Flags
Interrupt Vector 地址
ADCIF – A/D converter interrupt
*See Keil C about C51 User’s Guide about Interrupt Function 描述
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
-3-
Application Notes
3.2
SM59A16U1
ADCC1[7:0]
ADCCH[2:0]
VDD
Start Trigger
PWM Trigger
EXT Trigger
ADC0
…
…
…
…
ADC6
MUX
ADC7
AVDD
M
U
X
ADC8
ADCD[9:0]
High Speed
10 Bits
ADC Module
OP0ToADC
ADC_ISR
P34
ADCEN
ADC
Clock
Divider
Fosc
ADCEN
To P34
AVSS
ADCCS[4:0]
VSS
图 3-1: ADC 模块工作方块图
符号
描述
地址
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
重置值
ADC2
EN
ADC1
EN
ADC0
EN
00H
ADC
ADCC1
ADC Control
register 1
ABh
ADC7
EN
ADC6
EN
ADC5E
N
ADC4
EN
ADC3
EN
ADCC2
ADC Control
register 2
ACh
Start
ADJU
ST
PWM
Trigger
EN
EXT
Trigge
rEN
ADC
MODE
ADCDH
ADC data high
byte
ADh
ADCDH [7:0]
00H
ADCDL
ADC data low
byte
AEh
ADCDL [7:0]
00H
ADCCS
ADC clock
select
IEN1
IRCON
ADCCH[2:0]
00H
AFh
OP0
ToAD
C
-
ADCEN
ToP34
Interrupt Enable
1 register
B8h
EXEN
2
-
IEIIC
IELVI
IEKBI
IEAD
C
IESPI
-
00h
Interrupt
request register
C0H
EXF2
TF2
IICIF
LVIIF
KBIIF
ADCIF
SPIIF
PWMIF
00H
ADCCS[4:0]
00H
符号: ADCC1
地址: ABh
7
6
5
4
3
2
1
0
Reset
ADC7EN ADC6EN ADC5EN ADC4EN ADC3EN ADC2EN ADC1EN ADC0EN
00H
ADC7EN: 使能 ADC 通道 7.
ADC7EN = 1 –使能 ADC 通道 7
ADC6EN: 使能 ADC 通道 6.
ADC6EN = 1 –使能 ADC 通道 6
ADC5EN: 使能 ADC 通道 5.
ADC5EN = 1 –使能 ADC 通道 5
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
-4-
Application Notes
ADC4EN: 使能 ADC 通道 4.
ADC4EN = 1 –使能 ADC 通道 4
ADC3EN: 使能 ADC 通道 3.
ADC3EN = 1 –使能 ADC 通道 3
ADC2EN: 使能 ADC 通道 2.
ADC2EN = 1 –使能 ADC 通道 2
ADC1EN: 使能 ADC 通道 1.
ADC1EN = 1 –使能 ADC 通道 1
ADC0EN: 使能 ADC 通道 0.
ADC0EN = 1 –使能 ADC 通道 0
符号: ADCC2
7
6
Start ADJUST
5
PWMTriggerEN
4
EXTTriggerEN
3
ADCMODE
地址: ACh
2
1
0 Reset
ADCCH[2:0] 00H
Start: 当该位被置位时,ADC 将启动连续转换.
ADJUST: ADC 数字输出格式调整.
ADJUST = 0: (默认)
ADC 数字输出高字节 ADCD [9:2] = ADCDH [7:0].
ADC 数字输出低字节 ADCD [1:0] = ADCDL [1:0].
ADJUST = 1:
ADC 数字输出高字节 ADCD [9:8] = ADCDH [1:0].
ADC 数字输出低字节 ADCD [7:0] = ADCDL [7:0].
PWMTriggerEN PWM 触发 ADC 开始转换
(HW 内部触发转换)
0 =禁止
1 =使能
EXTTriggerEN 外部引脚触发 ADC 开始转换
(HW 外部触发转换)
0 =禁止
1 =使能
ADCMOD 0 =连续模式
1 =单次转换模式
ADCCH[2:0]: ADC 通道选择.
ADCCH [2:0]
000
通道
0
001
1
010
2
011
3
100
4
101
5
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
-5-
Application Notes
110
6
111
7
ADJUST = 0:
符号: ADCDH
地址: ADh
7
6
5
4
3
2
1
0
Reset
ADCD[9] ADCD[8] ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2]
00H
符号: ADCDL
7
6
-
5
-
4
-
3
-
2
-
1
ADCD[1]
0
ADCD[0]
地址: AEh
Reset
00H
ADJUST = 1:
符号: ADCDH
7
6
-
5
-
4
-
3
-
2
-
地址: ADh
1
0
Reset
ADCD[9] ADCD[8]
00H
符号: ADCDL
地址: AEh
7
6
5
4
3
2
1
0
Reset
ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2] ADCD[1] ADCD[0]
00H
ADCD[9:0]: ADC 数字寄存器.
符号: ADCCS
7
6
5
4
3
OP0ToADC - ADCENToP34 ADCCS[4] ADCCS[3]
2
ADCCS[2]
1
ADCCS[1]
地址: AFh
0
Reset
ADCCS[0]
00H
OP0ToADC: 选择 ADC 通道 8 作为输入源
0 = 设置 ADC 输入源由 ADCC2 决定.
1 = 设置 ADC 输入源作为 Op0 输出.
ADCENToP34: ADC 内部信号测试和监视器.
0 = 禁止 ADC 内部信号输出至 P3.4
1 = 使能 ADC 内部信号输出至 P3.4
ADCCS[4:0]: ADC 时钟选择.
* ADC 时钟最大为 12.5MHz.
* ADC 转换率最高为 961KHz
ADC _ Clock =
Fosc
2 × ( ADCCS + 1)
ADC _ Conversion _ Rate =
ADC_Clock
13
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
-6-
Application Notes
符号: IEN1
7
EXEN2
6
-
5
IEIIC
4
IELVI
3
IEKBI
2
IEADC
1
IESPI
地址: B8h
0
Reset
IEPWM
00h
IEADC: A/D 转换中断使能位
IEADC = 0 –禁能 ADC 中断.
IEADC = 1 –使能 ADC 中断.
符号: IRCON
7
6
EXF2
TF2
5
IICIF
4
LVIIF
3
KBIIF
2
ADCIF
1
SPIIF
地址: C0h
0
Reset
PWMIF
00H
ADCIF: A/D 转换中断旗标位,当有开启 ADC 中断时,转换完成会设为 1,进中断后硬件自动清为 0.
若未开 ADC 中断,则必须手动软件清除为 0.
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
-7-
Application Notes
3.2.1
ADC一般应用流程图
Entry ADC
function
SFR ADCC2 set
(bit Adjust)
(bit ADCCH[2:0])
SFR ADCC1 set
SFR ADCC2 set
(bit START)
If ADCIF=0
Read SFR
ADCDH
Read SFR
ADCDL
Finish ADC
3.2.2
If ADCIF=1
SFR IRCON
(bit ADCIF)
ADC一般程序范例
Describe:
main
Program:
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "..\h\SM39A16U1.h"
void main(void)
{
unsigned char temp_H,temp_L;
ADCC1 = 0x01;
ADCC2 = 0x00;
ADCCS = 0x00;
}
//ADC Chanel 0 enable
//Continuous mode, ADC Chanel 0 is analog input, Adiust=0
//ADC clock Fosc/2
while(1)
{
ADCC2 |= 0x80;
//sbit ADC START = 1, will auto clear after finish
while(!IRCON && 0x04); //finish if ADCIF=1, converting if ADCIF=0
temp_L = ADCDL;
//ADC result, the Adjust=0, the ADCDL[1:0]=ADCD[1:0]
temp_H = ADCDH;
//the ADCDH[7:0]=ADCD[9:2]
IRCON &= 0xFB;
//Clear ADCIF flag for next ADC conversion
}
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
-8-
Application Notes
3.2.3
ADC外部触发应用流程图
Entry ADC
function
SFR ADCC1 set
SFR ADCC2 set
(bit EXTTriggerEN)
(bit ADCMODE)
(bit Adjust)
(bit ADCCH[2:0])
SFR ADCCS set
(ADC clock)
SFR IEN0 set
(bit EA)
SFR IEN1 set
(bit IEADC)
Read SFR
ADCDH
Read SFR
ADCDL
ADC ISR
3.2.4
Clear ADCIF flag
Finish ADC
ADC外部触发程序范例
Describe:
main
Program:
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "..\h\SM39A16U1.h"
void main(void)
{
ADCC1 = 0x01;
ADCC2 = 0x18;
ADCCS = 0x00;
}
EA = 1;
IEADC = 1;
while(1){}
//ADC Chanel 0 enable
//EXT TriggerADC Enable, single-shot mode, ADC Chane 0 is
// analog input, Adiust=0
//ADC clock Fosc/2
//Enable all inierrupt
//Enable ADC inierrupt
void ADC_ISR(void) interrupt d_ADC_Vector
{
unsigned char temp_H,temp_L;
}
temp_L = ADCDL;
temp_H = ADCDH;
ADCIF =0;
// 地址: 0x53
//ADC result, the Adjust=0, the ADCDL[1:0]=ADCD[1:0]
//the ADCDH[7:0]=ADCD[9:2]
//Clear ADCIF flag for next ADC conversion
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
-9-
Application Notes
3.2.5
PWM触发ADC应用流程图
Entry ADC
function
SFR ADCC1 set
SFR IEN0 set
(bit EA)
SFR IEN1 set
(bit IEADC)
Read SFR
ADCDH
Read SFR
ADCDL
ADC ISR
3.2.6
SFR ADCC2 set
(bit PWMTriggerEN)
(bit ADCMODE)
(bit Adjust)
(bit ADCCH[2:0])
SFR SEVTCMPL set
SFR SEVTCMPH set
Clear ADCIF flag
SFR ADCCS set
(ADC clock)
PWM initail
Finish ADC
PWM触发ADC程序范例
Describe:
main
Program:
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "..\h\SM39A16U1.h"
void main(void)
{
PAGESEL = 0x01;
ADCC1 = 0x01;
ADCC2 = 0x28;
}
ADCCS = 0x00;
PAGESEL = 0x03;
SEVTCMPL = 0x00;
SEVTCMPH = 0x00;
PAGESEL = 0x01;
PWM_Init();
EA = 1;
IEADC = 1;
while(1){}
//Page Mode: Page0
//ADC Chanel 0 enable
//PWM TriggerADC Enable, single-shot mode, ADC Chanel
// 0 is analog input, Adiust=0
//ADC clock Fosc/2
//Page Mode: Page1
//Special Event Compare Low byte
//Special Event Compare High byte
//Page Mode: Page0
//Enable all inierrupt
//Enable ADC inierrupt
void ADC_ISR(void) interrupt d_ADC_Vector
{
unsigned char temp_H,temp_L;
}
temp_L = ADCDL;
temp_H = ADCDH;
ADCIF =0;
// 地址: 0x53
//ADC result, the Adjust=0, the ADCDL[1:0]=ADCD[1:0]
//the ADCDH[7:0]=ADCD[9:2]
//Clear ADCIF flag for next ADC conversion
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 10 -
Application Notes
3.2.7
OP0输出转ADC应用流程图
Entry ADC
function
SFR ADCC2 set
(bit Adjust)
(bit ADCCH[2:0])
SFR ADCCS set
(bit OP0ToADC)
(ADC clock)
OP0 initail
If ADCIF=0
Finish ADC
3.2.8
Read SFR
ADCDH
Read SFR
ADCDL
If ADCIF=1
SFR IRCON
(bit ADCIF)
SFR ADCC2 set
(bit START)
OP0输出转ADC程序范例
Describe:
main
Program:
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "..\h\SM39A16U1.h"
void main(void)
{
unsigned char temp_H,temp_L;
ADCCS = 0x80;
ADCC2 = 0x00;
OP0_Init();
}
//ADC Chanel 8 enable, ADC clock Fosc/2
//Continuous mode, Adiust=0
while(1)
{
ADCC2 |= 0x80;
//sbit ADC START = 1, will auto clear after finish
while(!IRCON && 0x04); //finish if ADCIF=1, converting if ADCIF=0
temp_L = ADCDL;
//ADC result, the Adjust=0, the ADCDL[1:0]=ADCD[1:0]
temp_H = ADCDH;
//the ADCDH[7:0]=ADCD[9:2]
IRCON &= 0xFB;
//Clear ADCIF flag for next ADC conversion
}
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 11 -
Application Notes
3.3
SM59R04A2、SM59R05A5、SM59R09A5、SM59R16A5
ADCC1[7:0]
VDD
ADCCH[2:0]
Start
ADC0
AVDD
…
…
…
…
ADCD[9:0]
MUX
ADC6
High Speed
10 Bits
ADC Module
ADC7
ADC
Clock
Divider
Fosc
ADC_ISR
AVSS
ADCCS[4:0]
VSS
图 3-2: ADC 模块工作方块图
符号
描述
地址
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
重置值
ADC2
EN
ADC1
EN
ADC0
EN
00H
ADC
ADCC1
ADC Control
register 1
ABh
ADC7
EN
ADC6
EN
ADC5E
N
ADC4
EN
ADC3
EN
ADCC2
ADC Control
register 2
ACh
Start
ADJUST
-
-
-
ADCDH
ADC data high
byte
ADh
ADCDH [7:0]
00H
ADCDL
ADC data low
byte
AEh
ADCDL [7:0]
00H
ADCCS
ADC clock
select
AFh
-
-
-
IEN1
Interrupt Enable
1 register
B8h
EXEN2
-
IEIIC
IELVI
IEKBI
IEADC
IESPI
IEPWM
00H
IRCON
Interrupt
request register
C0H
EXF2
TF2
IICIF
LVIIF
KBIIF
ADCIF
SPIIF
PWMIF
00H
ADCCH[2:0]
00H
ADCCS[4:0]
00H
符号: ADCC1
地址: ABh
7
6
5
4
3
2
1
0
Reset
ADC7EN ADC6EN ADC5EN ADC4EN ADC3EN ADC2EN ADC1EN ADC0EN
00H
ADC7EN: 使能 ADC 通道 7.
ADC7EN = 1 –使能 ADC 通道 7
ADC6EN: 使能 ADC 通道 6.
ADC6EN = 1 –使能 ADC 通道 6
ADC5EN: 使能 ADC 通道 5.
ADC5EN = 1 –使能 ADC 通道 5
ADC4EN: 使能 ADC 通道 4.
ADC4EN = 1 –使能 ADC 通道 4
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 12 -
Application Notes
ADC3EN: 使能 ADC 通道 3.
ADC3EN = 1 –使能 ADC 通道 3
ADC2EN: 使能 ADC 通道 2.
ADC2EN = 1 –使能 ADC 通道 2
ADC1EN: 使能 ADC 通道 1.
ADC1EN = 1 –使能 ADC 通道 1
ADC0EN: 使能 ADC 通道 0.
ADC0EN = 1 –使能 ADC 通道 0
符号: ADCC2
7
6
Start ADJUST
5
-
4
-
3
-
2
1
ADCCH[2:0]
0
地址: ACh
Reset
00H
Start: 当该位被置位时,ADC 将启动连续转换.
ADJUST: DC 数字输出格式调整.
ADJUST = 0: (默认)
ADC 数字输出高字节 ADCD [9:2] = ADCDH [7:0].
ADC 数字输出低字节 ADCD [1:0] = ADCDL [1:0]..
ADJUST = 1:
ADC 数字输出高字节 ADCD [9:8] = ADCDH [1:0].
ADC 数字输出低字节 ADCD [7:0] = ADCDL [7:0].
ADCCH[2:0]: ADC 通道选择.
ADCCH [2:0]
000
Channel
0
001
1
010
2
011
3
100
4
101
5
110
6
111
7
ADJUST = 0:
符号: ADCDH
地址: ADh
7
6
5
4
3
2
1
0
Reset
ADCD[9] ADCD[8] ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2]
00H
符号: ADCDL
7
6
-
5
-
4
-
3
-
2
-
1
ADCD[1]
0
ADCD[0]
地址: AEh
Reset
00H
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 13 -
Application Notes
ADJUST = 1:
符号: ADCDH
7
6
-
5
-
4
-
3
-
2
-
地址: ADh
1
0
Reset
ADCD[9] ADCD[8]
00H
符号: ADCDL
地址: AEh
7
6
5
4
3
2
1
0
Reset
ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2] ADCD[1] ADCD[0]
00H
ADCD[9:0]: ADC 数字寄存器.
符号: ADCCS
7
6
5
-
4
3
2
1
0
ADCCS[4] ADCCS[3] ADCCS[2] ADCCS[1] ADCCS[0]
地址: AFh
Reset
00H
ADCCS[4:0]: ADC 时钟选择.
* ADC 时钟最大为 12.5MHz.
* ADC 转换率最高为 500KHz
Fosc
2 × ( ADCCS + 1)
ADC_Clock
ADC _ Conversion _ Rate =
23
ADC _ Clock =
符号: IEN1
7
EXEN2
6
-
5
IEIIC
4
IELVI
3
IEKBI
2
IEADC
1
IESPI
地址: B8h
0
Reset
IEPWM
00h
IEADC: A/D 转换中断使能位
IEADC = 0 –禁能 ADC 中断.
IEADC = 1 –使能 ADC 中断.
符号: IRCON
7
6
EXF2
TF2
5
IICIF
4
LVIIF
3
KBIIF
2
ADCIF
1
SPIIF
地址: C0h
0
Reset
PWMIF
00H
ADCIF: A/D 转换中断旗标位,当有开启 ADC 中断时,转换完成会设为 1,进中断后硬件自动清为 0.
若未开 ADC 中断,则必须手动软件清除为 0.
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 14 -
Application Notes
3.3.1
ADC应用流程图
Entry ADC
function
SFR ADCC2 set
(bit Adjust)
(bit ADCCH[1:0])
SFR ADCC1 set
SFR ADCC2 set
(bit START)
If ADCIF= 0
Read SFR
ADCDH
Read SFR
ADCDL
Finish ADC
3.3.2
SFR IRCON
If ADCIF= 1 (bit ADCIF)
ADC程序范例
Describe:
main
Program:
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "..\h\SM59R04A2.h"
void main(void)
{
unsigned char temp_H,temp_L;
ADCC1 = 0x01;
ADCC2 = 0x00;
//ADC Chanel 0 enable
//ADC Chanel 0 is analog input, Adiust=0
while(1)
{
ADCC2 |=0x80;
//sbit ADC START = 1, will auto clear after finish
while(!IRCON && 0x04);
//finish if ADCIF=1, converting if ADCIF=0
}
}
temp_L = ADCDL; /
temp_H = ADCDH;
IRCON &= 0xFB;
/ADC result, the Adjust=0, the ADCDL[1:0]=ADCD[1:0]
//the ADCDH[7:0]=ADCD[9:2]
//Clear ADCIF flag for next ADC conversion
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 15 -
Application Notes
3.4
SM39A16M1、SM39R16A6
ADCC1[7:0]
VDD
ADCCH[2:0]
Start
ADC0
AVDD
…
…
…
…
ADCD[9:0]
MUX
ADC6
High Speed
10 Bits
ADC Module
ADC7
ADC
Clock
Divider
Fosc
ADC_ISR
AVSS
ADCCS[4:0]
VSS
图 3-3: ADC 模块工作方块图
符号
描述
地址
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
重置值
ADC2
EN
ADC1
EN
ADC0
EN
00H
ADC
ADCC1
ADC Control
register 1
ABh
ADC7
EN
ADC6
EN
ADC5
EN
ADC4
EN
ADC3
EN
ADCC2
ADC Control
register 2
ACh
Start
ADJU
ST
PWMT
rigger
EN
EXTTri
ggerE
N
ADCM
ODE
ADCDH
ADC data high
byte
ADh
ADCDH [7:0]
00H
ADCDL
ADC data low
byte
AEh
ADCDL [7:0]
00H
ADCCS
ADC clock select
AFh
-
-
-
IEN1
Interrupt Enable 1
register
B8h
EXEN
2
-
IEIIC
IELVI
-
IEAD
C
IESPI
-
00H
IRCON
Interrupt request
register
C0H
EXF2
TF2
IICIF
LVIIF
-
ADCIF
SPIIF
-
00H
ADCCH[2:0]
08H
ADCCS[4:0]
00H
符号: ADCC1
地址: ABh
7
6
5
4
3
2
1
0
Reset
ADC7EN ADC6EN ADC5EN ADC4EN ADC3EN ADC2EN ADC1EN ADC0EN
00H
ADC7EN: 使能 ADC 通道 7.
ADC7EN = 1 –使能 ADC 通道 7
ADC6EN: 使能 ADC 通道 6.
ADC6EN = 1 –使能 ADC 通道 6
ADC5EN: 使能 ADC 通道 5.
ADC5EN = 1 –使能 ADC 通道 5
ADC4EN: 使能 ADC 通道 4.
ADC4EN = 1 –使能 ADC 通道 4
ADC3EN: 使能 ADC 通道 3.
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 16 -
Application Notes
ADC3EN = 1 –使能 ADC 通道 3
ADC2EN: 使能 ADC 通道 2.
ADC2EN = 1 –使能 ADC 通道 2
ADC1EN: 使能 ADC 通道 1.
ADC1EN = 1 –使能 ADC 通道 1
ADC0EN: 使能 ADC 通道 0.
ADC0EN = 1 –使能 ADC 通道 0
符号: ADCC2
7
6
Start ADJUST
5
PWMTriggerEN
4
EXTTriggerEN
3
ADCMODE
地址: ACh
2
1
0 Reset
ADCCH[2:0] 08H
Start: 当该位被置位时,ADC 将启动连续转换.
ADJUST: ADC 数字输出格式调整.
ADJUST = 0: (默认)
ADC 数字输出高字节 ADCD [9:2] = ADCDH [7:0].
ADC 数字输出低字节 ADCD [1:0] = ADCDL [1:0].
ADJUST = 1:
ADC 数字输出高字节 ADCD [9:8] = ADCDH [1:0].
ADC 数字输出低字节 ADCD [7:0] = ADCDL [7:0].
PWMTriggerEN PWM 触发 ADC 开始转换
(HW 内部触发转换)
0 =禁用
1 =使能
EXTTriggerEN 外部引脚触发 ADC 开始转换
(HW 外部触发转换)
0 =禁用
1 =使能
ADCMODE 0 =连续模式
1 =单次转换模式
ADCCH[2:0]: ADC 通道选择.
ADCCH [2:0]
000
通道
0
001
1
010
2
011
3
100
4
101
5
110
6
111
7
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 17 -
Application Notes
ADJUST = 0:
符号: ADCDH
地址: ADh
7
6
5
4
3
2
1
0
Reset
ADCD[9] ADCD[8] ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2]
00H
符号: ADCDL
7
6
-
5
-
ADJUST = 1:
符号: ADCDH
7
6
-
4
-
5
-
3
-
4
-
2
-
3
-
1
ADCD[1]
2
-
0
ADCD[0]
地址: AEh
Reset
00H
地址: ADh
1
0
Reset
ADCD[9] ADCD[8]
00H
符号: ADCDL
地址: AEh
7
6
5
4
3
2
1
0
Reset
ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2] ADCD[1] ADCD[0]
00H
ADCD[9:0]: ADC 数字寄存器.
符号: ADCCS
7
6
5
-
4
3
2
1
0
ADCCS[4] ADCCS[3] ADCCS[2] ADCCS[1] ADCCS[0]
地址: AFh
Reset
00H
ADCCS[4:0]: ADC 时钟选择.
* ADC 时钟最大为 12.5MHz.
* ADC 转换率最高为 961KHz
ADC _ Clock =
Fosc
2 × ( ADCCS + 1)
ADC _ Conversion _ Rate =
符号: IEN1
7
EXEN2
6
-
5
IEIIC
4
IELVI
ADC_Clock
13
3
IEKBI
2
IEADC
1
IESPI
地址: B8h
0
Reset
IEPWM
00h
IEADC: A/D 转换中断使能位
IEADC = 0 –禁能 ADC 中断.
IEADC = 1 –使能 ADC 中断.
符号: IRCON
7
6
EXF2
TF2
5
IICIF
4
LVIIF
3
KBIIF
2
ADCIF
1
SPIIF
地址: C0h
0
Reset
PWMIF
00H
ADCIF: A/D 转换中断旗标位,当有开启 ADC 中断时,转换完成会设为 1,进中断后硬件自动清为 0.
若未开 ADC 中断,则必须手动软件清除为 0.
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 18 -
Application Notes
3.4.1
ADC一般应用流程图
Entry ADC
function
SFR ADCC2 set
(bit Adjust)
(bit ADCCH[2:0])
SFR ADCC1 set
SFR ADCC2 set
(bit START)
If ADCIF=0
Read SFR
ADCDH
Read SFR
ADCDL
Finish ADC
3.4.2
If ADCIF=1
SFR IRCON
(bit ADCIF)
ADC一般程序范例
Describe:
main
Program:
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "..\h\SM39A16M1.h"
void main(void)
{
unsigned char temp_H,temp_L;
PAGESEL = 0x01;
CKCON = 0x00;
//SFE Page0
// Defult 2T(CKCON=0x10), Change to 1T. (CKCON SFR at
//page 0)
ADCC1 = 0x01;
ADCC2 = 0x00;
//ADC Chanel 0 enable
//Continuous mode, ADC Chanel 0 is analog input,
// Adiust=0
//ADC clock Fosc/2
ADCCS = 0x00;
}
while(1)
{
ADCC2 |= 0x80;
//sbit ADC START = 1, will auto clear after finish
while(!IRCON && 0x04); //finish if ADCIF=1, converting if ADCIF=0
temp_L = ADCDL;
//ADC result, the Adjust=0, the ADCDL[1:0]=ADCD[1:0]
temp_H = ADCDH;
//the ADCDH[7:0]=ADCD[9:2]
IRCON &= 0xFB;
//Clear ADCIF flag for next ADC conversion
}
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 19 -
Application Notes
3.4.3
ADC外部触发应用流程图
Entry ADC
function
SFR ADCC1 set
SFR ADCC2 set
(bit EXTTriggerEN)
(bit ADCMODE)
(bit Adjust)
(bit ADCCH[2:0])
SFR ADCCS set
(ADC clock)
SFR IEN0 set
(bit EA)
SFR IEN1 set
(bit IEADC)
Read SFR
ADCDH
Read SFR
ADCDL
ADC ISR
3.4.4
Clear ADCIF flag
Finish ADC
ADC外部触发程序范例
Describe:
main
Program:
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "..\h\SM39A16M1.h"
void main(void)
{
PAGESEL = 0x01;
CKCON = 0x00;
ADCC1 = 0x01;
ADCC2 = 0x18;
ADCCS = 0x00;
}
EA = 1;
IEADC = 1;
while(1){}
//SFE Page0
// Defult 2T(CKCON=0x10), Change to 1T. (CKCON SFR at page
// 0)
//ADC Chanel 0 enable
//EXT TriggerADC Enable, single-shot mode, ADC Chane 0 is
//analog input, Adiust=0
//ADC clock Fosc/2
//Enable all inierrupt
//Enable ADC inierrupt
void ADC_ISR(void) interrupt d_ADC_Vector
{
unsigned char temp_H,temp_L;
}
temp_L = ADCDL;
temp_H = ADCDH;
ADCIF =0;
// 地址: 0x53
//ADC result, the Adjust=0, the ADCDL[1:0]=ADCD[1:0]
//the ADCDH[7:0]=ADCD[9:2]
//Clear ADCIF flag for next ADC conversion
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 20 -
Application Notes
3.4.5
PWM触发ADC应用流程图
Entry ADC
function
SFR ADCC1 set
SFR IEN0 set
(bit EA)
SFR IEN1 set
(bit IEADC)
Read SFR
ADCDH
Read SFR
ADCDL
ADC ISR
3.4.6
SFR ADCC2 set
(bit PWMTriggerEN)
(bit ADCMODE)
(bit Adjust)
(bit ADCCH[2:0])
SFR SEVTCMPL set
SFR SEVTCMPH set
Clear ADCIF flag
SFR ADCCS set
(ADC clock)
PWM initail
Finish ADC
PWM触发ADC程序范例
Describe:
main
Program:
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "..\h\SM39A16M1.h"
void main(void)
{
PAGESEL = 0x01;
CKCON = 0x00;
ADCC1 = 0x01;
ADCC2 = 0x28;
}
ADCCS = 0x00;
PAGESEL = 0x03;
SEVTCMPL = 0x00;
SEVTCMPH = 0x00;
PAGESEL = 0x01;
PWM_Init();
EA = 1;
IEADC = 1;
while(1){}
//SFE Page0
// Defult 2T(CKCON=0x10), Change to 1T. (CKCON SFR at
// page 0)
//ADC Chanel 0 enable
//PWM TriggerADC Enable, single-shot mode, ADC Chanel
// 0 is analog input, Adiust=0
//ADC clock Fosc/2
//SFE Page1
//Special Event Compare Low byte
//Special Event Compare High byte
//SFE Page0
//Enable all inierrupt
//Enable ADC inierrupt
void ADC_ISR(void) interrupt d_ADC_Vector
{
unsigned char temp_H,temp_L;
// 地址: 0x53
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 21 -
Application Notes
}
temp_L = ADCDL;
temp_H = ADCDH;
ADCIF =0;
//ADC result, the Adjust=0, the ADCDL[1:0]=ADCD[1:0]
//the ADCDH[7:0]=ADCD[9:2]
//Clear ADCIF flag for next ADC conversion
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 22 -
Application Notes
3.5
SM39R08A2、SM39R16A2
ADCC1[7:0]
ADCCH[2:0]
ADC0
…
…
…
…
Start
MUX
ADC6
ADC7
ADCD[9:0]
High Speed
10 Bits
ADC Module
ToADC
Fosc
AVDD
ADC
Vref
M
U
X
Op0Out
VDD
ADCR[1:0]
ADC
Clock
Divider
ADC_ISR
AVSS
ADCCS[4:0]
ADC clock=Fosc/2…Fosc/64=15KHZ~12.5MHZ
ADC conversion rate Max = 500KHZ
VSS
图 3-4: ADC 模块工作方块图
符号
描述
地址
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
重置值
ADC4
EN
ADC3
EN
ADC2
EN
ADC1
EN
ADC0E
N
00H
ADC
ADCC1
ADC Control
register 1
ABh
ADC7E
N
ADC6
EN
ADCC2
ADC Control
register 2
ACh
Start
ADJU
ST
ADCDH
ADC data high
byte
ADh
ADCDH [7:0]
00H
ADCDL
ADC data low
byte
AEh
ADCDL [7:0]
00H
ADCCS
ADC clock select
AFh
-
-
-
IEN1
Interrupt Enable 1
register
B8h
EXEN2
-
IEIIC
IELVI
IEKBI
IEAD
C
IESPI
IEPW
M
00h
Interrupt request
register
C0H
EXF2
TF2
IICIF
LVIIF
KBIIF
ADCIF
SPIIF
PWMI
F
00H
IRCON
ADC5
EN
ADCR[1:0]
-
ADCCH[2:0]
00H
ADCCS[4:0]
00H
符号: ADCC1
地址: ABh
7
6
5
4
3
2
1
0
Reset
ADC7EN ADC6EN ADC5EN ADC4EN ADC3EN ADC2EN ADC1EN ADC0EN
00H
ADC7EN: 使能 ADC 通道 7.
ADC7EN = 1 –使能 ADC 通道 7
ADC6EN: 使能 ADC 通道 6.
ADC6EN = 1 –使能 ADC 通道 6
ADC5EN: 使能 ADC 通道 5.
ADC5EN = 1 –使能 ADC 通道 5
ADC4EN: 使能 ADC 通道 4.
ADC4EN = 1 –使能 ADC 通道 4
ADC3EN: 使能 ADC 通道 3.
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 23 -
Application Notes
ADC3EN = 1 –使能 ADC 通道 3
ADC2EN: 使能 ADC 通道 2.
ADC2EN = 1 –使能 ADC 通道 2
ADC1EN: 使能 ADC 通道 1.
ADC1EN = 1 –使能 ADC 通道 1
ADC0EN: 使能 ADC 通道 0.
ADC0EN = 1 –使能 ADC 通道 0
符号: ADCC2
7
6
Start ADJUST
5
4
ADCR[1:0]
3
-
2
1
ADCCH[2:0]
0
地址: ACh
Reset
00H
Start: 当该位被置位时,ADC 将启动连续转换.
ADJUST: ADC 数字输出格式调整.
ADJUST = 0: (默认)
ADC 数字输出高字节 ADCD [9:2] = ADCDH [7:0].
ADC 数字输出低字节 ADCD [1:0] = ADCDL [1:0].
ADJUST = 1:
ADC 数字输出高字节 ADCD [9:8] = ADCDH [1:0].
ADC 数字输出低字节 ADCD [7:0] = ADCDL [7:0].
不可使用 ANL
ADCR[1:0]: ADC 转换电压区间选择. (ADCR 为 write only,若 ADCR 设定 01 或 10 时,
或 ORL 去写入 ADCC2)
ADCR [1:0]
电压区间
00
0 ~ Vdd
01
0~
4
× Vdd
5
10
0~
3
× Vdd
5
11
ADCCH[2:0]: ADC 通道选择.
ADCCH [2:0]
保留
000
通道
0
001
1
010
2
011
3
100
4
101
5
110
6
111
7
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 24 -
Application Notes
ADJUST = 0:
符号: ADCDH
地址: ADh
7
6
5
4
3
2
1
0
Reset
ADCD[9] ADCD[8] ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2]
00H
符号: ADCDL
7
6
-
5
-
4
-
3
-
2
-
1
ADCD[1]
0
ADCD[0]
地址: AEh
Reset
00H
ADJUST = 1:
符号: ADCDH
7
6
-
5
-
4
-
3
-
地址: ADh
1
0
Reset
ADCD[9] ADCD[8]
00H
2
-
符号: ADCDL
地址: AEh
7
6
5
4
3
2
1
0
Reset
ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2] ADCD[1] ADCD[0]
00H
ADCD[9:0]: ADC 数字寄存器.
符号: ADCCS
7
6
5
-
4
3
2
1
0
ADCCS[4] ADCCS[3] ADCCS[2] ADCCS[1] ADCCS[0]
地址: AFh
Reset
00H
ADCCS[4:0]: ADC 时钟选择.
* ADC 时钟最大为 12.5MHz.
* ADC 转换率最高为 500KHz
ADC _ Clock =
Fosc
2 × ( ADCCS + 1)
ADC _ Conversion _ Rate =
符号: IEN1
7
EXEN2
6
-
5
IEIIC
4
IELVI
3
IEKBI
ADC_Clock
23
2
IEADC
1
IESPI
地址: B8h
0
Reset
IEPWM
00h
IEADC: A/D 转换中断使能位
IEADC = 0 –禁能 ADC 中断.
IEADC = 1 –使能 ADC 中断.
符号: IRCON
7
6
EXF2
TF2
5
IICIF
4
LVIIF
3
KBIIF
2
ADCIF
1
SPIIF
地址: C0h
0
Reset
PWMIF
00H
ADCIF: A/D 转换中断旗标位,当有开启 ADC 中断时,转换完成会设为 1,进中断后硬件自动清为 0.
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 25 -
Application Notes
若未开 ADC 中断,则必须手动软件清除为 0.
3.5.1
ADC应用流程图
Entry ADC
function
SFR ADCC2 set
(bit Adjust)
(bit ADCCH[1:0])
SFR ADCC1 set
SFR ADCC2 set
(bit START)
If ADCIF= 0
Read SFR
ADCDH
Read SFR
ADCDL
Finish ADC
3.5.2
If ADCIF= 1
SFR IRCON
(bit ADCIF)
ADC 程序范例
Describe:
main
Program:
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "SM39R16A2.h"
void main(void)
{
unsigned char temp_H,temp_L;
ADCC1 = 0x01;
ADCC2 = 0x00;
while(1)
{
ADCC2 =0x80;
while(ADCIF);
}
}
temp_L = ADCDL;
temp_H = ADCDH;
ADCIF = 0;
//ADC Chanel 0 enable
//ADC Chanel 0 is analog input, Adiust=0
//sbit ADC START = 1, will auto clear after finish
//finish if ADCIF=1, converting if ADCIF=0
//ADC result, the Adjust=0, the ADCDL[1:0]=ADCD[1:0]
//the ADCDH[7:0]=ADCD[9:2]
//Clear ADCIF flag for next ADC conversion
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 26 -
Application Notes
3.6
SM39R08A3、SM39R16A3
Vref
(ADC0)
ADCC1[7:1]
VDD
ADCCH[2:0]
Start
ADC1
AVDD
…
…
…
…
ADCD[9:0]
MUX
ADC6
High Speed
10 Bits
ADC Module
ADC7
ADC
Clock
Divider
Fosc
ADC_ISR
AVSS
ADCCS[4:0]
VSS
图 3-5: ADC 模块工作方块图
符号
描述
地址
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
重置值
ADC4
EN
ADC3
EN
ADC2
EN
ADC1
EN
ADC0E
N
00H
ADC
ADCC1
ADC Control
register 1
ABh
ADC7
EN
ADC6
EN
ADCC2
ADC Control
register 2
ACh
Start
ADJU
ST
ADCDH
ADC data high
byte
ADh
ADCDH [7:0]
00H
ADCDL
ADC data low
byte
AEh
ADCDL [7:0]
00H
ADCCS
ADC clock select
AFh
-
-
-
IEN1
Interrupt Enable 1
register
B8h
EXEN
2
-
IEIIC
IELVI
IEKBI
IEADC
IESPI
Interrupt request
register
C0H
EXF2
TF2
IICIF
LVIIF
KBIIF
ADCIF
SPIIF
IRCON
ADC5
EN
-
-
ADCCH[2:0]
00H
ADCCS[4:0]
00H
IEP
WM
00H
PWM
IF
00H
符号: ADCC1
地址: ABh
7
6
5
4
3
2
1
0
Reset
ADC7EN ADC6EN ADC5EN ADC4EN ADC3EN ADC2EN ADC1EN ADC0EN
00H
ADC7EN: 使能 ADC 通道 7.
ADC7EN = 1 –使能 ADC 通道 7
ADC6EN: 使能 ADC 通道 6.
ADC6EN = 1 –使能 ADC 通道 6
ADC5EN: 使能 ADC 通道 5.
ADC5EN = 1 –使能 ADC 通道 5
ADC4EN: 使能 ADC 通道 4.
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 27 -
Application Notes
ADC4EN = 1 –使能 ADC 通道 4
ADC3EN: 使能 ADC 通道 3.
ADC3EN = 1 –使能 ADC 通道 3
ADC2EN: 使能 ADC 通道 2.
ADC2EN = 1 –使能 ADC 通道 2
ADC1EN: 使能 ADC 通道 1.
ADC1EN = 1 –使能 ADC 通道 1
符号: ADCC2
7
6
Start
ADJUST
5
-
4
3
-
2
1
ADCCH[2:0]
0
地址: ACh
Reset
00H
Start: 当该位被置位时,ADC 将启动连续转换.
ADJUST: ADC 数字输出格式调整.
ADJUST = 0: (默认)
ADC 数字输出高字节 ADCD [9:2] = ADCDH [7:0].
ADC 数字输出低字节 ADCD [1:0] = ADCDL [1:0].
ADJUST = 1:
ADC 数字输出高字节 ADCD [9:8] = ADCDH [1:0].
ADC 数字输出低字节 ADCD [7:0] = ADCDL [7:0].
ADCCH[2:0]: ADC 通道选择.
ADCCH [2:0]
000
通道
0
001
1
010
2
011
3
100
4
101
5
110
6
111
7
切换至 ADC0 通道后即可读取来自内部 Vref 1.2V±10%,无外部输入管脚.
ADJUST = 0:
符号: ADCDH
地址: ADh
7
6
5
4
3
2
1
0
Reset
ADCD[9] ADCD[8] ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2]
00H
符号: ADCDL
7
6
-
5
-
4
-
3
-
2
-
1
ADCD[1]
0
ADCD[0]
地址: AEh
Reset
00H
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 28 -
Application Notes
ADJUST = 1:
符号: ADCDH
7
6
-
5
-
4
-
3
-
2
-
地址: ADh
1
0
Reset
ADCD[9] ADCD[8]
00H
符号: ADCDL
地址: AEh
7
6
5
4
3
2
1
0
Reset
ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2] ADCD[1] ADCD[0]
00H
ADCD[9:0]: ADC 数字寄存器.
符号: ADCCS
7
6
5
-
4
3
2
1
0
ADCCS[4] ADCCS[3] ADCCS[2] ADCCS[1] ADCCS[0]
地址: AFh
Reset
00H
ADCCS[4:0]: ADC 时钟选择.
* ADC 时钟最大为 12.5MHz.
* ADC 转换率最高为 961KHz
ADC _ Clock =
Fosc
2 × ( ADCCS + 1)
ADC _ Conversion _ Rate =
符号: IEN1
7
EXEN2
6
-
5
IEIIC
4
IELVI
ADC_Clock
13
3
IEKBI
2
IEADC
1
IESPI
地址: B8h
0
Reset
IEPWM
00h
IEADC: A/D 转换中断使能位
IEADC = 0 –禁能 ADC 中断.
IEADC = 1 –使能 ADC 中断.
符号: IRCON
7
6
EXF2
TF2
5
IICIF
4
LVIIF
3
KBIIF
2
ADCIF
1
SPIIF
地址: C0h
0
Reset
PWMIF
00H
ADCIF: A/D 转换中断旗标位,当有开启 ADC 中断时,转换完成会设为 1,进中断后硬件自动清为 0.
若未开 ADC 中断,则必须手动软件清除为 0.
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 29 -
Application Notes
3.6.1
ADC应用流程图
Entry ADC
function
SFR ADCC2 set
(bit Adjust)
(bit ADCCH[1:0])
SFR ADCC1 set
SFR ADCC2 set
(bit START)
If ADCIF= 0
Read SFR
ADCDH
Read SFR
ADCDL
Finish ADC
3.6.2
SFR IRCON
If ADCIF= 1 (bit ADCIF)
ADC程序范例
說明: 利用內部 Vref 去換算外部電池電壓方式,可省去外部參考電源(TL-431)
Describe:
Program:
//====================================================================
main
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "SM39R16A3.h"
#define Vref
1.22
//only for A3
#define d_ADC_CH0_IN
0
#define d_ADC_CH1_IN
1
#define d_ADC_CLK_DIV6
0x02
unsigned int uiVoltage = 0,uiVref = 0,
void ADCInit(unsigned char n_ADC_CLK)
{
ADCCS = n_ADC_CLK; //Select ADC clock
}
void ADCstart(void)
{
ADCIF = 0;
ADCC2 = ADCC2|0xC0; //ADC start conversion
}
void ADCChannel(unsigned char n_ADC_CH)
{
ADCC2 = n_ADC_CH;
//Set conversion channel
}
void ADC_stop(void)
{
ADCC2 &= 0x7F;
//ADC stop conversion
}
unsigned int ADC_Channel(unsigned char c_ADC_channel)
{
unsigned int uiADC10;
switch(c_ADC_channel&0xFF)
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 30 -
Application Notes
{
case 0:
ADCC1 = 0x01; //Set ADC channel
break;
case 1:
ADCC1 = 0x02; //Set ADC channel
break;
case 2:
ADCC1 = 0x04; //Set ADC channel
break;
case 3:
ADCC1 = 0x08; //Set ADC channel
break;
case 4:
ADCC1 = 0x10; //Set ADC channel
break;
case 5:
ADCC1 = 0x20; //Set ADC channel
break;
case 6:
ADCC1 = 0x40; //Set ADC channel
break;
case 7:
ADCC1 = 0x80; //Set ADC channel
break;
}
ADCChannel(c_ADC_channel);
ADCstart();
while(!ADCIF);
uiADC10 = (ADCDH * 256)+ ADCDL;
ADC_stop();
ADCC1 = 0x00; //Set ADC channel
}
return uiADC10
unsigned int Check_Vref_Voltage(unsigned char ADC_ch) //VREF
{
unsigned int uiBAT;
float ftemp;
}
ftemp=(ADC_Channel(ADC_ch));
uiBAT=(unsigned int)ftemp;
return uiBAT;
unsigned int Check_Battery_Voltage(unsigned char ADC_ch)
{
unsigned int uiBAT;
float ftemp;
//BAT_VOL_DET
ftemp=((Vref*(ADC_Channel(ADC_ch)))/(uiVref))*1000;
uiBAT=(unsigned int)ftemp;
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 31 -
Application Notes
}
return uiBAT;
void main(void)
{
}
ADCInit(d_ADC_CLK_DIV6);
while(1)
{
uiVref=Check_Vref_Voltage(d_ADC_CH0_IN); //only for A3 internal 1.2V
uiVoltage=Check_Battery_Voltage(d_ADC_CH1_IN);
}
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 32 -
Application Notes
3.7
SM39R08A5
ADCC1[7:0]
VDD
ADCCH[2:0]
Start
ADC0
AVDD
…
…
…
…
ADCD[9:0]
MUX
ADC6
High Speed
10 Bits
ADC Module
ADC7
ADC
Clock
Divider
Fosc
ADC_ISR
AVSS
ADCCS[4:0]
VSS
图 3-6: ADC 模块工作方块图
符号
描述
地址
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
重置值
ADC2
EN
ADC1
EN
ADC0
EN
00H
ADC
ADCC1
ADC Control
register 1
ABh
ADC7
EN
ADC6
EN
ADC5E
N
ADC4
EN
ADC3
EN
ADCC2
ADC Control
register 2
ACh
Start
ADJUST
-
-
-
ADCDH
ADC data high
byte
ADh
ADCDH [7:0]
00H
ADCDL
ADC data low
byte
AEh
ADCDL [7:0]
00H
ADCCS
ADC clock
select
AFh
-
-
-
IEN1
Interrupt Enable
1 register
B8h
EXEN2
-
IEIIC
IELVI
IEKBI
IEADC
IESPI
IEPWM
00h
IRCON
Interrupt
request register
C0H
EXF2
TF2
IICIF
LVIIF
KBIIF
ADCIF
SPIIF
PWMIF
00H
ADCCH[2:0]
00H
ADCCS[4:0]
00H
符号: ADCC1
地址: ABh
7
6
5
4
3
2
1
0
Reset
ADC7EN ADC6EN ADC5EN ADC4EN ADC3EN ADC2EN ADC1EN ADC0EN
00H
ADC7EN: 使能 ADC 通道 7.
ADC7EN = 1 –使能 ADC 通道 7
ADC6EN: 使能 ADC 通道 6.
ADC6EN = 1 –使能 ADC 通道 6
ADC5EN: 使能 ADC 通道 5.
ADC5EN = 1 –使能 ADC 通道 5
ADC4EN: 使能 ADC 通道 4.
ADC4EN = 1 –使能 ADC 通道 4
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 33 -
Application Notes
ADC3EN: 使能 ADC 通道 3.
ADC3EN = 1 –使能 ADC 通道 3
ADC2EN: 使能 ADC 通道 2.
ADC2EN = 1 –使能 ADC 通道 2
ADC1EN: 使能 ADC 通道 1.
ADC1EN = 1 –使能 ADC 通道 1
ADC0EN: 使能 ADC 通道 0.
ADC0EN = 1 –使能 ADC 通道 0
符号: ADCC2
7
6
Start ADJUST
5
-
4
-
3
-
2
1
ADCCH[2:0]
0
地址: ACh
Reset
00H
Start: 当该位被置位时,ADC 将启动连续转换.
ADJUST: ADC 数字输出格式调整.
ADJUST = 0: (默认)
ADC 数字输出高字节 ADCD [9:2] = ADCDH [7:0].
ADC 数字输出低字节 ADCD [1:0] = ADCDL [1:0].
ADJUST = 1:
ADC 数字输出高字节 ADCD [9:8] = ADCDH [1:0].
ADC 数字输出低字节 ADCD [7:0] = ADCDL [7:0].
ADCCH[2:0]: ADC 通道选择.
ADCCH [2:0]
000
Channel
0
001
1
010
2
011
3
100
4
101
5
110
6
111
7
ADJUST = 0:
符号: ADCDH
地址: ADh
7
6
5
4
3
2
1
0
Reset
ADCD[9] ADCD[8] ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2]
00H
符号: ADCDL
7
6
-
5
-
4
-
3
-
2
-
1
ADCD[1]
0
ADCD[0]
地址: AEh
Reset
00H
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 34 -
Application Notes
ADJUST = 1:
符号: ADCDH
7
6
-
5
-
4
-
3
-
2
-
地址: ADh
1
0
Reset
ADCD[9] ADCD[8]
00H
符号: ADCDL
地址: AEh
7
6
5
4
3
2
1
0
Reset
ADCD[7] ADCD[6] ADCD[5] ADCD[4] ADCD[3] ADCD[2] ADCD[1] ADCD[0]
00H
ADCD[9:0]: ADC 数字寄存器.
符号: ADCCS
7
6
5
-
4
3
2
1
0
ADCCS[4] ADCCS[3] ADCCS[2] ADCCS[1] ADCCS[0]
地址: AFh
Reset
00H
ADCCS[4:0]: ADC 时钟选择.
* ADC 时钟最大为 11.0592MHz.
* ADC 转换率最高为 851KHz
ADC _ Clock =
Fosc
2 × ( ADCCS + 1)
ADC _ Conversion _ Rate =
符号: IEN1
7
EXEN2
6
-
5
IEIIC
4
IELVI
ADC_Clock
13
3
IEKBI
2
IEADC
1
IESPI
地址: B8h
0
Reset
IEPWM
00h
IEADC: A/D 转换中断使能位
IEADC = 0 –禁能 ADC 中断.
IEADC = 1 –使能 ADC 中断.
符号: IRCON
7
6
EXF2
TF2
5
IICIF
4
LVIIF
3
KBIIF
2
ADCIF
1
SPIIF
地址: C0h
0
Reset
PWMIF
00H
ADCIF: A/D 转换中断旗标位,当有开启 ADC 中断时,转换完成会设为 1,进中断后硬件自动清为 0.
若未开 ADC 中断,则必须手动软件清除为 0.
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 35 -
Application Notes
3.7.1
ADC应用流程图
Entry ADC
function
SFR ADCC2 set
(bit Adjust)
(bit ADCCH[1:0])
SFR ADCC1 set
SFR ADCC2 set
(bit START)
If ADCIF= 0
Read SFR
ADCDH
Read SFR
ADCDL
Finish ADC
3.7.2
SFR IRCON
If ADCIF= 1 (bit ADCIF)
ADC程序范例
Describe:
main
Program:
//====================================================================
//
//
SYNCMOS
TECHNOLOGY
//
//====================================================================
#include "..\h\SM39R08A5.h"
void main(void)
{
unsigned char temp_H,temp_L;
ADCC1 = 0x01;
ADCC2 = 0x00;
//ADC Chanel 0 enable
//ADC Chanel 0 is analog input, Adiust=0
while(1)
{
ADCC2 |=0x80;
//sbit ADC START = 1, will auto clear after finish
while(!IRCON && 0x04);
//finish if ADCIF=1, converting if ADCIF=0
}
}
temp_L = ADCDL; /
temp_H = ADCDH;
IRCON &= 0xFB;
/ADC result, the Adjust=0, the ADCDL[1:0]=ADCD[1:0]
//the ADCDH[7:0]=ADCD[9:2]
//Clear ADCIF flag for next ADC conversion
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 36 -
Application Notes
4.
最佳ADC取样频率选择说明
适用型号:SM39R16A3、SM39R08A3、SM39R08A5、SM39R16A6、SM39A16M1、SM59A16U1。
Rout 阻值的选择必须符合下列公式:
Rout < 3.33 * Ta * 1010
Ta:
1
ADC clock
范例 1:
Fosc = 22.1184MHz, ADCCS[4:0] = Fosc/2.
U1
VCC
+ C2
10uF
C1
0.1uF
1
2
3
4
5
6
7
8
9
10
P0.0
P1.7
P1.6
P1.5
VSS
P3.1
P3.0
P1.4
SDA
SCL
ADC1/P0.1
ADC2/P0.2
ADC3/P0.3
ADC4/P0.4
ADC5/P0.5
VDD
ADC6/P0.6
ADC7/P0.7
P1.0
P1.1
20
19
18
17
16
15
14
13
12
11
VCC
VCC
R1
RESISTOR
R2
RESISTOR
39R16A3(20pin)
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 37 -
Application Notes
10
Rout < 3.33*(1/11.0592MHz)* 10
Rout < 3011Ω
因 Rout = R1//R2 (并联等校阻抗),
所以若 R1 与 R2 使用相同阻值,则 R1 与 R2 阻值以小于 1505Ω 为宜。
范例 2:
当客户使用于电池应用时,基于省电考量,ADC 阻值会使用较大的阻值来达到省电目的,导致无法符合 Rout 公式的
要求。这时可在 ADC 通道多加一个 0.1uF,来达成 ADC 的精准度需求。
VCC
+ C2
10uF
U1
C1
0.1uF
1
2
3
4
5
6
7
8
9
10
ADC1/P0.1
ADC2/P0.2
ADC3/P0.3
ADC4/P0.4
ADC5/P0.5
VDD
ADC6/P0.6
ADC7/P0.7
P1.0
P1.1
P0.0
P1.7
P1.6
P1.5
VSS
P3.1
P3.0
P1.4
SDA
SCL
39R16A3(20pin)
20
19
18
17
16
15
14
13
12
11
VCC
VCC
C3
0.1uF
R1
750K
R2
750K
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 38 -
Application Notes
5.
注意事项
每一颗零件号码因频率、通道或设计上不同,使用上可能会有些差异,请使用者务必参照上述的不同群组的归类方式
来设定所需的数据。
Specifications subject to change without notice contact your sales representatives for the most recent information.
ISSFA-0250
Ver B ADC 03/18/2014
- 39 -