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/CC2640R2F: Issue with edge counting mode

Part Number: CC2640R2F


Tool/software: Code Composer Studio

Hi,

I am implementing a pulse counter using CC2640R2F. I tried it by following way but I am facing issue. timercallback function for edge count up mode is not executing. 

I wanted to capture the input provided on DIO0 pin.

Also I am getting warning that  function "PINCC26XX_setMux" declared implicitly. 

Can any one tell me what is the issue with this code?

GPTimerCC26XX_Handle hTimerA;

PIN_Handle timerPinHandle;

static PIN_State timerPinState;

PIN_Config GptPinInitTable[] =
{
IOID_0 | PIN_GPIO_OUTPUT_DIS | PIN_INPUT_EN | PIN_IRQ_DIS,

PIN_TERMINATE
};

void timerCallbackA(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
{
       GPTimerCC26XX_getValue(hTimerA);
}

void *mainThread(void *arg0)

{

GPTimerCC26XX_Params paramsA;
GPTimerCC26XX_Params_init(&paramsA);
paramsA.width = GPT_CONFIG_16BIT;
paramsA.mode = GPT_MODE_EDGE_COUNT_UP;
paramsA.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
hTimerA = GPTimerCC26XX_open(Board_GPTIMER0A, &paramsA);

if(hTimerA == NULL)
{
Log_error0("Failed to open GPTimer");
Task_exit();
}

PIN_Config pinCfg = PIN_ID(0) | PIN_GPIO_OUTPUT_EN | PIN_PUSHPULL | PIN_GPIO_HIGH | PIN_IRQ_POSEDGE;
timerPinHandle = PIN_open(&timerPinState, GptPinInitTable);
GPTimerCC26XX_PinMux pinMux = GPTimerCC26XX_getPinMux(hTimerA);
PIN_setConfig(timerPinHandle, PIN_BM_DRVSTR, pinCfg);
PINCC26XX_setMux(timerPinHandle,PIN_ID(0) , IOC_PORT_MCU_PORT_EVENT0);

GPTimerCC26XX_setCaptureEdge(hTimerA, GPTimerCC26XX_POS_EDGE);
GPTimerCC26XX_setLoadValue(hTimerA,0xFFFFFF);
GPTimerCC26XX_registerInterrupt(hTimerA, timerCallbackA, GPT_INT_CAPTURE);

GPTimerCC26XX_start(hTimerA);

}

  • Hi,
    In general the warning «function "XXXX" declared implicitly» shows you forgot to include some files. Here adding “#include <ti/drivers/pin/PINCC26XX.h>” should solve the problem (however, do you really want to use this device specific API instead of the generic API PIN.h?)


    Regarding your code, “pinCfg” is not correct: if I am correct you want to count the edges on DIO0, so you should set DIO0 as an input (and not as an input). You can use the examples within the SDK to get details.

    Regards,

  • Hi,

    I had also noticed that about "pinCfg" and changed it to input enable, but still it is not working. I am always getting the zero value in timer register.

    What should I do so that I will get the pulse count in timer register?

    Thanking you.

  • Hi,

    Please check if you do have the right configuration for your inputs (depending on how the electronic at the input, you could need or not a pull up or pull down internal resistor).

    For the rest, you are reading the number of edges count only when you are matching a certain number of interrupts. But you do not have set this number (default should be something like 0xFFFFFFF) and you did not enable GPT interrupts…

    You can try the following code. I read every second the number of edges count. After a given number of edges I will execute the callback. (Note I am using launchpad's button BTN-1 mapped on DIO13).

    /* For usleep() */
    #include <unistd.h>
    #include <stdint.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/pin/PINCC26XX.h>
    #include <ti/drivers/timer/GPTimerCC26XX.h>
    
    /* Board Header file */
    #include "Board.h"
    
    uint8_t toto = 0;
    
    GPTimerCC26XX_Handle hTimerA;
    
    PIN_Handle timerPinHandle;
    
    static PIN_State timerPinState;
    
    PIN_Config GptPinInitTable[] =
    {
     IOID_13 | PIN_INPUT_EN | PIN_PULLUP,
     PIN_TERMINATE
    };
    
    void timerCallbackA(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
    {
           // Do what you want here
    }
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        GPTimerCC26XX_Params paramsA;
        GPTimerCC26XX_Params_init(&paramsA);
        paramsA.width = GPT_CONFIG_16BIT;
        paramsA.mode = GPT_MODE_EDGE_COUNT_UP;
        paramsA.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
        hTimerA = GPTimerCC26XX_open(Board_GPTIMER0A, &paramsA);
    
        if(hTimerA == NULL)
        {
            while(1);
        }
    
        PIN_Config pinCfg = PIN_ID(13) | PIN_INPUT_EN | PIN_PULLUP;
        timerPinHandle = PIN_open(&timerPinState, GptPinInitTable);
        GPTimerCC26XX_PinMux pinMux = GPTimerCC26XX_getPinMux(hTimerA);
        PIN_setConfig(timerPinHandle, PIN_BM_PULLING, pinCfg);
        PINCC26XX_setMux(timerPinHandle,PIN_ID(13) , IOC_PORT_MCU_PORT_EVENT0);
    
        GPTimerCC26XX_setCaptureEdge(hTimerA, GPTimerCC26XX_POS_EDGE);
        GPTimerCC26XX_setLoadValue(hTimerA,0xFFFF);
        GPTimerCC26XX_setMatchValue(hTimerA, 0x0005);  /* Set the number of edges expected */
        GPTimerCC26XX_registerInterrupt(hTimerA, timerCallbackA, GPT_INT_CAPTURE);
        GPTimerCC26XX_enableInterrupt(hTimerA, 0xFFFF);  /* Don't forget to enable GPTimer interrupts */
    
        GPTimerCC26XX_start(hTimerA);
    
        while(1){
            sleep(1);
            toto = GPTimerCC26XX_getValue(hTimerA);
        }
    }

    Best regards,

  • Hi Clément,

    Thanks for your response.
    Now I am able to count the pulses. But I wanted to reset TAR register after every 1 sec,but TAR is of type "R" (read only as per datasheet).
    I tried it by stopping the timer and again started it, but it is still giving me the incremented value of TAR register.

    what should I do to reset timer after every 1 sec so that TAR will give me the same value after every 1 sec?
  • Hi,

    Maybe the easiest solution is to count down instead of counting up (that's often easier in this way with GPT)...

    /* For usleep() */
    #include <unistd.h>
    #include <stdint.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/pin/PINCC26XX.h>
    #include <ti/drivers/timer/GPTimerCC26XX.h>
    
    /* Board Header file */
    #include "Board.h"
    
    uint8_t toto = 0;
    
    GPTimerCC26XX_Handle hTimerA;
    
    PIN_Handle timerPinHandle;
    
    static PIN_State timerPinState;
    
    PIN_Config GptPinInitTable[] =
    {
     IOID_13 | PIN_INPUT_EN | PIN_PULLUP,
     PIN_TERMINATE
    };
    
    void timerCallbackA(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
    {
           // Do what you want here
    }
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        GPTimerCC26XX_Params paramsA;
        GPTimerCC26XX_Params_init(&paramsA);
        paramsA.width = GPT_CONFIG_16BIT;
        paramsA.mode = GPT_MODE_EDGE_COUNT_UP;
        paramsA.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
        paramsA.direction = GPTimerCC26XX_DIRECTION_DOWN;
        hTimerA = GPTimerCC26XX_open(Board_GPTIMER0A, &paramsA);
    
        if(hTimerA == NULL)
        {
            while(1);
        }
    
        PIN_Config pinCfg = PIN_ID(13) | PIN_INPUT_EN | PIN_PULLUP;
        timerPinHandle = PIN_open(&timerPinState, GptPinInitTable);
        GPTimerCC26XX_PinMux pinMux = GPTimerCC26XX_getPinMux(hTimerA);
        PIN_setConfig(timerPinHandle, PIN_BM_PULLING, pinCfg);
        PINCC26XX_setMux(timerPinHandle,PIN_ID(13) , IOC_PORT_MCU_PORT_EVENT0);
    
        GPTimerCC26XX_setCaptureEdge(hTimerA, GPTimerCC26XX_POS_EDGE);
        GPTimerCC26XX_setLoadValue(hTimerA,0x0005); /* Set the number of edges expected */
        GPTimerCC26XX_setMatchValue(hTimerA, 0x0000);  /* Value of the timer when triggering the interrupt */
        GPTimerCC26XX_registerInterrupt(hTimerA, timerCallbackA, GPT_INT_CAPTURE);
        //GPTimerCC26XX_enableInterrupt(hTimerA, 0xFFFF);  /* This line is not mandatory! */
    
        GPTimerCC26XX_start(hTimerA);
    
        while(1){
            sleep(1);
            toto = GPTimerCC26XX_getValue(hTimerA);
            GPTimerCC26XX_setLoadValue(hTimerA,0x0005);
        }
    }
    
    
    

    Regards,

  • Hi Clément,

    If we set the load value in while loop it shows that value continuously.
    It is unable to increment the counter.
    I am still finding how to reset the timer after every 1 sec, so that the value given by TAR register should be same every time.
  • Hi,
    Now I am able to count the pulses. I am using 16 Bit timer in edge count up mode. But I am only getting the frequency upto 40KHz and I need to measure the frequency upto 60KHz.
    why it is only showing the frequencies upto 40KHz?