rust-embedded / embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Apache License 2.0
1.95k stars 197 forks source link

Periodic timer - when to start new count down? #437

Open Molorius opened 1 year ago

Molorius commented 1 year ago

I am not sure when to start a new count down when implementing a periodic timer. The documentation currently says, "the timer will start a new count down right after the last one finishes", but I'm not sure if that's after the last successful wait or as soon as the last count down reaches zero.

Say I have a periodic timer set to 1 second. I start it:

timer.start(1.second());

Then do something else for 5 seconds. I then read the timer twice:

block!(timer.wait()).ok();
block!(timer.wait()).ok();

The first block will immediately return because the timer has finished counting down by 1 second. Should the second block return immediately or wait for 1 additional second before returning?

Molorius commented 1 year ago

For context, I have a microcontroller with one continuous read-only timer. I want to use that to create a periodic timer implementation, so I want to know when exactly the new count down should begin. It's a similar idea/question as #435.