本帖最后由 有意思 于 2010-11-11 11:39 编辑
我在使用AD时发现一个问题,AD在采样时,该通道居然有2V的电平输出,我已经断开了外围电路,AIN2只有一个电阻到地,应该是0V,我用示波器看到口线居然是200us左右的脉冲,高电平正好是采样期间,问题是,同样的software,有的板子OK,有的不行。Vref+直接使用VCC做参考电压,,下面是测试code
void ADCConfig(void){
ADC2_DeInit(); //ADC2_Init(ADC2_ConvMode_TypeDef ADC2_ConversionMode, ADC2_Channel_TypeDef ADC2_Channel, //ADC2_PresSel_TypeDef ADC2_PrescalerSelection, ADC2_ExtTrig_TypeDef ADC2_ExtTrigger, //FunctionalState ADC2_ExtTriggerState, ADC2_Align_TypeDef ADC2_Align, ADC2_Init(ADC2_CONVERSIONMODE_SINGLE, ADC2_CHANNEL_0, ADC2_PRESSEL_FCPU_D4, ADC2_EXTTRIG_TIM, DISABLE, ADC2_ALIGN_RIGHT, ADC2_SCHMITTTRIG_CHANNEL0, DISABLE);
ADC2_Init(ADC2_CONVERSIONMODE_SINGLE, ADC2_CHANNEL_1, ADC2_PRESSEL_FCPU_D4, ADC2_EXTTRIG_TIM, DISABLE, ADC2_ALIGN_RIGHT, ADC2_SCHMITTTRIG_CHANNEL1, DISABLE); ADC2_Init(ADC2_CONVERSIONMODE_SINGLE, ADC2_CHANNEL_2, ADC2_PRESSEL_FCPU_D4, ADC2_EXTTRIG_TIM, DISABLE, ADC2_ALIGN_RIGHT, ADC2_SCHMITTTRIG_CHANNEL2, DISABLE);
ADC2_SchmittTriggerConfig(ADC2_SCHMITTTRIG_ALL, DISABLE); ADC2_ITConfig(DISABLE); ADC2_Cmd(ENABLE); /*Start Conversion */ //ADC2_StartConversion();}
u16 GetADCAverageValue(u8 ch)
{
u8 i=0;
u16 Conversion_Value=0;
//ADC2_ConversionConfig(ADC2_CONVERSIONMODE_SINGLE, ch, //ADC2_ALIGN_RIGHT);
/* Clear the ADC2 channels */
ADC2->CSR &= (u8)(~ADC2_CSR_CH);
/* Select the ADC2 channel */ ADC2->CSR |= (u8)(ch);
for (i=0; i<8;i++) {
ADC2_StartConversion();
while (!ADC2_GetFlagStatus());
Conversion_Value += ADC2_GetConversionValue();
}
Conversion_Value = Conversion_Value >> 3; return Conversion_Value;
}
void BusADCSample(P_ADCValue AD)
{
AD->BusHighADC = GetADCAverageValue(ADCHANEL_BUSHIGH);
AD->BusLowADC = GetADCAverageValue(ADCHANEL_BUSLOW);
}
in main()
{
while (1) {
BusADCSample(&AD);
}
}
|