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.

How to Get 180 degree phase shift between two pwm pulses in MSP430G2553

Other Parts Discussed in Thread: MSP430G2553

hi i amusing MSP430G2553 to generate pulses for Interleaved boost converter which requires 180 degree phase shift between to pulses .so can you help me it this? 

  • Timer in up/down mode, CCR0 - period, CCR1 output mode: toggle/set, CCR2 output mode: toggle/reset.

    For more info please refer to x2xx series User's Guide (SLAU144), timer chapter

  • YEAH I TRIED that but forgot to mention that i need fixed shift between the pulses.how to get fixed delay between the pulses though duty cycle is varying.since i am musing this for MPPT tracking so i need 180 degree plus fixed delay between the pulses 

  • Two synchronous timers in up mode?

    [edit] But as I know, you can't easily synchronize timers on msp430 - at least I have no clue.

    Anyway push-pull and interleaved converters need symmetric pulses but if pulse length is equal, then shift for up/down symmetric PWM mode is equal too. So you can use up/down configuration I suggested first.

  • I do not quite understand your required waveform.180 degree phase shift and a fixed delay?

    I think you need a Timer with at least 3 CC channels and use either up mode or up-down mode. Use CC0 for the common period. Use other CCx for each PWM output. TimerB can also generate 2 PWM with a dead-band in hardware. 

  • old_cow_yellow said:
    I do not quite understand your required waveform.180 degree phase shift and a fixed delay?

    I think, fixed delay for rising edges makes sense in particular (interleaved converter) context.

    So I don't see how your advise to use up mode can work for particular application. I'm curious - please explain

  • I think in up-mode, all six waveforms with phase relation as shown can be generated by OUTMODE  4, 4, 4, 4, 7 and 3 respectively. CC0 can only generate the first two while CCn other than CC0 can generate all six.

  • Neat :)  But honestly I don't see solution for "problem" we are talking about. Waveforms 1 till 4 does not seem to be PWM. And waveforms 5 and 6 does not have fixed time delay between rising edges of PWM pulses equal to timer period (CCR0) as required for interleaved or push-pull converted.

  • Ilmars said:
    But as I know, you can't easily synchronize timers on msp430 - at least I have no clue.

    Not too easy, but possible.

    Stop the timers. Configure them. Set the TAR registers to 0 and x, where x is the delay you need minus the the number of clock cycles needed to start the timer, then start the timers. (with interrupts disabled).

    If done properly, you should get what you want.

    Or you use just one timer and one output signal, and introduce the delay as well as the phase shift by external circuitry (e.g. a cheap chain of inverters)

  • first waveform for 68% duty cycke and 2nd one for 42% duty cycle

  • srinivas nandam said:
    68% duty cycke and 2nd one for 42% duty cycle

    To me both waveforms seems to have more or less equal duty cycles.

  • srinivas nandam said:

    Use Continuous mode timer.

    Well you have 20KHz so if you use a 16MHz clock for your timer, 800 counts would give you an interrupt every 50 usec. And since your phase is 90 degrees you could space another interrupt at 200 counts from the first interrupt. (¼ 360 deg = 90 deg, ¼ 800 counts = 200 counts). In your main () set TA0CCR1 = 0, TA1CCR2 = 200.

    In your interrupt routine split up the 800 counts for the appropriate duty cycle: i.e for 68% duty cycle, pulse needs to be high for 544 clock cycles and low for 256 clock cycles = 800. So one interrupt occurs at 544 counts (pulse is high for 544 counts) and then another interrupt at 256 counts (pulse is low).

    Handle the second pulse which occurs 90 degs later similarly.

    Maybe something like this to handle duty cycle:

    #pragma vector=TIMER0_A0_VECTOR

    __interrupt void Timer0_A(void)

    {

    switch( TA0IV )

    {

    case 2: // CCR1

    {

    If (Pulse1Flg == 0)

    {

    TA0CCR1 += 544; //Make pulse high for 68% duty cycle high time, then interrupt to make it low

    P1OUT |= BIT0;

    Pulse1Flg =1;

    }

    // else

     

    //set the pulse low for 256 counts, toggle Pulse1Flg (so next interrupt will set pulse high)

    break;

    }

    case 4:

    {

    //Handle the second pulse here which should occur 90 deg later

    }

    break;

    case 10: break; // overflow not used

    }

     

  • thank you so much. but how to ensure the second pulse with 90degree delay

  • srinivas nandam said:

    thank you so much. but how to ensure the second pulse with 90degree delay

    In your main () you choose 200 timer counts offset between TA0CCR1 and TA0CCR2 which is 90 degrees.

    The case2: and case4: interrupts to start the pulse going high will occur 200 counts apart.

    First interrupt in case2 @

    TA0CCR1 = 5;

    First interrupt in case4 @

    TA0CCR2 = 205;

    each gets incremented by a total of 800 counts in the interrupt routine.

    I picked 5, 205 rather than 0, 200 because TA0R starts at 0 and will have to overflow before reaching 0 again.

    So case2: occurs every 800 additional counts to set the pulse high TA0R = 5, 805, 1605, …64005, 64805, 70, 870, ...

    And case4: occurs every 800 additional counts to set its pulse high TA0R = 205, 1005, 1805, …64205, 65005, 270, 1070, …

    As long as the time taken to add 800 counts to TA0R in case2 is the same time taken in case4 and as long as interrupts don't delay each other, you should be able to maintain 90 degrees phase.

    Otherwise you'll have to figure out some way to save the TA0R value gotten in case2 to use in case4 to add the 200 counts to constantly maintain 90 degrees separation.

  • HI,

    i written code something like this but i am getting pulses only at BIT4, but i'm not getting any pulse at BIT0

    #include <msp430g2553.h>

    void main()
    {
        WDTCTL = WDTPW + WDTHOLD;
        BCSCTL1 = CALBC1_16MHZ;        // 16 MHz
        DCOCTL  = CALDCO_16MHZ;            // Stop watchdog timer
        P1DIR |= BIT0;                     // Set P1.0 to output direction
        P1OUT &= ~BIT0;                      // Set the red LED on
        TA0CCR0 = 400;                    // Count limit (16 bit)
        TA0CCTL0 = 0x10;                    // Enable counter interrupts, bit 4=1
        TA0CTL = TASSEL_1 + MC_1;     
        P2DIR |= BIT4;
        P2DIR |= BIT2;
        P2SEL |= BIT2;
        P2SEL |= BIT4;
        TA1CCR0 = 1200;
        TA1CCTL2 = OUTMOD_7;
        TA1CCR1 = 600;
        TA1CTL = TASSEL_2+MC_1;
            // Timer A 0 with ACLK @ 12KHz, count UP

        _BIS_SR(LPM0_bits + GIE);               // LPM0 (low power mode) with interrupts enabled
    }

    #pragma vector=TIMER0_A0_VECTOR
       __interrupt void Timer0_A0 (void)
       {        // Timer0 A0 interrupt service routine
        
        TA1CCR2 = 600;
                        // Toggle red LED
    }

    just for checking i interchanged TA1CCR2 and CCR1still i am getting pulses at BIT4 only BIT0 i am not getting . please help me?

**Attention** This is a public forum