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
After creation and configuration of a ledc::Channel, as done in the example, the duty-cycle is not be updated via set_duty() or set_duty_hw().
This is because modification of some register in the LEDC peripheral, are buffered and are only applied when LEDC_PARA_UP_CHn is set.
The HAL contains a macro that does this, update_channel!(), but it is currently not public.
Instead of making it public it could also called from within set_duty() and set_duty_hw(). I think this would a bit more user friendly, and less surprising.
But after setting LEDC_PARA_UP_CHn manually, the duty-cycle still didn't update. By referencing the esp-idf source code and reconstructing their register access, I found that setting the LEDC_DUTY_START_CHn is also required. Although this is as far as I could see in the technical reference manual, not mentioned to be needed for normal PWM mode. LEDC_DUTY_START_CHn is mentioned for the more advanced fading options. My guess is that the hardware implement regular PWM just as fading with step size of zero. An therefor still needs the LEDC_DUTY_START_CHn trigger to start the "fading" action, which updates the duty-cycle.
So currently the following extra steps need to be done to updated the duty-cycle:
I can work on a PR that fixes the issue for the ESP32-C3 but I don't have the hardware to test the other ESP32 variants. Let me known if/how I can help.
Here are some other usability improvements suggestions for the LEDC:
Allow set_duty(0) instead of returning Error::Duty. When precision is required set_duty_hw() should be used instead IMHO.
The addition of a trait without generic type parameter for the channels, so something like this becomes easier:
impl<'a,R,G,B>Rgb<'a,R,G,B>whereR:AnyChannel,G:AnyChannel,B:AnyChannel{pubfnnew(r:&'a R,g:&'a G,b:&'a B) -> Self{Self{ r, g, b }}}
The embedded_hal::PwmPin trait might be a good option as well.
The text was updated successfully, but these errors were encountered:
Great find! For sure a PR would be very welcome. We also have plans to rewrite this driver since it's currently not really compile time safe - just didn't get to it
Also implementing embedded_hal::PwmPin is a great suggestion
No problem if you can't verify it on other chips than ESP32-C3 - we can (and will) test it on all supported chips. Would be nice if it at least compiles for all targets
After creation and configuration of a
ledc::Channel
, as done in the example, the duty-cycle is not be updated viaset_duty()
orset_duty_hw()
.This is because modification of some register in the LEDC peripheral, are buffered and are only applied when
LEDC_PARA_UP_CHn
is set.The HAL contains a macro that does this,
update_channel!()
, but it is currently not public.Instead of making it public it could also called from within
set_duty()
andset_duty_hw()
. I think this would a bit more user friendly, and less surprising.But after setting
LEDC_PARA_UP_CHn
manually, the duty-cycle still didn't update. By referencing the esp-idf source code and reconstructing their register access, I found that setting theLEDC_DUTY_START_CHn
is also required. Although this is as far as I could see in the technical reference manual, not mentioned to be needed for normal PWM mode.LEDC_DUTY_START_CHn
is mentioned for the more advanced fading options. My guess is that the hardware implement regular PWM just as fading with step size of zero. An therefor still needs theLEDC_DUTY_START_CHn
trigger to start the "fading" action, which updates the duty-cycle.So currently the following extra steps need to be done to updated the duty-cycle:
I can work on a PR that fixes the issue for the ESP32-C3 but I don't have the hardware to test the other ESP32 variants. Let me known if/how I can help.
Here are some other usability improvements suggestions for the LEDC:
set_duty(0)
instead of returningError::Duty
. When precision is requiredset_duty_hw()
should be used instead IMHO.The
embedded_hal::PwmPin
trait might be a good option as well.The text was updated successfully, but these errors were encountered: