Skip to content

christianbator/microsecond-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Arduino Microsecond Timer

When micros() just isn't enough.

The microsecond time resolution on 16MHz ATmega-based Arduino boards (Uno, Mega, Nano, etc.) is 4 microseconds, but if you want finer precision, you can use this little timer instead.

Notes:

  • Precision: 1μs
  • Based on Timer/Counter2
  • Respects and restores the current interrupts enabled status

Installation:

  • Drop the microsecond_time.h and microsecond_time.cpp files into your Arduino project's src directory:
Project/
    Sketch.ino
    src/
        microsecond-time/
            microsecond_time.h
            microsecond_time.cpp

Usage:

// Include the header
#include "src/microsecond-time/microsecond_time.h"

void setup() {
    // Enable the microsecond timer:
    enableMicrosecondTime();
}

void loop() {
    // Retrieve a 1μs precise time snapshot:
    unsigned long currentMicrosecondTime = microsecondTime();
}

// If you want to disable the microsecond timer at any point:
disableMicrosecondTime();

About

1μs time for Arduino

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published