[hal] Use std::log2() for base-2 logarithm (#5278)

This commit is contained in:
Tyler Veness
2023-04-28 20:52:03 -07:00
committed by GitHub
parent ba8c64bcff
commit fd2d8cb9c1
2 changed files with 2 additions and 5 deletions

View File

@@ -200,8 +200,7 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status) {
if (*status != 0) {
return;
}
uint16_t pwmPeriodPower =
std::lround(std::log(1.0 / (16 * 1.0E-6 * rate)) / std::log(2.0));
uint16_t pwmPeriodPower = std::lround(std::log2(1.0 / (16 * 1.0E-6 * rate)));
digitalSystem->writePWMPeriodPower(pwmPeriodPower, status);
}

View File

@@ -127,9 +127,7 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status) {
// higher freq.
// TODO: Round in the linear rate domain.
// uint8_t pwmPeriodPower = static_cast<uint8_t>(
// std::log(1.0 / (kExpectedLoopTiming * 0.25E-6 * rate)) /
// std::log(2.0) +
// 0.5);
// std::log2(1.0 / (kExpectedLoopTiming * 0.25E-6 * rate)) + 0.5);
// TODO(THAD) : Add a case to set this in the simulator
// digitalSystem->writePWMPeriodPower(pwmPeriodPower, status);
}