• Resolved

MSP430FR5994: TA0 in EXTERNAL CLOCK PULSE COUNTING MODE

Part Number: MSP430FR5994

-

Board Used: MSP-EXP430FR5994

-

Hi, I am trying to use the Timer A0 in external clock pulse counting mode. I have used the code as presented below. The code seems to work fine if I set the clock source as TIMER_A_CLOCKSOURCE_ACLK. This ensures that the timer configurations are correct.

Now I am trying to map MCU pin 3 (Port 1.2) of the MCU chip to the clock input of the Timer/Counter 0. To achieve this, I have used the function GPIO_setAsPeripheralModuleFunctionInputPin() where the last parameter I have tried all three (GPIO_PRIMARY_MODULE_FUNCTION, GPIO_SECONDARY_MODULE_FUNCTION & GPIO_TERNARY_MODULE_FUNCTION). But none of these options seems to work.

Single stepping the code in debug mode showed no change in TA0R register under TA0 in Register Watch Window. If clock source is selected as ACLK, then I am noticing gradual increase of TA0R register value in debug mode.

To send clock pulses to the MCU pin 3, I have used a jumper wire to connect the P1.2 pin in the board's header. The other end of the jumper wire I was connecting alternately to GND and 3.3V pins of the headers. Can anyone suggest whether there is anything missed out in the code? Or may be I am doing something wrong conceptually.

-

Code:

-

    //  Configure counter

    Timer_A_initContinuousModeParam timerAContiModeCfgParams;

    timerAContiModeCfgParams.clockSource = TIMER_A_CLOCKSOURCE_EXTERNAL_TXCLK;

    timerAContiModeCfgParams.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;

    timerAContiModeCfgParams.startTimer = true;

    timerAContiModeCfgParams.timerClear = TIMER_A_DO_CLEAR;

    timerAContiModeCfgParams.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;

    Timer_A_initContinuousMode(TIMER_A0_BASE,

                               &timerAContiModeCfgParams);

    //  Configure GPIO pin for external CLK input

    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,

                                               GPIO_PIN2,

                                               GPIO_TERNARY_MODULE_FUNCTION);

    //  Test Loop

    while(1)

    {

        counterValue_u16 = Timer_A_getCounterValue(TIMER_A0_BASE);

        if(counterValue_u16 % 2)

        {

            LED_RED_ON;

        }

        else

        {

            LED_RED_OFF;

        }

    }

-

Regards

Soumyajit

Email: mail567@yahoo.co.in

  • I don't see where you

         PM5CTL0 &= ~LOCKLPM5;                   // Engage GPIOs
    

    Also, I'm pretty sure you want the SECONDARY module function (P1SEL=10).

  • In reply to Bruce McKenney47378:

    Hi Bruce,

     Thanks for your reply. Sorry for creating the confusion by not posting the initial codes getting executed. Please see below the initial code. The code does have call to function PMM_unlockLPM5(). Any other suggestions from your side regarding what else might be going wrong?

    -

    #define INPUT_SWITCH_TO_LED_BLINK_TEST 0

    #define LPM_WAKEUP_BY_INTERRUPT_TEST 0

    #define CPU_WAKEUP_BY_RTC 0

    #define VLO_MODE 0

    #define LFXT_MODE 0

    #define PULSE_COUNTING_IN_LPM3_MODE 1

    #define FRAM_DATA_RETENTION_TEST 0

    #define LED_RED_OFF     GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0);

    #define LED_RED_ON      GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0);

    #define LED_GREEN_OFF     GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN1);

    #define LED_GREEN_ON      GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN1);

    #define DELAY_HIGH(i) for(i=100000; i>0; i--)

    #define DELAY_MEDIUM(i) for(i=20000; i>0; i--)

    #define DELAY_LOW(i) for(i=10000; i>0; i--)

    #define DELAY_VERY_LOW(i) for(i=1000; i>0; i--)

    #define DELAY_VERY_VERY_LOW(i) for(i=100; i>0; i--)

    #define DELAY_VERY_VERY_VERY_LOW(i) for(i=10; i>0; i--)

    int main(void)

    {

       volatile uint32_t i, j;

    #if(PULSE_COUNTING_IN_LPM3_MODE)

       uint16_t counterValue_u16 = 0;

    #endif

       // Stop watchdog timer

       WDT_A_hold(WDT_A_BASE);

       // Set P1.0 to output direction

       GPIO_setAsOutputPin(

           GPIO_PORT_P1,

           GPIO_PIN0

           );

       // Set P1.1 to output direction

       GPIO_setAsOutputPin(

           GPIO_PORT_P1,

           GPIO_PIN1

           );

       //  SW2 Config

       GPIO_setAsInputPinWithPullUpResistor(

               GPIO_PORT_P5,

               GPIO_PIN5

               );

       //  SW1 Config

       GPIO_setAsInputPinWithPullUpResistor(

               GPIO_PORT_P5,

               GPIO_PIN6

               );

       // Disable the GPIO power-on default high-impedance mode

       // to activate previously configured port settings

       PMM_unlockLPM5();

       //  RED LED ON

       LED_RED_ON;

       DELAY_LOW(i);

       //  RED LED OFF

       LED_RED_OFF;

       for(j = 0; j < 5; j++)

       {

           LED_GREEN_ON;

           DELAY_VERY_LOW(i);

           LED_GREEN_OFF;

           DELAY_LOW(i);

       }

       //  GREEN LED ON

       LED_GREEN_ON;

       // Delay

    //    for(i=100000; i>0; i--);

       DELAY_HIGH(i);

    #if(PULSE_COUNTING_IN_LPM3_MODE)

       //  Configure counter to external clock pulse source

       Timer_A_initContinuousModeParam timerAContiModeCfgParams;

       timerAContiModeCfgParams.clockSource = TIMER_A_CLOCKSOURCE_EXTERNAL_TXCLK;

       timerAContiModeCfgParams.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;

       timerAContiModeCfgParams.startTimer = true;

       timerAContiModeCfgParams.timerClear = TIMER_A_DO_CLEAR;

       timerAContiModeCfgParams.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;

       Timer_A_initContinuousMode(TIMER_A0_BASE,

                                  &timerAContiModeCfgParams);

       //  Configure GPIO pin for external CLK input

       GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,

                                                  GPIO_PIN2,

                                                  GPIO_SECONDARY_MODULE_FUNCTION);

       //  Test Loop

       while(1)

       {

           counterValue_u16 = Timer_A_getCounterValue(TIMER_A0_BASE);

           if(counterValue_u16 % 2)

           {

               LED_RED_ON;

           }

           else

           {

               LED_RED_OFF;

           }

       }

    #endif

    }

    -

    Thanking You

    -

    Regards

    Soumyajit

    Email: mail567@yahoo.co.in

  • In reply to Soumyajit Das:

    Your timer configuration is fine.

    The problem seems to be in the test case. Moving a patch wire between 3V3 and GND caused erratic counts (often none), and mostly when it was floating, as I was moving it. It may be that the signal conditioning in the timer is doing something.

    I did succeed by patching the P1.2 pin to one of the buttons (the high side pin -- closer to the USB end of the board -- on the bottom of the Launchpad). Since you had the internal pullup set, I got very clean edges and one (occasionally 2 from bounce) TA0R tick for each button push.

    I also succeeded giving it a slightly faster signal by patching P1.2 to P1.3 (TA1.2) and generating a 2Hz signal on TA1.2:

    #define TRIGGER_PERIOD 62500u   // 8*62.5ms -> 2Hz
       P1SEL0 |= BIT3;             // P1.3 as TA1.2
       P1SEL1 &= ~BIT3;            //  per SLASE54B Table 6-21
       P1DIR |= BIT3;
       TA1CCR0 = TRIGGER_PERIOD-1; // Cycle 500000 clocks (2Hz)
       TA1CCR2 = TRIGGER_PERIOD/2; // Halfway for 50% duty cycle
       TA1CCTL2 = OUTMOD_7;        // Reset/Set
       TA1CTL = TASSEL_2 |ID_3 | MC_1 | TACLR; // SMCLK/8, Up [,Clear]

  • In reply to Bruce McKenney47378:

    Hi Bruce,

     I tried the jumper wire from LED RED pin (J7) on the board to the Port P1.2 with the modified code presented below. It worked. Thanks for your suggestions.

    -

    #if(PULSE_COUNTING_MODE)

        //  IMPORTANT:

        //  Connect a jumper wire from LED RED pin of MCU to PORT P1.2

        //  This is done so that ON/OFF pulses from LED RED is fed as pulse input to TA0 CLK input source

        //  Configure counter to external clock pulse source

        Timer_A_initContinuousModeParam timerAContiModeCfgParams;

        timerAContiModeCfgParams.clockSource = TIMER_A_CLOCKSOURCE_EXTERNAL_TXCLK;

        timerAContiModeCfgParams.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;

        timerAContiModeCfgParams.startTimer = true;

        timerAContiModeCfgParams.timerClear = TIMER_A_DO_CLEAR;

        timerAContiModeCfgParams.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;

        Timer_A_initContinuousMode(TIMER_A0_BASE,

                                   &timerAContiModeCfgParams);

        //  Configure GPIO pin for external CLK input

        GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,

                                                   GPIO_PIN2,

                                                   GPIO_SECONDARY_MODULE_FUNCTION);

        uint8_t loopCounter_u8 = 0;

        //  Test Loop

        while(1)

        {

            counterValue_u16 = Timer_A_getCounterValue(TIMER_A0_BASE);

            if(counterValue_u16 % 2)

            {

                LED_GREEN_ON;

            }

            else

            {

                LED_GREEN_OFF;

            }

            if((loopCounter_u8++) % 2)

            {

                LED_RED_ON;

            }

            else

            {

                LED_RED_OFF;

            }

            DELAY_LOW(i);

        }

    #endif

    -

    Regards

    Soumyajit

    Email: mail567@yahoo.co.in