Skip to main content
ELee.9
Associate II
February 17, 2023
Solved

STM32 PWM Generate when Input Capture Update Event

  • February 17, 2023
  • 1 reply
  • 1560 views

Hi, I'm doing a project with STM32F769I-EVAL.

In my project, I set Timer 2 Channel 1 to input capture mode, and I made a clock to TIM2 CH1 Pin with Function Generator. And Timer 5 Channel1 to PWM Generation CH1 to make a PWM.

I calculate frequency of input clock and set same frequency to Timer 5 and start HAL_TIM_PWM_Start and It works succefully.

Now, I wonder how to generate PWM same phase with Input clock.

Can I generate TIM5 PWM signals when Timer 2 update event occurs to generate same phase with Input clock and TIM5 PWM Signals?

This topic has been closed for replies.
Best answer by waclawek.jan

Set up TIM5, but don't enable it in software (don't set TIMx_CR1.CEN, I don't use Cube/HAL). Set TIM5's Slave-mode controller to be triggered from TIM2 (in TIM5_SMCR.TS, there's a table in description of TIM5_SMCR with TS values for individual master-slave timer pairs) and set it to Trigger mode in TIM5_SMCR.SMS.

In TIM2_CR2.MMS, set TIM2 to output TRGO upon Compare Pulse (it's badly named, it will trigger also upon Capture on CH1). The next edge which causes TIM2_CH1 capture will then also start TIM5.

JW

1 reply

waclawek.jan
waclawek.janBest answer
Super User
February 17, 2023

Set up TIM5, but don't enable it in software (don't set TIMx_CR1.CEN, I don't use Cube/HAL). Set TIM5's Slave-mode controller to be triggered from TIM2 (in TIM5_SMCR.TS, there's a table in description of TIM5_SMCR with TS values for individual master-slave timer pairs) and set it to Trigger mode in TIM5_SMCR.SMS.

In TIM2_CR2.MMS, set TIM2 to output TRGO upon Compare Pulse (it's badly named, it will trigger also upon Capture on CH1). The next edge which causes TIM2_CH1 capture will then also start TIM5.

JW