FreeRTOS V7.0.1 Software Timers

Hey all, I tried to implement software timers in my application and I have trobules with this new feature. If the timer task, which is initialised while the scheduler is started, works with the highest priority in system, nothing works. I’m wondering about this, because also the timer callback functions don’t work. If there is one task in the system which has a priority above the priority of the timer task, everything works fine. Can anyone help me understanding this? Greets.

FreeRTOS V7.0.1 Software Timers

I have just done a quick experiment and cannot replicate this behaviour. The timer task will be in the Blocked state unless a timer API function is being called, or a timer has expired.  If another task or interrupt is continuously using timer API functions, or a timer has its period set to a very low number (so it continuously expires) then the timer task will have processing to perform all the time – and therefore starve lower priority tasks of processing time (just like any other task would).  If the timer task has the highest priority, and it is performing processing all the time, then no other tasks would run (again, it just behaves like any other task). Are you using timers with very short periods?
Are you continuously calling timer API functions?
Do you have configASSERT() defined to trap some misuse scenarios? Regards.

FreeRTOS V7.0.1 Software Timers

My system looks like this: I initialize a task with priority 10. The task only counts up a variable as indication that it lives or doesn’t. After this, I create a timer, and start this timer. Parameters: auto reload = 1, timer period = 1000. After this I start the created timer. In my FreeRTOSconfig.h File, I chose as TimerTaskPriority 11. Now I start the scheduler. Now I expect, that my timer callback function, which also counts up a variable, works every second, and my normal task doesn’t work. But nothing happens, the task doesn’t work (understandable because of the lower priority) but the timer callback function also doesn’t work. I stepped through the timer task and found out, that my timers don’t become inserted to the timer lists. (pxCurrentTimerList).

FreeRTOS V7.0.1 Software Timers

What is configMAX_PRIORITIES set to?
Can you post your code? Regards.

FreeRTOS V7.0.1 Software Timers

configMAX_PRIORITIES ist set to 20 …. I think this should be OK….
#define configUSE_TIMERS                    1
#define configTIMER_TASK_PRIORITY           11
#define configTIMER_QUEUE_LENGTH        50
#define configTIMER_TASK_STACK_DEPTH    256
... this is ah short form of my code...
void main()
{
    xTaskCreate(Test1,(const signed char*)"TEST1",32,NULL,10,NULL);
    Timer1 = xTimerCreate((const signed char*)"TIMER1",1,1,0,cbfTimer1);
    xTimerStart(Timer1,1);
    vTaskStartScheduler();
}
/* Task Fkt */
void Test1(void* pvParam)
{
    while(1)
    {
        ct1 ++;
        vTaskDelay(100);
    }
}
/* Timer Callback */
void cbfTimer1( xTimerHandle pxTimer )
{
    TimerCount1 ++;
}

FreeRTOS V7.0.1 Software Timers

You have set a timer period of 1.  It is always expired, so the timer task will always be executing. Regards.

FreeRTOS V7.0.1 Software Timers

Sure, the timer task is always executing, but the callback isn’t executed…. And this is what I can’t understand

FreeRTOS V7.0.1 Software Timers

And it doesn’t have any consequence when I change the timer period from 1 to 1000. Same problem. I just found out, that I have the same problem, when the timer task has the same priority as the normal user task. The system only works if the timer task has a lower priority than the user task.

FreeRTOS V7.0.1 Software Timers

Hi, I am facing a similar problem although I have not been able to run timers even once successfully. I am using FreeRTOS v 7.1.0 on ATmega32 (on STK 500 kit) using avr-gcc on Fedora 11. Standard demo like toggle LEDs executed successfully on my hardware. My question relates to TimerDemo.c in Demo/Common/Minimal directory. I called vStartTimerDemoTask((portTickType)500); in the main function in Demo/AVR_ATMega323_WinAVR directory. I had included timers.c and TimerDemo.c in the makefile. It complied and got burnt into the hardware but it does not call the callback functions of the timers. I checked that by setting a particular value on PORTB connected to LEDs. Kindly, guide how do I test a simple timer.
Thanking you,
Yours sincerely,
Shubham Jain

FreeRTOS V7.0.1 Software Timers

The code contained in timerdemo.c is very comprehensive and used also to test the timer functionality.  Consequently, it loads the processor up and uses quite a lot of resources. If you want a simple time demo then I suggest something along the following. 1) Ensure timers.h is included in your C file and timers.c is included in your build. 2) Ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h, and that the associated timers configuration constants have sensible values (they are explained here http://www.freertos.org/RTOS-software-timer.html ) 3) rite a very simple callback function along the lines of:
static void prvTimerCallback( xTimerHandle xTimer );
static void prvTimerCallback( xTimerHandle xTimer )
{
    ToggleLED(); /* However that is implemented. */
}
4) Create and start the timer using something like:
xTimerHandle xTimer = NULL;
    xTimer = xTimerCreate( ( const signed char * ) “Timer”, /* A text name, purely to help debugging. */
                                            ( 200 / portTICK_RATE_MS ),  /* The timer period in ticks, this should be 200ms )
                                            pdTRUE,                                   /* Auto reload the timer. */
                                           ( void * ) 0,                                  /* The ID is not used, so can be set to anything. */
                                           prvTimerCallback                       /* The callback function. */     if( xTimer != NULL )
    {
        xTimerStart( xTimer, 0 );
    }   ); Regards.

FreeRTOS V7.0.1 Software Timers

Hi Richard, I had already done the following in FreeRTOSConfig.h.
#define configUSE_TIMERS                1
#define configTIMER_TASK_PRIORITY       configMAX_PRIORITIES – 1
#define configTIMER_QUEUE_LENGTH        ( ( unsigned short ) 50 )
#define configTIMER_TASK_STACK_DEPTH    ( ( unsigned short ) 85 ) Then as you suggested:
static void prvTimerCallback(xTimerHandle xTimer1);
xTimerHandle xTimer1 = NULL;
short main( void )
{
        DDRA = 0xFF;
        PORTA = 0xAA;
xTimer1 = xTimerCreate( ( const signed char * ) “Timer”, /* A text name, purely to help debugging. */ ( 200 / portTICK_RATE_MS ), /* The timer period in ticks, this shouldbe 200ms ) */pdTRUE, /* Auto reload the timer. */ ( void * ) 0, /* The ID is not used, so can be set to anything. */ prvTimerCallback); /* The callback function. */
        if(xTimer1 != NULL)
        {
        xTimerStart(xTimer1, 0);
        PORTA = 0x33;
        } if( xTimerIsTimerActive(xTimer1)==pdFALSE)
PORTA = 0x11;
else
PORTA = 0x22;         return 0;
}
static void prvTimerCallback(xTimerHandle xTimer)
{
PORTA = ~PORTA;
}
I am not getting the toggling effect on the LEDs. They just get initialised to 0x11 on PORTA meaning that the timer is inactive even after starting successfully. I was getting this in TimerDemo.c also where I had created and scheduled a task for the timer.
Kindly, help. Thanking you,
Yours sincerely,
Shubham Jain

FreeRTOS V7.0.1 Software Timers

if( xTimerIsTimerActive(xTimer1)==pdFALSE)
I think this line will always return pdFALSE in your code because the timer is not active until the timer task is created, and the timer task is not created until the scheduler is started. At that point in your code there is a message in the timer queue telling the timer task to activate the timer, that’s all.
return 0;
Your main() function appears to exit before starting the scheduler, so the kernel never runs, so timers will never even get started.
#define configTIMER_QUEUE_LENGTH        ( ( unsigned short ) 50 )
50 seems to be a massive number for the timer queue length.

FreeRTOS V7.0.1 Software Timers

Hi Richard, Thanks a lot. Initialization of timer handle to NULL and starting the scheduler were important things that I missed. But now, I want two auto-reload timers of periods 5 seconds and 10 seconds. I am not able to toggle LEDs even at interval of 800 ms. I am able to do it at 700 ms. Again the callback is not getting called for 800 ms and beyond. 700 ms is too short for the exercise that I want to do. portTickType is unsigned int for the port on which I am working (GCC/ATmega32). It should accept both 5000 and 10000. Kindly, help. Thanking you,
Yours sincerely,
Shubham Jain

FreeRTOS V7.0.1 Software Timers

Hi Richard, I changed configTICK_RATE_HZ   from 1000 to 1. And then I passed (10000/portTICK_RATE_MS) in xTimerCreate for a 10 second timer period. Now the LEDs are blinking but not at the frequency of 10 seconds (0.1 Hz). It seems to blink at frequency of around 1 second (1 Hz) only. Thanking you,
Yours sincerely,
Shubham Jain

FreeRTOS V7.0.1 Software Timers

So previously you have configTICK_RATE_HZ at 1000, and you were setting the time period to ( 200 / portTICK_RATE_MS ), is that correct? If that is the case then I’m not sure why that would not work. portTICK_RATE_MS will be ( 1000 / 1000 ) == 1.  So the timer period will have been 200 / 1 = 200.  So there should not be any overflow. Can you step through the code with your original settings and view the numbers that are being used in the debugger to see if you can explain why it didn’t work? Regards.

FreeRTOS V7.0.1 Software Timers

Hi Richard, Yes, you are right. I had previously configTICK_RATE_HZ at 1000 and I was setting the time period to (200 / portTICK_RATE_MS). But if I increase time period from 200 to 800, timer callback doesn’t get called. I have never used JTAG debugger successfully although I have it. So I tried simulating the FreeRTOS code on AVR Studio on Windows. I got the same result. I stepped through the code but I don’t know what numbers should I check for? The code has nothing but two timers toggling two ports in their callback functions. On using StepInto for xTimerCreate(), the control goes to vStartRegTestTasks(). On doing the same thing for vTaskStartScheduler(), the control goes again to vStartRegTestTasks() and then to vApplicationIdleHook() where it remains forever. I could not understand the linkages. I am sorry but I don’t know which numbers can I verify unless the control goes into the implementation of xTimerCreate in timers.c. Thanking you,
Yours sincerely,
Shubham Jain

FreeRTOS V7.0.1 Software Timers

Hi Richard, There are three problems that  I am facing with timers. 1). Even on setting 100ms or 200ms period auto-reload timer, I get LED blinking at about observable > 500ms period. 2). Initially I was using 2 timers. Then I removed the create and start of one but did not remove the initialization of the unused timer handle to NULL. Then the running timer although created with 200 ms period started blinking LEDs at observable period of almost exactly 1 minute! The period was the same one minute even for 100 ms timer. So it is not getting scaled but something wrong is happening. If I do not initialize the unused timer, then I get LEDs blinking as in 1). 3). If I increment a counter in the callback and then blink the LEDs on the counter attaining a particular value, then either the LEDs don’t blink or they blink after a large time which I did not have patience to look at. Kindly, help. Thanking you,
Yours sincerely,
Shubham Jain

FreeRTOS V7.0.1 Software Timers

I have confidence in the timer implementation, as it is extremely thoroughly tested, so it still sounds like an application issue.  Have you stepped through the code in the debugger to see exactly what it is doing – for example, the result of the calculations that determine the frequencies (checking for over flows, etc.).  Have you checked that the functions are returning values indicating that they have passed?  Have you checked that your system clock is clocking the chip at the frequency you think it is and that the tick frequency is therefore the frequency you think it is? Regards.