fix stop pwm

This commit is contained in:
lilian 2017-11-23 19:12:31 +01:00
parent 221d3551e2
commit 4fdf2e2857

View file

@ -140,7 +140,7 @@ void pwm_set_duty(uint16_t duty)
pwmInfo.dutyCycle = duty; pwmInfo.dutyCycle = duty;
if (duty == 0 || duty == UINT16_MAX) if (duty == 0 || duty == UINT16_MAX)
{ {
pwmInfo.output = (duty == UINT16_MAX); pwmInfo.output = (duty == UINT16_MAX);
} }
debug("Duty set at %u",pwmInfo.dutyCycle); debug("Duty set at %u",pwmInfo.dutyCycle);
pwm_restart(); pwm_restart();
@ -176,10 +176,10 @@ void pwm_start()
} }
else else
{ {
for (uint8_t i = 0; i < pwmInfo.usedPins; ++i) for (uint8_t i = 0; i < pwmInfo.usedPins; ++i)
{ {
gpio_write(pwmInfo.pins[i].pin, pwmInfo.reverse ? !pwmInfo.output : pwmInfo.output ); gpio_write(pwmInfo.pins[i].pin, pwmInfo.reverse ? !pwmInfo.output : pwmInfo.output );
} }
} }
debug("PWM started"); debug("PWM started");
pwmInfo.running = 1; pwmInfo.running = 1;
@ -189,13 +189,10 @@ void pwm_stop()
{ {
timer_set_interrupts(FRC1, false); timer_set_interrupts(FRC1, false);
timer_set_run(FRC1, false); timer_set_run(FRC1, false);
if (pwmInfo.dutyCycle == 0 || pwmInfo.dutyCycle == UINT16_MAX) for (uint8_t i = 0; i < pwmInfo.usedPins; ++i)
{ {
for (uint8_t i = 0; i < pwmInfo.usedPins; ++i)
{
gpio_write(pwmInfo.pins[i].pin, pwmInfo.reverse ? true : false); gpio_write(pwmInfo.pins[i].pin, pwmInfo.reverse ? true : false);
} }
}
debug("PWM stopped"); debug("PWM stopped");
pwmInfo.running = 0; pwmInfo.running = 0;
} }