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.

simple Timer setup for TMS320F28016 needed!

Hello,

I have a very simple problem, I could not solve unfortunatly. I need to measure the loop time of my application. With other controllers I would simply start a timer at the beginning of the loop, save its count to any variable and reset the timer afterwards.

Following the Timer manual (SPRU712G) I did not found a setting to make e.g. CpuTimer0 count up. And the version from the Example_280xCpuTimer using the timers interruptcount is a bit to heavy for my simple concern.

If anyone knows a easy way to solve this problem I would appreciate any idea.

regards stephan

  • There are two approaches to your problem:

    1) Using the timer.  Set up the timer as in the Example except don't enable its interrupt. Make sure it runs directly off the system clock and has the maximum period (2^32-1).  Now read CpuTimer0.RegsAddr->TIM.all and TIMH.all.  These are read the timer directly.  For example:

    CpuTimer0.RegsAddr->PRD.all = 0xFFFFFFFF;

        CpuTimer0.RegsAddr->TPR.all  = 0;
        CpuTimer0.RegsAddr->TPRH.all = 0;

    When your code starts:

        CpuTimer0.RegsAddr->TCR.bit.TRB = 1;      // 1 = reload timer
         CpuTimer0.RegsAddr->TCR.bit.TSS = 0;      // 0 = start timer

    When your code ends:

    The length of time taken to run the code is in CpuTimer0.RegsAddr->TIMH.all:CpuTimer0.RegsAddr->TIM.all. 

    Note this code is written from the F2812 example so may need to be changed slightly for your code. 

    2) Using a GPIO.

    Set a spare GPIO high when your code starts and low when it ends.  Use a scope to measure the time length.

    Hopefully at least one of these methods will help you solve your problem,

    Tim

  • hello tim,

    first of all thank you for your suggestions - helped me a lot . Inspired by your first idea using the timer I found some decent commands in the DSP280x_CpuTimers.h :

    //---------------------------------------------------------------------------
    // Usefull Timer Operations:
    //
    // Start Timer:
    #define StartCpuTimer0()  CpuTimer0Regs.TCR.bit.TSS = 0

    // Stop Timer:
    #define StopCpuTimer0()   CpuTimer0Regs.TCR.bit.TSS = 1

    // Reload Timer With period Value:
    #define ReloadCpuTimer0() CpuTimer0Regs.TCR.bit.TRB = 1

    // Read 32-Bit Timer Value:
    #define ReadCpuTimer0Counter() CpuTimer0Regs.TIM.all

    // Read 32-Bit Period Value:
    #define ReadCpuTimer0Period() CpuTimer0Regs.PRD.all

    And the timer settings are made with the InitCpuTimers() from DSP280x_CpuTimers.c .

    So just in case anyone else has a similar problem, this is my code snippet for the loop time:

    [...]

    InitCpuTimers()              //before loop starts

    for(;;)  {                           //app loop

    [...]

    loop_time=(ReadCpuTimer0Period() - ReadCpuTimer0Counter())/60000000;              //Time in seconds= (period - counter)/60Mhz

    ReloadCpuTimer0();

    StartCpuTimer0();

    [...]

    }                                     //end of app loop

    Please correct me if I am wrong but I thought I have to use period-counter because of the timer just being able to count down.

    Another little tweak I would like to make is replacing the number 60000000 by the exact value of sysclkout. Does anyone know a way to read out sysclkout easily? Is it stored in any register?

  • Unfortunately the value of SYSCLKOUT is not available easily on the C2000, as the frequency of the input clock is not measured by the C2000.  However, there is one exception.  If you are using a Picollo with an internal oscillator, you already know the base clock frequency and you can read the clock scale registers to find the exact SYSCLKOUT.

    Instead most code just uses a #define to cast it to a pre known value. 

    Tim

  • The results I get with the 60Mhz written within the code directly are quite satisfying. But thanks again for the information.

    regards stephan