我在双模下使用STM32 G431,尝试捕获10 kHz波形。我一直很难通过HAL库接口/预分频器控制采样速率。我注意到,如果启用扫描功能,我可以实现速率并控制所述速率。如果没有扫描功能,速率似乎被限制在~300 ksps并且预分频器对其几乎没有影响。对于扫描模式1,数据更好,但我还剩下一堆其他数据(从通道的序列)那是垃圾。如果我减少扫描序列的转换次数,采样率按比例下降。2有没有办法让我得到我需要的采样率,并且在激活扫描模式功能的情况下得到(〉1 Msps),而不使用这个功能?
我附上了ADC初始化函数和数据的图像(左图显示低采样速率,右图显示高采样速率和垃圾数据)。
void MX_ADC1_Init(void)
{
ADC_MultiModeTypeDef multimode = {0};
ADC_ChannelConfTypeDef sConfig = {0};
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.GainCompensation = 0;
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc1.Init.EOCSelection =ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.NbrOfConversion = 10; // ADC_BUFFER_LEN;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc1.Init.OversamplingMode = DISABLE;
/*
oversmp.Ratio = ADC_OVERSAMPLING_RATIO_16;
oversmp.RightBitShift = 0;
oversmp.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
oversmp.OversamplingStopReset = ADC_REGOVERSAMPLING_RESUMED_MODE;
hadc1.Init.Oversampling = oversmp;
*/
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
}
// Configure the ADC multi-mode
multimode.Mode = ADC_DUALMODE_REGSIMULT;
multimode.DMAAccessMode = ADC_DMAACCESSMODE_12_10_BITS;
multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
}
// Configure Regular Channel
sConfig.Channel = ADC_CHANNEL_15;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_6CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
//Error_Handler();
}
HAL_ADC_Start(&hadc2);
}
/**
* Initializes ADC2
*/
void MX_ADC2_Init(void)
{
/* USER CODE BEGIN ADC1_Init 0 */
/* USER CODE END ADC1_Init 0 */
ADC_MultiModeTypeDef multimode = {0};
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC1_Init 1 */
/* USER CODE END ADC1_Init 1 */
/** Common config
*/
hadc2.Instance = ADC2;
hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
hadc2.Init.Resolution = ADC_RESOLUTION_12B;
hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc2.Init.GainCompensation = 0;
hadc2.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc2.Init.EOCSelection =ADC_EOC_SINGLE_CONV;
hadc2.Init.LowPowerAutoWait = DISABLE;
hadc2.Init.ContinuousConvMode = ENABLE;
hadc2.Init.NbrOfConversion = 2;//ADC_BUFFER_LEN;
hadc2.Init.DiscontinuousConvMode = DISABLE;
hadc2.Init.DMAContinuousRequests = DISABLE;
hadc2.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc2.Init.OversamplingMode = DISABLE;
/*hadc2.Init.Oversampling = oversmp;*/
if (HAL_ADC_Init(&hadc2) != HAL_OK)
{
// Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_17;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_6CYCLES_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
//Error_Handler();
}
/* USER CODE END ADC1_Init 2 */
HAL_ADC_Start(&hadc2);
}
2条答案
按热度按时间vm0i2vca1#
启用连续转换可解决此问题。
6jjcrrmo2#
如serge所述,尝试在循环模式下使用DMA开启的ADC,并开启连续对话。
您也可以按照MyaqoobEmbedded教程在多个ADC与stm 32在YouTube上.