#wait #timer #rp2040 #hal #delay #accurate #times

rp2040_wait

Crate for more accurate wait times than Delay using rp2040_hal::timer::Timer

1 unstable release

0.1.0 May 23, 2023

#17 in #accurate

MIT license

8KB
58 lines

wait_timer

Crate for more accurate wait times than Delay using rp2040_hal::timer::Timer. In addition to wait function that waits for a specified number of seconds, gate function is implemented that keeps the time until it is re-executed constant.

How to use

  1. Create rp2040_hal::timer::Timer.
let timer = hal::timer::Timer::new(pac.TIMER, &mut pac.RESETS);
  1. Create wait_timer::Wait.
let wait = Wait::new(&timer);
  1. Use wait and/or gate methods.

Methods

wait functions

More accurate waiting times than Delay.

wait.wait_us(1_000_000);
wait.wait_ms(1_000);
wait.wait_sec(1);

gate functions

Wait a specified number of seconds since the last execution.

loop {
    wait.gate_sec(1); // A
    // ...
    wait.gate_ms(500); // B
    // ...
}
  1. A is ignored the first time.
  2. The process from A to B is executed in 500 milliseconds.
  3. Processes from B onwards (B to A) are executed in a second.

Dependencies

~7MB
~142K SLoC