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.
This commit is contained in:
hogthrob
2019-10-20 13:50:56 +02:00
committed by Martin Jäger
parent d7ed3cdd13
commit c5fd08d836
+2 -2
View File
@@ -297,10 +297,10 @@ void half_bridge_set_duty_cycle(float duty)
{
_half_bridge_set_duty_cycle(_pwm_resolution * duty);
}
#include <stdio.h>
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()