-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
feature(ledc): Add output invert option for LEDC pin + minor fixes #9257
Conversation
👋 Hello P-R-O-C-H-Y, we appreciate your contribution to this project! Click to see more instructions ...
Review and merge process you can expect ...
|
eced014
to
c15582b
Compare
c15582b
to
ab16eca
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A minor suggestion for the function parameter description.
A suggestion about testing resolution for Zero (which may be not allowed).
Check if this makes sense. Overall it is good.
Just as a suggestion about resolution being 0. So a resolution of 0 could perhaps be interpreted like "leave as it is or lower resolution if needed". If this is not practical, then maybe this class could have some static function to compute the max. frequency given some resolution and vice verse? |
Co-authored-by: Rodrigo Garcia <[email protected]>
I think this is not ideal, as the resolution will be kind of "unknown" to the user, so it will be hard for them to set right duty for the PWM. It will make sense, if we also add a function like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Should this also fix #9212 ? |
I was not albe to reproduce that, but as I have fixed part, where if the pin was already attached to the LEDC was wrongly reattached. Now if the pin is already attached to the LEDC, the So you are not able to call |
That sounds good. Just a question, is there a generic/preferred function to clear any assigned bus/peripheral from a pin, regardless of what was using it? |
Arduino Core 3.0.0 has the Peripheral Manager API. This is the way it works when a pin is already attached to a peripheral, like PWM (LEDC), and then it is used as RMT: RMT #include "esp32-hal-periman.h"
// Turn `Core Debug Level: "Verbose"` to see all messages from Peripheral Manager
#define PIN 2
void setup() {
// Peripheral Manager will attach pin 2 UART (RX) - TX is the UART0 default pin.
Serial.begin(115200, SERIAL_8N1, PIN);
Serial.println("Serial pins - RX (pin 2) and TX (default) are attached");
delay(1000);
//Peripheral manage will detach pin 2 from UART (TX) and attach it to LEDC
analogWrite(PIN, 100); // by default it will use 1KHz, 8 bits resolution
Serial.println("Pin 2 is attached to LEDC");
delay(5000);
// Peripheral manager will detach pin 2 from LEDC and attach it to SigmaDelta
sigmaDeltaAttach(PIN, 312500);
sigmaDeltaWrite(PIN, 10); // Start SigmaDelta
Serial.println("Pin 2 is attached to SigmaDelta");
delay(5000);
// Peripheral manager will detach pin 2 from SigmaDelta and attach it to GPIO Ouput
pinMode(PIN, OUTPUT);
digitalWrite(PIN, HIGH); // pin 2 in HIGH state.
Serial.println("Pin 2 is attached to GPIO");
delay(5000);
digitalWrite(PIN, LOW); // pin 2 in LOW state.
// General PIN detaching from what ever it was attached previously...
perimanClearPinBus(PIN);
Serial.println("Pin 2 is fully detached");
delay(1000);
// Detached UART0 TX default pin
Serial.println("UART0 TX is fully detached");
Serial.flush(); // message is out!
Serial.end();
}
void loop() {} |
@TD-er To check what bus(peripheral) is assigned to a pin you can use There is no need to clear the bus first as @SuGlider mentioned. The detaching is automatic before attaching new bus(peripheral). But if you want to clear the pins bus(peripheral) without knowing, what peripheral is attached to the pin, you can use |
@P-R-O-C-H-Y - I found an issue... Try running the example from #9257 (comment)
Final NoteLEDC is OK. Issue is in SigmaDelta Attaching. |
@SuGlider Will do some testing tomorrow. |
Issue was in SigmaDelta. Solved with #9268 |
Both thanks for the extensive explanation and apparently answering this led to another bug :) I will have another close look at those periman functions to see how I can use them in ESPEasy. |
Description of Change
ledcOutputInvert(uint8_t pin, bool out_invert)
function, to enable setting inverting LEDC output for selected pin. Can be called afterledcAttach()
anytime.ledc_handle.used_channels
never initialised before use.Tests scenarios
Tested on ESP32. On screen below
ledcOutputInvert
on LED2 was called on the black line, and LED2 output was immediately inverted.Related links
Closes #7501
Closes #9213
Closes #9212