madhephaestus / ESP32Servo

Arduino-compatible servo library for the ESP32
139 stars 55 forks source link

Minimum bit width trigerring a "bit width too big (maximum 14)" error with ESP32-C3 #27

Open loicreboursiere opened 2 years ago

loicreboursiere commented 2 years ago

When runing the examples of the library with a ESP32-C3-DevKitM1 I ran in the following error : [ 111][E][esp32-hal-ledc.c:60] ledcSetup(): No more LEDC channels available! (maximum 6) or bit width too big (maximum 14) Even using setTimerWidth function didn't change anything.

It appeared that the minimum bit width in your library is equal to DEFAULT_TIMER_WIDTH which is 16. I'm not sure where it comes from. I've seen here and there on the internet when looking at examples of PWM and ESP32 that the ledcSetup function that you rely on can accept bit width lower than 16.

I managed to make your library work with the ESP32-C3-DevKitM1 by doing several modifications :

Modifications are here : https://github.com/madhephaestus/ESP32Servo/commit/6729cb0c6630a6a0b291f1f9e1abd1cea808aa7b Let me know what you think and if this fix was the correct way to go !

Cheers !

madhephaestus commented 2 years ago

it would be best to surround these changes with #ifdef terms so that it is only changing the C3 variants.

Thank you for taking time to make this library better for everyone! Let me know when it is regression tested and open a PR :)

loicreboursiere commented 2 years ago

Ok first time I'm doing that, so can you elaborate on how you do a regression test ? I've used #ifdef in the header file, defining MAXIMUM_TIMER_WIDTH alongside DEFAULT_TIMER_WIDTH. I've tried this code with my setup (ESP-C3-DEVKitM1) as well as a Adafruit Feather ESP32 (ESP32WROOM). Everything seems to be ok for me. The commit is here. When I know more about regression test, I'll open a PR.

Cheers

mopore commented 1 year ago

The problem was also present to me when I add (attach) a third servo to be controlled by an Unexpected Maker FeatherS3 (ESP32-S3). I therefore switched to the 'ESP32 ESP32S2 AnalogWrite' library by David Lloyd to control more than two servos simultaneously with an ESP32-S3.