Output compare unit.
- February 14, 2024
- 6 replies
- 1736 views
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 END WHILE */
/* USER CODE BEGIN 3 */
if(HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_1) == HAL_OK)
{
HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
HAL_Delay(100);
}
if(HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_2) == HAL_OK)
{
HAL_GPIO_TogglePin(LD4_GPIO_Port, LD4_Pin);
HAL_Delay(200);
}
if(HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_3) == HAL_OK)
{
HAL_GPIO_TogglePin(LD5_GPIO_Port, LD5_Pin);
HAL_Delay(300);
}
if(HAL_TIM_OC_Start(&htim1, TIM_CHANNEL_4) == HAL_OK)
{
HAL_GPIO_TogglePin(LD6_GPIO_Port, LD6_Pin);
HAL_Delay(400);
}
}
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,
Community.