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.

Set DMTimer priority , using Task

Other Parts Discussed in Thread: AM3359, SYSBIOS

Hello,

i am using the  DMTimer and Tasks with SYS/BIOS and the ICE AM3359 rev 1.0a

In the .cfg file i am using the Timer Freq. Timer.intFreq.lo = 24000000;. & Clock_tickPeriod: 1000

Before i create the timer with timer_create(id,fxn,params,eb) i use DMTimer3ModuleClkConfig();

Is it correct? It seems to be necessary

-

 DMTimer2 calls the "clock_tick()" function:

Clock.tickSource =  Clock.TickSource_USER;

and timer2Params.period = 1000; or timer2Params.period = 10;

In a Task i toggle a GPIO: Result is 100Hz with a .period of 1000 and 10kHz with a .period of 10.

(AND with timer2Params.period = 5;  i reach 20kHz)(see question 2)

1) Is it right that the DMTimer2 as source for the clock_tick() function generates the clock for the Tasks?

__________________________________________________

DMTimer 3 calls a function ( also toggle a GPIO) every 50us:

timer3Params.period = 1200;      //  24MHz/1200 counts = 20kH   // CLK_M_OSC = 24MHz  // (TLDR Register)

___________________________________

Both DMTimer are using the Timer Mode and

CLK_M_OSC: CLKSEL_TIMERx_CLK Register --> 0x1 = SEL2 : Select CLK_M_OSC clock

timer2Params.runMode = Timer_RunMode_CONTINUOUS;    // Timer is periodic and runs continuously.

timer2Params.twer.ovf_wup_ena=1;                     // Enable overflow wake-up

2) With DMTimer3 i have a period of 50us (20kHz), why is the DMTimer 2 slower? How i can reach a higher frequency?

With .period i can reach a higher Hz, but why is there a factor of 240 (period 1200 to 5) between DMTimer 2 and 3.

3) How can i prioritize the DMTimer? Because the DMTimer 3 is the timer for a motor control calculation

Thank You

  • Hi,

    Where did the DMTimer3ModuleClkConfig() come from?  I don't think its part of SYSBIOS so I don't know what it is doing.

    Its fine to use DMTimer2 as the source of the Clock.  I believe this is what the code is doing.

    2.  Just depends on what frequency the timer is actually running at.  Could very well be that they are being clocked with different sources so they run at different frequencies.

    3.  When you create the DMTimer3, you should be able to specify the priority of the Hwi using the hwiParams of the Timer instance.

    Judah

  • Thank for your response,

    DMTimer_X_ModuleClkConfig() comes from /sdk/starterware...../evmAM335x.h without this function, the Timer won´t be initialized.

    If you have a hint how to avoid using this function(DMTimer_X_ModuleClkConfig()), then PLEASE let me know. I found the function in starterware/platform/evmam335x/ dmtimer.c. There are the functions for Dmtimer 2,3,4,7.

    2. Both Timer are running with the M-OSC as source, this would be 24 MHz. I write directly to this registers:

        *((unsigned int*) 0x44E0050C) = 0x00000001;        // CM_DPPL + CLKSEL_TIMER3_CLK Register (offset = Ch) 
        *((unsigned int*) 0x44E00508) = 0x00000001;        // CM_DPPL + CLKSEL_TIMER2_CLK Register (offset = 8h)

    3.Code from DMTimer3 (in .c not in .cfg):

        Timer_Handle timer3;
        Timer_Params timer3Params;
        Timer_Params_init(&timer3Params);
        timer3Params.instance->name = "timer3";
        timer3Params.period = 1200;                          //  24MHz/1200 counts = 20kH  CLK_M_OSC = 24MHz (TLDR Register)
        timer3Params.periodType = Timer_PeriodType_COUNTS;     // _COUNTS or _MICROSECS

        timer3Params.runMode = Timer_RunMode_CONTINUOUS;    // Timer is periodic and runs continuously.
        timer3Params.arg = 1;
        timer3Params.twer.ovf_wup_ena=1;                     // Enable overflow wake-up

        timer3 = Timer_create(1,timer3isr,&timer3Params,&eb);

    Where do you mean to use the hwiParams, Timer 3 hast Int.Nr. 69.

    When i create a hwi_create(), the function needs a "pointer to ISR function",  but I call the ISR function with Timer3, Timer_Crate(1,timer3isr,......) .

    Something like this?:

        Hwi_Handle hwiTimer3;
        Hwi_Params hwiTimer3Params;
        Hwi_Params_init(&hwiTimer3Params);
        hwiTimer3Params.priority = 0;   
        hwiTimer3 = Hwi_create(69,&timer3isr,&hwiTimer3Params,&eb);

    But now Timer3 and hwiTimer3 calls the function timer3isr() .... ?!

    Is it that what you mean?

    Thanks, Daniel

  • Daniel,

    I see that Timer3 is created using SYSBIOS APIs just encapsulated so I don't see it necessary to get rid of.

    When say use the hwiParams paramer of the Timer params I mean something like:

        Timer_Handle timer3;
        Timer_Params timer3Params;
        Hwi_Params hwiTimer3Params;
        
        Timer_Params_init(&timer3Params);
        Hwi_Params_init(&hwiTimer3Params);
        hwiTimer3Params.priority = 0;

        timer3Params.hwiParams = &hwiTimer3Params;
        timer3 = Timer_create(1,timer3isr,&timer3Params,&eb);

    AS far as the Timers running at the same frequencies...I think you need to let SYSBIOS know that they both are running at 24 Mhz.  Set the following field in the .cfg file:  Timer.intFreqs[];

    Judah
       

  • Hello and thanks,

    with this line "timer3Params.hwiParams = &hwiTimer3Params;"   I got an error:


    #515 a value of type "ti_sysbios_family_arm_a8_intcps_Hwi_Params *" cannot be assigned to an
    entity of type "ti_sysbios_hal_Hwi_Params *"    


    @ the .cfg file:. do you mean that, "i am using the Timer Freq. Timer.intFreq.lo = 24000000;"

  • Try using <ti/knl/hal/Hwi.h> instead of ti/sysbios/family/arm/a8/intcps/Hwi.h

    Which SYSBIOS version are you using?

    I think there was a recent fix made in SYSBIOS 6.37.00 that added Timer.intFreqs[].  Probably because Timer.intFreq only sets one of the Timers.

    I can suggest a work around hack for now to see if it works for you.  Make a backup of the original ti/sysbios/timers/dmtimer.xs file.  Then open it up and search for "AM335X".  Look for "DMTimer2" and "DMTimer3" and change the intFreq.lo field from 32768 to 24000000.  Rebuilt your project.

                         {
                            name: "DMTimer2",
                            baseAddr: 0x48040000,
                            intNum:  68,
                            eventId: -1,
                            intFreq: {
                                lo: 32768,
                                hi: 0,
                            },
                        },
                        {
                            name: "DMTimer3",
                            baseAddr: 0x48042000,
                            intNum:  69,
                            eventId: -1,
                            intFreq: {
                                lo: 32768,
                                hi: 0,
                            },
                        },

    Judah

  • I am using this bios_6_35_01_29 version and i can´t find the dmtimer.xs file.

    Only timer.xs in the dmtimer-folder. There i changed the lo: value.

    But still the dmTimer 2 is slower then dmtimer3.

    timer2Params.period = 100; timer3Params.period = 1200

    And timer2 is for myClock function with Clock_tick().

    In .cfg file:

    Clock.tickSource = Clock.TickSource_USER;
    Clock.tickPeriod = 1000;


    Result oscilloscope:
    Timer2: 1kHz
    Timer3: 20kHz

    remark: Timer2 is for the clock.ticksource. and the clock calls the tasks and timer3 for the ISR

    2 Tasks with task_sleep(1). (here i got 1kHz)

    For now without task_sleep is only one task running at 2,08MHz (?! if i change the .period or clock.tickperiod value, nothing changes). But with only 1 Task I expected that both timer are at the same frequency when the timerX.period = 1200 are equal for dmtimer2&3.

    In ROV window i can see the period of Dmtimer2 = 28799 and Dmtimer3= 1200

    i want to reach that the task(timer2) and the ISR (timer3) have the same frequency?! Or is it not possible because with timer2 i trigger the clock.source and the task.?!

  • Anyone an idea / answer?

  • Daniel,

    One correction from my previous post.  I told you to change DMTimer2 and DMTimer3 but you should Change DMTimer4 and DMTimer4 as Timer id 2 and 3 corresponds to those Timers.

    Secondly, I've been able to produce the right results with Timer2 and Timer3 both being 24 Mhz on the beagle bone AM3359 board.  I've got to believe there's something not quite right with your setup.  Either the Clocks aren't being clocked at the right frequency as you expected or BIOS thinks its clock at one frequency but really running at another.

    Judah

  • At the moment i am not working on the DMTImer project, because SPI with EDMA is more important. In a free minute i take a look back.

    Can you show me your setup code concern the TimerSetup? Is the change in timer.xs necessary?

  • Daniel,

    Yes, I believe the change to Timer.xs is necessary because in your SYSBIOS version, there's isn't a way to change it via the .cfg file.

    Here's an example of what I did.  I confirmed that Timer 2 runs twice before Timer 3 gets to run.

    var Timer = xdc.useModule('ti.sysbios.hal.Timer');
    Program.global.tim0 = Timer.create(2, '&myIsr', {period: 4000,
            runMode: Timer.RunMode_CONTINUOUS,
            periodType: Timer.PeriodType_MICROSECS,
            startMode: Timer.StartMode_AUTO, arg:2});

    Program.global.tim1 = Timer.create(3, '&myIsr2',{period: 10000,
            runMode: Timer.RunMode_ONESHOT,
            periodType: Timer.PeriodType_MICROSECS,
            startMode: Timer.StartMode_AUTO, arg:3});

    Another key thing is I had to do the following in a .gel file to set Timers 4 and 5 to the 24Mhz.
    Logical Timer 2 = Physical Timer 4 and Logical Timer 3 = Physical Timer 5.

    #define CM_PER   (0x44e00000)
    #define CM_DPLL   (0x44e00500)

    #define CM_PER_TIMER2_CLKCTRL (CM_PER + 0x80)
    #define CM_PER_TIMER3_CLKCTRL (CM_PER + 0x84)
    #define CM_PER_TIMER4_CLKCTRL (CM_PER + 0x88)
    #define CM_PER_TIMER5_CLKCTRL (CM_PER + 0xEC)
    #define CM_PER_TIMER6_CLKCTRL (CM_PER + 0xF0)
    #define CM_PER_TIMER7_CLKCTRL (CM_PER + 0x7C)

    #define CLKSEL_TIMER2_CLK (CM_DPLL + 0x04)
    #define CLKSEL_TIMER3_CLK (CM_DPLL + 0x08)
    #define CLKSEL_TIMER4_CLK (CM_DPLL + 0x0C)
    #define CLKSEL_TIMER5_CLK (CM_DPLL + 0x18)
    #define CLKSEL_TIMER6_CLK (CM_DPLL + 0x1C)
    #define CLKSEL_TIMER7_CLK (CM_DPLL + 0x00)

    hotmenu EnableTimers_32KHz()
    {
     WR_MEM_32(CM_PER_TIMER2_CLKCTRL, 0x2);
     WR_MEM_32(CLKSEL_TIMER2_CLK, 0x2);

     WR_MEM_32(CM_PER_TIMER3_CLKCTRL, 0x2);
     WR_MEM_32(CLKSEL_TIMER3_CLK, 0x2);

     WR_MEM_32(CM_PER_TIMER4_CLKCTRL, 0x2);
     //WR_MEM_32(CLKSEL_TIMER4_CLK, 0x2); // 32 Khz clock
     WR_MEM_32(CLKSEL_TIMER4_CLK, 0x1); // CLK_M_OSC clock

     WR_MEM_32(CM_PER_TIMER5_CLKCTRL, 0x2);
     //WR_MEM_32(CLKSEL_TIMER5_CLK, 0x2); // 32 Khz clock
     WR_MEM_32(CLKSEL_TIMER5_CLK, 0x1); // CLK_M_OSC clock

     WR_MEM_32(CM_PER_TIMER6_CLKCTRL, 0x2);
     WR_MEM_32(CLKSEL_TIMER6_CLK, 0x2);

     WR_MEM_32(CM_PER_TIMER7_CLKCTRL, 0x2);
     WR_MEM_32(CLKSEL_TIMER7_CLK, 0x2);

    }

    Judah

  • Ok thank you for some workarounds, it´s good to know. But i think it´s not the TimerSetup.

    I am using the TMDCICE3359.gel file and the modified timer.xs

    Timer2 and 3 are initialize with the same values.

    I choose Timer2 as input for the clock. The ISR calls the clock_tick() function.

    Clock.tickSource = Clock.TickSource_USER;

    Clock.tickPeriod = 1; //us

    timer2Params.period = 1200;

    .runMode = Timer_RunMode_CONTINUOUS;

    .twer.ovf_wup_ena=1;

    The clock for the task is genrated now by the Timer2 >> is that right?

    Timer3 ISR: toggle GPIO with 20kHz , period in ROV: 1200

    TASK: toggle GPIO with ~1kHz  (because eperiod is 1200 not 1000us (1kHz) period in ROV: 28799

    How i can get a faster clock for the TASK???

    With timer2Params.period = 10, i have a 50 kHz Task, but how i can get a faster period of/for the task?

    Without task_sleep(1) i have a frequency of 2MHz and sometimes a little delay and then the oscilloscope shows 500kHz.

    Thank you.

  • Daniel,

    I'm not exactly following what's going on with your app.  Two things that jumped at me.

    1.  When you do timer2Params.period = 1200.  Is this 1200 cycles or 1200 microseconds?  The default is 1200 microseconds I think.  If its 1200 cycles you want you need to specify the periodType.

    2.  Are you doing what the following statement says in the cdoc for Clock?

             TickSource_USER The Application is responsible for calling
             Clock_tick() periodically. Make sure tickPeriod
             is set to the period that Clock_tick() is called.

    Judah

  • 1.

    The periodType is in cycles/counts: periodType = Timer_PeriodType_COUNTS;

    2.

    In .cfg File:

    Clock.tickSource = Clock.TickSource_USER;

    Clock.tickPeriod = 1;

    in C.file:

    timer2Params.period = 10;   //counts

    timer2 = Timer_create(0,myTimerTick,&timer2Params,&eb);

    Void myTimerTick(UArg arg)
    {
         Clock_tick();
    }

    I think its right this way, it works and i can reach 100kHz with .period = 10.

  • Hello,

    with this line "timerParams.hwiParams = &hwiParams;"   I got an error:

    #515 a value of type "ti_sysbios_family_arm_a8_intcps_Hwi_Params *" cannot be assigned to an
    entity of type "ti_sysbios_hal_Hwi_Params *"    

    hal/Hwi.h is included in /dmtimer/Timer.h (  ti_sysbios_hal_Hwi_Params* hwiParams; ) and not the specified arm/a8/intcps/Hwi.h

    my code:
        Timer_Handle timer3;
        timerParams.instance->name = "timer3";
        timerParams.period = 1200;        

        // HWI *********************************************
        UInt  intNum;
        Hwi_Params hwiParams;
        intNum = 69;
        Hwi_Params_init(&hwiParams);
        hwiParams.arg = 1;
        hwiParams.priority = 0;
        hwiParams.enableInt = true;

        timerParams.hwiParams = &hwiParams;

        TimerFuncPointer = timer3isr;
        timer3 = Timer_create(1,TimerFuncPointer,&timerParams,&eb);

    If i include this line:
    #include <ti/sysbios/hal/hwi.h>
    I got a lot of warnings "redefinition 0f macros xyz" because they are declared in /sysbios/family/arm/a8/intcps/Hwi.h