-
Notifications
You must be signed in to change notification settings - Fork 616
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
for(int i = 0; i < 3; i++){ | |
group_channels_used[group]++; | |
if(!_ledcAttachChannelAdvanced(pins[i], group_channels_used[group], group, pwm_frequency, _PWM_RES_BIT, false)){ | |
SIMPLEFOC_DEBUG("EP32-DRV: ERROR - Failed to configure pin:", pins[i]); | |
return SIMPLEFOC_DRIVER_INIT_FAILED; | |
} | |
params->channels[i] = static_cast<ledc_channel_t>(group_channels_used[group]); | |
params->groups[i] = (ledc_mode_t)group; | |
} |
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