From c5fd08d836d0faa146461e9bd3c1237bcfa88164 Mon Sep 17 00:00:00 2001 From: hogthrob Date: Sun, 20 Oct 2019 13:50:56 +0200 Subject: [PATCH] Fix rounding issue (#60) In some cases the old code would cause a +1/-1 step not actually changing the PWM due to rounding issues. New code directly changes the integer value and thus avoids this issue. --- src/half_bridge_tim.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/half_bridge_tim.cpp b/src/half_bridge_tim.cpp index f75ee04..1f149b9 100644 --- a/src/half_bridge_tim.cpp +++ b/src/half_bridge_tim.cpp @@ -297,10 +297,10 @@ void half_bridge_set_duty_cycle(float duty) { _half_bridge_set_duty_cycle(_pwm_resolution * duty); } - +#include void half_bridge_duty_cycle_step(int delta) { - half_bridge_set_duty_cycle(((float)(PWM_TIM_HW::get_ccr() + delta))/_pwm_resolution); + _half_bridge_set_duty_cycle(PWM_TIM_HW::get_ccr() + delta); } float half_bridge_get_duty_cycle()