环境: STM32CubeMX 5.6.1(库为:STM32F11.8.0) IAR for ARM 8.40.2 STM32F103C8T6 BluePill问题: 使用PA1~PA4进行4路ADC采集,采用时间为7.5周期,测试出来每通道采样时间居然为10ms,当采用时间为239.5周期时,采样时间高达134ms。换了另一块板也一样。 设置: 时钟设置 ADC设置 原代码: int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_ADC1_Init(); MX_RTC_Init(); uint16_t ADC_Value[4]; TestPin_Toggle; //翻转Pin脚电平,测试时间用 ADC1_Conversion(ADC_Value); //获取ADC值 while (1) { } } void ADC1_Conversion(uint16_t *p) { uint8_t j; for(j=0;j<4;j++) { HAL_ADC_Start(&hadc1); HAL_ADC_PollForConversion(&hadc1,0xFFFF); //等待转换完成 *p++ = HAL_ADC_GetValue(&hadc1); TestPin_Toggle; //翻转Pin脚电平,测试时间用 } HAL_ADC_Stop(&hadc1); } 其中 HAL_ADC_PollForConversion(&hadc1,0xFFFF); 就耗费了10ms /* ADC1 init function */ void MX_ADC1_Init(void) { ADC_ChannelConfTypeDef sConfig = {0}; /**Common config */ hadc1.Instance = ADC1; hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; hadc1.Init.ContinuousConvMode = DISABLE; hadc1.Init.DiscontinuousConvMode = ENABLE; hadc1.Init.NbrOfDiscConversion = 1; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 4; if(HAL_ADC_Init(&hadc1) != HAL_OK) { Error_Handler(); } /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_1; sConfig.Rank = ADC_REGULAR_RANK_1; sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); } /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_2; sConfig.Rank = ADC_REGULAR_RANK_2; if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); } /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_3; sConfig.Rank = ADC_REGULAR_RANK_3; if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); } /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_4; sConfig.Rank = ADC_REGULAR_RANK_4; if(HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); } } |
启动DMA用了94.4us
HAL_ADC_Start_DMA(&hadc1,(uint32_t*)(ADCSample),2);
转换完成,再用了1.09ms
而我希望每隔20us对4个通道进行一次ADC,并记录。