Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

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.


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists