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.

LAUNCHCC3220MODASF: How To Configure TIMER0, TIMER1. TIMER2 in 16 bit timer A and B mode....?

Part Number: LAUNCHCC3220MODASF

Hello,

               in my project i am using CC3220SF launchXL development board. I am stuck at the configurations at Timers of CC3220SF.

can anyone helip Regarding How to configure Timer 0, Timer 1 and Timer 2 in ther respective 16 bit mode individually...?

already Timer 1 is configures as a 16 bit mode A and B in the Board.c file but when i am calling api timer open i am getting Error and its failing.

Below is my configurations structures in Board.c file

const Timer_Config Timer_config[CC3220SF_LAUNCHXL_TIMERCOUNT] = {
    {
        .fxnTablePtr = &TimerCC32XX_fxnTable,
        .object = &timerCC3220SFObjects[CC3220SF_LAUNCHXL_TIMER0],
        .hwAttrs = &timerCC3220SFHWAttrs[CC3220SF_LAUNCHXL_TIMER0]
    },
    {
        .fxnTablePtr = &TimerCC32XX_fxnTable,
        .object = &timerCC3220SFObjects[CC3220SF_LAUNCHXL_TIMER1],
        .hwAttrs = &timerCC3220SFHWAttrs[CC3220SF_LAUNCHXL_TIMER1]
    },
    {
        .fxnTablePtr = &TimerCC32XX_fxnTable,
        .object = &timerCC3220SFObjects[CC3220SF_LAUNCHXL_TIMER2],
        .hwAttrs = &timerCC3220SFHWAttrs[CC3220SF_LAUNCHXL_TIMER2]
    },
    {
        .fxnTablePtr = &TimerCC32XX_fxnTable,
        .object = &timerCC3220SFObjects[CC3220SF_LAUNCHXL_TIMER1A],
        .hwAttrs = &timerCC3220SFHWAttrs[CC3220SF_LAUNCHXL_TIMER1A]
    },
    {
        .fxnTablePtr = &TimerCC32XX_fxnTable,
        .object = &timerCC3220SFObjects[CC3220SF_LAUNCHXL_TIMER1B],
        .hwAttrs = &timerCC3220SFHWAttrs[CC3220SF_LAUNCHXL_TIMER1B]
    },
};

below is my configuration structures and hw attributes....


const TimerCC32XX_HWAttrs timerCC3220SFHWAttrs[CC3220SF_LAUNCHXL_TIMERCOUNT] = {
    {
        .baseAddress = TIMERA0_BASE,
        .subTimer = TimerCC32XX_timer32,
        .intNum = INT_TIMERA0A,
        .intPriority = ~0
    },
    {
        .baseAddress = TIMERA1_BASE,
        .subTimer = TimerCC32XX_timer32,
        .intNum = INT_TIMERA1A,
        .intPriority = ~0
    },
    {
         .baseAddress = TIMERA2_BASE,
         .subTimer = TimerCC32XX_timer32,
         .intNum = INT_TIMERA2A,
         .intPriority = ~0
    },
    {
        .baseAddress = TIMERA1_BASE,
        .subTimer = TimerCC32XX_timer16A,
        .intNum = INT_TIMERA1A,
        .intPriority = ~0
    },
    {
        .baseAddress = TIMERA1_BASE,
        .subTimer = TimerCC32XX_timer16B,
        .intNum = INT_TIMERA1B,
        .intPriority = ~0
    },
};

and this is my user application files where i am calling respective interface files.

void _WL_TIMER_INIT(void)
{
    int32_t Status = -1;
    Timer_Handle handle_timer_0;
    //Timer_Handle handle_timer_1;
    Timer_Handle handle_timer_1A;
    Timer_Handle handle_timer_1B;
    //Timer_Handle handle_timer_2;
    Timer_Params params_timer_0;
    //Timer_Params params_timer_1;
    Timer_Params params_timer_1A;
    Timer_Params params_timer_1B;
    //Timer_Params params_timer_2;

    //initialize timer parameters
    Timer_Params_init(&params_timer_0);         //timer 0
    //Timer_Params_init(&params_timer_1);         //timer 1
    Timer_Params_init(&params_timer_1A);         //timer 1A
    Timer_Params_init(&params_timer_1B);         //timer 1B
    //Timer_Params_init(&params_timer_2);         //timer 2

    //timer 0
    params_timer_0.periodUnits = Timer_PERIOD_US;
    params_timer_0.period = 5000000;
    params_timer_0.timerMode  = Timer_CONTINUOUS_CALLBACK;
    params_timer_0.timerCallback = TIMER0_ISR_Handler;

    handle_timer_0 = Timer_open(Board_TIMER0, &params_timer_0);
    if(handle_timer_0 == NULL) {
        UART_PRINT("Unable to open to Timer 0 Handle\n\n\r");
        while(1);
    }

    Status = Timer_start(handle_timer_0);
    if(Status == Timer_STATUS_ERROR) {
        UART_PRINT("Unable to Start Timer 0 \n\n\r");
        while(1);
    }

    //timer 1
    params_timer_1.periodUnits = Timer_PERIOD_US;
    params_timer_1.period = 5000000;
    params_timer_1.timerMode  = Timer_CONTINUOUS_CALLBACK;
    params_timer_1.timerCallback = TIMER1_ISR_Handler;

    handle_timer_1 = Timer_open(Board_TIMER1, &params_timer_1);
    if(handle_timer_1 == NULL) {
        UART_PRINT("Unable to open to Timer 1 Handle\n\n\r");
        while(1);
    }

    Status = Timer_start(handle_timer_1);
    if(Status == Timer_STATUS_ERROR) {
        UART_PRINT("Unable to Start Timer 1 \n\n\r");
        while(1);
    }

#if 1
    //timer 1A
    params_timer_1A.periodUnits = Timer_PERIOD_US;
    params_timer_1A.period = 5000000;
    params_timer_1A.timerMode  = Timer_CONTINUOUS_CALLBACK;
    params_timer_1A.timerCallback = TIMER1A_ISR_Handler;

    handle_timer_1A = Timer_open(Board_TIMER1, &params_timer_1A);
    if(handle_timer_1A == NULL) {
        UART_PRINT("Unable to open to Timer 1A Handle\n\n\r");
        while(1);
    }

    Status = Timer_start(handle_timer_1A);
    if(Status == Timer_STATUS_ERROR) {
        UART_PRINT("Unable to Start Timer 1A \n\n\r");
        while(1);
    }

    //timer 1B
    params_timer_1B.periodUnits = Timer_PERIOD_US;
    params_timer_1B.period = 5000000;
    params_timer_1B.timerMode  = Timer_CONTINUOUS_CALLBACK;
    params_timer_1B.timerCallback = TIMER1B_ISR_Handler;

    handle_timer_1B = Timer_open(Board_TIMER1, &params_timer_1B);
    if(handle_timer_1B == NULL) {
        UART_PRINT("Unable to open to Timer 1B Handle\n\n\r");
        while(1);
    }

    Status = Timer_start(handle_timer_1B);
    if(Status == Timer_STATUS_ERROR) {
        UART_PRINT("Unable to Start Timer 1B \n\n\r");
        while(1);
    }
#endif

and following from board.h file...

#define Board_TIMER0                 CC3220SF_LAUNCHXL_TIMER0
#define Board_TIMER1                 CC3220SF_LAUNCHXL_TIMER1
#define Board_TIMER2                 CC3220SF_LAUNCHXL_TIMER2
#define Board_TIMER1A                 CC3220SF_LAUNCHXL_TIMER1A
#define Board_TIMER1B                 CC3220SF_LAUNCHXL_TIMER1B

and following from launchxl.h file

typedef enum CC3220SF_LAUNCHXL_TimerName {
    CC3220SF_LAUNCHXL_TIMER0 = 0,
    CC3220SF_LAUNCHXL_TIMER1,
    CC3220SF_LAUNCHXL_TIMER2,
    CC3220SF_LAUNCHXL_TIMER1A,
    CC3220SF_LAUNCHXL_TIMER1B,

    CC3220SF_LAUNCHXL_TIMERCOUNT
} CC3220SF_LAUNCHXL_TimerName;

can someone explain me what is wrong with this code....?

and how to configure all GPT as 16 bit mode...?

Any help appreciated.....

  • Hi Kaushik,

    I think you are trying to open Board_TIMER1 multiple times in your code, instead of using Board_TIMER1A and Board_TIMER1B as you have defined and setup in CC3220SF_LAUNCHXL.c/.h. Please use the Board_TIMER1A and Board_TIMER1B when opening those timers.

    Also, you cannot open a timer peripheral as a 32 bit timer, and as two 16bit timers at the same time. If you want to use TIMER1 as two 16 timers, then please remove your Timer_open(Board_TIMER1,..) call, so that you only have the 16bit timer open calls.

    That should resolve the errors you are seeing with your code. Let me know if you still run into issues, or have other questions.

    Regards,
    Michael
  • Hi Michael,

    Based on you reply i have tried some other things now...but still it doesn't resolved my problem Still Timer_open() API call fails.

    lets us say i want to use Board_TIMER1 as a 16 bit mode A and B. and Board_TIMER0 as 32 bit mode So below is my code snippets please check it out..

    this from my application files....

        int32_t Status = -1;
        Timer_Handle handle_timer_0;
        //Timer_Handle handle_timer_1;
        Timer_Handle handle_timer_1A;
        Timer_Handle handle_timer_1B;
        //Timer_Handle handle_timer_2;
        Timer_Params params_timer_0;
        //Timer_Params params_timer_1;
        Timer_Params params_timer_1A;
        Timer_Params params_timer_1B;
        //Timer_Params params_timer_2;
    
        //initialize timer parameters
        Timer_Params_init(&params_timer_0);         //timer 0
        //Timer_Params_init(&params_timer_1);         //timer 1
        Timer_Params_init(&params_timer_1A);         //timer 1A
        Timer_Params_init(&params_timer_1B);         //timer 1B
        //Timer_Params_init(&params_timer_2);         //timer 2
    
        //timer 0
        params_timer_0.periodUnits = Timer_PERIOD_US;
        params_timer_0.period = 5000000;
        params_timer_0.timerMode  = Timer_CONTINUOUS_CALLBACK;
        params_timer_0.timerCallback = TIMER0_ISR_Handler;
    
        handle_timer_0 = Timer_open(Board_TIMER0, &params_timer_0);
        if(handle_timer_0 == NULL) {
            UART_PRINT("Unable to open to Timer 0 Handle\n\n\r");
            while(1);
        }
    
        Status = Timer_start(handle_timer_0);
        if(Status == Timer_STATUS_ERROR) {
            UART_PRINT("Unable to Start Timer 0 \n\n\r");
            while(1);
        }
    /*
        //timer 1
        params_timer_1.periodUnits = Timer_PERIOD_US;
        params_timer_1.period = 5000000;
        params_timer_1.timerMode  = Timer_CONTINUOUS_CALLBACK;
        params_timer_1.timerCallback = TIMER1_ISR_Handler;
    
        handle_timer_1 = Timer_open(Board_TIMER1, &params_timer_1);
        if(handle_timer_1 == NULL) {
            UART_PRINT("Unable to open to Timer 1 Handle\n\n\r");
            while(1);
        }
    
        Status = Timer_start(handle_timer_1);
        if(Status == Timer_STATUS_ERROR) {
            UART_PRINT("Unable to Start Timer 1 \n\n\r");
            while(1);
        }
    */
    
        //timer 1A
        params_timer_1A.periodUnits = Timer_PERIOD_US;
        params_timer_1A.period = 5000000;
        params_timer_1A.timerMode  = Timer_CONTINUOUS_CALLBACK;
        params_timer_1A.timerCallback = TIMER1A_ISR_Handler;
    
        handle_timer_1A = Timer_open(Board_TIMER1A, &params_timer_1A);
        if(handle_timer_1A == NULL) {
            UART_PRINT("Unable to open to Timer 1A Handle\n\n\r");
            while(1);
        }
    
        Status = Timer_start(handle_timer_1A);
        if(Status == Timer_STATUS_ERROR) {
            UART_PRINT("Unable to Start Timer 1A \n\n\r");
            while(1);
        }
    
        //timer 1B
        params_timer_1B.periodUnits = Timer_PERIOD_US;
        params_timer_1B.period = 5000000;
        params_timer_1B.timerMode  = Timer_CONTINUOUS_CALLBACK;
        params_timer_1B.timerCallback = TIMER1B_ISR_Handler;
    
        handle_timer_1B = Timer_open(Board_TIMER1B, &params_timer_1B);
        if(handle_timer_1B == NULL) {
            UART_PRINT("Unable to open to Timer 1B Handle\n\n\r");
            while(1);
        }
    
        Status = Timer_start(handle_timer_1B);
        if(Status == Timer_STATUS_ERROR) {
            UART_PRINT("Unable to Start Timer 1B \n\n\r");
            while(1);
        }

    Below is my configuration from Board.h file

    #define Board_TIMER0                 CC3220SF_LAUNCHXL_TIMER0
    //#define Board_TIMER1                 CC3220SF_LAUNCHXL_TIMER1
    //#define Board_TIMER2                 CC3220SF_LAUNCHXL_TIMER2
    #define Board_TIMER1A                 CC3220SF_LAUNCHXL_TIMER1A          //this is not present by default in board.h 
    #define Board_TIMER1B                 CC3220SF_LAUNCHXL_TIMER1B          //this is not present by default in board.h 

    please note that in above snippet Board_TIMER1A, and Board_TIMER1B is i have defined my self and didnt came in SDK originally so this both are user defined...

    Below is my code snippet from launchxl.h file

    /*!
     *  @def    CC3220SF_LAUNCHXL_TimerName
     *  @brief  Enum of Timer names on the CC3220SF_LAUNCHXL dev board
     */
    typedef enum CC3220SF_LAUNCHXL_TimerName {
        CC3220SF_LAUNCHXL_TIMER0 = 0,
        //CC3220SF_LAUNCHXL_TIMER1,
        //CC3220SF_LAUNCHXL_TIMER2,
        CC3220SF_LAUNCHXL_TIMER1A,
        CC3220SF_LAUNCHXL_TIMER1B,
    
        CC3220SF_LAUNCHXL_TIMERCOUNT
    } CC3220SF_LAUNCHXL_TimerName;
    
    

    Same in above code 

    CC3220SF_LAUNCHXL_TIMER1A, and
    CC3220SF_LAUNCHXL_TIMER1B  both are here is user defined i have defined by myself.


    and below config structure from Board.c file

    const TimerCC32XX_HWAttrs timerCC3220SFHWAttrs[CC3220SF_LAUNCHXL_TIMERCOUNT] = {
        {
            .baseAddress = TIMERA0_BASE,
            .subTimer = TimerCC32XX_timer32,
            .intNum = INT_TIMERA0A,
            .intPriority = ~0
        },
        {
            .baseAddress = TIMERA1_BASE,
            .subTimer = TimerCC32XX_timer16A,
            .intNum = INT_TIMERA1A,
            .intPriority = ~0
        },
        {
            .baseAddress = TIMERA1_BASE,
            .subTimer = TimerCC32XX_timer16B,
            .intNum = INT_TIMERA1B,
            .intPriority = ~0
        },
    };

    and timer config structures is

    const Timer_Config Timer_config[CC3220SF_LAUNCHXL_TIMERCOUNT] = {
        {
            .fxnTablePtr = &TimerCC32XX_fxnTable,
            .object = &timerCC3220SFObjects[CC3220SF_LAUNCHXL_TIMER0],
            .hwAttrs = &timerCC3220SFHWAttrs[CC3220SF_LAUNCHXL_TIMER0]
        },
        {
            .fxnTablePtr = &TimerCC32XX_fxnTable,
            .object = &timerCC3220SFObjects[CC3220SF_LAUNCHXL_TIMER1A],
            .hwAttrs = &timerCC3220SFHWAttrs[CC3220SF_LAUNCHXL_TIMER1A]
        },
        {
            .fxnTablePtr = &TimerCC32XX_fxnTable,
            .object = &timerCC3220SFObjects[CC3220SF_LAUNCHXL_TIMER1B],
            .hwAttrs = &timerCC3220SFHWAttrs[CC3220SF_LAUNCHXL_TIMER1B]
        },
    };

    so this all my configurations regarding TIMER0 as well as for TIMER1

    but if my Run my Application code i am again getting Error...Timer_Open Call is failing here....

    Can you Suggest me Something Where i am doing Mistake here..

    Thanks for your Support Michael.....

    Hope for A Reply....





     

  • Hi Kaushik,

    If you import the Timer.c and TimerCC32XX.c into your workspace (simply drag and drop in the files from the SDK at /source/ti/drivers/ and /source/ti/drivers/timer respsectively) and then step through a Timer_open() call, where does it fail?

    Also, have you called Timer_init() before the rest of your timer code?

    Regards,
    Michael
  • Hi Michael,

                              Thanks for you reply. As you suggested i have include both the Timer Driver files in my projects Timer.c and TimerCC32xx.c Both.

    When i have Debug my programs through CCS version 8.1 and i am using Ti-RTOS also, i have found in code TimerCC32XX_open() Function call is failing at some place.

    below is code snippet for TimerCC32xx_open() api call code.

    in this function call i am getting NULL at particular this stage....in TimerCC32xx.c driver file.

    /* If using a half timer */
        if (hwAttrs->subTimer != TimerCC32XX_timer32) {
    
            if (object->period > 0xFFFF) {
    
                /* 24-bit resolution for the half timer */
                if (object->period >= (1 << 24)) {
    
                    TimerCC32XX_close(handle);
    
                    return (NULL);
                }
    
                getPrescaler(handle);
            }
        }

    so above you can see when it comes to see 24 bit resolution for the half timer its checking object period >= (1 << 24)

    this condition becomes true and its closing the handle here and returning NULL.

    what i have to do to resolve this issue....

    Can you Suggest something.......please....?

  • and I am Calling Timer_init() Function in my main_tirtos.c file...
  • Hi Kaushik,

    The error you are getting is due to the desired period of 5s being longer than the max period that is configurable on a 16bit timer with a 8bit prescaler. As explained in section 9.3.2.1 of the TRM:
    www.ti.com/.../swru465.pdf
    The max value of a 16+8bit timer is 2^24-1. At the system clock rate of 80MHz, counting to that number will be completed in around 210ms. Thus, the max period of a 16bit timer is 210ms. Setting a period larger than that will result in undesired behavior, thus the driver will return an error if you attempt to do so.

    Please change your 16 bit timers to 32 bit timers if you wish to use a period longer than 210ms.

    Regards,
    Michael