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/CC3220S: Using Multiple capture compare pins (one works other skips one edge)

Part Number: CC3220S


Tool/software: Code Composer Studio

I am using on board capture compare pins 4 and 5. I am initializing 4 first then 5. So the one that is started 2nd works properly(gives me interval between rising then falling edge) but the one that is started 1st skips the first rising edge(as a result gives me interval between falling and rising edge of two different pulses)

Capture_ANY_EDGE is used in both (I am using capture modules to detect the pulse given out by an ultrasonic sensor after its is triggered) 

    Capture_Params_init(&captureParams1);
    captureParams1.mode = Capture_ANY_EDGE;
    captureParams1.periodUnit = Capture_PERIOD_US;
    captureParams1.callbackFxn = captureCallback1;
           
    Capture_Params_init(&captureParams2);
    captureParams2.mode = Capture_ANY_EDGE;
    captureParams2.periodUnit = Capture_PERIOD_US;
    captureParams2.callbackFxn = captureCallback2;

    capture1 = Capture_open(Board_CAPTURE0, &captureParams1);           //setting up the capture pin (Echo pin ----> pin 04)
    if (capture1 == NULL)                                               //Board_CAPTURE0 ----> pin 04  on launchpad
    {
       Display_printf(display, 0, 0, "Failed to initialized Capture!\n");
       while(1);
    }


    capture2 = Capture_open(Board_CAPTURE1, &captureParams2);           //setting up the capture pin (Echo pin ----> pin 05)
    if (capture2 == NULL)                                               //Board_CAPTURE1 ----> pin 05  on launchpad
    {
        Display_printf(display, 0, 0, "Failed to initialized Capture!\n");
        while(1);
    }


    if(Capture_start(capture1)==Capture_STATUS_ERROR)
       {
           Display_printf(display, 0, 0, "Failed to start capture!\n");
       }

    if(Capture_start(capture2)==Capture_STATUS_ERROR)
    {
        Display_printf(display, 0, 0, "Failed to start capture!\n");
    }
 while(1)
    {
        /*
         **************************************************************************************************
         **************************************     Ultrasonic 1    ***************************************
         **************************************************************************************************
        */

        GPIO_write(4,1);                                                 //pin 64 ----> HIGH
        usleep(10);                                                       //delay in microseconds to trigger the ultrasonic sensor(10us as per datasheet)
        GPIO_write(4,0);                                                 //pin 64 ----> LOW

                                                                         //starts capture instance
        SemaphoreP_pend(captureSem1, SemaphoreP_WAIT_FOREVER);
        distance1 = (float)curInterval1/58;

        a = distance1;                                                    //converting 4 decimal place float to 2 decimal place without rounding off
        b = distance1*100.0f;                                             //using this approach as the build in 0.2f style formating is not working
        b = b-(a*100);
        if(b<0)
        {
            b*=-1;
        }
         **************************************************************************************************
         **************************************     Ultrasonic 2    ***************************************
         **************************************************************************************************
        */


        GPIO_write(1,1);                                                 //pin 15 ----> HIGH
        usleep(10);                                                      //delay in microseconds to trigger the ultrasonic sensor(10us as per datasheet)
        GPIO_write(1,0);                                                 //pin 15 ----> LOW

                                                                         //starts capture instance
        SemaphoreP_pend(captureSem2, SemaphoreP_WAIT_FOREVER);
        distance2 = (float)curInterval2/58;

        c = distance2;                                                    //converting 4 decimal place float to 2 decimal place without rounding off
        d = distance2*100.0f;                                             //using this approach as the build in 0.2f style formating is not working
        d = d-(c*100);
        if(d<0)
        {
            d*=-1;
        }

        Display_printf(display, 0, 0,"%f   %f  %lu",distance1,distance2,time1);
        usleep(250000);

In the above code distance 2 is correct but distance 1 is not (in fact the interval is the time of usleep-->250ms) as it is the time between falling ans rising edge of the pulse given by the ultrasonic sensor.

Inverting the Capture_start() function call makes distance 1 to be right and 2 to skip the rising edge