cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 PWM Generate when Input Capture Update Event

ELee.9
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

1 REPLY 1

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