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.

LAUNCHXL-CC1352R1: captured time difference is not accurate for higher frequencies

Part Number: LAUNCHXL-CC1352R1

while (1)
{
// Check if capture is generated
if(interrupt_flag > 0){
if(interrupt_flag == 1){
captureTime_1 = GPTimerCC26XX_getValue(timerHandle); // first capture
}
if(interrupt_flag == 2){
captureTime_2 = GPTimerCC26XX_getValue(timerHandle); // second capture
timeDifference = (65535*overflow + captureTime_2) - captureTime1; // take time difference
printf("Time Difference: %d\n", timeDifference); // debug

// Reset global variables
interrupt_flag = 0;
overflow = 0;
}
GPTimerCC26xx_start(timerHandle); // start timer
}
}
 

void timerCallback(GPTimerCC26XX_Handle timerHandle, int_fast16_t status){
overflow++; // update overflow
}

void gpioInterruptHandler(uint_least8_t index){
interrupt_flag++; // update interrupt_flag
GPTimerCC26xx_stop(timerHandle); // stop timer
}
Here is the code implementation for input capture by accessing the current value of the timer using the built-in library, GPTimerCC26xx.h. The usual configuration is used for GPIO using the GPIO.h library. Unfortunately, this implementation provides inaccurate captures leading to erroneous time difference. Is there a limitation to the header function used? 

Thank you! 
  • Hi cvfab, 

    What is the error you see? You may benefit from using semaphores or events.  It seems that if there are cases like 2 GPIO interrupts, it is not handled correctly. And your starting and stopping the timer logic may go out of sync if that is the case. 

    Regards,

    Sid