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.

MSP-EXP430F5529: Problem with MSP430F5529 Launchpad input capture both edges

Part Number: MSP-EXP430F5529


Hello,

I have been trying to implement this input capture functionality to measure the high time and low time of a continuous 1 Hz square wave with 50% duty cycle. Just to make it simple I started out with this.

I am able to trigger the interrupt on a rising edge. But for some reason, the interrupt won't trigger on a falling edge. Whenever I set CM to input capture both edges, the interrupt would only trigger on a rising edge.

I am using TA0.1. Please help. Below is my code and the ISR

void EnableCaptureTA01(void)
{
    GPIO_setAsPeripheralModuleFunctionInputPin(
                      GPIO_PORT_P1, GPIO_PIN2
                      );

    Timer_A_initContinuousModeParam initContParam = {0};
    initContParam.clockSource = TIMER_A_CLOCKSOURCE_ACLK;
    initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;
    initContParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;
    initContParam.timerClear = TIMER_A_DO_CLEAR;
    Timer_A_initContinuousMode(TIMER_A0_BASE, &initContParam);

    Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_CONTINUOUS_MODE);
    Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);

    Timer_A_initCaptureModeParam initCapParam = {0};
    initCapParam.captureRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;
    initCapParam.captureMode = TIMER_A_CAPTUREMODE_RISING_AND_FALLING_EDGE;
    initCapParam.captureInputSelect = TIMER_A_CAPTURE_INPUTSELECT_CCIxA;
    initCapParam.synchronizeCaptureSource = TIMER_A_CAPTURE_SYNCHRONOUS;
    initCapParam.captureInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;
    initCapParam.captureOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE;
    Timer_A_initCaptureMode(TIMER_A0_BASE, &initCapParam);
}//end void EnableCaptureTA01(void)


void TIMERA0ISR (void)
{
    uint8_t integerArray[10];
    //uint8_t integerArray[10];
    //Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
    switch(__even_in_range(TA0IV,0x0E))
    {
        case 0x0: break;
        case 0x2:
            Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
                GPIO_toggleOutputOnPin(GPIO_PORT_P4, GPIO_PIN7);

                Edge= Timer_A_getCaptureCompareCount(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1);
                UINT32ToASCII(Edge, integerArray);
                WriteUARTA1("\n\rEdge = ");
                WriteUARTA1(integerArray);


                Time = (double)(Edge- PreviousEdge);
                if(Time < 0)
                {
                    Time = Time + 65535;
                }

                Time = (Time + 1) / ACLKValue;
                DoubleToASCII(Time, 3, integerArray);
                WriteUARTA1("\n\rTime = ");
                WriteUARTA1(integerArray);

                PreviousEdge = Edge;

                if(TIMER_A_CAPTURE_OVERFLOW == Timer_A_getCaptureCompareInterruptStatus
                    (TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, TIMER_A_CAPTURE_OVERFLOW ))
                {
                    WriteUARTA1("\n\rOverflow occurred ");
                }
            break;
        case 0x4: break;
        case 0x6: break;
        case 0x8: break;
        case 0xA: break;
        case 0xC: break;
        default:  break;
    }//end switch(__even_in_range(TA0IV,0x0E))

}//end void TIMERA0ISR (void)

Here is the output from my terminal. Since the squarewave is 1 HZ, and I have set the capture to both edges, I'd expect a .5 sec high and .5 sec low time. But I'm just getting the entire period

because the interrupt triggers only on the rising edge. Am I missing anything? Thanks a lot

Edge = 14264
Time = 1.000
Edge = 47033
Time = 1.000
Edge = 14267
Time = 1.000
Edge = 47036
Time = 1.000
Edge = 14268
Time = 1.000
Edge = 47038
Time = 1.000
Edge = 14271
Time = 1.000
Edge = 47040
Time = 1.000
Edge = 14272
Time = 1.000
Edge = 47041
Time = 1.000

AJ 

  • Just additional info, whenever I set the capture to occur on falling edge, for some reason, the interrupt still gets triggered on a rising edge. It's weird why it's happening that way
  • Here is an update, it looks like I might have figured out the solution, but I am not entirely convinced yet. I added a 1K pull up resistor to TA0.1 pin. Now I am getting the result below, which is what I was expecting. But I've got a few questions. Why is there a need to add a pull up resistor? I was under the impression that there is an internal pull up once we've configured the pins for capture. Also, I noticed that sometimes connecting the scope probe would make it unstable if the capture edge is set to either falling edge or both edges. Seems like the falling edge is problematic. Any thoughts on this matter? And is the 1K pull up good enough?

    Thanks.


    AJ

    Edge = 13011
    Time = 0.498
    Edge = 29440
    Time = 0.501
    Edge = 45779
    Time = 0.498
    Edge = 62209
    Time = 0.501
    Edge = 13012
    Time = 0.498
    Edge = 29443
    Time = 0.501
    Edge = 45782
    Time = 0.498
    Edge = 62210
    Time = 0.501
    Edge = 13014
    Time = 0.498
    Edge = 29444
    Time = 0.501
  • By the way, if anyone wants to replicate the problem a I had in the beginning, just connect a wire to TA0.1 and and also GND then clip the function generator and a scope leads to those wires and no pull up resistor. With that set up, the capture interrupt is triggered only on the rising edge even if I have set it to falling edge or both edges.
  • The F5529 has pull-up and pull-down resistors on all pins. It cannot know which one you want, so you have to configure them explicitly.

    The optimal value of the pull-up resistor depends on how fast the signals are that you want to capture, and how much power you can afford to use. In your case, neither one is a concern; anything between a few hundred ohms and a few hundred kiloohms would be fine.
  • I looked at an example program for timer d for both edges under the mspware430 driverlib examples but I did not see anything line there that enabled pull ups or pull downs. It was just the function to configure the pin for alternate purpose which is capture in this case. I thought by configuring it for alternate function, the pull ups were already part of that. And I was under the impression that manually enabling pull ups or pull downs by was for gpio use. Could you please clarify this matter? Thanks

    AJ

  • Section 6.10.1 of the datasheet shows that the pull-up resistor is enabled only if P1REN.x is set. (Pull-up resistors are never enabled automatically.)

    The driverlib does not have a function to enable a pullup for a module pin, so call GPIO_setAsInputPinWithPullUpResistor() before GPIO_setAsPeripheralModuleFunctionInputPin().

**Attention** This is a public forum