High-precision microsecond delay functionality.
More...
High-precision microsecond delay functionality.
#include< HiResDelay.h>
The High Resolution Delay Timer provides microsecond-precision timing by utilizing hardware system timers. This is ideal for applications requiring precise timing control such as:
- Protocol timing requirements
- Sensor polling with specific intervals
- Hardware interface timing
- Signal generation
Usage Overview
When a DelayObject is created, it automatically allocates an available hardware system timer from the processor's timer pool. The timer remains allocated for the lifetime of the object and is automatically freed when the object goes out of scope or is destroyed.
Timing Precision
- Minimum delay: Platform-dependent, typically ~1-10 microseconds
- Maximum delay: Limited by 32-bit counter (up to ~4,294 seconds)
- Precision: Hardware timer precision (typically sub-microsecond)
- Accuracy: Depends on system load and interrupt latency
Example Usage
#include <HiResDelay.h>
void performPreciseTiming() {
if (!myHiResDelay.
valid()) {
iprintf("Error: No free timers available\n");
return;
}
}
High-resolution microsecond delay timer class.
Definition HiResDelay.h:164
bool valid()
Verify the delay object is valid and ready to use.
Definition HiResDelay.h:318
void DelayUsec(uint32_t usec)
Perform a blocking delay with microsecond precision.
Important Notes
- Hardware timers are a limited resource - check valid() after construction
- Delays block the calling task (use RTOS tasks for concurrent operations)
- Very short delays (<10us) may have reduced accuracy due to overhead
- For non-blocking timing, consider using the Interval Timer classes
- Static or global DelayObjects prevent timer reallocation overhead
Comparison with Other Timing Methods
| Method | Resolution | Blocking | Use Case |
| OSTimeDly() | 20ms (1 tick) | Yes | General delays |
| DelayObject | Microseconds | Yes | Precise hardware timing |
| IntervalTimer | Microseconds | No | Periodic callbacks |
| Stopwatch | Microseconds | No | Time measurement |
- See also
- Interval Timer Interval Timer for non-blocking periodic operations
-
Stopwatch Timer Stopwatch for time measurement
-
OSTimeDly() Standard RTOS delay function