ME 507 Romi++
Cylindrical Differential Drive Robot created for ME 507 at Cal Poly in Spring 2025
Loading...
Searching...
No Matches
time_utils.h File Reference

Utility functions for microsecond-level timing. More...

#include <stm32f4xx_hal.h>
#include <stdint.h>

Go to the source code of this file.

Functions

uint32_t micros (void)
 Returns the number of microseconds since the timer started.
void delay_us (uint32_t us)
 Delays execution for a specified number of microseconds.

Detailed Description

Utility functions for microsecond-level timing.

Provides lightweight timing utilities based on hardware timers, useful for precise control loop execution and delay functions.

Function Documentation

◆ delay_us()

void delay_us ( uint32_t us)

Delays execution for a specified number of microseconds.

Parameters
usDelay duration in microseconds.
Note
Busy-wait implementation; not RTOS-friendly.

Delays execution for a specified number of microseconds.

Parameters
usNumber of microseconds to delay.

Uses a busy-wait loop based on the micros() counter.

Note
Not suitable for power-sensitive applications or inside ISRs.

◆ micros()

uint32_t micros ( void )

Returns the number of microseconds since the timer started.

Returns
Elapsed time in microseconds as a 32-bit unsigned integer.
Note
Requires a configured timer (e.g., TIM2) running at 1 MHz.

Returns the number of microseconds since the timer started.

Reads the current counter value from the TIM2 peripheral.

Returns
Current microsecond timestamp as a 32-bit unsigned integer.