Skip to content

baskapteijn/ErriezTimestamp

 
 

Repository files navigation

Timestamp measuring library for Arduino

Build Status

This is a timestamp library for Arduino to measure execution durations in microseconds or milliseconds resolution.

Timestamp

Hardware

Any Arduino / ESP8266 board.

Library documentation

Examples

Arduino IDE | Examples | Erriez Timestamp:

Example output Timestamp | Microseconds

Timestamp with microseconds resolution example
  
Printing this message takes: 768us
And this message takes: 2044us
delayMicroseconds(15) duration: 20us
analogRead() duration: 212us
digitalRead() duration: 4us

Example output Timestamp | Milliseconds

Timestamp with milliseconds resolution example
  
delay(15) takes:
15ms
14ms
16ms
15ms
15ms
16ms
14ms
15ms
16ms
15ms

Usage

Initialization

Add include file:

#include <ErriezTimestamp.h>

Create timestamp object with microseconds resolution:

TimestampMicros timestamp;

Create timestamp object with milliseconds resolution:

TimestampMillis timestamp;

Single measurement

unsigned long duration;

// Start measurement
timestamp.start();
// Do something
duration = timestamp.delta();

// Start new measurement
timestamp.start();
// Do something
duration = timestamp.delta();

Multiple measurements

// Start timestamp
timestamp.start();
// Do something and print timstamp
timestamp.print();

// Do something and print timestamp without calling start()
timestamp.print();

Constraints

TimestampMicros uses the function micros().
TimestampMillis uses the function millis().

Please refer to the description of these functions for the maximum possible duration and minimum resolution:

The micro seconds timestamp functions have small overhead on low-end microcontrollers. For example calling start() and delta may result in it may take 4..8us deviation on an Arduino UNO. This is overhead is negligible on targets with a higher CPU clock such as the ESP8266.

Library installation

Please refer to the Wiki page.

Other Arduino Libraries and Sketches from Erriez

About

Timestamp library for Arduino

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 100.0%