简体   繁体   English

stm32 同时 adc 读取

[英]stm32 simultaneous adc READS

I have been using STM32 IDE which incorporates the CUBE MX.我一直在使用包含 CUBE MX 的 STM32 IDE。

Using the HAL code I am able to read on three pins using a separate ADC for each pin.使用 HAL 代码,我可以对每个引脚使用单独的 ADC 读取三个引脚。 I have started all the ADC's at the same time and then I poll for completion.我同时启动了所有的 ADC,然后我轮询完成。 I am I correct in thinking these ADC reads should be practically simultaneous (ie they all read in at a very similar time)?我认为这些 ADC 读取实际上应该是同时的(即它们都在非常相似的时间读取)是正确的吗?

Code fragment below.下面的代码片段。 Using a NUCLEO-STM32 F446RE btw.顺便说一句,使用 NUCLEO-STM32 F446RE。

  MX_ADC1_Init();
  MX_ADC2_Init();
  MX_ADC3_Init();
  MX_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
      static int flip,sysclk=0,old_sysclk=0,adc1,adc2,adc3;//adc3_0,adc3_1,adc3_2, adc_pstat0,
      int adc_pstat1, adc_pstat2, adc_pstat3;

      flip ^= 1;

          HAL_GPIO_WritePin(GPIOC,GPIO_PIN_0/*|GPIO_PIN_2|GPIO_PIN_6*/, flip);


           HAL_ADC_Start(&hadc3);
           HAL_ADC_Start(&hadc2);
           HAL_ADC_Start(&hadc1);
           adc_pstat1 = HAL_ADC_PollForConversion(&hadc1, 10);
          adc_pstat3 = HAL_ADC_PollForConversion(&hadc3, 10); // should already be done!
          adc_pstat2 = HAL_ADC_PollForConversion(&hadc2, 10); // should already be done!
          adc3 = HAL_ADC_GetValue(&hadc3);
          adc2 = HAL_ADC_GetValue(&hadc2);
          adc1 = HAL_ADC_GetValue(&hadc1);

                  if (adc_pstat2 ||adc_pstat3)
                     asm("\t nop");
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
          sysclk = HAL_GetTick();

          if ( (sysclk - 1000) > old_sysclk ){
              //printf("nucleo F446 0x%X adc3_0 0x%X adc3_1 0x%X adc3_2 0x%X\n",sysclk,adc3_0,adc3_1,adc3_2);
              printf("|->nucleo F446 sysclk=0x%X adc1=0x%X adc2=0x%X adc3=0x%X\n",sysclk,adc1,adc2,adc3);
              old_sysclk = sysclk;
          }
      }
      /* USER CODE END 3 */
    }

Your code does not read it simultaneously as you do not start the ADCs at the sime moment.您的代码不会同时读取它,因为您没有同时启动 ADC。

You need to use the same external trigger for all of them or use ADCs in the double or tripple mode.您需要对所有这些都使用相同的外部触发器,或者在双重或三重模式下使用 ADC。

CubeMX ADC 设置 I found a way to do this easily.我找到了一种轻松做到这一点的方法。 I set up a timer and used to to update a trigger event.我设置了一个计时器并用于更新触发事件。 The ADC's then triggered off this event (TIM8_TRGO).然后 ADC 触发此事件 (TIM8_TRGO)。 Using this trigger I can get two or three ADCs to read simultaneously.使用此触发器,我可以同时读取两个或三个 ADC。 The Dual Simultaneous mode seems to support ADCs reading at the same time Dual Simultaneous 模式似乎支持同时读取 ADC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM