Skip to content

Commit

Permalink
Turn off PWM when duty cycle is set to zero
Browse files Browse the repository at this point in the history
It is generally expected that a PWM signal should remain low if it has a
duty cycle of zero. This commit introduces such behaviour by turning PWM
off when duty cycle is set to zero (or lower).

Fixes: #3
  • Loading branch information
Mangero committed Sep 30, 2019
1 parent 5818662 commit a0344b7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/esp8266/esp_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ bool mgos_pwm_set(int pin, int freq, float duty) {
*/
if (freq > 0 && freq < 10) return false;

p = find_or_create_pwm_info(pin, (freq > 0));
p = find_or_create_pwm_info(pin, (freq > 0) && (duty > 0));
if (p == NULL) {
return false;
}

if (freq <= 0) {
if (freq <= 0 || duty <= 0) {
remove_pwm_info(p);
pwm_configure_timer();
mgos_gpio_write(pin, 0);
Expand Down

0 comments on commit a0344b7

Please sign in to comment.