2024-08-20 01:03 PM
Is there a way to connect TIM4 to TIM1 were I will be able to slightly phase shift the PWM signal generated by TIM4 compared to TIM1? TIM1 will be configured as master, TIM4 will be configured as slave.
Solved! Go to Solution.
2024-08-21 05:45 AM
Combined PWM mode 2 is the easier way.
Your one timer is resetting the other. Assuming you want to keep that functionality, there's not going to be another way to achieve this without involving other peripherals.
2024-08-20 01:32 PM
Sure, set TIM4->CNT to a nonzero value. When you start it, it will start from that value instead of 0. Change this to affect the phase shift between the timers.
Could also sync the timers and use PWM mode 2 to modify phase shift without adjusting CNT.
2024-08-21 01:13 AM
My TIM1 setting:
- TRGO: Compare pulse OC1
- TRGO2: Reset
My TIM4 setting:
Slave mode: Reset mode
Trigger source: ITR0
PWM Mode 2
This is how it looks:
Now, I would like to slightly shift the red signal to the right, like 1us or so. If I increase the period of TIM4, I can delay the rising edge, but the falling edge is a different story since it's synced with TIM1:
2024-08-21 03:37 AM
By putting in an additional timer I can achieve what I want, but maybe there is an easier way:
2024-08-21 05:36 AM
G4 supports "combine PWM" mode, read Reference Manual. It allows to adjust both sides - rising and falling edges, and have some reference pulses on onother two channels out of 4, using just one timer.
2024-08-21 05:45 AM
Combined PWM mode 2 is the easier way.
Your one timer is resetting the other. Assuming you want to keep that functionality, there's not going to be another way to achieve this without involving other peripherals.
2024-08-21 11:11 AM
So now I have:
TIM1 master => slave TIM5 master => slave TIM4
TIM5 pulse value determines phase the shift. In theory I have control over both, rising and falling edge, by adjusting TIM5 pulse I can change the rising edge moment, by changing TIM4 pulse I'm able to control the falling edge moment. So basically I have 2 timers to achieve wat I want.
I'm tied to TIM4 due to pinmap restriction.
If I understand you correctly, using combined PWM mode 2 on TIM4, I will be able to eliminate TIM5, that would be great, I will look into the reference manual, thanks for pointing me in the right direction.
2024-08-21 01:50 PM
Can confirm it works :) Thanks