STM32L073 AD转换
大神们好,我刚接触STM32L0系列芯片,现在搞AD转换,用HAL库,可以正常转换,但是转换时间太长了,效率很低。不知道是我程序有问题还是什么,现在想换寄存器写,不用库,用寄存器现在很没头绪,望大神们指点,最好给点例程。谢谢。下面是我用库写的void vInitAdc(void)
{
AdcHandle.Instance = ADC1;
AdcHandle.Init.OversamplingMode = DISABLE;
AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;
AdcHandle.Init.LowPowerAutoPowerOff= DISABLE;
AdcHandle.Init.LowPowerFrequencyMode = ENABLE;
AdcHandle.Init.LowPowerAutoWait = DISABLE;
AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
AdcHandle.Init.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
AdcHandle.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle.Init.ContinuousConvMode = DISABLE;//ENABLE;
AdcHandle.Init.DiscontinuousConvMode = DISABLE;
AdcHandle.Init.ExternalTrigConvEdge= ADC_EXTERNALTRIGCONVEDGE_NONE;
AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
AdcHandle.Init.DMAContinuousRequests = DISABLE;
/* Initialize ADC peripheral according to the passed parameters */
if (HAL_ADC_Init(&AdcHandle) != HAL_OK)
{
;//Error_Handler();
}
/* ### - 2 - Start calibration ############################################ */
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
{
;//Error_Handler();
}
}
unsigned int uiADC_Result(unsigned char ucChannel)
{
unsigned char i;
unsigned int uiMaxResult = 0, uiMinResult = 0xFFFF;
unsigned int j,uiResult = 0;
ADC_ChannelConfTypeDef sConfig;
ADC1->CHSELR=0;
ADC1->CHSELR=ucChannel;//sConfig.Channel;
HAL_ADC_Start(&AdcHandle);
for (i = 0;i < 6;i++)
{
HAL_ADC_PollForConversion(&AdcHandle, 10);
/* Check if the continous conversion of regular channel is finished */
if ((HAL_ADC_GetState(&AdcHandle) & HAL_ADC_STATE_REG_EOC) == HAL_ADC_STATE_REG_EOC)
{
j = HAL_ADC_GetValue(&AdcHandle);
}
if (j > uiMaxResult)
{
uiMaxResult = j;
}
if (j < uiMinResult)
{
uiMinResult = j;
}
uiResult += j;
}
uiResult -= uiMaxResult;
uiResult -= uiMinResult;
uiResult /= 4;
return uiResult;
}
你可以,把试下adc+dma方式。。。hal库里有例程,或者社区里也很多。 Paderboy 发表于 2017-5-18 22:27
你可以,把试下adc+dma方式。。。hal库里有例程,或者社区里也很多。
我现在就需要的是单通道连续采集 song-407678 发表于 2017-5-18 22:39
我现在就需要的是单通道连续采集
adc+dma也可以单通道多次采样的。。
页:
[1]