AnsweredAssumed Answered

Generate a square wave in output compare mode

Question asked by Christophe on Mar 10, 2015
Latest reply on Mar 10, 2015 by Clive One

I'm using the STM32F411RE Nucleo board and I would like to generate
a 25 MHz square wave by using the output compare of timer3 in toggle mode.

Timer is configure as follow :

  TimHandle.Instance = TIM3;
  TimHandle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
  TimHandle.Init.Period = 65535;
  TimHandle.Init.Prescaler = 0;

  Config.OCPolarity = TIM_OCPOLARITY_HIGH;
  Config.Pulse = 1;

  if(HAL_TIM_OC_ConfigChannel(&TimHandle,&Config,TIM_CHANNEL_1) != HAL_OK)

  if(HAL_TIM_OC_Start_IT(&TimHandle,TIM_CHANNEL_1) != HAL_OK)

The pulse value is updated in the callback function after two period of timer clock (cnt = capture compare), so that generate a 25 MHz which is half timer clock frequency.

But when i'm watching the output pin on oscilloscope, the signal appears to have a half period of 1.3 ms, which is the value of 65535 clock cycles, while i'm expecting to have a capture compare value incremented by one and changing the state of the pin every 20 ns.

Thanks in advance,