2020-01-30 12:10 PM
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);
```
2020-01-30 01:17 PM
Doesn't using CHx from advanced timer require to enable it also by setting TIMx_BDTR.MOE?
JW
2020-01-30 02:41 PM
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.
2020-01-30 04:27 PM
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
2020-01-30 04:42 PM
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.
2020-01-31 02:03 AM
> 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.
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
2020-01-31 11:36 AM
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.