Yatin Goyal
Yatin Goyal

Reputation: 13

Is there a way to convert fugit Instant to micoseconds?

I am using rp2040 and rp2040_hal and it uses fugit. I am using a function timer.get_conter() which returns a Instant of Fugit and I want to convert that Instant to a microseconds passed since start of micro-controller. Is there a way in fugit itself to achieve that?

Upvotes: 0

Views: 299

Answers (1)

Aleksander Krauze
Aleksander Krauze

Reputation: 6165

From the documentation you linked to it seems that you should do the following things:

  1. Get Duration between two Instants (for example using Instant::checked_duration_since
  2. Get number of ticks in this duration using Duration::ticks
  3. Calculate duration in seconds with formula stated in documentation: duration in seconds = NOM / DENOM * ticks
  4. Convert it to microseconds by multiplying it by 1_000_000

Upvotes: 0

Related Questions