Is This code correct for interfacing ultra-sonic sensor into i.mx93 (cortex-m33) ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is This code correct for interfacing ultra-sonic sensor into i.mx93 (cortex-m33) ?

805 Views
Manjunathb
Contributor II
/*
 * Copyright (c) 2015, Freescale Semiconductor, Inc.
 * Copyright 2016-2021 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "fsl_debug_console.h"
#include "board.h"
#include "app.h"
#include "fsl_tpm.h"
#include "fsl_rgpio.h"

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/
volatile bool tpmIsrFlag = false;
volatile uint32_t risingTime = 0;
volatile uint32_t fallingTime = 0;
volatile bool gotRisingEdge = false;

/*******************************************************************************
 * Code
 ******************************************************************************/
void SetUp(void)
{
    rgpio_pin_config_t out_config ={
        kRGPIO_DigitalOutput,
        0,
    };
   
    /* Trigger pin */
    RGPIO_PinInit(BOARD_RGPIO,TRIG_PIN,&out_config);
    RGPIO_PinWrite(BOARD_RGPIO,TRIG_PIN,0);
}

void SendTrigPulse(void)
{
    RGPIO_PinWrite(BOARD_RGPIO, TRIG_PIN, 1);
    SDK_DelayAtLeastUs(10, SystemCoreClock);
    RGPIO_PinWrite(BOARD_RGPIO, TRIG_PIN, 0);
}

void TPM_INPUT_CAPTURE_HANDLER(void)
{
    uint32_t status = TPM_GetStatusFlags(DEMO_TPM_BASEADDR);
    if (status & TPM_CHANNEL_FLAG)
    {
        uint32_t capturedValue = TPM_GetChannelValue(DEMO_TPM_BASEADDR, BOARD_TPM_INPUT_CAPTURE_CHANNEL);
        // PRINTF("CAPTURED VALUE : %u\r\n",capturedValue);

        if (!gotRisingEdge)
        {
            risingTime = capturedValue;
            gotRisingEdge = true;

            // TPM_SetupInputCapture(DEMO_TPM_BASEADDR,BOARD_TPM_INPUT_CAPTURE_CHANNEL,kTPM_FallingEdge);

        }
        else
        {
            fallingTime = capturedValue;
            tpmIsrFlag = true;
            gotRisingEdge = false;

            // TPM_SetupInputCapture(DEMO_TPM_BASEADDR,BOARD_TPM_INPUT_CAPTURE_CHANNEL,kTPM_RisingEdge);
        }
       
        /* Clear interrupt flag.*/
        TPM_ClearStatusFlags(DEMO_TPM_BASEADDR, TPM_CHANNEL_FLAG);
    }
    SDK_ISR_EXIT_BARRIER;
}

/*!
 * @brief Main function
 */
int main(void)
{
    tpm_config_t tpmInfo;

    /* Board pin, clock, debug console init */
    BOARD_InitHardware();

    SetUp();

    /* Print a note to terminal */
    PRINTF("\r\nTPM input capture example\r\n");
    PRINTF("\r\nOnce the input signal is received the input capture value is printed\r\n");

    TPM_GetDefaultConfig(&tpmInfo);
    /* Initialize TPM module */
    TPM_Init(DEMO_TPM_BASEADDR, &tpmInfo);

    /* Setup input capture on a TPM channel */
    TPM_SetupInputCapture(DEMO_TPM_BASEADDR, BOARD_TPM_INPUT_CAPTURE_CHANNEL, kTPM_RiseAndFallEdge);

    /* Set the timer to be in free-running mode */
    TPM_SetTimerPeriod(DEMO_TPM_BASEADDR,
    TPM_MAX_COUNTER_VALUE(DEMO_TPM_BASEADDR));

    /* Enable channel interrupt when the second edge is detected */
    TPM_EnableInterrupts(DEMO_TPM_BASEADDR, TPM_CHANNEL_INTERRUPT_ENABLE);

    /* Enable at the NVIC */
    EnableIRQ(TPM_INTERRUPT_NUMBER);

    TPM_StartTimer(DEMO_TPM_BASEADDR, kTPM_SystemClock);
 
    while (1)
    {
        SendTrigPulse();
       
        while (tpmIsrFlag != true)
        {
        }
 
        uint32_t ticks = 0;
        if (fallingTime >= risingTime)
            ticks = fallingTime - risingTime;
        else
            ticks = (TPM_MAX_COUNTER_VALUE(DEMO_TPM_BASEADDR) - risingTime) + fallingTime;
   
        float PulseUs = (ticks * 1000000) / TPM_SOURCE_CLOCK ;
        PRINTF("RISING TIME  : %u\r\n",risingTime);
        PRINTF("FALLING TIME : %u\r\n",fallingTime);
        PRINTF("Micro second is : %.2f\r\n",PulseUs);

        SDK_DelayAtLeastUs(60000,SystemCoreClock);
    }
}
 
I have some problems in this code to check the object distance ?
Here SDK_DelayAtLeastUs(10,SystemCoreClock); This API is not giving the 10 us for trigger the pin to start measurement ?
 
Labels (1)
0 Kudos
Reply
4 Replies

786 Views
JorgeCas
NXP TechSupport
NXP TechSupport

Hello,

The sections of your code are according to the TPM configuration and generation/reading of TRIG and ECHO signals of the ultra-sonic sensor.

To confirm if your function is generating the 10 us signal, I suggest you measure the signal with an oscilloscope or digital analyzer. If the timing is not the expected, you could tune the values to generate the delay since the compiler may optimize the code in such a way that the pulse does not last as expected.

Did you check the operation of the sensor in the board?

Here an example as a reference:

Tutorial: Ultrasonic Ranging with the Freedom Board | MCU on Eclipse

Best regards.

0 Kudos
Reply

755 Views
Manjunathb
Contributor II
/*
 * Copyright (c) 2015, Freescale Semiconductor, Inc.
 * Copyright 2016-2021 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "fsl_debug_console.h"
#include "board.h"
#include "app.h"
#include "fsl_tpm.h"
#include "fsl_rgpio.h"

/*******************************************************************************
 * Definitions
 ******************************************************************************/

/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/
volatile bool tpmIsrFlag = false;
volatile uint32_t risingTime = 0;
volatile uint32_t fallingTime = 0;
volatile bool gotRisingEdge = false;

/*******************************************************************************
 * Code
 ******************************************************************************/
void SetUp(void)
{
    rgpio_pin_config_t out_config ={
        kRGPIO_DigitalOutput,
        0,
    };
   
    /* Trigger pin */
    RGPIO_PinInit(BOARD_RGPIO,TRIG_PIN,&out_config);
    RGPIO_PinWrite(BOARD_RGPIO,TRIG_PIN,0);
}

void SendTrigPulse(void)
{
    RGPIO_PinWrite(BOARD_RGPIO, TRIG_PIN, 1);
    SDK_DelayAtLeastUs(10, SystemCoreClock);
    RGPIO_PinWrite(BOARD_RGPIO, TRIG_PIN, 0);
}

void TPM_INPUT_CAPTURE_HANDLER(void)
{
    uint32_t status = TPM_GetStatusFlags(DEMO_TPM_BASEADDR);
    if (status & TPM_CHANNEL_FLAG)
    {
        uint32_t capturedValue = TPM_GetChannelValue(DEMO_TPM_BASEADDR, BOARD_TPM_INPUT_CAPTURE_CHANNEL);
        // PRINTF("CAPTURED VALUE : %u\r\n",capturedValue);

        if (!gotRisingEdge)
        {
            risingTime = capturedValue;
            gotRisingEdge = true;

            // TPM_SetupInputCapture(DEMO_TPM_BASEADDR,BOARD_TPM_INPUT_CAPTURE_CHANNEL,kTPM_FallingEdge);

        }
        else
        {
            fallingTime = capturedValue;
            tpmIsrFlag = true;
            gotRisingEdge = false;

            // TPM_SetupInputCapture(DEMO_TPM_BASEADDR,BOARD_TPM_INPUT_CAPTURE_CHANNEL,kTPM_RisingEdge);
        }
       
        /* Clear interrupt flag.*/
        TPM_ClearStatusFlags(DEMO_TPM_BASEADDR, TPM_CHANNEL_FLAG);
    }
    SDK_ISR_EXIT_BARRIER;
}

/*!
 * @brief Main function
 */
int main(void)
{
    tpm_config_t tpmInfo;

    /* Board pin, clock, debug console init */
    BOARD_InitHardware();

    SetUp();

    /* Print a note to terminal */
    PRINTF("\r\nTPM input capture example\r\n");
    PRINTF("\r\nOnce the input signal is received the input capture value is printed\r\n");

    TPM_GetDefaultConfig(&tpmInfo);
    /* Initialize TPM module */
    TPM_Init(DEMO_TPM_BASEADDR, &tpmInfo);

    /* Setup input capture on a TPM channel */
    TPM_SetupInputCapture(DEMO_TPM_BASEADDR, BOARD_TPM_INPUT_CAPTURE_CHANNEL, kTPM_RiseAndFallEdge);

    /* Set the timer to be in free-running mode */
    TPM_SetTimerPeriod(DEMO_TPM_BASEADDR, TPM_MAX_COUNTER_VALUE(DEMO_TPM_BASEADDR));

    /* Enable channel interrupt when the second edge is detected */
    TPM_EnableInterrupts(DEMO_TPM_BASEADDR, TPM_CHANNEL_INTERRUPT_ENABLE);

    /* Enable at the NVIC */
    EnableIRQ(TPM_INTERRUPT_NUMBER);

    TPM_StartTimer(DEMO_TPM_BASEADDR, kTPM_SystemClock);

       while (1)
    {
        SendTrigPulse();
       
        while (tpmIsrFlag != true)
        {
        }

    // PRINTF("\r\nCapture value C(n)V=%x\r\n", TPM_GetChannelValue(DEMO_TPM_BASEADDR, BOARD_TPM_INPUT_CAPTURE_CHANNEL));
        uint32_t ticks = 0;
        if (fallingTime >= risingTime)
            ticks = fallingTime - risingTime;
        else
            ticks = (TPM_MAX_COUNTER_VALUE(DEMO_TPM_BASEADDR) - risingTime) + fallingTime;
   
        uint32_t tpm_clock = CLOCK_GetIpFreq(LPTPM_CLOCK_ROOT);
        float PulseUs = (ticks * 1000000) / tpm_clock ;
        PRINTF("RISING TIME  : %u\r\n",risingTime);
        PRINTF("FALLING TIME : %u\r\n",fallingTime);
        PRINTF("Micro second is : %.2f\r\n",PulseUs);

        float Distance = PulseUs / 58;
        PRINTF("DISTANCE : %.2f\r\n",Distance);

        SDK_DelayAtLeastUs(60000,SystemCoreClock);
    }
}
 
i checked using oscilloscope , its trigger 10 us is correct. But problem is now echo pin ?
its not reading the correct value ?
Tags (1)
0 Kudos
Reply

773 Views
Manjunathb
Contributor II
I have already verified the signal using an oscilloscope, and it shows a 10 µs pulse.

Next, I tested by looping the TRIG pin to the ECHO pin directly and measured the pulse width in code. However, it is printing approximately 66 µs instead of the expected 10 µs.

If the TRIG and ECHO pins are directly connected in a loop, it should measure exactly 10 µs, matching the signal generated. I’m unable to identify where the discrepancy is occurring.

Could this be due to a clock configuration issue or some timing inaccuracy in the capture logic?

I would appreciate your help in identifying and resolving this issue.

Thank you in advance!
0 Kudos
Reply

775 Views
Manjunathb
Contributor II
Thank you for your response!
0 Kudos
Reply
%3CLINGO-SUB%20id%3D%22lingo-sub-2135797%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EIs%20This%20code%20correct%20for%20interfacing%20ultra-sonic%20sensor%20into%20i.mx93%20(cortex-m33)%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2135797%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Copyright%20(c)%202015%2C%20Freescale%20Semiconductor%2C%20Inc.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Copyright%202016-2021%20NXP%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20All%20rights%20reserved.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20SPDX-License-Identifier%3A%20BSD-3-Clause%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23include%20%3C%2FSPAN%3E%3CSPAN%3E%22fsl_debug_console.h%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23include%20%3C%2FSPAN%3E%3CSPAN%3E%22board.h%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23include%20%3C%2FSPAN%3E%3CSPAN%3E%22app.h%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23include%20%3C%2FSPAN%3E%3CSPAN%3E%22fsl_tpm.h%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23include%20%3C%2FSPAN%3E%3CSPAN%3E%22fsl_rgpio.h%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%2F*******************************************************************************%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Definitions%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B******************************************************************************%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%2F*******************************************************************************%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Prototypes%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B******************************************************************************%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%2F*******************************************************************************%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Variables%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B******************************************************************************%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Evolatile%3C%2FSPAN%3E%20%3CSPAN%3Ebool%3C%2FSPAN%3E%3CSPAN%3E%20tpmIsrFlag%20%3D%20%3C%2FSPAN%3E%3CSPAN%3Efalse%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Evolatile%3C%2FSPAN%3E%20%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E%20risingTime%20%3D%20%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Evolatile%3C%2FSPAN%3E%20%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E%20fallingTime%20%3D%20%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Evolatile%3C%2FSPAN%3E%20%3CSPAN%3Ebool%3C%2FSPAN%3E%3CSPAN%3E%20gotRisingEdge%20%3D%20%3C%2FSPAN%3E%3CSPAN%3Efalse%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%2F*******************************************************************************%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Code%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B******************************************************************************%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Evoid%3C%2FSPAN%3E%3CSPAN%3E%20SetUp(%3C%2FSPAN%3E%3CSPAN%3Evoid%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20rgpio_pin_config_t%20out_config%20%3D%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EkRGPIO_DigitalOutput%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%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N%3ETPM_CHANNEL_FLAG%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E%20capturedValue%20%3D%20TPM_GetChannelValue(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3EBOARD_TPM_INPUT_CAPTURE_CHANNEL%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%2F%2F%20PRINTF(%22CAPTURED%20VALUE%20%3A%20%25u%5Cr%5Cn%22%2CcapturedValue)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%20(!gotRisingEdge)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20risingTime%20%3D%20capturedValue%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20gotRisingEdge%20%3D%20%3C%2FSPAN%3E%3CSPAN%3Etrue%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%2F%2F%20TPM_SetupInputCapture(DEMO_TPM_BASEADDR%2CBOARD_TPM_INPUT_CAPTURE_CHANNEL%2CkTPM_FallingEdge)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Eelse%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20fallingTime%20%3D%20capturedValue%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20tpmIsrFlag%20%3D%20%3C%2FSPAN%3E%3CSPAN%3Etrue%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20gotRisingEdge%20%3D%20%3C%2FSPAN%3E%3CSPAN%3Efalse%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%2F%2F%20TPM_SetupInputCapture(DEMO_TPM_BASEADDR%2CBOARD_TPM_INPUT_CAPTURE_CHANNEL%2CkTPM_RisingEdge)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Clear%20interrupt%20flag.*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20TPM_ClearStatusFlags(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3ETPM_CHANNEL_FLAG%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3ESDK_ISR_EXIT_BARRIER%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%2F*!%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20%3C%2FSPAN%3E%3CSPAN%3E%40brief%3C%2FSPAN%3E%3CSPAN%3E%20Main%20function%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eint%3C%2FSPAN%3E%3CSPAN%3E%20main(%3C%2FSPAN%3E%3CSPAN%3Evoid%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20tpm_config_t%20tpmInfo%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Board%20pin%2C%20clock%2C%20debug%20console%20init%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20BOARD_InitHardware()%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20SetUp()%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Print%20a%20note%20to%20terminal%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EPRINTF%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22%5Cr%5CnTPM%20input%20capture%20example%5Cr%5Cn%22%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EPRINTF%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22%5Cr%5CnOnce%20the%20input%20signal%20is%20received%20the%20input%20capture%20value%20is%20printed%5Cr%5Cn%22%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_GetDefaultConfig(%26amp%3BtpmInfo)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Initialize%20TPM%20module%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_Init(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%26amp%3BtpmInfo)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Setup%20input%20capture%20on%20a%20TPM%20channel%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_SetupInputCapture(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3EBOARD_TPM_INPUT_CAPTURE_CHANNEL%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3EkTPM_RiseAndFallEdge%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Set%20the%20timer%20to%20be%20in%20free-running%20mode%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_SetTimerPeriod(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_MAX_COUNTER_VALUE%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E))%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Enable%20channel%20interrupt%20when%20the%20second%20edge%20is%20detected%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_EnableInterrupts(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3ETPM_CHANNEL_INTERRUPT_ENABLE%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Enable%20at%20the%20NVIC%20*%2F%3C%2FSPA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C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E%20ticks%20%3D%20%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%20(fallingTime%20%26gt%3B%3D%20risingTime)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20ticks%20%3D%20fallingTime%20-%20risingTime%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Eelse%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20ticks%20%3D%20(%3C%2FSPAN%3E%3CSPAN%3ETPM_MAX_COUNTER_VALUE%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E)%20-%20risingTime)%20%2B%20fallingTime%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Efloat%3C%2FSPAN%3E%3CSPAN%3E%20PulseUs%20%3D%20(ticks%20*%20%3C%2FSPAN%3E%3CSPAN%3E1000000%3C%2FSPAN%3E%3CSPAN%3E)%20%2F%20%3C%2FSPAN%3E%3CSPAN%3ETPM_SOURCE_CLOCK%3C%2FSPAN%3E%3CSPAN%3E%20%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EPRINTF%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22RISING%20TIME%20%26nbsp%3B%3A%20%25u%5Cr%5Cn%22%3C%2FSPAN%3E%3CSPAN%3E%2CrisingTime)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EPRINTF%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22FALLING%20TIME%20%3A%20%25u%5Cr%5Cn%22%3C%2FSPAN%3E%3CSPAN%3E%2CfallingTime)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EPRINTF%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22Micro%20second%20is%20%3A%20%25.2f%5Cr%5Cn%22%3C%2FSPAN%3E%3CSPAN%3E%2CPulseUs)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SDK_DelayAtLeastUs(%3C%2FSPAN%3E%3CSPAN%3E60000%3C%2FSPAN%3E%3CSPAN%3E%2CSystemCoreClock)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EI%20have%20some%20problems%20in%20this%20code%20to%20check%20the%20object%20distance%20%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EHere%26nbsp%3BSDK_DelayAtLeastUs(10%2CSystemCoreClock)%3B%20This%20API%20is%20not%20giving%20the%2010%20us%20for%20trigger%20the%20pin%20to%20start%20measurement%20%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fcommunity.nxp.com%2Ft5%2Fc-pwmxy87654%2Fi.MX93EVK%2Fpd-p%2Fi.MX93EVK%22%20class%3D%22lia-product-mention%22%20data-product%3D%222927-1%22%20target%3D%22_blank%22%3Ei.MX93EVK%3C%2FA%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2135797%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EClock%7CTimers%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2136596%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Is%20This%20code%20correct%20for%20interfacing%20ultra-sonic%20sensor%20into%20i.mx93%20(cortex-m33)%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2136596%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%2F*%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Copyright%20(c)%202015%2C%20Freescale%20Semiconductor%2C%20Inc.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Copyright%202016-2021%20NXP%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20All%20rights%20reserved.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20SPDX-License-Identifier%3A%20BSD-3-Clause%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23include%20%3C%2FSPAN%3E%3CSPAN%3E%22fsl_debug_console.h%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23include%20%3C%2FSPAN%3E%3CSPAN%3E%22board.h%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23include%20%3C%2FSPAN%3E%3CSPAN%3E%22app.h%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23include%20%3C%2FSPAN%3E%3CSPAN%3E%22fsl_tpm.h%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%23include%20%3C%2FSPAN%3E%3CSPAN%3E%22fsl_rgpio.h%22%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%2F*******************************************************************************%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Definitions%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B******************************************************************************%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%2F*******************************************************************************%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Prototypes%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B******************************************************************************%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%2F*******************************************************************************%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Variables%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B******************************************************************************%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Evolatile%3C%2FSPAN%3E%20%3CSPAN%3Ebool%3C%2FSPAN%3E%3CSPAN%3E%20tpmIsrFlag%20%3D%20%3C%2FSPAN%3E%3CSPAN%3Efalse%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Evolatile%3C%2FSPAN%3E%20%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E%20risingTime%20%3D%20%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Evolatile%3C%2FSPAN%3E%20%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E%20fallingTime%20%3D%20%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Evolatile%3C%2FSPAN%3E%20%3CSPAN%3Ebool%3C%2FSPAN%3E%3CSPAN%3E%20gotRisingEdge%20%3D%20%3C%2FSPAN%3E%3CSPAN%3Efalse%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%2F*******************************************************************************%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B*%20Code%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B******************************************************************************%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Evoid%3C%2FSPAN%3E%3CSPAN%3E%20SetUp(%3C%2FSPAN%3E%3CSPAN%3Evoid%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20rgpio_pin_config_t%20out_config%20%3D%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EkRGPIO_DigitalOutput%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN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EADDR%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%20(status%20%26amp%3B%20%3C%2FSPAN%3E%3CSPAN%3ETPM_CHANNEL_FLAG%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E%20capturedValue%20%3D%20TPM_GetChannelValue(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3EBOARD_TPM_INPUT_CAPTURE_CHANNEL%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%2F%2F%20PRINTF(%22CAPTURED%20VALUE%20%3A%20%25u%5Cr%5Cn%22%2CcapturedValue)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%20(!gotRisingEdge)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20risingTime%20%3D%20capturedValue%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20gotRisingEdge%20%3D%20%3C%2FSPAN%3E%3CSPAN%3Etrue%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%2F%2F%20TPM_SetupInputCapture(DEMO_TPM_BASEADDR%2CBOARD_TPM_INPUT_CAPTURE_CHANNEL%2CkTPM_FallingEdge)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Eelse%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20fallingTime%20%3D%20capturedValue%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20tpmIsrFlag%20%3D%20%3C%2FSPAN%3E%3CSPAN%3Etrue%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20gotRisingEdge%20%3D%20%3C%2FSPAN%3E%3CSPAN%3Efalse%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%2F%2F%20TPM_SetupInputCapture(DEMO_TPM_BASEADDR%2CBOARD_TPM_INPUT_CAPTURE_CHANNEL%2CkTPM_RisingEdge)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%2F*%20Clear%20interrupt%20flag.*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20TPM_ClearStatusFlags(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3ETPM_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%3E%26nbsp%3B%20%26nbsp%3B%20SetUp()%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Print%20a%20note%20to%20terminal%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EPRINTF%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22%5Cr%5CnTPM%20input%20capture%20example%5Cr%5Cn%22%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3EPRINTF%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%22%5Cr%5CnOnce%20the%20input%20signal%20is%20received%20the%20input%20capture%20value%20is%20printed%5Cr%5Cn%22%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_GetDefaultConfig(%26amp%3BtpmInfo)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Initialize%20TPM%20module%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_Init(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%26amp%3BtpmInfo)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Setup%20input%20capture%20on%20a%20TPM%20channel%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_SetupInputCapture(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3EBOARD_TPM_INPUT_CAPTURE_CHANNEL%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3EkTPM_RiseAndFallEdge%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Set%20the%20timer%20to%20be%20in%20free-running%20mode%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_SetTimerPeriod(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3ETPM_MAX_COUNTER_VALUE%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E))%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%2F*%20Enable%20channel%20interrupt%20when%20the%20second%20edge%20is%20detected%20*%2F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20TPM_EnableInterrupts(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E%2C%20%3C%2FSPAN%3E%3CSPAN%3ETPM_CHANNEL_INTERRUPT_ENABLE%3C%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B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Ewhile%3C%2FSPAN%3E%3CSPAN%3E%20(tpmIsrFlag%20!%3D%20%3C%2FSPAN%3E%3CSPAN%3Etrue%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3E%2F%2F%20PRINTF(%22%5Cr%5CnCapture%20value%20C(n)V%3D%25x%5Cr%5Cn%22%2C%20TPM_GetChannelValue(DEMO_TPM_BASEADDR%2C%20BOARD_TPM_INPUT_CAPTURE_CHANNEL))%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E%20ticks%20%3D%20%3C%2FSPAN%3E%3CSPAN%3E0%3C%2FSPAN%3E%3CSPAN%3E%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%20(fallingTime%20%26gt%3B%3D%20risingTime)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20ticks%20%3D%20fallingTime%20-%20risingTime%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Eelse%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20ticks%20%3D%20(%3C%2FSPAN%3E%3CSPAN%3ETPM_MAX_COUNTER_VALUE%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3EDEMO_TPM_BASEADDR%3C%2FSPAN%3E%3CSPAN%3E)%20-%20risingTime)%20%2B%20fallingTime%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Euint32_t%3C%2FSPAN%3E%3CSPAN%3E%20tpm_clock%20%3D%20CLOCK_GetIpFreq(%3C%2FSPAN%3E%3CSPAN%3ELPTPM_CLOCK_ROOT%3C%2FSPAN%3E%3CSPAN%3E)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3C%2FSPAN%3E%3CSPAN%3Efloat%3C%2FSPAN%3E%3CSPAN%3E%20PulseUs%20%3D%20(ticks%20*%20%3C%2FSPAN%3E%3CSPAN%3E1000000%3C%2FSPAN%3E%3CSPAN%3E)%20%2F%20tpm_clock%20%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nb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TANCE%20%3A%20%25.2f%5Cr%5Cn%22%3C%2FSPAN%3E%3CSPAN%3E%2CDistance)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20SDK_DelayAtLeastUs(%3C%2FSPAN%3E%3CSPAN%3E60000%3C%2FSPAN%3E%3CSPAN%3E%2CSystemCoreClock)%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Ei%20checked%20using%20oscilloscope%20%2C%20its%20trigger%2010%20us%20is%20correct.%20But%20problem%20is%20now%20echo%20pin%20%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eits%20not%20reading%20the%20correct%20value%20%3F%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2136240%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Is%20This%20code%20correct%20for%20interfacing%20ultra-sonic%20sensor%20into%20i.mx93%20(cortex-m33)%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2136240%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EI%20have%20already%20verified%20the%20signal%20using%20an%20oscilloscope%2C%20and%20it%20shows%20a%2010%20%C2%B5s%20pulse.%3CBR%20%2F%3E%3CBR%20%2F%3ENext%2C%20I%20tested%20by%20looping%20the%20TRIG%20pin%20to%20the%20ECHO%20pin%20directly%20and%20measured%20the%20pulse%20width%20in%20code.%20However%2C%20it%20is%20printing%20approximately%2066%20%C2%B5s%20instead%20of%20the%20expected%2010%20%C2%B5s.%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20the%20TRIG%20and%20ECHO%20pins%20are%20directly%20connected%20in%20a%20loop%2C%20it%20should%20measure%20exactly%2010%20%C2%B5s%2C%20matching%20the%20signal%20generated.%20I%E2%80%99m%20unable%20to%20identify%20where%20the%20discrepancy%20is%20occurring.%3CBR%20%2F%3E%3CBR%20%2F%3ECould%20this%20be%20due%20to%20a%20clock%20configuration%20issue%20or%20some%20timing%20inaccuracy%20in%20the%20capture%20logic%3F%3CBR%20%2F%3E%3CBR%20%2F%3EI%20would%20appreciate%20your%20help%20in%20identifying%20and%20resolving%20this%20issue.%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20in%20advance!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2136235%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Is%20This%20code%20correct%20for%20interfacing%20ultra-sonic%20sensor%20into%20i.mx93%20(cortex-m33)%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2136235%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EThank%20you%20for%20your%20response!%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2135963%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20Is%20This%20code%20correct%20for%20interfacing%20ultra-sonic%20sensor%20into%20i.mx93%20(cortex-m33)%20%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2135963%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CDIV%3E%0A%3CDIV%3E%0A%3CDIV%3E%0A%3CP%3EHello%2C%3C%2FP%3E%0A%3CP%3EThe%20sections%20of%20your%20code%20are%20according%20to%20the%20TPM%20configuration%20and%20generation%2Freading%20of%20TRIG%20and%20ECHO%20signals%20of%20the%20ultra-sonic%20sensor.%3C%2FP%3E%0A%3CP%3ETo%20confirm%20if%20your%20function%20is%20generating%20the%2010%20us%20signal%2C%20I%20suggest%20you%20measure%20the%20signal%20with%20an%20oscilloscope%20or%20digital%20analyzer.%20If%20the%20timing%20is%20not%20the%20expected%2C%20you%20could%20tune%20the%20values%20to%20generate%20the%20delay%20since%20the%20compiler%20may%20optimize%20the%20code%20in%20such%20a%20way%20that%20the%20pulse%20does%20not%20last%20as%20expected.%3C%2FP%3E%0A%3CP%3EDid%20you%20check%20the%20operation%20of%20the%20sensor%20in%20the%20board%3F%3C%2FP%3E%0A%3CP%3EHere%20an%20example%20as%20a%20reference%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmcuoneclipse.com%2F2013%2F01%2F01%2Ftutorial-ultrasonic-ranging-with-the-freedom-board%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ETutorial%3A%20Ultrasonic%20Ranging%20with%20the%20Freedom%20Board%20%7C%20MCU%20on%20Eclipse%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EBest%20regards.%3C%2FP%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3C%2FDIV%3E%3C%2FLINGO-BODY%3E