AnsweredAssumed Answered

PWM1 and TIM2 config for dual ADC

Question asked by Antoine.PM on Jul 27, 2016
Latest reply on Aug 3, 2016 by Clive One

I have a code, kindly provided by clive1, to use two ADC in dual mode on STM32F334, and it works well. I can modify some parameters, but something (the ADC itself, the DMA to fill the memory array, or just the loop for printf the values?) begins to stutter when I try to obtain more samples for a higher frequency input signal.

I'm quite ok with most of the code, but the timer config function bothers me.
Here it is:
void TIM_Configuration(void)
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  TIM_OCInitTypeDef TIM_OCInitStructure;
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_Period = (SystemCoreClock / 50) - 1; // 50 Hz Sample Rate
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
       /* Mode configuration: Channel2 & 3 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 10; // Some arbitary width
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  TIM_OC2Init(TIM2, &TIM_OCInitStructure);
  TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);

First, the TIM_Period parameter.
I have configured a DAC before, and for it, I divided SystemCoreClock by NumberOfSamples time DesiredFrequency, so I can see a certain logic there.
TIM_TimeBaseStructure.TIM_Period = (SystemCoreClock/ (32 * 100000)) - 1;

But a sampling frequency for an ADC is supposed to be way higher than the frequency of the input signal. From that, how is it possible to have 50 Hz as sample rate? (I changed it to 300 max but there I faced the stutter mentioned before)

My second question is about the purpose of PWM1 here. It is supposed to configure an output signal linked to the TIM2 timer, but 1) there's no pin connected to it and 2) I don't need it since the signals I study are input, but when I comment the part about PWM1 the ADC don't work anymore (data and common data registers stay empty). How is it possible?