This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F2132: Synchronization of timers

Part Number: MSP430F2132

Hi,

Anyone tried to synchronize two timers in MSP430 to get two PWM's that are in phase and precisely synced?

I cannot figure out how to start them at the same time.

Thanks,

Fredrik 

  • Hi Fredrik,

    without having details of your application my first suggestion would be to use the Timer0_A3 with three Capture/Compare registers which allows you two generate two PWMs (using CCR0 as period for both PWMs and then distinguishing the duty cycles of the PWMs by CCR1 and CCR2 respectively). Though this only works in case both PWMs shall run with the same timer frequency and periodicity.
    Would that be an option for your application?

    Best regards,
    Britta
  • Thanks Britta,

    I think I need to explain more in detail :)

    The two PWM signals shall be complementary, 180° out of phase with a small dead band:

    Do you think it is doable?

    Best regards,

    Fredrik

  • Hi Fredrik,

    the 180 degree phase shift is definitely doable as you could use complementary output modes, such as Set/Reset for PWM1 and Reset/Set for PWM2.
    Please correct me if I'm wrong but in the graph you're showing the ON time in PWM1 is slightly later and a bit shorter than the OFF time of PWM2. This is your intended dead band, correct?
    Should any of the edges be in sync?
    Sorry to pose more questions, but I hope we'll get to the best way to implement it.

    Best regards,
    Britta
  • Hi Britta,

    Sorry for not being more clear and thank you so much for your help.

    Let's call rising edge of PWM1 e1, falling edge of PWM1 e2, rising edge of PWM2 e3 , falling edge of PWM2 e4 and dead band d.

    Then if total period is T; e1 = 0, e2 = T/2-d, e3 = T/2 and e4 = T-d

    Hope this is clearer!

    Best regards,

    Fredrik

  • Hi Fredrik,

    thanks for the clarification here. To generate the two desired PWM outputs and achieve the delay in between you'll really need to use to different Timer modules.
    Then this comes down to the synchronization of the two Timer modules, as you've asked for in your initial thread: The easiest way to synchronize the two modules would be if you run both Timers from MCLK, disable the interrupts (just for the time of starting both timers) and then start one Timer module after the other. From your description I understood that you'll have the same timer period but a 180 degree phase shift. The easiest would be to initialize both Timer module settings, start Timer1 and wait T/2 (or actually a bit less than that)to start Timer 2 (with the same output mode configuration). You'd just need to take into account how many clock cycles are needed to start Timer2 so that it really starts counting at T/2 of Timer1.
    After both Timers are running you can enable the interrupts again.

    Please let me know if this is clear or if you'd need any more details.

    Thanks and best regards,
    Britta
  • Thank you very much Britta!
    I'm working on an implementation proposal and will suggest this implementation. I hope I get a chance to implement it in the near future.
    Have a nice day!
    Best regads,
    Fredrik
  • Hi Fredrik,

    I'm happy that this answers your question.
    Please feel free to reach out again in case any other questions or issues will come up.

    Best regards,
    Britta

**Attention** This is a public forum