Timer implementation using the us ticker.
More...
#include <Timer.h>
|
| void | start () |
| | Start the timer.
|
| |
| void | stop () |
| | Stop the timer.
|
| |
| void | reset () |
| | Reset the timer to 0.
|
| |
| float | read () const |
| | Get the time passed in seconds.
|
| |
| int | read_ms () const |
| | Get the time passed in milliseconds.
|
| |
| int | read_us () const |
| | Get the time passed in microseconds.
|
| |
| | operator float () const |
| | An operator shorthand for read()
|
| |
| us_timestamp_t | read_high_resolution_us () const |
| | Get (in a high resolution type) the time passed in microseconds.
|
| |
| std::chrono::microseconds | elapsed_time () const |
| | Get the time passed as chrono microseconds.
|
| |
Timer implementation using the us ticker.
Locks deep sleep while actively running.
Example:
#include "mbed.h"
#include <cinttypes>
int main() {
led = !led;
printf("Toggling the led takes %" PRIi64 " us", (end - begin).count());
}
A digital output, used for setting the state of a pin.
void start()
Start the timer.
std::chrono::microseconds elapsed_time() const
Get the time passed as chrono microseconds.
Timer implementation using the us ticker.
- Note
- When constructed, a Timer is stopped and reset to zero time.
-
Synchronization level: Interrupt safe
Definition at line 167 of file Timer.h.
◆ start()
Start the timer.
Will lock deep sleep if this is a Timer instance
◆ stop()
Stop the timer.
Will release the deep sleep lock if this is a Timer instance
◆ reset()
Reset the timer to 0.
If it was already running, it will continue
◆ read()
Get the time passed in seconds.
- Returns
- Time passed in floating-point seconds
- Deprecated:
- "Floating point operators should normally be avoided for code size. If really needed, you can use `duration<float>{elapsed_time()}.count()`" [since "mbed-os-6.0.0" ]
◆ read_ms()
Get the time passed in milliseconds.
- Returns
- Time passed in integer milliseconds
- Deprecated:
- "Use the Chrono-based elapsed_time method. If integer milliseconds are needed, you can use `duration_cast<milliseconds>(elapsed_time()).count()`" [since "mbed-os-6.0.0" ]
◆ read_us()
Get the time passed in microseconds.
- Returns
- Time passed in integer microseconds
- Warning
- Limited to 31 bits – will not return correct values for times larger than about 35 minutes. Use read_high_resolution_us or elapsed_time instead as they are not vulnerable to this problem.
- Deprecated:
- "Use the Chrono-based elapsed_time method. If integer microseconds are needed, you can use `elapsed_time().count()`" [since "mbed-os-6.0.0" ]
◆ operator float()
An operator shorthand for read()
- Returns
- Time passed in floating-point seconds
- Deprecated:
- "Floating point operators should normally be avoided for code size. If really needed, you can use `duration<float>{elapsed_time()}.count()`" [since "mbed-os-6.0.0" ]
◆ read_high_resolution_us()
Get (in a high resolution type) the time passed in microseconds.
- Returns
- Time passed as 64-bit microseconds.
- Deprecated:
- "Use the Chrono-based elapsed_time method. If integer microseconds are needed, you can use `elapsed_time().count()`" [since "mbed-os-6.0.0" ]
◆ elapsed_time()
| std::chrono::microseconds elapsed_time |
( |
| ) |
const |
|
inherited |
Get the time passed as chrono microseconds.
- Returns
- Time passed
as std::chrono::microseconds