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.

CC1354P10: Setting up PinMux for Input Edge Time mode

Part Number: CC1354P10
Other Parts Discussed in Thread: SYSCONFIG,

Tool/software:

Hello E2E,

I was trying to implement Edge Time capture on a GPIO pin. My intension is to capture the time between two edges on a GPIO pin. 

When I try to implement using GPTimerCC26XX.h. Somehow, I don't see any definition/reference for "PINCC26XX_setMux".  Below is my sample code... 

GPTimerCC26XX_Handle capTimer;
GPTimerCC26XX_Params tParams;
GPTimerCC26XX_Params_init(&tParams);

tParams.width = GPT_CONFIG_16BIT;
tParams.mode = GPT_MODE_EDGE_TIME;
tParams.direction = GPTimerCC26XX_DIRECTION_UP;
tParams.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;

capTimer = GPTimerCC26XX_open(GPT_A, &tParams);

if(capTimer == NULL) {
    Log_error0("Failed to open GPTimer");
    Task_exit();
    while(1);
}

GPTimerCC26XX_setCaptureEdge(capTimer, GPTimerCC26XX_BOTH_EDGES);
GPTimerCC26XX_registerInterrupt(capTimer, captureTimerCallback, GPT_INT_CAPTURE);

GPTimerCC26XX_start(capTimer);

Appreciate your help in sorting this out. 

Regards,

Satya 

  • Hi Satya

    You need to ise the PINCC26XX_setMux(); instead of the PINCC26XX_setMux, since the pin driver is not longer supported.

    BR

    Siri

  • I tried using PINCC26XX_setMux();. I guess no where it was defined. Can you please elaborate a little more. 

    Regards,

    Satya 

  • Sorry, typo on my end.

    I meant to say that you should use GPIO_setConfigAndMux instead of PINCC26XX_setMux();

    Siri

  • Hi Siri, 

    The capture pin configuration is working good now. Thanks for that.

    But again the counter reading the same value all the time, irrespective of the input pulse width. I can see the ISR calling with the correct timing. But when I try to read the counter value using the following code... 

    GPTimerCC26XX_setCaptureEdge(capTimer, GPTimerCC26XX_NEG_EDGE);
    GPTimerCC26XX_registerInterrupt(capTimer, captureTimerCallback, GPT_INT_CAPTURE);

    GPIO_setConfigAndMux(GPIO_USS_ECHO, GPIO_CFG_INPUT, GPT_PIN_0A);
    GPTimerCC26XX_start(capTimer);

    void captureTimerCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask) {GPIO_toggle(GPIO_USS_N);
        /*In input edge time, this register contains the timer value at which the last edge event took place*/
        captureValue = GPTimerCC26XX_getValue(capTimer);

        ussTriggerFlag = 0xFF;
    }

    Appreciate your help. Regards

  • Hi

    Can you please take the empty example from the SDK and implement a small demo code of what you are doing exactly in your code, so that I can test the same thing here?

    Send me the modified e,pty.c file and your sysConfig file, and I can use that in my empty example.

    the example should run on a LaunchPad

    Siri

  • I made the simple code below and where able to read the timer values as expected:

    #include <unistd.h>
    #include <stdint.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/timer/GPTimerCC26XX.h>
    
    #include "ti_drivers_config.h"
    
    GPTimerCC26XX_Handle hTimer;
    GPTimerCC26XX_Params timerParams;
    
    uint32_t edgeCount_1 = 0;
    uint32_t edgeCount_2 = 0;
    bool edge1 = true;
    
    void buttonCallbackFunction(uint_least8_t index) {
    
        // Simple debounce logic
        CPUdelay((uint32_t)((48000000/3)*0.050f));
        GPIO_toggle(CONFIG_GPIO_LED_GREEN);
    }
    
    void timerCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
    {
    
        GPIO_write(CONFIG_GPIO_LED_RED, 1);
        if (edge1)
        {
            edgeCount_1 = GPTimerCC26XX_getValue(handle);
            edge1 = false;
        }
        else
        {
            edgeCount_2 = GPTimerCC26XX_getValue(handle);
            edge1 = true;
        }
        GPIO_write(CONFIG_GPIO_LED_RED, 0);
    }
    
    void *mainThread(void *arg0)
    {
        GPIO_init();
    
        // Toggle the RLED the BTN-1 toggles (pushed and released)
        // RLED is connected to the input CONFIG_GPIO_EDGE_INPUT (DIO0) which is connected to the GPTimer
        GPIO_setConfig(CONFIG_GPIO_BTN1, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_BOTH_EDGES);
        GPIO_setCallback(CONFIG_GPIO_BTN1, buttonCallbackFunction);
        GPIO_enableInt(CONFIG_GPIO_BTN1);
    
        GPTimerCC26XX_Params_init(&timerParams);
        timerParams.mode = GPT_MODE_EDGE_TIME;
        timerParams.width = GPT_CONFIG_16BIT;
        timerParams.direction = GPTimerCC26XX_DIRECTION_UP;
        timerParams.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
    
        hTimer = GPTimerCC26XX_open(CONFIG_GPTIMER_0, &timerParams);
    
        GPTimerCC26XX_registerInterrupt(hTimer, timerCallback, GPT_INT_CAPTURE);
    
        GPTimerCC26XX_PinMux pinMux = GPTimerCC26XX_getPinMux(hTimer);
    
        GPIO_setConfigAndMux(CONFIG_GPIO_EDGE_INPUT,(GPIO_CFG_INPUT_INTERNAL | GPIO_CFG_PULL_NONE_INTERNAL), pinMux);
    
        GPTimerCC26XX_setCaptureEdge(hTimer, GPTimerCC26XX_BOTH_EDGES);
    
        GPTimerCC26XX_start(hTimer);
        while (1);
    }

  • Hi Siri,

    My application also does the same as your example code except in the ISR section, where I was only counting for one edge. Now I copied your example, as per my understanding this code should store timer values for rise and fall edges into the variables edgeCount_1 and edgeCount_2. 

    I supplied my capture pin with a 1mSec on/off timing pulse, I am seeing some random count values. It supposed to give 48000-1 every time, since I am using a 48MHz (using Ti's CC1354P10_1 evaluation board). I understand the timer should automatically goes to zero after an ISR executed by the the Capture pin. Which I don't see in the real time. Please help me if I miss anything.      

    Further, can you please help me with the pre-scaler setup for the same timer. Appreciate your help.

    Regards,

    Satya Raji

  • The timer is not restarting/going to zero after it has capture an event.

    The timer counts from 0 to 0xFFFF and then starts from 0 again.

    Counting from 0 to 0xFFFF at 48 mHz only takes 1.36 ms

    When you are trying to measure a pulse that is 1 ms wide, you will only get the correct value (48000) when both edgeCount_1 and edgeCount_2 has been captured during the same "count period"

    If you run the code below, you will see that diff = 48000, when making sure that edgeCount_1 < edgeCount_2.

    void timerCallback(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
    {
        if (edge1)
        {
            edgeCount_1 = GPTimerCC26XX_getValue(handle);
            edge1 = false;
        }
        else
        {
            edgeCount_2 = GPTimerCC26XX_getValue(handle);
            edge1 = true;
    
            if(edgeCount_1 < edgeCount_2)
            {
                diff = edgeCount_2 - edgeCount_1;
            }
        }
    }
    
    void *mainThread(void *arg0)
    {
        GPIO_init();
    
        GPTimerCC26XX_Params_init(&timerParams);
        timerParams.mode = GPT_MODE_EDGE_TIME;
        timerParams.width = GPT_CONFIG_16BIT;
        timerParams.direction = GPTimerCC26XX_DIRECTION_UP;
        timerParams.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
    
        hTimer = GPTimerCC26XX_open(CONFIG_GPTIMER_0, &timerParams);
    
        GPTimerCC26XX_registerInterrupt(hTimer, timerCallback, GPT_INT_CAPTURE);
    
        GPTimerCC26XX_PinMux pinMux = GPTimerCC26XX_getPinMux(hTimer);
    
        GPIO_setConfigAndMux(CONFIG_GPIO_EDGE_INPUT,(GPIO_CFG_INPUT_INTERNAL | GPIO_CFG_PULL_NONE_INTERNAL), pinMux);
    
        GPTimerCC26XX_setCaptureEdge(hTimer, GPTimerCC26XX_BOTH_EDGES);
    
        GPTimerCC26XX_start(hTimer);
        while (1);
    }
    

    Siri

  • Hi Siri, 

    Thanks for your help. I was supplying a pulse more than 2mSec width, which essentially 16-it timer was overflowing results wrong count on my variable. Sorted now. Trying to use the pre-scaler, somehow I am missing some APIs and related documentation. I have the TRM, but there is a big gap between the stack and the TRM. Can you please help me in that, setting up the pre scaler? Regards.

    Satya Raji 

  • You need to use GPTimerCC26XX_setLoadValue to write to the TAPR register.

    You can see how it is accessed/used in GPTimerCC26XX.c

    /*!
     *  @brief  Shared code to be used by GPTimerCC26XX_setLoadValue / GPTimerCC26XX_setMatchValue
     *          Sets load/match values using input value and register offset for
     *          prescaler and load/match register
     *          Functions calling this should specifiy which the register offset
     *          within the module base to the corresponding timer A register.
     */
    static void GPTimerCC26XXSetLoadMatch(GPTimerCC26XX_Handle handle,
                                          GPTimerCC26XX_Value loadMatchVal,
                                          uint32_t regPre,
                                          uint32_t regLoadMatch)
    {
        /* Get the pointer to the object and hwAttrs */
        GPTimerCC26XX_HWAttrs const *hwAttrs = handle->hwAttrs;
        GPTimerCC26XX_Object *object         = handle->object;
        uint32_t offset                      = GPT_LUT[handle->timerPart].offset;
    
        /* Split value into correct timer and prescaler register for 16 bit modes. */
        if (object->width == GPT_CONFIG_16BIT)
        {
            /* Upper byte is used by prescaler */
            uint8_t prescaleValue = 0xFF & (loadMatchVal >> 16);
            /* Discard upper byte (24 bits max) */
            loadMatchVal &= 0xFFFF;
    
            /* Set prescale value */
            HWREG(hwAttrs->baseAddr + offset + regPre) = prescaleValue;
        }
    
        /* Set load / match value */
        HWREG(hwAttrs->baseAddr + offset + regLoadMatch) = loadMatchVal;
    }
    
    /*!
     *  @brief  Set GPTimer load value. For 32-bit configuration all 32 bits can
     *          be used. For split mode / 16-bit mode maximum value is 24 bits.
     *          Function concatenates prescaler functionality automatically
     */
    void GPTimerCC26XX_setLoadValue(GPTimerCC26XX_Handle handle, GPTimerCC26XX_Value loadValue)
    {
        GPTimerCC26XXSetLoadMatch(handle, loadValue, GPT_O_TAPR, GPT_O_TAILR);
    }

    Siri

  • Thanks for your continuous support.