Skip to content

The explanation for example of delayMicroseconds() is not accurate #2683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mikecat opened this issue Feb 24, 2015 · 4 comments
Closed

The explanation for example of delayMicroseconds() is not accurate #2683

mikecat opened this issue Feb 24, 2015 · 4 comments
Assignees
Labels
Component: Documentation Related to Arduino's documentation content
Milestone

Comments

@mikecat
Copy link

mikecat commented Feb 24, 2015

When I executed the example on the reference of delayMicroseconds()(WebArchive)

int outPin = 8;                 // digital pin 8

void setup()
{
  pinMode(outPin, OUTPUT);      // sets the digital pin as output
}

void loop()
{
  digitalWrite(outPin, HIGH);   // sets the pin on
  delayMicroseconds(50);        // pauses for 50 microseconds      
  digitalWrite(outPin, LOW);    // sets the pin off
  delayMicroseconds(50);        // pauses for 50 microseconds      
}

configures pin number 8 to work as an output pin. It sends a train of pulses with 100 microseconds period.

on my Arduino UNO R3 and Arduino 1.0.6, the signal observed on pin 8 was approximately 9207Hz.
It means that the period is approximately 108.6 microseconds, and I think this error is caused due to the execution time of instructions other than delayMicroseconds() (i.e. digitalWrite() and the loop).

From this test, we can say that the sample do not send a train of pulses with 100 microseconds period but sends a train of pulses with approximately 100 microseconds period.
I think this explanation on the reference is a little bit misleading.
The problem becomes bigger when I change the delay from 50 microseconds to 5 microeconds: the output was approximately 55566Hz instead of expected 100kHz.

@mikaelpatel
Copy link

@mikecat
Did you try removing the delays? What would you expect then?

@cmaglie cmaglie added the Component: Documentation Related to Arduino's documentation content label Feb 24, 2015
@mikecat
Copy link
Author

mikecat commented Feb 24, 2015

@mikaelpatel
I think it is a tough question to answer, but the result of my test on my Arduino was approximately 115160Hz.

@cmaglie cmaglie assigned agdl and unassigned cmaglie Jul 1, 2015
@agdl
Copy link
Member

agdl commented Sep 4, 2015

@mikecat I wrote this:

It sends a train of pulses of approximately 100 microseconds period. The approximation is due to execution of the other instructions in the code.

Is it ok for you? If so close the issue please otherwise tell me what you want to add to this page please

@agdl agdl added this to the Release 1.6.6 milestone Sep 4, 2015
@agdl agdl added the Waiting for feedback More information must be provided before we can proceed label Sep 4, 2015
@agdl
Copy link
Member

agdl commented Sep 10, 2015

@mikecat I'm closing this. Reopen it if needed please

@agdl agdl closed this as completed Sep 10, 2015
@cmaglie cmaglie removed the Waiting for feedback More information must be provided before we can proceed label Oct 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Documentation Related to Arduino's documentation content
Projects
None yet
Development

No branches or pull requests

4 participants