Arduino-FOC icon indicating copy to clipboard operation
Arduino-FOC copied to clipboard

[BUG] esp32 ledc skips first channel index

Open ervinoro opened this issue 6 months ago • 1 comments

Describe the bug

Symptom: It is not possible to initialize two 3PWM drivers on ESP32-C3. The .init() function of the second driver will print the following error during setup of the 6th pin: E (1116) ledc: ledc_get_duty(824): channel argument is invalid E (1116) ledc: ledc_channel_config(663): ledc_channel argument is invalid

Diagnosis: The _configure3PWM has group_channels_used[group]++; before calling _ledcAttachChannelAdvanced. Therefore the first pin will use channel 1, and 6th pin will try to use channel 6. However, the channels are 0-indexed, therefore channel 0 will be unused and channel 6 will throw error of invalid argument. https://github.com/simplefoc/Arduino-FOC/blob/fb0be07488ed26db7cbc16dff0ef43c30bda818c/src/drivers/hardware_specific/esp32/esp32_ledc_mcu.cpp#L227-L236

Solution: By simply moving the group_channels_used[group]++; statement to the end of that for block, I got two 3PWM drivers initiated.

Describe the hardware setup ESP32-C3 supermini Has 6 LEDC channels

IDE you are using Arduino IDE esp32 v3.1.3 Simple FOC v2.3.4

ervinoro avatar May 18 '25 11:05 ervinoro