这是初始化代码
static void AD_Configuration(void)
{
GPIO_Init(GPIOD,GPIO_PIN_3, GPIO_MODE_IN_FL_NO_IT);
GPIO_Init(GPIOD,GPIO_PIN_5, GPIO_MODE_IN_FL_NO_IT);
GPIO_Init(GPIOD,GPIO_PIN_6, GPIO_MODE_IN_FL_NO_IT);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, ENABLE);
/* De-Init ADC peripheral*/
ADC1_DeInit();
/* Init ADC1 peripheral */
ADC1_Init(ADC1_CONVERSIONMODE_SINGLE, (ADC1_CHANNEL_4|ADC1_CHANNEL_5|ADC1_CHANNEL_6), ADC1_PRESSEL_FCPU_D2,\
ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL4,DISABLE);
ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_CHANNEL5,DISABLE); //ad功能 关闭施密特触发器 减少对ad影响
ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_CHANNEL6,DISABLE);
ADC1_ScanModeCmd(ENABLE);
ADC1_DataBufferCmd(ENABLE);
ADC1_ITConfig(ADC1_IT_EOCIE,DISABLE);
}
[code]这是读数据的代码,在timer4中断中调用,4ms一次,ad读取正常,只是会影响AIN2,3的输出
void ReadAdResult(void)
{
DS_INT16U i,ADResult[3];
SYSGLDATA *pSysData=NULL;
DS_INT16U *pDataPtr=NULL;
pSysData=&g_pSysGloble->SysData;
pSysData->AD1[pSysData->Ptr]=ADC1_GetBufferValue(4);
pSysData->AD2[pSysData->Ptr]=ADC1_GetBufferValue(5);
pSysData->AD3[pSysData->Ptr]=ADC1_GetBufferValue(6);
pSysData->Ptr++;
if(pSysData->Ptr>=10) pSysData->Ptr=0;
pDataPtr=pSysData->AD1;
for(i=0;i<3;i++) ADResult[i]=0;
for(i=0;i<10;i++)
{
ADResult[0]+=*(pDataPtr+i);
ADResult[1]+=*(pDataPtr+i+10);
ADResult[2]+=*(pDataPtr+i+20);
}
pSysData->ADdata1=ADResult[0]/10;
pSysData->ADdata2=ADResult[1]/10;
pSysData->ADdata3=ADResult[2]/10;//1.8
g_pSysGloble->SysData.ADVoltage1=(g_pSysGloble->SysData.ADdata1*1.82)/g_pSysGloble->SysData.ADdata3; //vo报警点
g_pSysGloble->SysData.ADVoltage2=(g_pSysGloble->SysData.ADdata2*1.82)/g_pSysGloble->SysData.ADdata3; // TEST 自检点
//g_pSysGloble->SysData.ADVoltage3=(g_pSysGloble->SysData.ADdata3*4.95)/1023; //1.8V
g_pSysGloble->SysData.ADVoltage3=(g_pSysGloble->SysData.ADdata3*5)/1023; //1.8V
/* De-Init ADC peripheral*/
ADC1_DeInit();
/* Init ADC1 peripheral */
ADC1_Init(ADC1_CONVERSIONMODE_SINGLE, (ADC1_CHANNEL_4|ADC1_CHANNEL_5|ADC1_CHANNEL_6), ADC1_PRESSEL_FCPU_D2,\
ADC1_EXTTRIG_TIM, DISABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_CHANNEL4,DISABLE);
ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_CHANNEL5,DISABLE); //ad功能 关闭施密特触发器 减少对ad影响
ADC1_SchmittTriggerConfig(ADC1_SCHMITTTRIG_CHANNEL6,DISABLE);
ADC1_ScanModeCmd(ENABLE);
ADC1_DataBufferCmd(ENABLE);
ADC1_ITConfig(ADC1_IT_EOCIE,DISABLE);
/*Start Conversion */
ADC1_Cmd(ENABLE);//启用ADC1
ADC1_StartConversion();
}
/*Start Conversion */
ADC1_Cmd(ENABLE);//启用ADC1
ADC1_StartConversion();
}[/code] |