Hello to every one.
I'm trying set LEDC frequency and PWM on the fly and the code works but not the way I'm expecting, there are bumps or glitches every time de frequency gets changed and also the PWM has glitches but is a little less notorious.
For both Frequency and PWM I need a glitch free transitions and frequencyresolution should be at least 0.1 Hz.
I'm using arduino-esp32 esp32-hal-ledc.h, esp32-hal-ledc.c
I've read on ESP32_TECHNICAL_REFERENCE_manual that using LEDC High Speed Channels transitions are glitch free.
But I don't know how to achieve it primarily because I'm not a C/C++ programmer and I'm very new to ESP32.
Below is a basic code I'm using.
Any advice will be very wellcome
Best regards
Fernando
Change LEDC frequency and pwm on the fly without glitches
Re: Change LEDC frequency and pwm on the fly without glitches
Or a more defined question:
How can I integrate ledc_intr_type_t with the code attached in my last post?
So that it only update pwm frequency when LEDC Counter reaches max count, LEDC_INTR_MAX?
How can I integrate ledc_intr_type_t with the code attached in my last post?
So that it only update pwm frequency when LEDC Counter reaches max count, LEDC_INTR_MAX?
Re: Change LEDC frequency and pwm on the fly without glitches
I'm sort of doing the same - and having similar problems..
ESP32 ledc PWM features and functions.
The Arduino framework seems to allow only a subset of the Ledc PWM features.
The ESP has auto fading functionality but the Arduino framework does not appear to support these.
Also there appears not to be a method to change the duty cycle without glitches.. The ESP framework has an update_duty function which may accomplish this.
Has anyone successfully used ledc in Arduino to get glitchless live adjustments of the ledc PWM output?
Perhaps accessing the Espressif framework at a lower level may achieve that (I've tried but it didn't work ).
Which begs another question, since I can access the espressif functions, why is there an Arduino layer on top?
ESP32 ledc PWM features and functions.
The Arduino framework seems to allow only a subset of the Ledc PWM features.
The ESP has auto fading functionality but the Arduino framework does not appear to support these.
Also there appears not to be a method to change the duty cycle without glitches.. The ESP framework has an update_duty function which may accomplish this.
Has anyone successfully used ledc in Arduino to get glitchless live adjustments of the ledc PWM output?
Perhaps accessing the Espressif framework at a lower level may achieve that (I've tried but it didn't work ).
Which begs another question, since I can access the espressif functions, why is there an Arduino layer on top?
Re: Change LEDC frequency and pwm on the fly without glitches
Hi,
I had the same problem.
I dug in to ESP IDF source code to figure out what the problem is.
I found out that calling "ledc_set_freq" to change the frequency always resets the timer which is the source of the glitches.
Basically this means that even for high speed timer which is glitch free you will see glitches because of this reset.
I didn't find another API to set frequency on the fly so to fix the issue I copied and modified the ESP IDF code to make it possible to set frequency without glitches with my own "ledc_set_freq_no_reset" function.
You can find reference for my fix here:
https://github.com/zimgir/esp-sstc-cont ... dc_fix.cpp
Please note that I use Arduino framework with PlatformIO in VSCode so it allows me to call ESP IDF functions directly and bypass Arduino layer if I need to mess with low level stuff while still having the options to stay at Arduino level if I want to.
I had the same problem.
I dug in to ESP IDF source code to figure out what the problem is.
I found out that calling "ledc_set_freq" to change the frequency always resets the timer which is the source of the glitches.
Basically this means that even for high speed timer which is glitch free you will see glitches because of this reset.
I didn't find another API to set frequency on the fly so to fix the issue I copied and modified the ESP IDF code to make it possible to set frequency without glitches with my own "ledc_set_freq_no_reset" function.
You can find reference for my fix here:
https://github.com/zimgir/esp-sstc-cont ... dc_fix.cpp
Please note that I use Arduino framework with PlatformIO in VSCode so it allows me to call ESP IDF functions directly and bypass Arduino layer if I need to mess with low level stuff while still having the options to stay at Arduino level if I want to.
Re: Change LEDC frequency and pwm on the fly without glitches
Hi @zimgir
Like me, you have a single post, so you probably do not read this, but I want to thank you for your workaround.
I borrowed the code from your GIT and got it to work. Nice, glitch-free freq and duty adjustments from within the Arduino framework on VStudio/PlatformIO
Thanks!
Like me, you have a single post, so you probably do not read this, but I want to thank you for your workaround.
I borrowed the code from your GIT and got it to work. Nice, glitch-free freq and duty adjustments from within the Arduino framework on VStudio/PlatformIO
Thanks!
Re: Change LEDC frequency and pwm on the fly without glitches
A big thank you from me too the code worked beautifully without any "glitches"
Who is online
Users browsing this forum: No registered users and 133 guests