Showing results for 
Search instead for 
Did you mean: 

Output compare unit.

Associate II

Good afternoon community,
I am starting implementation of Output compare unit for STM32F407G Discovery board.
I get output as GPIO toggling on board.
I configure TIM1 and it's 4 channels for different frequency generation as output at different pulse,
and mode is "match on toggle".

Issue is that I got toggling once in while(1) loop.
This code is set in main function.
Please where should I need to correct and need to change the parameters.
I am sharing the code for your reference here.


while (1)

    /* USER CODE BEGIN 3 */
	  if(HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_1) == HAL_OK)
		  HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
	  if(HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_2) == HAL_OK)
	  		  HAL_GPIO_TogglePin(LD4_GPIO_Port, LD4_Pin);
	  if(HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_3) == HAL_OK)
	  		  HAL_GPIO_TogglePin(LD5_GPIO_Port, LD5_Pin);
	  if(HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_4) == HAL_OK)
	  		  HAL_GPIO_TogglePin(LD6_GPIO_Port, LD6_Pin);



Issue is that GPIOs are toggling only one time and then it will not continue his cycle.
So need to add function for reset the compare register?
Here I also share my project with you.
I am sharing with you two different code implementations for same purpose, So suggest which one is more reliable for output compare unit.
Also provide solution for that.

Generate frequency are:
TIM_CH1: 1000Hz
TIM_CH2: 1500Hz
TIM_CH3: 2000Hz
TIM_CH4: 2500Hz.
Please guide me for this and also give your reference project for my requirements.
Hope you are getting my problem.
Thank you, 


> I configure TIM1 and it's 4 channels for different frequency generation

You can't generate different frequencies from one timer. There is only one counter per timer.


Associate II

Good afternoon community,
I am traying to change the pulse value in TIMER Configuration.
Calculation is Frequency = Reference clock/Pulse value.
So, concern is that Can I change the value of Pulse for STM32F407G Discovery board?
It will generate 12.5Khz frequency at PE9 pin. I can read by oscilloscope. 
My configuration is:
TIM1 16bit Channel 1
Reference clock is 12.5Mhz.
Getting frequency is 12.5Khz with 50% of duty cycle.
How to measure the duty cycle? for above project mentioned in this query.
Can I generate different frequency by changing value of pulse?

> Calculation is Frequency = Reference clock/Pulse value.

Where do you have this from?

What is called "Pulse" in Cube, is the PWM pulse width, not the PWM frequency.


Associate II


Here mentioned that:
TIM_CNT_CLK = 25Mhz and desired frequency is 500Hz.
So, on period time is 0.001 second and off period is 0.001 for 1Khz frequency.
Pulse value is 25000.
So, it will generate 1Khz frequency.
By change this value can I get other frequency?


> So, on period time is 0.001 second and off period is 0.001 for 1Khz frequency.

No, that's 500Hz, as you've said yourself in previous sentence.

> Pulse value is 25000.

That determines the ON period. But by changing "pulse value", the OFF period also changes, so that the sum of the two remains the same (and so the frequency remains the same).


Associate II

Good morning community,
I am trying to capture output compare frequency.
I successfully complete on TIM1_CH1 which is 16bit timer.
Reference clock is 12.5Mhz and pulse value is 1000. So, it will generate 12.5Khz with 50% of Duty cycle.
I am trying to ask you, Can I generate 10Khz frequency? On this channel?
If yes, then how it will possible?

Or can I change the duty cycle value?
Project is same as above.