cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 ADC external TIM1 trigger

_EFrie
Senior

Is it possible to externally trigger the ADC in group conversion mode + DMA continually? Nothing I have tried seems to work. It appears that I have to call a software conversion for each synced conversion?

```

 LL_ADC_REG_SetTriggerSource(ADC1, LL_ADC_REG_TRIG_EXT_TIM1_TRGO2);

 LL_ADC_REG_SetContinuousMode(ADC1, LL_ADC_REG_CONV_SINGLE);

 LL_ADC_REG_SetDMATransfer(ADC1, LL_ADC_REG_DMA_TRANSFER_UNLIMITED);

 LL_ADC_REG_SetSequencerLength(ADC1, LL_ADC_REG_SEQ_SCAN_ENABLE_8RANKS);

 LL_ADC_SetSequencersScanMode(ADC1, LL_ADC_SEQ_SCAN_ENABLE);

 LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_8);

 LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_5);

 LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_9);

 LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_4, LL_ADC_CHANNEL_6);

 LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_5, LL_ADC_CHANNEL_13);

 LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_6, LL_ADC_CHANNEL_0);

 LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_7, LL_ADC_CHANNEL_12);

 LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_8, LL_ADC_CHANNEL_4);

 LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_0, SAMPLING_CYCLES);

 LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_4, SAMPLING_CYCLES);

 LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_5, SAMPLING_CYCLES);

 LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_6, SAMPLING_CYCLES);

 LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_8, SAMPLING_CYCLES);

 LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_9, SAMPLING_CYCLES);  

 LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_12, SAMPLING_CYCLES);

 LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_13, SAMPLING_CYCLES);

 LL_ADC_EnableIT_OVR(ADC1);

 LL_ADC_Enable(ADC1);

/* Setup Timer 1 */

 NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 2);

 NVIC_EnableIRQ(TIM1_UP_TIM10_IRQn);

 LL_TIM_SetPrescaler(TIM1, 0);

 LL_TIM_SetAutoReload(TIM1, SystemCoreClock / (FADER_PWM_HZ * FADER_PWM_RESOLUTION));

  /* Setup Channel 2 for adc trigger */

 LL_TIM_OC_SetMode(TIM1, LL_TIM_CHANNEL_CH2, LL_TIM_OCMODE_FROZEN);

 LL_TIM_OC_SetCompareCH2(TIM1, SystemCoreClock / (FADER_PWM_HZ * FADER_PWM_RESOLUTION) / 2);

 LL_TIM_CC_EnableChannel(TIM1, LL_TIM_CHANNEL_CH2);

 /* Enable update */

 LL_TIM_EnableIT_UPDATE(TIM1);

  

 LL_TIM_SetRepetitionCounter(TIM1, FADER_PWM_RESOLUTION * (FADER_PWM_HZ / FADER_PID_HZ));

 /* Enable counter */

 LL_TIM_EnableCounter(TIM1);

LL_ADC_REG_SetTriggerSource(ADC1, LL_ADC_REG_TRIG_EXT_TIM1_CH2);

```

6 REPLIES 6

Doesn't using CHx from advanced timer require to enable it also by setting TIMx_BDTR.MOE?

JW

I don't claim to understand it, but it would seem to me like maybe that is about GPIO outputs? I tried it here, setting the AOE bit, It doesn't go, it must be something else.

I said, MOE, not AOE.

Read back and check the content of timer and ADC registers.

You may also want to try a different timer, some of the "general purpose" ones.

JW

_EFrie
Senior

Not sure what to say, the datasheet says MOE not directly writeable. Anyway, readback does show MOE on. Or, perhaps there is some nuance I'm not getting.

Unfortunately, I am already using timer this to dma pwm gpio, and it really needs to be synchronized to it.

> Not sure what to say, the datasheet says MOE not directly writeable.

Then you must have a different datasheet (here: Reference Manual) than I have.

0690X00000BxAPSQA3.png

Anyway - read out and check all TIMx registers. Check that it's running and generating a waveform on the given channel - assign it to an appropriate pin in GPIO and observe using oscilloscope.

Read out also the ADC registers and check if they are properly set.

> Unfortunately, I am already using timer this to dma pwm gpio, and it really needs to be synchronized to it.

Okay; but you can use a different timer just to test if the concept is OK. In case you hit troubles like these, you should start with a minimal example anyway, to exclude external influences; and if you get it going then gradually add other features.

JW

_EFrie
Senior

Coming back to this, I'm not sure how to actively use CHx, but I did get TRGO2 to work in this fasion:

```

 LL_ADC_REG_StartConversionExtTrig(ADC1, LL_ADC_REG_TRIG_EXT_FALLING);

 LL_TIM_OC_SetMode(TIM1, LL_TIM_CHANNEL_CH2, LL_TIM_OCMODE_TOGGLE);//<-- This has to toggle so the thing will fire

 LL_TIM_SetTriggerOutput2(TIM1, LL_TIM_TRGO2_OC2);

```

The datasheet for the timers could be improved, stuff is pretty vague.