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.

MSP430G2553 PWM not generated at P2.4 (Out2)

Other Parts Discussed in Thread: MSP430G2553

Hi,

It's kind of shame to ask a question like this, but I don't see any errors, so it must be a very basic one: I am trying to have PWM signal at P2.4 of MSP430g2553 (Launchpad), and I have erratic behaviour (by 'erratic' I mean I can't even figure out a system in my readings). So I just clipped everything down to a single main() function and yet the PWM is not genereated at all (in IAR):

void main()

{   WDTCTL = WDTPW + WDTHOLD;

// DCO();  

float duty  = 0.25;

P2DIR |= BIT4; // output direction 

P2SEL |= BIT4; // select C&C module

// timer A: clocked from SMCLK + continuos count to TBCL0                

TA1CTL = TASSEL_2 + MC_1; 

// compare mode +  CCI0B input ? + syncronous count + compare mode + set/reset mode 

TA1CCTL2 = OUTMOD_3;

TA1CCR0 = 1000;

TA1CCR2 = TA1CCR0 * (1 - duty);              

}

I do not have a scope, but there's an LED connected as well as I have a multimeter and suppose to see RMS voltage proportional to my duty cycle. Again, I am trying to use P2.4 and DCO (I commented explicit DCO parameters setting as to my understanding I should have it running by default after power-up). So, what's wrong here? Thanks.

  • Try these values:
    TA1CCR0 = 65000;
    TA1CCR2 = 32500;

    Here is how I do it with P1.6 set as TA0.1

    #define TA0second (unsigned int) 1024      // 1024 when aclk div8 and timmer div4  (tick:0.977ms)
    #define read &
    #define clear &= ~
    #define set |=
    #define toggle ^=
    #define ActivePull(y,x)  (P1 ##x y BIT6)  // my super cool macro
    
    int main( void )
    {  
    WDTCTL = WDTPW + WDTHOLD;			   // Stop watchdog timer 
    BCSCTL1 |= DIVA_3;					   // add the div the ALCK by 8 (saves power)
    BCSCTL3 |= XCAP_3;				       // 12.5pF 32K crystal
    
    ActivePull(set,SEL);
    ActivePull(set,DIR);
    
    TA0CTL = TACLR;
    TA0CCR0 = TA0second/8 -1;              // Set Timer to 8Hz
    TA0CCR1 = 2;                           // 2ms low pulse
    TA0CCTL1 = OUTMOD_3;                   // TA0.1 pin PWM set/reset
    TA0CTL = TASSEL_1 + MC_1 + ID_2;       // ACLK source, up to ccr0, input divider /4
    ...

  • I have a few comments about the original code by Maxim Boiko in reference to Tony's code.

    (1) Tony did not use floating point. The original code from Maxim uses floating point to calculate 1000 * (1 - 0.25). There is nothing wrong with using floating point other than its is inefficient both in code size and CPU cycles. But isn't the result obviously 750? If not obvious, one could use a calculator, search the internet, or ask for help ;)

    (2) Tony's line #17 to #21 are setting up all the Timer settings before starting that Timer. The original code from Maxim stated the Timer before any Timer setup. This opens the possibility that the Timer start to do strange things before it does what the setup says.

    (3) Tony's line #22 is "..." -- meaning there are other lines following line #21. The original code from Maxim did not have that, and ended with a "}". This will let the CPU run to the end of road -- so the speak.
  • Hi Maxim!

    Beside from the already mentioned things: You do not set the controller to a low power mode, so adding a

    while( 1 );

    loop inside your main function wouldn't be a bad idea to prevent the program from running into it's end. Anyway, since you are using the hardware PWM, this might work here and it does! I tested your code as it is and there is a PWM output at P2.4:

    Dennis

    Edit:

    I just saw that OCY mentioned the problem with an ending program in his last comment:

    old_cow_yellow said:
    (3) Tony's line #22 is "..." -- meaning there are other lines following line #21. The original code from Maxim did not have that, and ended with a "}". This will let the CPU run to the end of road -- so the speak.

  • Hi,

    Could you solve your problem?

    I was looking for a way to put out the PWM output of TA0.2 in the MSP430G2553 launchpad and it seems that there is not a direct output (like there is for TA0.0 and TA0.1). The pin P2.4 is the output for TA1.2 (Timer1_A and not for Timer0_A as your code uses). I'm I wrong?

    Cheers

  • Hi Maxim,

    My first suggestion would be to remove the floating point altogether. You really shouldn't be using floating point on the G2553 because it simply does not have the memory (flash) or RAM required to do such calculations. I suspect your problem is related to that because when you calculate TA1CCR2 you are subtracting a floating point 0.25 (float) from 1 (integer by default) which always results in 1. To confirm this, please try hardcoding TA1CCR2 to 500 and see if you get a reasonable output from the PWM. If it works, then we know that is the problem and you can scale your calculations accordingly.

  • Hi Joao!

    Joao C. Martins said:
    I was looking for a way to put out the PWM output of TA0.2 in the MSP430G2553 launchpad and it seems that there is not a direct output (like there is for TA0.0 and TA0.1)

    This is correct for the 20 pin version of the MSP430G2553. Only the 28 pin version has TA0.2 routed to pins:

    But this device is not available for the MSP-EXP430G2 LaunchPad, of course.

    Dennis

**Attention** This is a public forum