我的芯片是dspic33ck32mp105, 使用MCC產生代碼,
我使用了AN0(可以了), AN3,AN4(這兩個有問題)
我看讀取結果時是有正確讀取的, 但是結果不對?
while(1)
{
DISC=1;
d_ms(1);
DISC=0;
d_ms(1);
uint32_t conversion,i=0;
ADC1_Initialize();
ADC1_Enable();
channel=channel_AN3;
ADC1_ChannelSelect(channel); //這裡選擇channel, 我已經改成了channel_AN3;
ADC1_SoftwareTriggerEnable();
//Provide Delay
for(i=0;i <1000;i++)
{
}
ADC1_SoftwareTriggerDisable();
while(!ADC1_IsConversionComplete(channel));
conversion = ADC1_ConversionResultGet(channel);//這裡讀取值, 結果是1033, 應該要接近0, 因為我量電壓是0V
ADC1_Disable();
conversion=0;
}
附上 ADC1_ChannelSelect(channel)的代碼:
inline static uint16_t ADC1_ConversionResultGet( ADC1_CHANNEL channel )
{
uint16_t result;
switch(channel)
{
case channel_AN3:
result = ADCBUF3;//確實有到這裡讀取值, 結果是1033, 應該要接近0, 因為我量電壓是0V
break;
case channel_AN4:
result = ADCBUF4;
break;
case channel_AN19:
result = ADCBUF19;
break;
case channel_AN20:
result = ADCBUF20;
break;
case channel_AN0:
result = ADCBUF0;
break;
default:
break;
}
return result;
|