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.

Enabling Timers on RM46

Other Parts Discussed in Thread: HALCOGEN

Hello,

I enabled timers in HALCoGen which sets a macro in the "FreeRTOS.h" header file. After I do this, the code in "sys_main.c" no longer runs - when I disable the timers everything works OK. I assume I need to setup interrupts (maybe?) and make sure I have ISR handlers in place (maybe?). Do you have something I can reference that will help me enable timers and allow my code to execute?

Thank you,

Ray

  • Timers are just like tasks in FreeRTOS.  Do you have FreeRTOS set up so the OS has a clock tick? Do you have tasks that run?

    If you do, you should just need to call _enable_interrupt_(); and start your scheduler to run your tasks. Create your timer and pass it the function you want it to call when it goes off.

    static void initSampleDataTimer()
    {
    	sampleDataTimerHandle = xTimerCreate(sampleDataTimerName, sampleDataTimerPeriod, sampleDataTimerAutoReload, (void*) sampleDataTimerId, sampleDataTimer);
    	configASSERT(sampleDataTimerHandle != NULL);
    
    	xTimerStart(sampleDataTimerHandle, convertMsecsToTicks(20));
    }
    
    
    /*
    *  PARAMETERS: xTimer - handle for the timer that called the function
    *
    *  DESCRIPTION: This kicks off sampling limit data.
    *
    *  RETURNS:		void
    *
    */
    static void sampleDataTimer(TimerHandle_t xTimer)
    {
    
    	if(xTimer == sampleDataTimerHandle)
    	{
    		//Do something
    	}
    }

  • David,

    Thanks for your quick response. Yes I have tasks running. When I enable timers, FreeRTOS attempts to initialize the timers task and it is failing while trying to create a queue for the timer task. I've set the heap to 65536 bytes and the stacks to 512 words, so I don't think that is the problem. I'm continuing to debug, but your help is much appreciated.

    THanks

    Ray

  • David,

    Sorry to create an alarm. I neglected to set the timer task parameters in "FreeRTOSConfig.h". Once I did that everything works OK.

    Ray

  • I agree with you. When you enable the timer, the stack size must not be zero (yet not too large) and the priority must be within limits. If left the default zero values, the initializations might fail.