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.

alternating pwm on msp430g2231

Other Parts Discussed in Thread: MSP430G2231, MSP430G2553

Hi

I am trying to drive a CFL lamp with alternating pwm's. It seems that it is almost impossible to generate two alternating pwm's on msp430g2231 as CCTL0 does not work properly with any of the ports. Can some one help me out on this. I am desperately in need of help as I am nearing some deadlines. I would really appreciate it.

Thanks in advance.

  • You said:"CCTL0 does not work properly". In what way?

    Is that in the Errata? Or, did you find an UN-documented bug?

  • I meant I cannot use it to toggle the outputs of any of the ports. and with the use of CCTL1 I am able to toggle only the ports1.2 and 1.6 but not in an alternating manner. Does anyone have the code for this?.

  • Pritam Kalaimani said:

    I meant I cannot use it to toggle the outputs of any of the ports. and with the use of CCTL1 I am able to toggle only the ports1.2 and 1.6 but not in an alternating manner. Does anyone have the code for this?.

    You can also toggle port 1.1 and/or 1.5 in addition to what you did with port 1.2 and/or 1.6. You can make 1.1 and/or 1.5 to have a different phase (including but not limited to 180 degrees) as compared with that of 1.2 and/or 1.6.

    Is that what you are after?

  • Hi 

    Thank you for your reply. Yes that is pretty much what I am looking for. It would be great if u could post the method/code for getting the alternating PWM's from P1.1 and P1.5 . It would be very helpful.

    Thanks.

  • #include <msp430.h>

    void main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;
      P1SEL = BIT6 | BIT5 | BIT2 | BIT1;
      P1DIR = BIT6 | BIT5 | BIT2 | BIT1;

      TACCR0 = 999;            // period - 1
      TACCR1 = 999;            // same

      TACCTL0 = 0;             // initially low
      TACCTL1 = OUT;           // opposite

      TACCTL0 = OUTMOD_4;      // toggle
      TACCTL1 = OUTMOD_4;      // same

      TACTL = TASSEL_2 | MC_1; // up-mode

      while (1);
    }

  • Hi 

    Thank you so much for the code. It is working fine. I have another problem though. I need to have some control over the dead time. I find that by varying the value of TACCR1 the phase of the PWM's change. How do I control the dead time. Can u help me on this as well. Thanks in advance.

  • The Timer in G2231 cannot do that without CPU assists. If the toggle frequency is slow, CPU may be able to help.

    What is the required toggle frequency?

  • well I need to initially generate the PWM's at 50KHz for a few seconds and then bring it down to 25KHz. .

  • @ old_cow_yellow

    Thank you for all the help so far. but can you also please post on how to get control of the dead time. Please, its kinda urgent. 

  • #include <msp430.h>

    void main(void)
    {
      WDTCTL = WDTPW | WDTHOLD;

      P1SEL = BIT6 | BIT5;
      P1DIR = BIT6 | BIT5;
     
      TACCR0 = 10;
      TACCR1 = 10-1;

      TACCTL0 = OUTMOD_1 | CCIE;

      TACTL = TASSEL_2 | MC_2;

      __bis_SR_register(GIE);
        
      while (1);
    }

    #pragma vector = TIMERA0_VECTOR
    __interrupt void Timer1_A0_ISR(void)
    {
      TACCR0 += 99;
      TACCTL0 = OUTMOD_5;
      TACCR1 += 101;
      TACCTL1 = OUTMOD_1 | CCIE;
    }

    #pragma vector = TIMERA1_VECTOR
    __interrupt void Timer1_A1_ISR(void)
    {
      if(TAIV == 2)
      {
        TACCR1 += 99;
        TACCTL1 = OUTMOD_5;
        TACCR0 += 101;
        TACCTL0 = OUTMOD_1 | CCIE;
      }
    }

  • Hi OCY

    Thank you for your post. I am looking to achieve results something like the pictures that I have attached. In your program by varying what I will be able to achieve this. Also can you please give a brief explanation of your code. 

     Thanks in advance.

  • Something like that can be done by using the time in up/down mode and use toggle/set and toggle/reset for the PWMs.

    Example:
    TAR=0 is at the middle line of your screenshot, TAR=CCR0= 100 is at the second one to the right.
    Blue runs in toggle/reset mode, so it resets on TAR=0, gets toggled (on) on TAR = TACCR1 = 60, 80 ticks later, when counting down from 100, it is toggled again (off) on 60, and when the timer reaches 0 it is reset (stays off).

    Yellow runs in toggle/set mode. It is set on TAR=0, gets toggled (off) on TAR = TACCR2 = 30, stays there for 70 ticks up and another r70 ticks down, gets toggled on again on 30 and stays set on 0. Exactly your signal (except for the absolute values)

    On the first cycle, the outputs may be reversed (depending on the initial values), which is corrected on the next TAR->0. But you may as well initialize them manually (setting the OUT bit while in OUTMOD_0)

  • Pritam,

    JMG’s method would work too. But my Apr 16 code is generating “something like the picture”. Both waveforms are 99 cycles high and 101 cycles low with a dead-band of 1 cycle between the two waveforms.

    -- OCY

  • Hi OCY 

    Thanks for your reply, this was a picture taken from that of a different microcontroller (MSP430g2553). However, the code that u have given also produces similar results but i'm not able to vary the frequency. Is it possible to post the code where varying the frequency will be possible. I would be really greatful.

    Thanks in advance.

    Regards

    Pritam

     

**Attention** This is a public forum