FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [February 2014 Threads] Frequency limit of binary semaphores?Posted by marcodg on February 20, 2014 I've run into this problem and not sure where to look next. This is a boiled down essence of a motor control.
I'm something of a FreeRTOS newbie but have been around a long time.
I have a timer tick interrupt. All it does is "give" the binary semaphore (ISR).
void TimerTick() { xSemaphoreGiveFromISR( sem ); }
void Foo()
{
...
sem = xSemaphoreCreateBinary();
xSemaphoreTake(sem);
n = 0;
while(1) {
xSemaphoreTake(sem); /* block until timer tick /
if (n++ & 1)
/ set IO pin high /
else
/ set IO pin low */
}
}
This works well for low frequencies. If I user a timer tick of 100Hz I get a beautiful 50Hz square wave. If I use a frequency of 1000Hz I get a 500Hz square wave most of the time. Occasionally it jitters and breaks and then restores itself. If I use, say 2kHz, it isn't even close. Changing the task priority doesn't matter and in fact is the only one of my tasks running. Since 1kHz is the breaking point is it related to the RTOS tick interval? I know the timer code works I can use much higher frequencies (e.g. sending audio data to a D/A) in other parts of my code. Any ideas?
Frequency limit of binary semaphores?Posted by rtel on February 20, 2014 The maximum frequency you can achieve with this technique is somewhat dependent on the processor you are running on. It goes without saying it also depends on how fast the hardware is clocked.
There is a limit to how fast it will function simply because code is running - and a context switch needs to be performed. How long a context switch takes is also dependent on the hardware. You will find an indicative number here: http://www.freertos.org/FAQMem.html#ContextSwitchTime
Are you using the xHigherPriorityTaskWoken parameter to the xSemaphoreGiveFromISR() function to ensure the interrupt returns directly to the task that calling xSemaphoreGiveFromISR() unblocked? It should not be related to the RTOS tick interval if you are, but will be if your not.
Regards.
Frequency limit of binary semaphores?Posted by marcodg on February 20, 2014 The processor is an NXP-1788 (Cortex M3) running at 120MHz. I am using the xHigherPriorityTaskWoken argument but I was not yielding. Thanks for the insight. I can now easily handle the frequencies required.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|