Example Path: examples/timers/HiResDelay
HiRes Delay Timer Example
Overview
The HiRes Delay Timer Example is a test application that demonstrates and validates the precision of microsecond-level delays using hardware timers. This application provides benchmarking capabilities for the HiResDelay class, which uses hardware timers to achieve high-precision timing delays.
Features
- High-Resolution Timing: Uses hardware timers for microsecond-precision delays
- Precision Measurement: Accurately measures actual delay times vs. requested delays
- Error Analysis: Calculates and displays timing errors for performance evaluation
- Comprehensive Testing: Tests delays ranging from 1 microsecond to 100+ milliseconds
- Priority Control: Runs tests at high priority to minimize interference from other tasks
How It Works
The application uses the HiResDelay class in conjunction with a StopWatch to:
- Request a specific delay duration in microseconds
- Measure the actual time taken for the delay
- Calculate the error between requested and actual delay times
- Display results for analysis
Test Sequence
The application runs a comprehensive test suite with the following delay values (each tested twice):
- Ultra-short delays: 1, 2 microseconds
- Short delays: 5, 10, 15, 20, 21 microseconds
- Medium delays: 50, 100 microseconds
- Long delays: 1ms, 2ms, 10ms, 20ms
- Very long delays: 100ms, 100.001ms
Usage
- Start the Application: The program initializes and displays "Application Started"
- Run Tests: Press any key when prompted to execute the delay test sequence
- View Results: Each test displays:
- Requested delay time (microseconds)
- Actual measured delay time
- Error between requested and actual time
Sample Output Format
1: 1.05 err: 0.05
2: 2.12 err: 0.12
5: 4.98 err: -0.02
Key Components
DelayObject Class
- Provides the DelayUsec() method for microsecond delays
- Utilizes hardware timers for precision timing
StopWatch Class
- High-precision timer for measuring elapsed time
- Converts timer ticks to microseconds for analysis
- Methods: Start(), Stop(), Clear(), Convert()
DOTest Function
Parameters:
- DelayObject &dob: Reference to the delay object
- int usec: Requested delay in microseconds
Functionality:
- Starts precision timing measurement
- Executes the requested delay
- Measures actual delay duration
- Calculates and displays timing error
System Requirements
- Compatible with embedded systems supporting:
- Hardware timers
- Real-time operating system with priority control
- Standard I/O operations (printf, getchar)
Technical Notes
- Priority Handling: Tests run at priority level 2 to minimize task interference
- System Diagnostics: Enabled for development (should be disabled in production)
- Precision: Capable of measuring sub-microsecond timing differences
- Error Reporting: Displays both positive and negative timing errors
Build Dependencies
Required header files:
Purpose
This application serves as:
- Validation Tool: Verifies HiResDelay class accuracy
- Benchmarking Utility: Measures system timing performance
- Development Aid: Helps optimize timing-critical applications
- Quality Assurance: Ensures timing requirements are met in embedded systems
The comprehensive test suite helps developers understand the timing characteristics and limitations of their hardware platform, enabling them to make informed decisions about timing-critical code implementation.