你好,
因為在 dsPIC33FJ & PIC24H 裡面的 ADC 為 10/12 bit configurable. 所以函數就只有一個共用啦. 在安裝完 MPLAB C30 之後 , 在桌面上會有一個 HTML 檔. 叫做 MPLAB C30 Documentation.html. 這個檔案就包括了所有 Peripheral library 的說明.
以下為 dsPIC33FJ 的 Peripheral Library 裡有關 OpenADCx() 的說明及使用範例, 其中就有一參數可以是 "ADC_AD12B_12BIT" 或 "ADC_AD12B_10BIT" 用來選要用的 AD 解析度.
你只要 include <adc.h> 就好了 :)
3.6 OpenADCx
Function Prototype
void OpenADC1(unsigned int config1,
unsigned int config2,
unsigned int config3,
unsigned int config4,
unsigned int configport_l,
unsigned int configport_h,
unsigned int configscan_h,
unsigned int configscan_l)
void OpenADC2(unsigned int config1,
unsigned int config2,
unsigned int config3,
unsigned int config4,
unsigned int configport_l,
unsigned int configport_h,
unsigned int configscan_h,
unsigned int configscan_l)
Include
adc.h
Description
This function configures the ADC.
Arguments
config1 - This contains the parameters to be configured in the ADxCON1 register as defined below:
Module On/Off
ADC_MODULE_ON
ADC_MODULE_OFF
Idle mode operation
ADC_IDLE_CONTINUE
ADC_IDLE_STOP
DMA Buffers Write Mode
ADC_ADDMABM_ORDER
ADC_ADDMABM_SCATTR
ADC Module Operation Mode
ADC_AD12B_12BIT
ADC_AD12B_10BIT
Result output format
ADC_FORMAT_SIGN_FRACT
ADC_FORMAT_FRACT
ADC_FORMAT_SIGN_INT
ADC_FORMAT_INTG
Conversion trigger source
ADC_CLK_AUTO
ADC_CLK_MPWM
ADC_CLK_TMR
ADC_CLK_INT0
ADC_CLK_MANUAL
Auto sampling select
ADC_AUTO_SAMPLING_ON
ADC_AUTO_SAMPLING_OFF
Sampling Mode Control
ADC_SIMULTANEOUS
ADC_MULTIPLE
Sample enable
ADC_SAMP_ON
ADC_SAMP_OFF
config2 - This contains the parameters to be configured in the ADCON2 register as defined below:
Voltage Reference
ADC_VREF_AVDD_AVSS
ADC_VREF_EXT_AVSS
ADC_VREF_AVDD_EXT
ADC_VREF_EXT_EXT
Scan selection
ADC_SCAN_ON
ADC_SCAN_OFF
A/D channels utilized
ADC_CONVERT_CH0123
ADC_CONVERT_CH01
ADC_CONVERT_CH0
DMA Address Increment Rate
ADC_DMA_ADD_INC_1
ADC_DMA_ADD_INC_2
.....
ADC_DMA_ADD_INC_15
ADC_DMA_ADD_INC_16
Buffer mode select
ADC_ALT_BUF_ON
ADC_ALT_BUF_OFF
Alternate Input Sample mode select
ADC_ALT_INPUT_ON
ADC_ALT_INPUT_OFF
config3 - This contains the parameters to be configured in the ADCON3 register as defined below:
Auto Sample Time bits
ADC_SAMPLE_TIME_0
ADC_SAMPLE_TIME_1
.....
ADC_SAMPLE_TIME_30
ADC_SAMPLE_TIME_31
Conversion Clock Source select
ADC_CONV_CLK_INTERNAL_RC
ADC_CONV_CLK_SYSTEM
Conversion clock select
ADC_CONV_CLK_Tcy2
ADC_CONV_CLK_Tcy
ADC_CONV_CLK_3Tcy2
ADC_CONV_CLK_2Tcy
.....
ADC_CONV_CLK_32Tcy
config4 - This contains the parameters to be configure in ADxCON4 register as defined below:
DMA Buffer Locations per Analog Input
ADC_DMA_BUF_LOC_128
ADC_DMA_BUF_LOC_64
ADC_DMA_BUF_LOC_32
.....
ADC_DMA_BUF_LOC_1
configport_h - This contains the pin select to be configured into the ADPCFG register as defined below:
ENABLE_ALL_ANA_16_31
ENABLE_ALL_DIG_16_31
ENABLE_AN16_ANA
ENABLE_AN17_ANA
ENABLE_AN18_ANA
.....
ENABLE_AN31_ANA
configport_l - This contains the pin select to be configured into the ADPCFG register as defined below:
ENABLE_ALL_ANA_0_15
ENABLE_ALL_DIG_0_15
ENABLE_AN0_ANA
ENABLE_AN1_ANA
ENABLE_AN2_ANA
.....
ENABLE_AN15_ANA
configscan_l - This contains the scan select parameter to be configured into the ADxCSSL register as defined below:
SCAN_NONE
SCAN_ALL
SKIP_SCAN_AN0
SKIP_SCAN_AN1
.....
SKIP_SCAN_AN15
configscan_h - This contains the scan select parameter to be configured into the ADxCSSH register as defined below:
SCAN_NONE
SCAN_ALL
SKIP_SCAN_AN16
SKIP_SCAN_AN1
.....
SKIP_SCAN_AN31
Return Value
None
Remarks:
This function configures the ADC for the following parameters:
Operating mode, Sleep mode behavior, DMA Buffer Write Mode, Data o/p format, ADC Module Mode, Conversion trigger source, Sampling control, VREF source, Scan selection, DMA address increment rate, Buffer Fill mode, Alternate i/p sample mod, Auto sample time, Conv. clock source, Conv Clock Select bits, Port Config Control bits.
Source File:
OpenADC1.c
OpenADC2.c
Code Example
unsigned int config1;
unsigned int config2;
unsigned int config3;
unsigned int config4;
unsigned int configport_h;
unsigned int configport_l;
unsigned int configscan_h;
unsigned int configscan_l;
config1 = ADC_MODULE_ON & ADC_IDLE_STOP &
ADC_ADDMABM_ORDER & ADC_AD_12B_12BIT &
ADC_FORMAT_SIGN_INT & ADC_CLK_TMR &
AUTO_SAMPLING_ON & ADC_MULTIPLE ;
config2 = ADC_VREF_AVDD_AVSS & ADC_SCAN_ON &
ADC_CONVERT_CH0123 & ADC_DMA_ADD_INC_1 ;
config3 = ADC_CONV_CLK_SYSTEM & ADC_SAMPLE_TIME_3 &
ADC_CONV_CLK_Tcy2;
config4 = ADC_DMA_BUF_LOC_32;
configport_h = ENABLE_ALL_ANA_16_31;
configport_l = ENABLE_ALL_ANA_0_15;
configscan_l = SCAN_ALL
configscan_l = SCAN_ALL;
OpenADC1(config1,config2,config3,config4,configport_l,configport_h, configscan_h,configscan_l);