Dlloydev / ESP32-ESP32S2-AnalogWrite

ESP32 PWM, Servo, Easing and Tone. Smart GPIO pin management and advanced control features.
MIT License
100 stars 17 forks source link

Can't acheive true 100% PWM (full on) with ESP32/ESP32S2 and LEDc functions #2

Closed Dlloydev closed 3 years ago

Dlloydev commented 3 years ago

Arduino's reference for analogWrite() describes the PWM wave characteristics for various hardware architecture. The general operational characteristic is 8-bit duty cycle control where the output will be always off for value 0 and always on for value 255. With the various devices and timer modes, sometimes a bit correction is required to achieve full off or on. The ESP8266 follows this mode of operation, but with the different timer architecture on the ESP32 devices, the LEDc PWM operates in a different manner, where duty value 0 is always off, but duty value 255 will give an output that's 255/256 duty cycle (not fully on). This happens for any setting for bit resolution.

Dlloydev commented 3 years ago

As of this version 1.2.0, this condition is detected and corrected, where the hardware is programmed with 2^resolution (bits)^, which drives the output signal fully on.