cancel
Showing results for 
Search instead for 
Did you mean: 

TIM1 master PWM, TIM4 Slave PWM with phase shift

CyberNerd
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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.

TDK_0-1724244334548.png

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

7 REPLIES 7
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

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:

CyberNerd_0-1724227578783.png

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:

CyberNerd_1-1724228024674.png

 

 

CyberNerd
Associate III

By putting in an additional timer I can achieve what I want, but maybe there is an easier way:

CyberNerd_0-1724236640528.png

 

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. 

TDK
Guru

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.

TDK_0-1724244334548.png

 

If you feel a post has answered your question, please click "Accept as Solution".

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.

CyberNerd
Associate III

Can confirm it works Thanks