[hal] Counter/Encoder: use std::numeric_limits::infinity (#6941)

This commit is contained in:
Ryan Blue
2024-08-11 02:26:07 -04:00
committed by GitHub
parent 19b478a33b
commit d4dd2f8028
2 changed files with 15 additions and 21 deletions

View File

@@ -4,6 +4,8 @@
#include "hal/Counter.h"
#include <limits>
#include <fmt/format.h>
#include "ConstantsInternal.h"
@@ -300,19 +302,14 @@ double HAL_GetCounterPeriod(HAL_CounterHandle counterHandle, int32_t* status) {
return 0.0;
}
tCounter::tTimerOutput output = counter->counter->readTimerOutput(status);
double period;
if (output.Stalled) {
// Return infinity
double zero = 0.0;
period = 1.0 / zero;
} else {
// output.Period is a fixed point number that counts by 2 (24 bits, 25
// integer bits)
period = static_cast<double>(output.Period << 1) /
static_cast<double>(output.Count);
return std::numeric_limits<double>::infinity();
}
return static_cast<double>(period *
2.5e-8); // result * timebase (currently 25ns)
// output.Period is a fixed point number that counts by 2 (24 bits, 25
// integer bits)
double period = static_cast<double>(output.Period << 1) /
static_cast<double>(output.Count);
return period * 2.5e-8; // result * timebase (currently 25ns)
}
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counterHandle, double maxPeriod,

View File

@@ -4,6 +4,7 @@
#include "FPGAEncoder.h"
#include <limits>
#include <memory>
#include <fmt/format.h>
@@ -128,18 +129,14 @@ double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpgaEncoderHandle,
return 0.0;
}
tEncoder::tTimerOutput output = encoder->encoder->readTimerOutput(status);
double value;
if (output.Stalled) {
// Return infinity
double zero = 0.0;
value = 1.0 / zero;
} else {
// output.Period is a fixed point number that counts by 2 (24 bits, 25
// integer bits)
value = static_cast<double>(output.Period << 1) /
static_cast<double>(output.Count);
return std::numeric_limits<double>::infinity();
}
double measuredPeriod = value * 2.5e-8;
// output.Period is a fixed point number that counts by 2 (24 bits, 25
// integer bits)
double value = static_cast<double>(output.Period << 1) /
static_cast<double>(output.Count);
double measuredPeriod = value * 2.5e-8; // result * timebase (currently 25ns)
return measuredPeriod / DECODING_SCALING_FACTOR;
}