请教下,使用
STM32L03xx
单片机进行adc转换,每次开机首次转换大概需要23s左右后才能够获得正确的值,
使用查询模式,单次转换
是怎么个情况 ???
相关配置如下:
ADC_HandleTypeDef AdcHandle;
ADC_UserTypeDef __adc_User;
void MX_ADC_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
memset(&__adc_User.aADCxConvertedData[0], 0, ADC_CONVERTED_DATA_BUFFER_SIZE);
__adc_User.aADCxConverVal = 0; // 求出平均值
__adc_User.aADCxConverVal_H = 0; // 求出平均值
__adc_User.aADCxConverVal_L = 0; // 求出平均值
__adc_User.aADC_ConvFinishFlag = 0; // adc 转换完成标志,=1说明转换完成,否则没有完成
__adc_User.aAdcConvCnt
time = 0; // adc 转换
计时
__adc_User.aAdcConvCntFlag = 0; // adc 转换标志 =1停止,=0开启
/* Configuration of ADCx init structure: ADC parameters and regular group */
AdcHandle.Instance = ADCx;
HAL_ADC_DeInit(&AdcHandle) ;
AdcHandle.Init.OversamplingMode = DISABLE;
AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;
AdcHandle.Init.LowPowe
RFrequencyMode = ENABLE;
#
IF defined(ADC_LOWPOWER)
AdcHandle.Init.LowPowerAutoWait = ENABLE; /* Enable the dynamic low power Auto Delay: new conversion start only when the previous conversion (for regular group) or previous sequence (for injected group) has been treated by user software. */
AdcHandle.Init.LowPowerAutoPowerOff = ENABLE; /* Enable the auto-off mode: the ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered (with startup time between trigger and start of sampling). */
#else
AdcHandle.Init.LowPowerAutoWait = DISABLE;
AdcHandle.Init.LowPowerAutoPowerOff = DISABLE;
#endif
AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
AdcHandle.Init.SamplingTime = ADC_SAMPLETIME_7CYCLES_5; //ADC_SAMPLETIME_7CYCLES_5;
AdcHandle.Init.ScanConvMode = DISABLE; //非扫描模式
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle.Init.ContinuousConvMode = DISABLE; //关闭连续转换
AdcHandle.Init.DiscontinuousConvMode = DISABLE;
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;//使用软件触发
AdcHandle.Init.EOCSelection = DISABLE; //关闭EOC中断
AdcHandle.Init.DMAContinuousRequests = DISABLE;
HAL_ADC_Init(&AdcHandle);
HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED);
sConfig.Channel = ADCx_CHANNELa;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);
// HAL_ADC_Start(&AdcHandle);
}
void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
{
GPIO_InitTypeDef GPIO_InitStruct;
// static DMA_HandleTypeDef DmaHandle;
if(adcHandle->Instance == ADCx)
{
__HAL_RCC_GPIOA_CLK_ENABLE();
ADCx_CLK_ENABLE();
// Enable DMA1 clock //
// __HAL_RCC_DMA1_CLK_ENABLE();
// PA1-CK_IN ------> ADC_IN1
GPIO_InitStruct.Pin = ADCx_CHANNELa_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(ADCx_CHANNELa_GPIO_PORT, &GPIO_InitStruct);
}
}
void ADC_Stop(void)
{
HAL_ADC_Stop(&AdcHandle);
}
void ADC_VoltageConversion(void)
{
uint8_t i;
for(i=0;i<ADC_CONVERTED_DATA_BUFFER_SIZE;i++)
{
HAL_ADC_Start(&AdcHandle);
HAL_ADC_PollForConversion(&AdcHandle, 5); //
if ((HAL_ADC_GetState(&AdcHandle) & HAL_ADC_STATE_REG_EOC) == HAL_ADC_STATE_REG_EOC)
{
__adc_User.aADCxConvertedData
= (uint16_t )HAL_ADC_GetValue(&AdcHandle);
}
}
ADC_Stop(); // 转换完成 后,adc 停止
__adc_User.aADC_ConvFinishFlag = 0;
__adc_User.aADCxConverVal_H = __adc_User.aADCxConverVal_L = 0;
__adc_User.aADCxConverVal = BubbleSort((uint16_t *)&__adc_User.aADCxConvertedData[0], ADC_CONVERTED_DATA_BUFFER_SIZE); // 求出平均值
__adc_User.aADCxConverVal_H = __adc_User.aADCxConverVal >> 4;
__adc_User.aADCxConverVal_L = (uint8_t)(__adc_User.aADCxConverVal & 0x000f);
/*
// 转换成实际电压值
ConValue = (float)(COMPUTATION_DIGITAL_12BITS_TO_VOLTAGE(aADCxConverVal));
sprintf((char *)&datdat[0], "ADC Voltage: %1.2fV", (float)ConValue);
printf("ADC Voltage: %s
", datdat);*
*/
}
再着调试功能性的东西先直接打印ADC值吧 之后才去考虑软件滤波的问题~~
一周热门 更多>