Use double for storing time instead of float

Float precision may be not enough after some time of operating
This commit is contained in:
Oleg Kalachev
2025-01-12 19:58:36 +03:00
parent d4e04c46cd
commit 70f5186c1b
10 changed files with 16 additions and 14 deletions

View File

@@ -6,7 +6,7 @@
float loopRate; // Hz
void step() {
float now = micros() / 1000000.0;
double now = micros() / 1000000.0;
dt = now - t;
t = now;
@@ -18,7 +18,7 @@ void step() {
}
void computeLoopRate() {
static float windowStart = 0;
static double windowStart = 0;
static uint32_t rate = 0;
rate++;
if (t - windowStart >= 1) { // 1 second window