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.

Clock Function in not called in the expected period

Other Parts Discussed in Thread: SYSBIOS, AM3359

Hello,

I'm not sure if this topics should be posted in the BIOS are or here - correct me if I'm wrong here.

Im trying build a run-time System with some SWI-Threads which are called at a fixed period. Therefore I use a Clock funcion to post the SWIs.

- SWI0 excecuted with every call of the Clock function
- SWI1 every 4th Clock call
- SWI2 every 16th
- SWI3 every 512th

Clock and SWI are created static in the .cfg File. The Lines are:

/****************************************************************************/

var clock0Params = new Clock.Params();
clock0Params.instance.name = "clock0";
clock0Params.period = 1;
clock0Params.startFlag = true;
Program.global.clock0 = Clock.create("&clk0Func", 200, clock0Params);

Clock.tickPeriod = 100;
Clock.timerId = -1;

var swi0Params = new Swi.Params();
swi0Params.instance.name = "hdl_swi0";
swi0Params.priority = 8;
Program.global.hdl_swi0 = Swi.create("&swi0Func", swi0Params);

var swi1Params = new Swi.Params();
swi1Params.instance.name = "hdl_swi1";
swi1Params.priority = 7;
swi1Params.trigger = 4;
Program.global.hdl_swi1 = Swi.create("&swi1Func", swi1Params);

var swi2Params = new Swi.Params();
swi2Params.instance.name = "hdl_swi2";
swi2Params.priority = 6;
swi2Params.trigger = 16;
Program.global.hdl_swi2 = Swi.create("&swi2Func", swi2Params);

var swi3Params = new Swi.Params();
swi3Params.instance.name = "hdl_swi3";
swi3Params.priority = 5;
swi3Params.trigger = 512;
Program.global.hdl_swi3 = Swi.create("&swi3Func", swi3Params);

/****************************************************************************/


The Clock-SWI-function calls the other SWIs in this way:

void clk0Func (void)
{
  GPIO0_7_toggle();    //Toggle testpin
  Swi_post(hdl_swi0);  //SWI0: every Clock-Tick
  Swi_dec(hdl_swi1);   //SWI1 executed every 4. Tick (Init_Trigger = 4)
  Swi_dec(hdl_swi2);   //SWI2 executed every 16. Tick (Init_Trigger = 16)
  Swi_dec(hdl_swi3);   //SWI3 executed every 512. Tick (Init_Trigger = 512);
}


At the moment the SWIs are only toggling onboard LEDs. Not more.

The Problem is that, SWI0 / clk0Func is not executed in the periode I expected:

- With Clock.tickPeriod = 100, I meassure about 92 us
- With 500, I get 488 us
- With 1000, I get 1005.1 us

Questions:
Why is there such a big difference between the configured time and the real period? How can I reduce it?

Another point is that the maximum frequency of the fastest Task I want to test will be 16 kHz / 62.5 us. When I reduce the Clock.tickPeriod value the Clock funktion doen't even get called anymore. How can i get faster Clock ticking?

My HW / SW Setup is:
- Code Composer Studio v5.4.0.00091with xdctools_3_25_00_48 , am335x_sysbios_ind_sdk_1.0.0.8 and bios_6_35_01_29
- AM3359 on ICE Evalboard

Regards,

Tim

  • Hi Tim,

    Do you know at what frequency your CPU clock is running? If it's running at a speed different from what BIOS thinks it's running at, it could account for the differences you're seeing.

    Once you find out how many Hz it's actually running at, you can tell BIOS in your cfg script by setting BIOS.cpuFreq.lo to that value.

    Whitney

  • I didn't make any changes to the Cpu clock frequency. Its 550 MHz - thats the initial value of the SYS/BIOS example programms .

    I guess if the CPU clock was wrong the difference between expected period and real period of the swi-clock-funktion would be bigger?!

  • Tim,

    I think the timer peripheral used by the Clock module must be configured for 32768Hz for your application, and this is limiting the resolution you can get for the Clock ticks.

    If the timer is running at 32768Hz, then 100usec is 3.2768 ticks.  Rounding downwards, this is 3 timer counts, and 3/32768 =  91.5usec.  Similarly, 500usec is 16.384 ticks, rounding down is 16 ticks, so 16/32768 = 488.2usec.  But for 1000usec I would have expected something like 977usec, versus the 1005usec you report, not sure why that one is different.

    Anyways, please see this thread about Clock and the tick rate resolution on an AM3359, and how to change it: http://e2e.ti.com/support/embedded/bios/f/355/p/267580/937908.aspx#937908

    Scott

  • Hi Scott,

    thank you for the answer.

    What you wrote makes sense to me. With (33 ticks) / (32768 ticks per s) = 1007 us that fits for the last value too.

    At the moment I'm using a Timer (24 MHz clocked) with a HWI to post the SWIs. This works fine, also for shorter periods.

    Void main()
    {
        Timer_Handle hdl_timer = 0;
        Timer_Params timerParams;
        Error_Block eb;

        mmuInit(applMmuEntries);

        Error_init(&eb);

        DMTimer3ModuleClkConfig();           //enable Clock for DMTimer 3

        Timer_Params_init(&timerParams);

        timerParams.extFreq.lo = 24000000;   //Timer Frequency
        timerParams.extFreq.hi = 0;
        timerParams.period = 63;             //Period 63 us
        timerParams.periodType = Timer_PeriodType_MICROSECS;
        timerParams.arg = 1;

        hdl_timer = Timer_create(1, (ti_sysbios_interfaces_ITimer_FuncPtr)Timer0Func, &timerParams, &eb);  // 1 stands for DMTimer3

        [...]
        BIOS_start();     /* enable interrupts and start SYS/BIOS */

    }

    I'll try to change the timer for the Clock Module later to get the perviously desired Clock/SWI solution without using HWIs. I'll report if it worked...

    Regards,

    Tim

  • Scott Gary said:

    Anyways, please see this thread about Clock and the tick rate resolution on an AM3359, and how to change it: http://e2e.ti.com/support/embedded/bios/f/355/p/267580/937908.aspx#937908

    To get a 24 MHz based Clock Tick I tried to use to use DMTimer4. After reading through the topic in your link I changed the connect-function of my GEL file to:

    OnTargetConnect()
    {
        unsigned int i;
        GEL_MapOff();
        GEL_MapReset();
        GEL_MapAddStr(0x00020000, 0, 0x0000C000, "R", 0);    // Boot ROM
        [...]
        GEL_MapAddStr(0x80000000, 0, 0x10000000, "R|W", 0);  // 256MB DDR2 external memory
        GEL_MapOn();
        GEL_Reset();             //reset the board to avoid conflicts with program running from NAND
        for(i=0;i<100000;i++);
        AM335xStartState();
        AM3359_ICE_Initialization();

        WR_MEM_32(CM_PER_TIMER4_CLKCTRL, 0x2);      //Enable Timer4
        WR_MEM_32(CLKSEL_TIMER4_CLK, 0x1);          //Clock source CLK_M_OSC (24 MHz)
        GEL_TextOut("Timer4 init done\n");

        Disable_Watchdog();
    }

    In the cfg script I changed timerID of the Clock Module from ANY to 2 (for DMTimer4). The important lines are:

    Clock.tickPeriod = 100;
    Clock.timerId = 2;
    [...]
    var clock0Params = new Clock.Params();
    clock0Params.instance.name = "clock0";
    clock0Params.period = 1;
    clock0Params.startFlag = true;
    Program.global.clock0 = Clock.create("&clk0Func", 200, clock0Params);
    Clock.tickMode = Clock.TickMode_PERIODIC;


    Theres no change in the behavior. Still the measured clock periods aren't right. Adding the following lines the the config code ends up in the same error as in the link you posted, although i changed the GEL file.

    var Timer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
    Timer.intFreq.hi = 0;
    Timer.intFreq.lo = 20000000;

    What is the trick to get the Clock module tick in multiples of a 24 MHz Timer?


  • Tim,

    I’ve not used an AM3359, but what you are doing looks right to me.

    By the “same error” do you mean the frequency mismatch error?  If so, what are the values displayed?

    I wonder if it is because you told the dmtimer module that the frequency is 20MHz, versus 24MHz that you mention elsewhere in your description?  If you set this instead, does that work?

    Timer.intFreq.lo = 24000000;

    Also, yes I agree the ~1000usec value looks right, I guess I hit some wrong keys on my calculator - twice! :OP

    Scott

  • Scott,

    it seems to work now. On friday I still meassured the wrong times although i changed the Timer settings... I can't reproduce that now so it probably was my fault.

    To put it all together:

    Added to the GEL File:
    #define CM_DPLL (0x44e00500)
    #define CM_PER_TIMER4_CLKCTRL (PRCM_BASE_ADDR + 0x88)
    #define CLKSEL_TIMER4_CLK (CM_DPLL + 0x10)
    [...]
             //Following Lines in the Connect Function
        WR_MEM_32(CM_PER_TIMER4_CLKCTRL, 0x2);      //Enable DMTimer4
        WR_MEM_32(CLKSEL_TIMER4_CLK, 0x1);          //Clk Source: CLK_M_OSC

    Changed / Added in the cfg file:
    var Timer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
    Timer.intFreq.hi = 0;
    Timer.intFreq.lo = 24000000;
    [...]
    Clock.timerId = 2;   //DMTimer4

    Regards,

    Tim