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.

RTOS/LAUNCHXL-CC2640R2: help with the function "GPTimerCC26XX_close(hTimer)" in the GPTimer library

Part Number: LAUNCHXL-CC2640R2

Tool/software: TI-RTOS

hello everyone, im am currently new on this field of microcontrollers, im trying to start a stoper (GPT_MODE_ONESHOT_UP mode) and then to reastart it in a loop with the function GPTimerCC26XX_close(hTimer),

the function suppoose the initilize the stoper time to zero , but its fail to do so. to stoper continue running after this function ( i have to problem to start it)

this is the code if someone maybe know the reason or can help me? thank you very much

void *mainThread(void *arg0)
{

/* 1 second delay */
uint32_t SLEEP = 2;
uint32_t Time = 1;


/* Call driver init functions */
GPIO_init();
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
GPTimerCC26XX_Handle hTimer;
sleep(SLEEP);
GPIO_toggle(Board_GPIO_LED0);


#define GPT_NUM_INTS 4



GPTimerCC26XX_Params params;
GPTimerCC26XX_Params_init(&params);
params.width = GPT_CONFIG_16BIT;
params.mode = ;
params.debugStallMode = GPTimerCC26XX_DEBUG_STALL_ON;
hTimer = GPTimerCC26XX_open(Board_GPTIMER0A , &params );
GPTimerCC26XX_enableInterrupt(hTimer, GPT_INT_TIMEOUT);

while(1){
Time = 0;
GPTimerCC26XX_start(hTimer);

while(PIN_getInputValue(Board_DIO12) != 1){
}
Time = GPTimerCC26XX_getValue(hTimer);
// GPTimerCC26XX_stop(hTimer);


GPTimerCC26XX_close(hTimer);
hTimer = GPTimerCC26XX_open(Board_GPTIMER0A , &params );



if(Time > 2000){
GPIO_toggle(Board_GPIO_LED0);
sleep(SLEEP);
}
}

  • Hi Yoav

    It is not clear to me what exactly you are trying to accomplish with your example code. I think it would be easier to help you if you try to explain what you want to implement on a higher level. What signal is connected to Board_DIO12 and what information do you want from this signal?

    BR
    Siri
  • siri hey, thank you for your response and your time. 

    ill try to be more specific and explain what im trying to do.

    well in high level im trying to mesure time between pulses.  starting a time when a specific GPIO going LOW , and stop the time when a specific GPIO (DIFFRENT) is going HIGH. I know that the best way for this is using "GPTIMER..." driver with ""GPT_MODE_EDGE_TIME_UP;" mode... but i didnt manage to configure it correctly so im using the "ONE_SHOT" mode and try to start and stop the time manually.

    maybe you can suggest me a better way to do so? or a good implementation with the "GPT_MODE_EDGE_TIME_UP" ? i fail to set the pin mux....

    another question, if for example im using a sensor "HC-SR04" you think its better and easier to use the sensor controller gui? or to stay with the GPTimer driver?

    again thank you very much for your time and attention

    best regards yoav

  • Did a quick test where I use Timer0A and 0B in GPT_MODE_EDGE_TIME_UP. Timer0A has a capture on positive edge of DIO21 and Timer0B has a capture on negative edge of DIO1.

    In the callback I calculate the difference between the two captures. The code does not handle wrap-arounds of the timers, and is only meant to demonstrate how the timers can be configured for GPT_MODE_EDGE_TIME_UP mode.

    The Timers uses 24 bits and wraps every (1/48000000)*224 = 349.5 ms

    PIN_Config pinTable[] =
    {
        Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        Board_PIN_LED2 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX,
        CC1310_LAUNCHXL_DIO21 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS,
        CC1310_LAUNCHXL_DIO1 | PIN_INPUT_EN | PIN_PULLUP | PIN_IRQ_BOTHEDGES | PIN_HYSTERESIS,
        PIN_TERMINATE
    };
    
    GPTimerCC26XX_Handle hTimer0A;
    GPTimerCC26XX_Handle hTimer0B;
    
    static GPTimerCC26XX_Value time0A = 0;
    static GPTimerCC26XX_Value time0B = 0;
    static GPTimerCC26XX_Value timeDiff = 0;
    static uint8_t tA = false;
    static uint8_t tB = false;
    
    void timerCallback0A(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
    {
        time0A = GPTimerCC26XX_getValue(handle);
        tA = true;
        
        if(tB)
        {
            timeDiff = time0A - time0B;
            tB = false;
        }
    }
    
    void timerCallback0B(GPTimerCC26XX_Handle handle, GPTimerCC26XX_IntMask interruptMask)
    {
        time0B = GPTimerCC26XX_getValue(handle);
        tB = true;
        
        if(tA)
        {
            timeDiff = time0B - time0A;
            tA = false;
        }
    }
    
    /***** Function definitions *****/
    
    void *mainThread(void *arg0)
    {
        /* Open LED pins */
        ledPinHandle = PIN_open(&ledPinState, pinTable);
        if (ledPinHandle == NULL)
        {
            while(1);
        }
    
        GPTimerCC26XX_Params params0A;
        GPTimerCC26XX_Params_init(&params0A);
        params0A.width          = GPT_CONFIG_16BIT;
        params0A.mode           = GPT_MODE_EDGE_TIME_UP;
        params0A.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
        hTimer0A = GPTimerCC26XX_open(CC1310_LAUNCHXL_GPTIMER0A, &params0A);
        if(hTimer0A == NULL)
        {
            while(1);
        }
        
        GPTimerCC26XX_Params params0B;
        GPTimerCC26XX_Params_init(&params0B);
        params0B.width          = GPT_CONFIG_16BIT;
        params0B.mode           = GPT_MODE_EDGE_TIME_UP;
        params0B.debugStallMode = GPTimerCC26XX_DEBUG_STALL_OFF;
        hTimer0B = GPTimerCC26XX_open(CC1310_LAUNCHXL_GPTIMER0B, &params0B);
        if(hTimer0B == NULL)
        {
            while(1);
        }
    
        GPTimerCC26XX_registerInterrupt(hTimer0A, timerCallback0A, GPT_INT_CAPTURE);
        GPTimerCC26XX_registerInterrupt(hTimer0B, timerCallback0B, GPT_INT_CAPTURE);
        
        GPTimerCC26XX_PinMux pinMux = GPTimerCC26XX_getPinMux(hTimer0A);
        PINCC26XX_setMux(ledPinHandle, CC1310_LAUNCHXL_DIO21, pinMux);
        
        pinMux = GPTimerCC26XX_getPinMux(hTimer0B);
        PINCC26XX_setMux(ledPinHandle, CC1310_LAUNCHXL_DIO1, pinMux);
    
        GPTimerCC26XX_setCaptureEdge(hTimer0A, GPTimerCC26XX_POS_EDGE);
        GPTimerCC26XX_setLoadValue(hTimer0A, 0xFFFFFF);
        GPTimerCC26XX_setCaptureEdge(hTimer0B, GPTimerCC26XX_NEG_EDGE);
        GPTimerCC26XX_setLoadValue(hTimer0B, 0xFFFFFF);
        GPTimerCC26XX_start(hTimer0A);
        GPTimerCC26XX_start(hTimer0B);
        
        while(1)
        {
            Task_sleep(BIOS_WAIT_FOREVER);
        }
    }
    

    BR

    Siri