2019-10-14 21:51发布
zhengxiaobin 发表于 2016-1-4 16:58 STM32L0xx内部ADC有一种模式叫做OverSampler模式;手册上说:这个模式通过软件配置当前ADC采集的次数,STM3 ...
最多设置5个标签!
void ADC_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
AdcHandle.Instance = ADC1;
AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4;//Config ADC Clock is PCLK Div4
AdcHandle.Init.Resolution = ADC_RESOLUTION12b;
AdcHandle.Init.ScanDirection = ADC_SCAN_DIRECTION_UPWARD;
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIG_EDGE_NONE;
AdcHandle.Init.EOCSelection = EOC_SINGLE_CONV;
AdcHandle.Init.DMAContinuousRequests = DISABLE;
AdcHandle.Init.DiscontinuousConvMode = DISABLE;
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle.Init.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
#if OVERSAMPLING ==1
AdcHandle.Init.OversamplingMode = ENABLE;
AdcHandle.Init.Oversample.Ratio = ADC_OVERSAMPLING_RATIO_16;
AdcHandle.Init.Oversample.RightBitShift = ADC_RIGHTBITSHIFT_4;
AdcHandle.Init.Oversample.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
AdcHandle.Init.LowPowerAutoOff = DISABLE;
AdcHandle.Init.LowPowerFrequencyMode = DISABLE;
AdcHandle.Init.LowPowerAutoWait = ENABLE;
AdcHandle.Init.ContinuousConvMode = ENABLE;
#else
AdcHandle.Init.OversamplingMode = DISABLE;
AdcHandle.Init.LowPowerAutoOff = ENABLE;
AdcHandle.Init.LowPowerFrequencyMode = DISABLE;
AdcHandle.Init.LowPowerAutoWait = DISABLE;
AdcHandle.Init.ContinuousConvMode = DISABLE;
#endif
HAL_ADC_Init(&AdcHandle);
HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED);
sConfig.Channel = ADC_CHSELR_CHSEL9;
HAL_ADC_ConfigChannel(&AdcHandle, &sConfig);
HAL_ADC_Start(&AdcHandle);
// ConfigADC_17();
}
uint16_t Get_singleADCValue()
{
uint16_t ADCvalue;
ADC1->CR |= ADC_CR_ADSTART;
HAL_ADC_PollForConversion(&AdcHandle,5000);
ADCvalue=HAL_ADC_GetValue(&AdcHandle);
return ADCvalue;
}
外面可能要用到电阻分压,然后用ADC就可以做到,这资源够少吧?
哪里有这个,我怎么没看到过
一周热门 更多>