diff --git a/drivers/CoreDAC/tests/CoreSTM32HalBasicTimer_test.cpp b/drivers/CoreDAC/tests/CoreSTM32HalBasicTimer_test.cpp index ae3cb1288f..5a4a43dc56 100644 --- a/drivers/CoreDAC/tests/CoreSTM32HalBasicTimer_test.cpp +++ b/drivers/CoreDAC/tests/CoreSTM32HalBasicTimer_test.cpp @@ -124,9 +124,9 @@ TEST_F(CoreSTM32HalBasicTimerTest, initializeConfig) { auto timer_handle = basic_timer.getHandle(); - auto CK_INT = 54'000'000; - auto default_sample_rate = 44'100; - auto divider = CK_INT / default_sample_rate; + auto CK_INT = float(108'000'000.0); + auto default_sample_rate = float(44'100.0); + auto divider = std::round(CK_INT / default_sample_rate); // The prescaler can divide the counter clock frequency by any factor between 1 and 65536, see 28.3.1 of RM auto prescaler = timer_handle.Init.Prescaler; @@ -139,7 +139,7 @@ TEST_F(CoreSTM32HalBasicTimerTest, initializeConfig) // To fit required frequency (default sample rate), multiplying prescaler and auto-reload value must give // approximately the divider - EXPECT_NEAR(prescaler * auto_reload_value, divider, 50); + EXPECT_NEAR(prescaler * auto_reload_value, divider, 1); // Disable shadow write EXPECT_EQ(timer_handle.Init.AutoReloadPreload, TIM_AUTORELOAD_PRELOAD_DISABLE);