cancel
Showing results for 
Search instead for 
Did you mean: 

trigger DMA with ADC1 and ADC2 using different timer

VidhiPa
Associate II

Hi, 

I want to have 2 ADC interrupts with DMA. ADC1 is triggered using TIM1 at 4kHz, while ADC2 is triggered using TIM4 at 74kHz. Two different timers are used for different ADC to have different sampling time. The ADC2 is set as Medium priority while the ADC1 is at low priority.

Questions are as below:

1. If more lines are added in "hadc==&hadc2" then it changes the ADC2 interrupt frequency from 74kHz to lower values. I did not understand why ?

2. How to confirm the conversion + sampling time for each ADCs ?

3. There is another timer interrupt triggered at 4 kHz, how to understand the priorities of all 3 Interrupts (ADC1(TIM2), ADC2(TIM4), TIM1) with respect to each other ?

Here is the code snippet. 

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)
{
if(hadc==&hadc1)

{

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_SET);

//2.5 cycles for sampling time

VA=ADC1_buffer1[0]; 
VB=ADC1_buffer1[1]; 
VC=ADC1_buffer1[2]; 
 
IA=ADC1_buffer1[3];
IB=ADC1_buffer1[4];
IC=ADC1_buffer1[5];
 
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_RESET);
 
Please help me !

}

if(hadc==&hadc1)

{

HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET);

// 12.5 cycles for sampling time

 X=ADC_buffer1[0];
 Y=ADC_buffer1[1];
 z=ADC_buffer1[2];
 
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET);

}

}

10 REPLIES 10

Of course, I would not even ask you to do that !

I tried to explain it in detail to understand better what you suggested "to reduce the sampling rate and using large buffers". Sampling rate I cannot change, since that is the customer requirement. I am already using buffers to slow down my loops further. thank you for the guideline.