微算機 Lab9 - A/D Converter
參考自去年教材
文章目錄
ADC簡介
什麼是ADC
主要功能 : 把輸入的類比訊號轉成數位數值
本次Lab會把可變電阻輸入的電壓轉成數值形式
更多參考 ADC - 成大資工
VREF與resolution
VREF+ : 上界的參考電壓,若輸入電壓為此值則輸出為最大值
VREF- : 下界的參考電壓,若輸入電壓為此值則輸出為最小值
Resolution : ADC的解析度,若為 10bit 代表輸出從 0 ~ 1023
e.g., VREF- = 0V, VREF+ = 10V, Resolution : 10bits (range = [0,1023])
0V-> 0
5V -> 511
10V -> 1023
ADC 流程:
Acquisition -> Convertion -> Discharge(wait before next acquisition) -> Idle until you set GODONE bit -> Acquisition -> …
Acquisition : 採樣輸入電壓
Conversion : 將電壓轉換成數值
Discharge : 釋放電壓
- A/D Clock period, the time required to convert one bit
- 越小越好,但要大於0.7μs
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
設定
透過查表設定ADCS(ADCON2)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
假設頻率 是 2.86 MHz, 則周期 ()會是 ,為了滿足最低 A/D Clock period ( ),要把設成兩倍的,Operation欄位中的數值即為
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
e.g.,假設頻率 (Fosc) 是 1 MHz,透過查表得知ADCS要設成000,
而Operation欄位是2×Tosc=2×,因此 為2𝜇𝑠
Acquisition
採樣輸入電壓,需要時間
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
依據data sheet的推導(p. 228),acquisition time最少會花
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
依據的時間決定ACQT,若為,則ACQT要設成001,也就是2= >
Conversion
將採樣電壓轉換成數值,需要時間
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
依據data sheet,conversion需要花11到12個
Discharge
釋放電壓
Left/Right justified
ADC轉換的結果放在ADRES register裡,存放的方式分為left justified與right justified,可依據使用需求設置
e.g., 需要8 bits resolution,設定為left justified,取ADRESH數值 ; 需要10 bits resolution,則設定為right justified,將ADRESH前兩bits與ADRESL結合
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
時間表
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
PIC18 ADC register introduction
ADCON0
CHS : 設定analog input 輸入腳位
GO/DONE : 設為1時(ADCON0bits.GO = 1)開始做ADC,轉換完後 GO/DONE會自動設為0
ADON : 開啟ADC功能
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
ADCON1
VCFG1 : 設定下界參考電壓
VCFG0 :設定上界參考電壓
PCFG : 設定ANx PORT為類比還是數位,使用 ADC 的同時若發現其他 PORT 的 input 值怪怪的也許是誤把那些 PORT 設成 analog input
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
ADCON2
ADFM : 設定justified
ADCS : 選擇conversion clock
ACQT : 選擇acquisition time要幾個
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
ADRESH、ADRESL
result of conversion
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Workflow of ADC using interrupt I/O
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- Select VREF (ADCON1.VCFG0, ADCON1.VCFG1)
- Select A/D port control(ADCON1.PCFG)
- Select A/D input channel (ADCON0.CHS)
- Select A/D conversion clock (ADCON2.ADCS)
- Select A/D acquisition time (ADCON2.ACQT)
- Select justified method (ADCON2.ADFM)
- Turn on A/D module (ADCON0.ADON)
Note : The port pins needed as analog inputs must have their corresponding TRIS bits set (input).
- Enable A/D interrupt (PIE1.ADIE)
- Clear A/D interrupt flag bit (PIR1.ADIF)
- Enable peripheral interrupt (INTCON.PEIE)
- Set GIE bit (INTCON.GIE)
Step3. Start conversion:
- Set GO/DONE bit (ADCON0.GO)
Step4. Conversion completed:
- Go to ISR
- Read value of ADRES register
- Do things you want
- Clear ADC interrupt flag bit (PIR1.ADIF)
Step5. Next conversion(if required) :
- You need to have a minimum wait of 2 before next acquisition start, then go back to step 3.
Variable resistor
左邊接 5V,右邊接地,中間接 Analog 輸入
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
範例code