lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

The delay() function

Tue Mar 01, 2016 9:19 pm

delay(100)

that means delaying 100ms.

where does it calibrated such each unit is equivalent to 1ms? not 1us . I can't find anywhere in code.

DOes this relate to crystal or system clock(for example, 16Mhz)? or instruction cycle period?

User avatar
buja
Posts: 506
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: The delay() function

Tue Mar 01, 2016 10:02 pm

In which library did you find delay()?

I know the following functions:
  • sleep() (#include <unistd.h>, duration in whole seconds.
  • nanosleep() (#include <time.h>, duration in nanoseconds (check the man page)
  • napms() (#include <ncurses.h>), duration in milliseconds.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: The delay() function

Tue Mar 01, 2016 10:11 pm

lilzz wrote:delay(100)

that means delaying 100ms.

where does it calibrated such each unit is equivalent to 1ms? not 1us . I can't find anywhere in code.

DOes this relate to crystal or system clock(for example, 16Mhz)? or instruction cycle period?
Assuming this is the wiringPi delay() function...

It's not calibrated as such, it's designed to delay in increments of 1mS. See: http://wiringpi.com/reference/timing/

It uses standard Linux system calls to achieve the delay so the exact underlying mechanism is not always obvious. The only thing you can guarantee is that the delay will be at least the number of mS you give, it might be longer but will never be shorter.

If you want to delay by a number of microseconds, then use delayMicroseconds().

-Gordon
--
Gordons projects: https://projects.drogon.net/

Return to “C/C++”