Skip to main content
Graduate
August 20, 2024
Solved

TIM1 master PWM, TIM4 Slave PWM with phase shift

  • August 20, 2024
  • 4 replies
  • 1934 views

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.

    This topic has been closed for replies.
    Best answer by TDK

    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

     

    4 replies

    Super User
    August 20, 2024

    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.

    CyberNerdAuthor
    Graduate
    August 21, 2024

    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

     

     

    CyberNerdAuthor
    Graduate
    August 21, 2024

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

    CyberNerd_0-1724236640528.png

     

    Explorer
    August 21, 2024

    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. 

    TDKAnswer
    Super User
    August 21, 2024

    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

     

    CyberNerdAuthor
    Graduate
    August 21, 2024

    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.

    CyberNerdAuthor
    Graduate
    August 21, 2024

    Can confirm it works :) Thanks