大佬们帮我看看哪里错了,感谢!!!!
这是ADC配置
[mw_shl_code=applescript,true]void Adc_Init(void)
{
ADC_InitTypeDef ADC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_AFIO |RCC_APB2Periph_ADC1 ,ENABLE);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
//PA0.1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
ADC_DeInit(ADC1);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //独立模式
ADC_InitStructure.ADC_ScanConvMode = DISABLE; //单通道
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //单次
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //软件触发
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //右对齐
ADC_InitStructure.ADC_NbrOfChannel = 1; //顺序1通道
ADC_Init(ADC1, &ADC_InitStructure);
ADC_Cmd(ADC1, ENABLE);
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
}
float Get_Adc1(u8 ch)
{
float adc=0;
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_239Cycles5 );
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC )){};
adc=(float)ADC_GetConversionValue(ADC1);
return adc;
}[/mw_shl_code]
main函数里的
[mw_shl_code=c,true] while(1)
{
PRE1= Get_Adc1(ADC_Channel_0);
PRE2= Get_Adc1(ADC_Channel_1);
PRE= PRE2- PRE1;
control(PRE);
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>