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


How to implement uS delay?

Posted by Kevin Cho on June 1, 2009
Hi all,

Thanks for Open community.

I'm working on SAM7S64, FreeRTOS port.

This port configTICK_RATE_HZ is defined 1000.

vTaskDelay(1); --> 1 ms Delay. I checked it with oscilloscope.

But, I need to 500 or 100 us delay function.

Is it possible?

or How to increse configTICK_RATE_HZ to 2000.


RE: How to implement uS delay?

Posted by MEdwards on June 1, 2009
If you set configTICK_RATE_HZ faster than 1000 then the constant portTICK_RATE_MS will be zero and the demo tasks will not run and most likely crash. This is just the demo tasks and not the kernel.

If you are not using the demo tasks then you can set the tick faster but this will result in inefficient code. 1000Hz is already too fast really.

You can use another timer to generate an interrupt at your required frequency, then perform the processing in the interrupt handler. Alternatively you can use the interrupt handler to wake a very high priority task and perform the processing in that. The SAM7 port does not use interrupt nesting though unless you modify the code. You can probably use the FIQ interrupt more easily with no or smaller changes.

RE: How to implement uS delay?

Posted by incrediball on June 4, 2009
Some changes are needed to use FIQ:

1. Create a stack for the FIQ.

2. Set up the FIQ vector. This is often coded as an endless loop or something equally pointless.

3. If interrupt latency is an issue (in my case it was), stop FreeRTOS from disabling the FIQ in portDISABLE_INTERRUPTS, vPortDisableInterruptsFromThumb and vPortEnterCritical.

The FIQ interrupt handler must not interact with FreeRTOS. If it needs to communicate with the rest of the system, it can raise a regular interrupt in software (use AT91F_AIC_Trig).

I wrote about it last year under https://sourceforge.net/forum/message.php?msg_id=4901759

RE: How to implement uS delay?

Posted by Kevin Cho on June 4, 2009

Many thanks, MEdwards and incrediball.

I got so many ideas from your articles.

Thanks again :)

RE: How to implement uS delay?

Posted by Alain Mouette on June 5, 2009
I think that you have to separate that in two diferent problems:

1) a function to wait "at least 50us" is one thing. I have used it in many situations, you can just read a HW timer and wait. It is very usefull if you don't want to waist 1ms for each action, but longer times are not a problem.

2) a time of 50us plus/or/minus 1us is much more complex. Normaly that would run all from ISRs, with HW timers. Doing it with a RTOS would be much more difficult.

Alain Mouette

[ 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