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.

CCS/MSP430F5529: Timer_A1 not working properly with exernal clock source (P1.6)

Part Number: MSP430F5529
Other Parts Discussed in Thread: MSP-EXP430F5529LP,

Tool/software: Code Composer Studio

I am programming MSP-EXP430F5529LP (LaunchPad) with 2 timers (Timer_A0 and Timer_A1) with the following condition:

Timer_A0: Internal clock (ACLK), Up mode, Capture/Compare interrupt enabled, Timer Interrupt disabled

Timer_A1: External clock (P1.6), interrupt disable, Continuous mode

Timer_A0 is working properly (generating interrupt accordingly).

Timer_A1: I have a problem. I connect P1.6 floating, ground and VCC, and counter still running under those 3 condition(float, GND, VCC), which mean when I read TA1R (Timer counter register), I get different value. It should be counting only when I place P1.6 to a signal, the reading should return zero if P1.6 is grounded.

Is there is misunderstanding from me in the way those timers should work ? Below is a summary of the code been used to initialize the device. Any help is welcome.

    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6);  // TA1CLK

    Timer_A_initUpModeParam gTimerA0params = {0};

    Timer_A_initContinuousModeParam gTimerA1params = {0};

    // Timer_A0 
    gTimerA0params.clockSource                                                      = TIMER_A_CLOCKSOURCE_ACLK;                    // Use ACLK as timer internal clock
    gTimerA0params.clockSourceDivider                                           = TIMER_A_CLOCKSOURCE_DIVIDER_1;          // Divide clock frequency by 1
    gTimerA0params.timerInterruptEnable_TAIE                                = TIMER_A_TAIE_INTERRUPT_DISABLE;           // Timer interrupt disabled in TAxCTL Reg
    gTimerA0params.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;  // Capture-Compare interrupt enabled in TAxCCTL0 Reg
    gTimerA0params.timerClear                                                          = TIMER_A_DO_CLEAR;                                       // Clear time counter TAxR Reg
    gTimerA0params.startTimer                                                           = false;                                                                    // Do not start timer yet.
    gTimerA0params.timerPeriod                                                         = 500;                                                                     // Set timer period

    // Clear pending interrupt (Clear flag TAIFG in TAxCTL Reg)
    Timer_A_clearTimerInterrupt(TIMER_A0_BASE);
    // Initialize TimerA0 with previous parameters
    Timer_A_initUpMode(TIMER_A0_BASE, &gTimerA0params);
    // *** Init TimerA1 ***
    gTimerA1params.clockSource                             = TIMER_A_CLOCKSOURCE_EXTERNAL_TXCLK;       // Use P1.6 as external clock source
    gTimerA1params.clockSourceDivider                  = TIMER_A_CLOCKSOURCE_DIVIDER_1;                     // Divide clock frequency by 1
    gTimerA1params.timerInterruptEnable_TAIE      = TIMER_A_TAIE_INTERRUPT_DISABLE;                      // Timer interrupt disabled in TAxCTL Reg
    gTimerA1params.timerClear                                = TIMER_A_DO_CLEAR;                                                 // Clear time counter TAxR Reg
    gTimerA1params.startTimer                                = false;                                                                               // Do not start timer yet.
    // Initialize TimerA1
    Timer_A_initContinuousMode(TIMER_A1_BASE, &gTimerA1params);
Thanks,
Francisco Cruz
  • I wrapped your code and ran it on an F5529 Launchpad, but I don't see the behavior you describe. I put a square wave at TA0 frequency out on P1.2, and patched it to P1.6, and TA1 counts correctly. If I connect P1.6 to GND, it doesn't count. 

    I'm not sure what we're doing differently.

    For reference (I compared TA0CNT0 with TA1R):

    #include "driverlib.h"
    int main(void)
    {
        WDT_A_hold(WDT_A_BASE);
        GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1, GPIO_PIN6); // TA1CLK
    
        Timer_A_initUpModeParam gTimerA0params = { 0 };
        Timer_A_initContinuousModeParam gTimerA1params = { 0 };
    
        // Timer_A0
        gTimerA0params.clockSource = TIMER_A_CLOCKSOURCE_ACLK; // Use ACLK as timer internal clock
        gTimerA0params.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; // Divide clock frequency by 1
        gTimerA0params.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; // Timer interrupt disabled in TAxCTL Reg
        gTimerA0params.captureCompareInterruptEnable_CCR0_CCIE =
                TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE; // Capture-Compare interrupt enabled in TAxCCTL0 Reg
        gTimerA0params.timerClear = TIMER_A_DO_CLEAR; // Clear time counter TAxR Reg
        gTimerA0params.startTimer = false;                // Do not start timer yet.
        gTimerA0params.timerPeriod = 500;                        // Set timer period
        // Clear pending interrupt (Clear flag TAIFG in TAxCTL Reg)
        Timer_A_clearTimerInterrupt(TIMER_A0_BASE);
        // Initialize TimerA0 with previous parameters
        Timer_A_initUpMode(TIMER_A0_BASE, &gTimerA0params);
    
        // *** Init TimerA1 ***
        gTimerA1params.clockSource = TIMER_A_CLOCKSOURCE_EXTERNAL_TXCLK; // Use P1.6 as external clock source
        gTimerA1params.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; // Divide clock frequency by 1
        gTimerA1params.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; // Timer interrupt disabled in TAxCTL Reg
        gTimerA1params.timerClear = TIMER_A_DO_CLEAR; // Clear time counter TAxR Reg
        gTimerA1params.startTimer = false;                // Do not start timer yet.
        // Initialize TimerA1
        Timer_A_initContinuousMode(TIMER_A1_BASE, &gTimerA1params);
    
        //  Make something for TA1 to count
        //  Jumper P1.2 to P1.6 to see it count
        TA0CCR1 = TA0CCR0/2;      // 50% duty for no real reason
        TA0CCTL1 = OUTMOD_7;      // Reset/Set gives square wave
        P1SEL |= BIT2;            // Output TA0.1 on P1.2 per SLAS590N Table 6-46
        P1DIR |= BIT2;
    
        Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_UP_MODE);
        Timer_A_startCounter(TIMER_A1_BASE, TIMER_A_CONTINUOUS_MODE);
        __enable_interrupt();
        LPM0;                     // Sleep forever
        return (0);
    }
    unsigned TA0CNT0;
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void TA0_CCR0_ISR(void)
    {
        ++TA0CNT0;
        return;
    }
    

  • Hi Francisco,

        I also tested your code on MSP430F5529LP Launchpad , did not make any changes, everything working properly, When connecting P1.6 to a clock signal, it's normal count, and If I connect P1.6 to GND or floating, it doesn't count. 

    Best Regards,

    Johnson He

  • Bruce,

    Thank you so much for your clarification. I want to be sure that my understanding of the MSP430F5529's timers are correct. After your feedback I went back to my code (which in larger than the one I sent), because I am, also, using USB communication API. The code I placed above is done calling a C function that initialize the timers and then I call API USB_setup(TRUE, TRUE), all of these from main(). When I changed the order of the call, calling first USB_setup() and then timer initialization, then timer started working properly. It looks like calling USB_setup() after the timer initialization was causing this mysterious behavior. I will try to look in details to the USB_setup() API to confirm, and to be sure it is not something else I am doing causing this mysterious behavior.

    Thank you so much for your quick support

  • Shuai,

    After your feedback I went back to my code (which in larger than the one I sent), because I am, also, using USB communication API. In the main function I am calling my function to initialize the timers and then call USB_setup() API. After changing the order of the call, first USB_setup(), then my timer initialization, everything (timers) started working fine.

    Thank you so much for your quick response.

**Attention** This is a public forum