cancel
Showing results for 
Search instead for 
Did you mean: 

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

Nsg1987
Senior

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.

2 REPLIES 2
Peter BENSCH
ST Employee

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
Senior

Hello Peter,

could you share some examples for the same.

Regards,

Nikhil