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 在ADC START之前,Port4[7:4]必須先輸出”0000”調校 2.6.2 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-A075 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) DCCS[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-A075 2 Ver. C 2009/02 ADC Application Note 為符合 spec,以下表格為設定 ADCCS 的建議值: ADCCS[1:0] 00 01 10 11 ADC Clock = Fclk/8 Fclk/16 Fclk/32 Fclk/64 ADC clock (Fclk: 1MHz ~ 4MHz) (Fclk: 4MHz ~ 8MHz) (Fclk: 8MHz ~ 16MHz) (Fclk: 16MHz ~ 32MHz) 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-A075 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-A075 4 Ver. C 2009/02