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 delay in nanosecond

Posted by Sebastian Aslund on April 9, 2009
Hello all

I am new to the FreeRTOS system and I need some delay to initializing a LCd display, but since it is only require a delay in nanosecond, then it seems a but overkill to use vTaskDelay in milisecond, but is it possible to make vTaskDelay to delay in nanoseconds? or is there another option? right now I use asm to create a delay.


RE: How to delay in nanosecond

Posted by Adam Turowski on April 9, 2009
VTaskDelay uses scheduler to make a delay. It means two things:
- delay time can be only a multiple of scheduler tick (usually multiple of 1ms)
- other tasks can run when the task is delayed.

To use scheduler for delay you have to check ready tasks list and (if necessary) switch context. All of this takes some time, for example approx 10us for ARM7TDMI running with 48MHz core clock.

The conclusion is that to make very small delays use the loop (as you are doing now), for bigger delays (more than lets say two scheduler tick) use VTaskDelay.

RE: How to delay in nanosecond

Posted by Adam Turowski on April 9, 2009
I forgot to add that if you need to do delay, which value is somewhere between 10us(task switching time) and 1ms(scheduler tick), you should use timer interrupts or get your hardware redesigned.

RE: How to delay in nanosecond

Posted by Jaume Ribot on April 9, 2009
Try to use an asm("nop") loop strategy. Knowing the system clock you can obtain very little delays. It skips all the OS scheduling but you can obtain you low desired delay values.

Best regards

RE: How to delay in nanosecond

Posted by Sebastian Aslund on April 9, 2009
Thanks for your replies.
I just assumed that using asm("nop") was a brutal way of doing things, but if that is your only option, I have to stick with that :)



RE: How to delay in nanosecond

Posted by incrediball on April 13, 2009
It might seem brutal and wasteful but compared to two task switches (to another task and back again), wasting small amounts of time with NOPs is insignificant.

Depending on your microprocessor and its clock speed, some of the required delays may be shorter than a single instruction. Therefore it's hard to get the timing optimal unless you use a logic analyser.

[ 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