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: Can't get the timers to function using LaunchPad on 2020 code that worked before

Part Number: MSP430G2553
Other Parts Discussed in Thread: MSP430G2231

Tool/software:

I have 4 products using the  MSP430G2231 and MSP430G2553. I am working on a third using the timers that are critical to my company.

I wrote this short code to create a PWM waveforms from 3 pins of the MSP430G2553. The last time I ran it was in 2002 using  Code Composer Ver10   10.1.1.00004  under windows 10.

The code ran great then. I recently attempted to try and toggle P1.2 using the timer on a MSP430G2231 and nothing happens. I can toggle the ports using while loops. But anything with the timer does not work. So I went back to the G2553 code and it doesn't work now.

I have tried debugging the issue see below.

  1. I tried using the same Launchpad on a different computer, No PWM
  2. I reverted back to the version 10.1.1 Code composer software, No PWM
  3. used a new out of the box Launchpad with a new G2553, No PWM

Please see the code below and the device settings of the G2553 on the launchpad.

// TA0CCR0  /* Timer A0 Capture/Compare 0 */
// TA0CCR1  /* Timer A0 Capture/Compare 1 */
// TA0CCR2  /* Timer A0 Capture/Compare 2 */

// TA1CCR0  /* Timer A1 Capture/Compare 0 */
// TA1CCR1  /* Timer A1 Capture/Compare 1 */
// TA1CCR2  /* Timer A1 Capture/Compare 2 */

// P2.2   Timer A1   CCR1  Out1
// P2.4   Timer A1   CCR1  Out2

// P1.2   Timer A0   CCR0  Out1

/**********************************************/





#include <msp430.h>


int main(void)
{
 


              P1DIR |= BIT2;                      // P1.2 output
              P1SEL |= BIT2;                      // P1.2 options select
              P2DIR = 0x14;                       // Set P2.2 and P2.4 to the output direction.
              P2SEL = 0x14;                       // Select P2.2 and P2.4  as our PWM output.



              TA1CCR0 = 1000-1;                   // PWM Period
              TA1CCTL1 = OUTMOD_7;                // CCR1 reset/set
              TA1CCR1 = 0;                        // P2.2 PWM duty cycle  
              TA1CCTL2 = OUTMOD_7;
              TA1CCR2 = 0;                        // P2.4 PWM duty cycle (500 = 50%)  
              TA1CTL = TASSEL_2 + MC_1 + TACLR;   // SMCLK, up mode, clear TAR

              P1DIR |= BIT2;                      // P1.2 output
              P1SEL |= BIT2;                      // P1.2 options select

              TA0CCR0 = 1000-1;                   // PWM Period    
              TA0CCTL1 = OUTMOD_7;                // CCR0 reset/set
              TA0CCR1 = 1000;                     // P1.2  PWM duty cycle
              TA0CTL = TASSEL_2 + MC_1 + TACLR;   // SMCLK, up mode, clear TAR

             // __bis_SR_register(LPM0_bits);     // Enter LPM0
             //  __no_operation();                  // For debugger


}

 

 

 

 

 

 

 

 

  • 1) I don't see where you turn off the Watchdog. Make sure this appears at the beginning of main():

    >  WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

    2) It looks like the LPM0 line has been removed, so main() returns, which may or may not be benign. Try uncommenting that line.

    [Edit: 3) Don't forget to remove the RXD jumper from J101.]

  • Thanks Bruce,

    I didn't cut and paste that line for some reason. I've been writing MSP430 code for 10 years using mostly loops and interrupts. I wrote this PWM code in 2020 and it functioned great. 

  • Does it need to be in low power mode to PWM? My application doesn't care about power consumption it powered by a car battery. 

  •               TA0CCR0 = 1000-1;                   // PWM Period    
                  TA0CCTL1 = OUTMOD_7;                // CCR0 reset/set
                  TA0CCR1 = 1000;                     // P1.2  PWM duty cycle
                  
    It is kind of important that CCR1 be somewhere between zero and CCR0.

  • Thanks David , where did you get that conclusion? I haven't read that anywhere . Can you point to some text that states that. 

    Can anyone add in the watchdog timer code and try this code. Let me know what happens. Can you reply with window's version and code composer version. I would really appreciate it.

  • David you're correct about the TACCR0 and TACCR1. Why does the other outputs not function?

  • Thanks David , where did you get that conclusion? I haven't read that anywhere . Can you point to some text that states that. 

    It is right there in the guide that describes the up mode and the operation of the output units. Nothing complicated.

  • Do you mean TA1?

    The documentation of the output unit says that the output will be reset when the timer counts to CCRx. But does the counter resetting to zero qualify as counting to?

    Off by one errors are a constant irritant. :-)

  • Hi Randy,
    Did any of the suggestions help you out in finding the solution to your issue?

    Best Regards,

    Diego Abad

  • Hi Randy,
    Did any of the suggestions help you out in finding the solution to your issue?

    Best Regards,

    Diego Abad

  • Diego,

    None of the suggestions was the answer. I went back and loaded some simple Timer examples. It partially works. I can only get the PWM to work is by pressing the resume button in debug mode. It want work at power up like the simple timer examples.

  • The code that gets  loaded in will stay in an infinite loop then should work fine. I will try that later.

  • Which code are you referring to? Now I'm not sure what the test case is.

    When I tried this last night (CCS 12.6, G2ET Launchpad, RXD/TXD jumpers removed), I got (1) constant high on P1.2 and (2) constant low on P2.2/P2.4.

    As David pointed out, this matches with what the (posted) code requests. (I added the WDT line back in.)

    When I changed all the CCR1/CCR2-s to 500, I got 1.04kHz, 50% duty cycle on all 3 pins. The program ends up spinning in abort() after returning from main().

    [Edit: Minor clarification.]

  • I didn't remove any jumpers. Look at my post about the debug mode

  • Apparently my Launch Pad is not working correctly . I can't get the code to run unless I press resume. See the TI sample code below.

    //******************************************************************************
    //  MSP430G2xx3 Demo - Timer_A, Toggle P1.0, CCR0 Cont. Mode ISR, DCO SMCLK
    //
    //  Description: Toggle P1.0 using software and TA_0 ISR. Toggles every
    //  50000 SMCLK cycles. SMCLK provides clock source for TACLK.
    //  During the TA_0 ISR, P1.0 is toggled and 50000 clock cycles are added to
    //  CCR0. TA_0 ISR is triggered every 50000 cycles. CPU is normally off and
    //  used only during TA_ISR.
    //  ACLK = n/a, MCLK = SMCLK = TACLK = default DCO
    //
    //           MSP430G2xx3
    //         ---------------
    //     /|\|            XIN|-
    //      | |               |
    //      --|RST        XOUT|-
    //        |               |
    //        |           P1.0|-->LED
    //
    //  D. Dang
    //  Texas Instruments Inc.
    //  December 2010
    //   Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
    //******************************************************************************

    #include <msp430.h>

    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT



       P1DIR |= 0x0C;                            // P1.2 and P1.3 output
       P1SEL |= 0x0C;                            // P1.2 and P1.3 TA1/2 options
       CCR0 = 512-1;                             // PWM Period
       CCTL1 = OUTMOD_7;                         // CCR1 reset/set
       CCR1 = 384;                               // CCR1 PWM duty cycle
       TACTL = TASSEL_1 + MC_1;                  // ACLK, up mode

     //  __bis_SR_register(LPM3_bits);             // Enter LPM3


    }

  • Bruce, I went back and tried the first code I posted it works. Even when I stop the debugger. It looks like the original problem was caused because I did not follow through with the complete flash process. I just stepped through the code and stopped. With this code I have press resume to finish flashing the chip. As for what's going on with the last code I posted. Your guess is probably better than mine. Thanks for your input.

  • Hi Randy,
    Glad to hear it worked. I'll be closing this thread. 

    Best Regards,

    Diego Abad

**Attention** This is a public forum