Description
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.
Arduino-FOC/src/drivers/hardware_specific/esp32/esp32_ledc_mcu.cpp
Lines 227 to 236 in fb0be07
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