ADC Application Note ADC Application Note 1 适用产品:SM59R16A2 / SM59R08A2 2 ADC 规格概述: 2.1 提供 4 组独立的 ADC 2.2 10-bit 或 8-bit 模式选择 2.3 ADC 为 SAR 架构 2.4 ADC clock(Hz)不可大于 500KHz,提供四组预除设定(请参考 SFR ADCCS 设定) 2.5 当 VDD=3.3,可侦测电压为 0V~3.3V 2.6 当 VDD=5.0 应用,说明如下: 2.6.1 2.6.2 在ADC START之前,Port4[7:4]必须先输出”0000”调校 ADC IP是3.3V,应用在Analog IN=5V时,要接分压电阻(如下图),总电阻不可超过50KΩ, 建议为17KΩ及33KΩ即可 (Analog IN=3.3V则不用) SM59R16A2 ADC Analog Voltage In 3 ADCDH ADCDL CH0~3 33KΩ SFR 特殊控制缓存器及特殊状态缓存器介绍: Mnemonic ADCC1 ADCC2 17KΩ Description Direct Bit 7 Bit 6 ADC Control 1 ADC Control 2 ADC data high byte ADC data low byte ABh ACh COM START Bit 5 ADC ADC8B ADh - Bit 3 Bit 2 ADC3E ADC2E ADCCH[1:0] - AEh Mnemonic: ADCC1 7 6 - Bit 4 Bit 1 Bit 0 ADC1E ADC0E ADCCS[1:0] 00h 00h ADCDH [1:0] 00h ADCDL[7:0] 5 - 4 - 3 ADC3E 2 ADC2E 1 ADC1E RESET 00h Address: ABh 0 Reset ADC0E 00h Specifications subject to change without notice, contact your sales representatives for the most recent information. IRFWX-A076 1 Ver. C 2009/02 ADC Application Note ADC3E: ADC Chanel 3 致能旗标 =0 : 禁能(预设) =1 : 致能 ADC2E: ADC Chanel 2 致能旗标 =0 : 禁能(预设) =1 : 致能 ADC1E: ADC Chanel 1 致能旗标 =0 : 禁能(预设) =1 : 致能 ADC0E: ADC Chanel 0 致能旗标 =0 : 禁能(预设) =1 : 致能 Mnemonic: ADCC2 7 6 COM START 5 ADC8B 4 - 3 2 ADCCH[1:0] Address: ACh 1 0 Reset ADCCS[1:0] 00h COM: ADC 转换完成旗标(只读) = 0:当 ADC module 转换启动时,该旗标由硬件自动设置为”0” = 1:当 ADC module 转换完成时,该旗标由硬件自动设置为”1” START: 开始(停止)转换旗标 = 0:表示 ADC modul 停止执行(预设) = 1:由软件设定 ADC module 开始执行,完成后该旗标由硬件自动清除为”0” ADC8B: 8-bit 模式旗标 = 0:选择 10-bit 模式(预设);转换后数据存在缓存器 ADCD[9:0] (High Byte: ADCD [9:8] = ADCDH [1:0],Low Byte: ADCD [7:0] = ADCDL [7:0]) = 1:选择 8-bit 模式;转换后数据存在缓存器(ADCD[7:0] = ADCDL [7:0] ) ADCCH[1:0] 模拟输入通道选择旗标(The analog input signal can be chosen with it): ADCC1.ADCxE ADCCH[1:0] 对应 MCU 引脚 ADC0E 00 P4.4/ADC0 ADC1E 01 P4.5/ADC1 ADC2E 10 P4.6/ADC2 ADC3E 11 P4.7/ADC3 PS. ADC 致能与模拟输入通道必定要相对应才可正确地转换 Note (default) ADCCS[1:0]: ADC除频选择旗标 = 00 : ADC clock 由系统频率除 8 = 01 : ADC clock 由系统频率除 16 = 10 : ADC clock 由系统频率除 32 = 11 : ADC clock 由系统频率除 64 Specifications subject to change without notice, contact your sales representatives for the most recent information. IRFWX-A076 2 Ver. C 2009/02 ADC Application Note 为符合 spec,以下表格为设定 ADCCS 的建议值: ADCCS[1:0] ADC clock 00 Fclk/8 (Fclk: 1MHz ~ 4MHz) 01 Fclk/16 (Fclk: 4MHz ~ 8MHz) 10 Fclk/32 (Fclk: 8MHz ~ 16MHz) 11 Fclk/64 (Fclk: 16MHz ~ 32MHz) ADC Clock = Fclk 8 × 2 ADCCS (ADC 输入频率频率,单位:Hz,ADC clock 不可大于 500KHz) ADC Conversion Time = 20 ADC Clock (ADC 取样率,单位:Hz,每次转换需要 20 个 ADC clock 时间) ADC Sample Rate = Mnemonic: ADCDH 7 6 5 1 ADC Conversion Time 4 3 2 Address: ADh 1 0 Reset ADCDH[1:0] 00h ADCDH[1:0]: 高位数据储存缓存器 The high bits of digital output of this ADC Mnemonic: ADCDL 7 6 5 4 3 ADCDL[7:0] 2 1 Address: AEh 0 Reset 00h ADCDL[7:0]: 低位数据储存缓存器 The low bits of digital output of this ADC Specifications subject to change without notice, contact your sales representatives for the most recent information. IRFWX-A076 3 Ver. C 2009/02 ADC Application Note 4 ADC 应用流程图: 5 ADC 程序范例: Describe: main Program: //==================================================================== // // S Y N C M O S T E C H N O L O G Y // //==================================================================== #include "..\h\SM59R16A2.h" void main(void) { unsigned char temp_H,temp_L; //ADCC1 ADCC1 = //ADCC2 ADCC2 = = 0x0F; 0x01; = 0x20; 0x03; //ADC //ADC //ADC //ADC Chanel Chanel 8-bit 10-bit all enable 0 enable mode, Chanel 0 is analog input, Div=8 mode, Chanel 0 is analog input, Div=64 while(1) { ADCC2 |=0x40; //sbit ADC START = 1, will auto clear after finish while(!ADCC2 && 0x80); //finish if COM=1, converting if COM=0 temp_L = ADCDL; //ADC result temp_H = ADCDH; } } Specifications subject to change without notice, contact your sales representatives for the most recent information. IRFWX-A076 4 Ver. C 2009/02