I cant create signals with different frequencies using timer.
- February 21, 2024
- 5 replies
- 5699 views
Hi,
I want to make an application in which 4 different signals to be produced with different frequencies. I am using timer output compare mode. My board is STM32F407VG-DISC1, so I use on board LEDs as TIM4_Channel1, TIM4_Channel2, TIM4_Channel3 and TIM4_Channel4.
I use HAL_TIM_OC_Start_IT API in order to change the value of CCR so that whenever interrupt occurs, the value in register is updated which enables me to control the generated frequency.
But this does not work.
First of all, 4 LEDs blink at the same rate, no matter what values I provide in the interrupt callback function via __HAL_TIM_SET_COMPARE function. I can control the frequency of the signal generated via the counter clock, under configuration tab of the TIM4 mode and configuration on STM32 Cube IDE.
The frequency increases when I lower the prescaler.
I have got few questions.
- Why cant I generate signals with different frequencies ?
- I suspect that the interrupt callback is never called, is that the case ?
- I can not debug the code, because it is halted at while(1), never reaches to HAL_TIM_ReadCapturedValue.
- I dont know what these parameters below (Pulse and Output Compare Preload) do exactly, could you please help me understand ?

Thank you.