-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Closed
Labels
Area: Peripherals APIRelates to peripheral's APIs.Relates to peripheral's APIs.Status: SolvedThe issue has been resolved and requires no further action.The issue has been resolved and requires no further action.
Milestone
Description
Board
ESP32
Device Description
ESP32-WROOM
Hardware Configuration
GPIO19 is LED PWM Pin
Version
v2.0.4
IDE Name
arduino-cli
Operating System
macOS 12.4
Flash frequency
40MHz
PSRAM enabled
no
Upload speed
921600
Description
ledcWrite makes it impossible to set the duty cycle to 50% for 1bit PWM because of this:
arduino-esp32/cores/esp32/esp32-hal-ledc.c
Lines 89 to 96 in 9432163
//Fixing if all bits in resolution is set = LEDC FULL ON | |
uint32_t max_duty = (1 << channels_resolution[chan]) - 1; | |
if(duty == max_duty){ | |
duty = max_duty + 1; | |
} | |
ledc_set_duty(group, channel, duty); |
when channels_resolution[chan]
is 1 the possible duty cycles should be 0 (0%), 1 (50%) and 2(100%).
But for a duty of 1 max_duty
will be 1 (1<<1 - 1
) and since duty == max_duty
the duty will be set to 2
Sketch
void setup() {
uint8_t channel = 0;
uint8_t bits = 1;
uint8_t pin = 19;
uint32_t freq = 40 * 1000 * 1000 // 40 MHz
uint8_t duty = 1; // 50% duty
ledcSetup(channel, freq, bits);
ledcAttachPin(pin, channel);
ledcWrite(channel, duty);
}
void loop(){}
Debug Message
None
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Metadata
Metadata
Assignees
Labels
Area: Peripherals APIRelates to peripheral's APIs.Relates to peripheral's APIs.Status: SolvedThe issue has been resolved and requires no further action.The issue has been resolved and requires no further action.
Type
Projects
Status
Done