Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


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.


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.

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner