Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
loicreboursiere opened this issue Sep 20, 2022 · 3 comments

Comments

@loicreboursiere
Copy link

loicreboursiere commented Sep 20, 2022

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 :

  • I've added #define MINIMUM_TIMER_WIDTH 8 (it could be a smaller value, but I'm not sure if it makes sense) in ESP32Servo.h
  • in the first if/else of the void Servo::setTimerWidth(int value) function I've changed the valiue 16 by MINIMUM_TIMER_WIDTH
  • in the int Servo::attach(int pin, int min, int max) I've just commented the lines
    this->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 modified setTimerWidth() to work.

Modifications are here : 6729cb0
Let me know what you think and if this fix was the correct way to go !

Cheers !

@madhephaestus
Copy link
Owner

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
Copy link
Author

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
Copy link

mopore commented May 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants