Open loicreboursiere opened 1 year 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 :)
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
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.
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 usingsetTimerWidth
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 theledcSetup
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 :
#define MINIMUM_TIMER_WIDTH 8
(it could be a smaller value, but I'm not sure if it makes sense) in ESP32Servo.hvoid Servo::setTimerWidth(int value)
function I've changed the valiue16
byMINIMUM_TIMER_WIDTH
int Servo::attach(int pin, int min, int max)
I've just commented the linesthis->ticks = DEFAULT_PULSE_WIDTH_TICKS; this->timer_width = DEFAULT_TIMER_WIDTH;
I'm not exactly sure how to handle those last two lines of code together with the following one (this->timer_width_ticks = pow(2,this->timer_width);
) as those lines are already called in the constructor. But the first two would prevent the my modifiedsetTimerWidth()
to work.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 !