Question
Generate a square wave in output compare mode
Posted on March 10, 2015 at 14:34
Hi,
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.OCMode = TIM_OCMODE_TOGGLE; Config.OCPolarity = TIM_OCPOLARITY_HIGH; Config.Pulse = 1; if(HAL_TIM_OC_ConfigChannel(&TimHandle,&Config,TIM_CHANNEL_1) != HAL_OK) { Error_Handler(); } if(HAL_TIM_OC_Start_IT(&TimHandle,TIM_CHANNEL_1) != HAL_OK) { Error_Handler(); } 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, Regards Christophe