Last active
September 14, 2015 23:20
-
-
Save indraastra/782d836f0ab5f5575a74 to your computer and use it in GitHub Desktop.
micros counter accuracy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void print_deltas(uint32_t t0_millis, uint32_t t0_micros) { | |
uint32_t t_m = millis(); | |
uint32_t t_u = micros(); | |
Serial.print(t_u - t0_micros); | |
Serial.print(", "); | |
Serial.println(t_m - t0_millis); | |
} | |
void setup() { | |
pinMode(D4, OUTPUT); | |
Serial.begin(9600); | |
delay(2000); | |
uint32_t t0_m = millis(); | |
uint32_t t0_u = micros(); | |
print_deltas(t0_m, t0_u); // Relative time 0. | |
__disable_irq(); | |
digitalWrite(D4, HIGH); | |
delayMicroseconds(5000); | |
digitalWrite(D4, LOW); | |
print_deltas(t0_m, t0_u); // Relative time 5000. | |
__enable_irq(); | |
print_deltas(t0_m, t0_u); // Relative time still 5000. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment