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.

SYS/BIOS Timer Example Code?

Guru 15580 points
Other Parts Discussed in Thread: OMAP-L138, SYSBIOS

I am working my way through the SYS/BIOS example projects in an effort to transition from DSP/BIOS to SYS/BIOS for my OMAP-L138 project. I would like to use the Timer module but am struggling with several fairly basic questions.

1. On the OMAP-L138 timers 0 & 1 are driven by AUXCLK, which on my board is 24MHz. And timers 2 & 3 are driven by SYSCLK2, which is 150MHz on my board. How and were are these frequencies specified in bios 6? Do I need to tell bios 6 this information? In bios 5 it is specified on the CLK Manager in the DSPBIOS config tool.

2. I would like to use the Timer_getFreq function. Can someone provide some sample code showing how to get the frequency of the timer? I am struggling with the correct syntax. Here is my test code, which throws an error for Types_FreqHz (undefined). I have created a static Timer (timer1) in xgconf with a period of 500 us which correctly calls myISR.

Types_FreqHz *freq;

 

 

Void main()

    Swi_post(swi0);

    Swi_post(swi1);

    Clock_start(clk1);

    Timer_start(timer1);    

    BIOS_start();

}

 

Void myISR()

{

Timer_getFreq(timer1, freq);

System_printf("Current period = %d\n", Timer_getPeriod(timer1));

}

Here is what is generated by xgconf

var ti_sysbios_hal_Timer = xdc.useModule('ti.sysbios.hal.Timer');

 

var instti_sysbios_hal_Timer1Params0 = new ti_sysbios_hal_Timer.Params();

instti_sysbios_hal_Timer1Params0.period = 500;

instti_sysbios_hal_Timer1Params0.instance.name = "timer1";

Program.global.timer1 = ti_sysbios_hal_Timer.create(1, "&myISR", instti_sysbios_hal_Timer1Params0);

 

3. I have specified a period of 500 us in the static config but the code above returns a timer period of 12000.  What am I doing wrong?

Your guidance is appreciated.

Thx,

MikeH

 

  • MikeH,

    1. On the OMAP-L138 timers 0 & 1 are driven by AUXCLK, which on my board is 24MHz. And timers 2 & 3 are driven by SYSCLK2, which is 150MHz on my board. How and were are these frequencies specified in bios 6? Do I need to tell bios 6 this information? In bios 5 it is specified on the CLK Manager in the DSPBIOS config tool.

    The default SYSBIOS value is exactly what you described above so there's no need to change the default values.  However, if you did need to change it, it can be done by setting the Timer.intFreqs[] config param in your static config file *.cfg.  Also, note that you may need to use ti/sybios/timers/timer64/Timer module directly in your .cfg file and not go through the hal/Timer.

    2. I would like to use the Timer_getFreq function. Can someone provide some sample code showing how to get the frequency of the timer? I am struggling with the correct syntax. Here is my test code, which throws an error for Types_FreqHz (undefined). I have created a static Timer (timer1) in xgconf with a period of 500 us which correctly calls myISR.

    Timer_Handle timer;

    Void myFunction(UArg arg)
    {
        Timer_Params prms;
        xdc_runtime_Types_FreqHz  freq;

        Timer_Params_init(&prms);
        prms.period = 10000;

        timer = Timer_create(Timer_ANY, myIsr, &prms, NULL);
       Timer_getFreq(timer, &freq);
    }

    If your getting a compiler error, you may have to #include <xdc/runtime/Types.h>

    As for #3, I would need to try to reproduce that and couldn't tell you why you are getting the value you are getting.

    Judah

  • Judah,

    judahvang said:
    If your getting a compiler error, you may have to #include <xdc/runtime/Types.h>

    That fixed the the compile error problem. 

    However, I am getting a value that is 24x the expected value for period. I have attached my modified code that produces this error. It is basically the "static" example code with the addition of a timer using timer64. Again, my board (Logic SOM-1) uses a 24HMz crystal and the PLL is running at 300MHz. FYI, I am running this on the ARM side of the chip, but since the ARM and DSP run at the same frequency it shouldn't matter.

    Let me know if you see an error that could cause this discrepancy.

    Thx,

    MikeH

    0005.test4-static1.zip

     

  • MikeH,

    I think I found your issue.  When you create the Timer, you didn't specify what the unit of the period is, by default its set to PeriodType_MICROSECS.  What you wanted was cycles, I think, therefore you need to specify PeriodType_COUNTS for the periodType.  For example:

    var Timer = xdc.useModule('ti.sysbios.hal.Timer'');

    Timer.create(1, '&myIsr', {period:500, periodType: Timer.PeriodType_COUNTS});

    Judah

  • Judah,

    Setting PeriodType_COUNTS does produce a value of 1000 as the timer period. But I am now confused about the definition of the term "COUNTS". I would like to generate a timer with a period of 500 microseconds. How do I do this?

    Thx,

    MikeH

  • MikeH,

    "COUNTS" is in terms of timer ticks.

    The timer is running at 24.0 Mhz with a period of 1 milliseconds, it would take 24,000 timer ticks.  So if you wanted a 500 microseconds period, its half of 24,000 or 12,000 timer ticks.  That's why in your original code, you were getting 12,000 for the period value.  The period is what's programmed into the Timer period register.

    Judah

  • Duh! I knew that......sort of....:)

    Thanks,

    MikeH