madhephaestus / ESP32Servo

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

ESP32 S3 Only 4 servo can work at the same time #35

Open adama119 opened 1 year ago

adama119 commented 1 year ago

I have tested many times with version 0.13.0.

When I use ESP32 S3 (ESP32 S3 DevKitC) , if the number of servo is more than 4, the middle servo doesn't work。 I tested 2 ESP32 S3 boards and got the same results .

But When I use another ESP32 board (ESP32 DEVKIT V1), The following 6 servo are all working fine

#define SL1_PIN GPIO_NUM_4  // fine
#define SL2_PIN GPIO_NUM_5   // fine

#define SL3_PIN GPIO_NUM_2   //not work
#define SR1_PIN GPIO_NUM_21  //not work

#define SR2_PIN GPIO_NUM_16  // fine
#define SR3_PIN GPIO_NUM_17  // fine

void CodelabOS::InitServo() {

  CrazyLog::d(kTag, "InitServo");
  s_left_1_.attach(SL1_PIN, 500, 2500);
  s_left_2_.attach(SL2_PIN, 500, 2500);

  s_left_3_.attach(SL3_PIN, 500, 2500);
  s_right_1_.attach(SR1_PIN, 500, 2500);

  s_right_2_.attach(SR2_PIN, 500, 2500);
  s_right_3_.attach(SR3_PIN, 500, 2500);
  delay(2000);
  .....
}

Then I checked the pin signals with my oscilloscope , the blue channel is SL3_PIN in the code above,PWM is not working. the yellow channel is the SL1_PIN pin in the above code, it works great.

servo

madhephaestus commented 1 year ago

we are working on updating this library to fully support the s3 core. @keionbis do you have a branch we could review as a PR?

In the mean time, here is some code we use to generate 16 servo PWM's as a server: https://github.com/OperationSmallKat/LunaMotherboardFirmware/blob/Esp32-s3-migration/src/ServoServer.cpp

flaviobattimo commented 1 year ago

Hello, same issue here with different PWMs sharing same frequency.

Not sure but it may be related to: https://github.com/madhephaestus/ESP32Servo/blob/1.1.0/src/ESP32PWM.cpp#L79 https://github.com/madhephaestus/ESP32Servo/blob/1.1.0/src/ESP32PWM.cpp#L87

ESP32-S2 has 2 channels per timer maximum, here the limit is 4.

madhephaestus commented 1 year ago

Hmm, could you add that parameterization to this pr?

On Mon, Oct 9, 2023, 10:49 AM Flavio Battimo @.***> wrote:

Hello, same issue here with different PWMs sharing same frequency.

Not sure but it may be related to: https://github.com/madhephaestus/ESP32Servo/blob/1.1.0/src/ESP32PWM.cpp#L79 http://url https://github.com/madhephaestus/ESP32Servo/blob/1.1.0/src/ESP32PWM.cpp#L87 http://url

ESP32-S2 has 2 channels per timer maximum, here the limit is 4.

— Reply to this email directly, view it on GitHub https://github.com/madhephaestus/ESP32Servo/issues/35#issuecomment-1753158097, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJSKRTYZOOOKBKPFTOM3YDX6QFJNAVCNFSM6AAAAAA2RV4RTWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJTGE2TQMBZG4 . You are receiving this because you commented.Message ID: @.***>

borntoleave commented 1 year ago

I cannot wait for the solution to this problem.

I found this ESP32_ISR_Servo library and activated all 16 PWMs. It seems to generate PWM signals on all pins but is unstable. Do you have any insights?

I'm attaching the test code: ESP32_MultipleServos.ino.zip

ESP32 S3 16 PWM

helicocrasher commented 11 months ago

I made a similar experience with the ESP32 S2. initially only servo1and servo2 worked but not 3 and 4. In the meantime I have 8 Servos working perfectly :-) I found out the the original ESP32 has 16 HW (LED) PWM channels ESP32 S2 has only 8 channels. (S3 also 8!?)

At this time I attach 14 PWM channels and then use the 8 working ones on 1st attach call return 0 = channel 0 usable on the S2 (Zero ist not error status - it is the channel nr) 2nd attach call return 1 = channel 1 usable on the S2 3rd attach call return 8 = channel 8 no HW on ESP32 S2 not working 4th attach call return 9 = channel 8 no HW on ESP32 S2 not working 5th attach call return 3 = channel 2 usable on the ESP32 S2 ... aftter that I use the the PWM channels 0..7 and all is fine.

As an improvement to ESP32Servo library it would be a cool improvement A) when the PWM channels 0..7 whould be attached first B) when it would return an error ("-1") when failing to assing an existing PWM channel HW

Thanks and cheers