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.

mcu timer period error

Part Number: TDA4VMXEVM

Tool/software: TI C/C++ Compiler

Hi:

  I use mcu timer with 10 seconds period,but the real value only has 768ms,my code just like this:

int main(void)
{

#ifdef UART_ENABLED
    AppUtils_Init();
#endif
    
    TimerP_Params timerParams;
    TimerP_Handle timer;

    /* Initialize the timer params */
    TimerP_Params_init(&timerParams);
    
    timerParams.startMode   = TimerP_StartMode_USER;
    timerParams.periodType  = TimerP_PeriodType_MICROSECS;
    timerParams.period      = 10000000;
    timerParams.arg         = NULL;

    timerParams.runMode     = TimerP_RunMode_CONTINUOUS;
    
    timer = TimerP_create(TimerP_ANY, App_TimerFxn, &timerParams);
    if(NULL != timer)
    {
        TimerP_start(timer);
    }
    else
    {
        BIOS_exit(0);
    }
    BIOS_start();    /* does not return */
    
    return(0);

}

static Void App_TimerFxn(UArg a0)
{
    AppUtils_Printf(APP_UTILS_PRINT_MSG_NORMAL, "Hello world!\r\n");
}

  • Hi,

    I've had a similar query recently and have resolved the same in the thread - https://e2e.ti.com/support/tools/ccs/f/81/t/896425

    Can you please look at the verified answer on that thread? I think that will solve your issue.

    Also, I tried to run the same code (I had use the below code, using TimerP_getTimeInUsecs() to get the timestamp)

    uint64_t timerStamp = 0;
    static Void App_TimerFxn(UArg a0)
    {
        
        timerStamp = TimerP_getTimeInUsecs();
        AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                       "timerStamp = %u\r\n", timerStamp);
    }
    

    Output - (running on mcu1_0)

    CAN Profile App:timerStamp = 10000147
    CAN Profile App:timerStamp = 20000146
    CAN Profile App:timerStamp = 30000147
    CAN Profile App:timerStamp = 40000146
    CAN Profile App:timerStamp = 50000146
    CAN Profile App:timerStamp = 60000146
    CAN Profile App:timerStamp = 70000146
    

    So I see a delta of 10secs, but I would still recommend looking at the above E2E and setting the freq in that manner.

    Regards,

    Karan 

  • Hi Karan:

        I have tried according your code,but the result is the same.

  • Hi,

    Can you please answer the following -

    • Which SDK are you using?
    • Is there a particular example you are trying to modify or you have your own example - if it is your own example can you please attach the full source?
    • When you say "result is the same" what are you seeing? You add the exact same code and the prints show a different delta and not 10s?
      • Are you using the same instrumentation as me to compute the time delta as me? Or is it something else?
      • Please add logs to your output.
    • Which boot mode are you using to boot the application?

    I had validated by add the piece of code in the existing can_profile_app in mcusw, and was using SDK 6.02 with CCS boot mode.

    Regards,

    Karan

  • Hi Karan:

    • SDK:6.02
    • I use mcu_app as demo to modify the application
    • boot from SD card
    • I use TimerP_getTimeInUsecs() to get the timestamp,and the result likes below:
    int main(void)
    {
        
    #ifdef UART_ENABLED
        AppUtils_Init();
    #endif
        
        TimerP_Params timerParams;
        TimerP_Handle timer;
    
        /* Initialize the timer params */
        TimerP_Params_init(&timerParams);
        
        timerParams.startMode   = TimerP_StartMode_USER;
        timerParams.periodType  = TimerP_PeriodType_MICROSECS;
        timerParams.period      = 10000000;
        timerParams.arg         = NULL;
    
        timerParams.runMode     = TimerP_RunMode_CONTINUOUS;
        
        timer = TimerP_create(TimerP_ANY, App_TimerFxn, &timerParams);
        if(NULL != timer)
        {
            TimerP_start(timer);
        }
        else
        {
            BIOS_exit(0);
        }
        BIOS_start();    /* does not return */
        
        return(0);
    
    }
    
    
    static Void App_TimerFxn(UArg a0)
    {
        uint64_t timerStamp = 0;
        timerStamp = TimerP_getTimeInUsecs();
        AppUtils_Printf(APP_UTILS_PRINT_MSG_NORMAL, "timerStamp = %u\r\n", timerStamp);
    }
    
    
    result:
    
    SBL Revision: 01.00.09.02 (Apr  8 2020 - 14:24:09)
    SYSFW  ver: 19.8.0-v2019.08 (Terrific Llama
    timerStamp = 768147
    timerStamp = 1536147
    timerStamp = 2304147
    timerStamp = 3072147
    timerStamp = 3840146
    timerStamp = 4608147
    timerStamp = 5376147
    timerStamp = 6144146
    timerStamp = 6912147
    timerStamp = 7680147
    timerStamp = 8448147
    timerStamp = 9216147
    timerStamp = 9984147
    
    

  • Hi,

    I think I know what is happening with SBL boot flow in you case.

    The MCU domain has 9 timers DMTimer0:8 and the DMTimer0 in case of running from SBL is configured for a frequency of 250MHz as compared to the other timers being configured for 19.2MHz. 

    You can see in the file bios_6_76_03_01/packages/ti/sysbios/timers/dmtimer/Timer.xs (line 1665 under the "J7.*_MCU" structure in DMTimer0) that all the timers are expected to be configured for 19.2MHz.

    So if there is a difference between what you actually configure (from the SBL or GELs) and what you expect it to be configured for (either sysbios cfg file or Timer.xs) then you will see a difference between what you configure the timer callback to be and what it actually gets configured to.

    Now when you use SBL, it configures the same DMTimer0 for a freq of 250MHz (you can look at the register 0x40F08100 i.e. the CTRLMMR_MCU_TIMER0_CLKSEL register the value there is 1)

    The reason why using CCS didn't give any abnormality with regard to the timer task getting called was because CCS GELs configure the same DMTimer0 for 19.2 MHz (mux value is 0)

    Now the solution to this -

    Override the frequency of the timer in the timer params like this:

    uint64_t timerStamp = 0;
    static Void App_TimerFxn(UArg a0)
    {
        
        timerStamp = TimerP_getTimeInUsecs();
        AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME
                       "timerStamp = %u\r\n", timerStamp);
    }
    
    int main(void)
    {
    
    #ifdef UART_ENABLED
        AppUtils_Init();
    #endif
        
        TimerP_Params timerParams;
        TimerP_Handle timer;
    
        /* Initialize the timer params */
        TimerP_Params_init(&timerParams);
        
        timerParams.startMode   = TimerP_StartMode_USER;
        timerParams.periodType  = TimerP_PeriodType_MICROSECS;
        timerParams.period      = 1000000;
        timerParams.arg         = NULL;
        /* Overriding frequency to set it to 250MHz */
        timerParams.intfreqLo = 250000000;
        timerParams.intfreqHi = 0;
        timerParams.extfreqLo = 250000000;
        timerParams.extfreqHi = 0;
    
        timerParams.runMode     = TimerP_RunMode_CONTINUOUS;
        
        timer = TimerP_create(TimerP_ANY, App_TimerFxn, &timerParams);
        if(NULL != timer)
        {
            TimerP_start(timer);
        }
        else
        {
            BIOS_exit(0);
        }
        BIOS_start();    /* does not return */
        
        return(0);
    
    }
    

    I was able to get a 1sec tick after this.

    I will probably get back on this once I get to know why this delta in freq of just one timer is there till then you can use the above.

    Regards,

    Karan

  • Hi Karan:

        Your last reply solved my problem. Thanks a lot!!!

    Regards,

    Lu