You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's a phase shift on the low-speed channels of esp32c3 whenever PWM output period or duty is changed. Even when setting the pulse width to 0 (disabled) there's a phase shift / extra pulse before the output stops:
Phase should not shift when updating the duty cycle.
Impact
In my use-case, the extra pulse when setting output to 0, causes the servo to jerk.
Logs and console output
Environment (please complete the following information):
OS: Linux
Toolchain: Zephyr SDK
Commit: v4.0.0
Additional context
Issue appears to be that the driver re-initializes the hardware each time pwm_led_esp32_set_cycles is called, e.g. it resets the counter here
I moved ledc_hal_init, ledc_hal_timer_rst, and pwm_led_esp32_configure_pinctrl to init and it seems to fix the issue. (Note: pinctl needs to move too or there's a short negative pulse if output is high when duty is changed).
// SPDX-License-Identifier: Apache-2.0
int pwm_led_esp32_init(const struct device *dev)
{
int ret;
const struct pwm_ledc_esp32_config *config = dev->config;
struct pwm_ledc_esp32_data *data = (struct pwm_ledc_esp32_data *const)(dev)->data;
if (!device_is_ready(config->clock_dev)) {
LOG_ERR("clock control device not ready");
return -ENODEV;
}
/* Enable peripheral */
clock_control_on(config->clock_dev, config->clock_subsys);
for (int i = 0; i < config->channel_len; i++) {
struct pwm_ledc_esp32_channel_config *channel = &config->channel_config[i];
ledc_hal_init(&data->hal, channel->speed_mode);
ledc_hal_timer_rst(&data->hal, channel->timer_num);
}
ret = pwm_led_esp32_configure_pinctrl(dev);
if (ret < 0) {
return ret;
}
return 0;
}
I can send a PR if this fix looks reasonable, but I'm just a little skeptical of performing ledc_hal_timer_rst before the timer/counter clock has been setup even though it appears to work fine. Unfortunately, I cannot completely initialize the peripheral in init because its not known what clock source the driver will select until an output period is specified by application code.
The text was updated successfully, but these errors were encountered:
Describe the bug
There's a phase shift on the low-speed channels of
esp32c3
whenever PWM output period or duty is changed. Even when setting the pulse width to 0 (disabled) there's a phase shift / extra pulse before the output stops:To Reproduce
Use the shell to change duty:
prj.conf
boards/esp32c3_devkitc.overlay
Expected behavior
Phase should not shift when updating the duty cycle.
Impact
In my use-case, the extra pulse when setting output to 0, causes the servo to jerk.
Logs and console output
Environment (please complete the following information):
Additional context
Issue appears to be that the driver re-initializes the hardware each time
pwm_led_esp32_set_cycles
is called, e.g. it resets the counter hereI moved
ledc_hal_init
,ledc_hal_timer_rst
, andpwm_led_esp32_configure_pinctrl
to init and it seems to fix the issue. (Note: pinctl needs to move too or there's a short negative pulse if output is high when duty is changed).I can send a PR if this fix looks reasonable, but I'm just a little skeptical of performing
ledc_hal_timer_rst
before the timer/counter clock has been setup even though it appears to work fine. Unfortunately, I cannot completely initialize the peripheral in init because its not known what clock source the driver will select until an output period is specified by application code.The text was updated successfully, but these errors were encountered: