Skip to main content
Nsg1987
Associate III
May 16, 2023
Question

How to read multiple ADC (ADC 1, ADC2, ADC3) and each with 4 channels at a time using timer interrupt

  • May 16, 2023
  • 2 replies
  • 1030 views

Hi,

I am working on STM32G474.

I want to read multiple ADC channels (ADC1 , ADC2 and ADC3 all with 4 channels at a time).

I generated interrupt using timer 3 (update event) and reading ADC channels under

 /* USER CODE BEGIN 2 */

        HAL_TIM_Base_Start_IT(&htim3);

        

       HAL_ADC_Start_IT(&hadc1);

       HAL_ADC_Start_IT(&hadc2);

HAL_ADC_Start_IT(&hadc3);

 /* USER CODE END 2 */

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

{

UNUSED(hadc);

adc_val1 = HAL_ADC_GetValue(&hadc1);

//HAL_GPIO_TogglePin(L5_GPIO_Port, L5_Pin);

}

adc_val1 = HAL_ADC_GetValue(&hadc1); will read only 1 channel and 1 ADC. I want to read 4 channels of ADC1 and likewise for ADC2 and ADC3 under same interrupt.

This topic has been closed for replies.

2 replies

Peter BENSCH
ST Technical Moderator
May 16, 2023

Well, there are indeed several instances of the ADC, so that each of these instances can also take a measurement at exactly the same time, which is important, for example, when measuring motor currents for an FOC.

However, the ADC channels are multiplexed per instance, so they are selected for one measurement each. In this respect, you cannot measure on 4 channels at the same time, but only individually after switching.

Does it answer your question?

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Nsg1987
Nsg1987Author
Associate III
May 16, 2023

Hello Peter,

could you share some examples for the same.

Regards,

Nikhil