大佬们帮我看看哪里错了,感谢!!!!
这是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]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
// 神舟1号 ADC->PB1
static void AdcInit(void)
{
u32 timeOut;
ADC_InitTypeDef adcInitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
adcInitStruct.ADC_Mode = ADC_Mode_Independent;
adcInitStruct.ADC_ScanConvMode = DISABLE;
adcInitStruct.ADC_ContinuousConvMode = DISABLE;
adcInitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
adcInitStruct.ADC_DataAlign = ADC_DataAlign_Right;
adcInitStruct.ADC_NbrOfChannel = 1;
ADC_Init(ADC1, &adcInitStruct);
timeOut = 10000;
ADC_ResetCalibration(ADC1);
while((ADC_GetResetCalibrationStatus(ADC1)) && (timeOut--));
timeOut = 10000;
ADC_StartCalibration(ADC1);
while((ADC_GetCalibrationStatus(ADC1)) && (timeOut--));
}
GLOBAL u16 GetAdc(void)
{
u16 AdcVal;
u32 DelayTime = 200;
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_55Cycles5);
ADC_Cmd(ADC1, ENABLE);
ADC_TempSensorVrefintCmd(ENABLE);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
while(DelayTime--);
AdcVal = ADC_GetConversionValue(ADC1);
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
ADC_TempSensorVrefintCmd(DISABLE);
ADC_SoftwareStartConvCmd(ADC1, DISABLE);
ADC_Cmd(ADC1, DISABLE);
return AdcVal;
}
这个可以采集 可以参考下啊
一周热门 更多>