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

PWM channels are not deallocated correctly: detach and attach can only occur 16 times #64

Open
arnaudlvq opened this issue Sep 5, 2024 · 1 comment

Comments

@arnaudlvq
Copy link

#include <ESP32Servo.h>

Servo myServo;

void setup() {
    Serial.begin(115200);
    for (int i = 0; i < 16; i++) {
        myServo.attach(18);
        myServo.detach();
    }

    // final attach and proceed to move 
    delay(3000);
    myServo.attach(18);
    myServo.write(90);
}

void loop() {
    Serial.println("finished");
}

this doesn't work, while this does :

#include <ESP32Servo.h>

Servo myServo;

void setup() {
    Serial.begin(115200);
    for (int i = 0; i < 15; i++) {
        myServo.attach(18);
        myServo.detach();
    }

    // final attach and proceed to move 
    delay(3000);
    myServo.attach(18);
    myServo.write(90);
}

void loop() {
    Serial.println("finished");
}

I did not succeed in updating this library to correctly manage this problem. Or am I missing something ?
I need to detach after each servo move

At first this was super weird to me. Why 16 ?? And I found out that ESP32 has 16 PWM channels..

@arnaudlvq arnaudlvq changed the title PWM channels are not reset correctly PWM channels are not deallocated correctly: detach and attach can only occur 16 times Sep 5, 2024
@stuzenz
Copy link

stuzenz commented Nov 14, 2024

I like this library a lot - thank you! I just want to write a note, that I am also having an error in the serial printout when detaching. This is only happening when using state machines versus delay(x)

dispense servo at 0 at 29554
MOVE_BACK_TO_START state, moving to HOLD_AT_START at 29554
HOLD_AT_START state at 29610
HOLD_AT_START state at 29656
HOLD_AT_START state at 29703
HOLD_AT_START state at 29749
HOLD_AT_START state at 29795
HOLD_AT_START state at 29841
HOLD_AT_START state at 29888
HOLD_AT_START state at 29934
HOLD_AT_START state at 29980
HOLD_AT_START state at 30026
HOLD_AT_START state at 30072
HOLD_AT_START state at 30119
HOLD_AT_START state at 30165
HOLD_AT_START state at 30211
HOLD_AT_START state at 30257
HOLD_AT_START state at 30304
HOLD_AT_START state at 30350
HOLD_AT_START state at 30397
HOLD_AT_START state at 30496
HOLD_AT_START state at 30543
HOLD_AT_START state at 30589
HOLD_AT_START state, moving to COMPLETE at 30589
COMPLETE state at 30635
dispense servo complete.
[ 30636][E][ESP32PWM.cpp:142] deallocate(): [ESP32PWM] PWM deallocating LEDc #0

If I don't detach, the above error is not present - just to state the obvious. I am trying to understand what the issue is and have momentarily just not used the detach() method - which might not be a good idea in itself.

Thanks again for the library - very handy!

    case COMPLETE:
      Serial.println("COMPLETE state at " + String(millis()));
      Serial.println("dispense servo complete.");
      dispenserServo.detach();
      Serial.println("COMPLETE state, moving to INIT at " + String(millis()));
      servoCurrentState = INIT; 
      dispenseConditionMet = false;
      break;
  }
}

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

2 participants