cancel
Showing results for 
Search instead for 
Did you mean: 

ADC DMA Timer trigger affects only the first callback

AlaaM
Associate III

Hi,

I'm using STM32F722RET, and I'm trying to do ADC sampling of 3 channels using DMA with a timer trigger.

I configured the following:

ADC:

hadc1.Instance = ADC1;
hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_TRGO;
hadc1.Init.NbrOfConversion = 3;
hadc1.Init.DMAContinuousRequests = ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
 
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
 
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = ADC_REGULAR_RANK_2;
 
sConfig.Channel = ADC_CHANNEL_2;
sConfig.Rank = ADC_REGULAR_RANK_3;

TIMER:

htim1.Instance = TIM1;
htim1.Init.Prescaler = 27000;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = 1000;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
 
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
 
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

APB1 Timer clocks: 54MHz

APB2 Timer clocks: 27MHz

But the problem is that only the first callback is triggered in the expected time, and the following ones are too fast. Here are the callback times from first to last: {949, 179, 180, 180, 195, 115}.

I'm using cubemx but if there's a solution with or without cubemx it's all good.

Please assist

UPDATE:

I tried enabling the TIM1 update interrupt, and noticed that it's triggered in the correct speed. It's just the ADC timer trigger that is not working well, although we're talking about the same timer (TIM1).

2 REPLIES 2
S.Ma
Principal

Try to use a physical pin for the timer output, then connect it to the ADC trigger input pin.

With an oscilloscope, you will be able to monitor what's going on an possibly understand where the bug's located. Once all looks file, re-internalize the signals.

AlaaM
Associate III

Thanks for the reply. Sorry what do you mean by connecting the timer output to the ADC pin? Physically connecting them? Also what do you mean by re-internalizing the signals?

Additional thing I noticed is there's a warning on TIM1 in cube which says:

Clock Source Conflict with USB_OTG_FS: Mode Device_Only.

Could that be the problem?