From b680649113c3e6cb20672cbd4ef35a26e53cdd54 Mon Sep 17 00:00:00 2001 From: Guillermo Ruffino Date: Thu, 8 Apr 2021 09:22:30 -0300 Subject: [PATCH] Fix servo detach chopped PWM (#1650) --- esphome/components/esp8266_pwm/esp8266_pwm.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/esphome/components/esp8266_pwm/esp8266_pwm.cpp b/esphome/components/esp8266_pwm/esp8266_pwm.cpp index 96290871e0..b3fd2398f3 100644 --- a/esphome/components/esp8266_pwm/esp8266_pwm.cpp +++ b/esphome/components/esp8266_pwm/esp8266_pwm.cpp @@ -37,6 +37,11 @@ void HOT ESP8266PWM::write_state(float state) { uint32_t duty_off = total_time_us - duty_on; if (duty_on == 0) { + // This is a hacky fix for servos: Servo PWM high time is maximum 2.4ms by default + // The frequency check is to affect this fix for servos mostly as the frequency is usually 50-300 hz + if (this->pin_->digital_read() && 50 <= this->frequency_ && this->frequency_ <= 300) { + delay(3); + } stopWaveform(this->pin_->get_pin()); this->pin_->digital_write(this->pin_->is_inverted()); } else if (duty_off == 0) {