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?
Asked
Active
Viewed 153 times
0

Yatin Goyal
- 3
- 1
-
Could you provide a link to the documentation of this `Instant` type? – Aleksander Krauze Oct 17 '22 at 07:43
-
https://docs.rs/fugit/0.1.2/fugit/struct.Instant.html – Yatin Goyal Oct 17 '22 at 07:48
1 Answers
0
From the documentation you linked to it seems that you should do the following things:
- Get
Duration
between twoInstant
s (for example usingInstant::checked_duration_since
- Get number of
ticks
in this duration usingDuration::ticks
- Calculate duration in seconds with formula stated in documentation:
duration in seconds = NOM / DENOM * ticks
- Convert it to microseconds by multiplying it by
1_000_000

Aleksander Krauze
- 3,115
- 7
- 18