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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user