Page 1 of 1

Pwm not super stable

Posted: Fri May 15, 2020 9:43 pm
by giorgio80
Hello guys ,

I’m using simple ledcsetup call to generate 1000hz pwm on a pin .

It looks to work ok but I’m getting minimum variation on signal .

Signal continue cycling (Every 5 sec ) between exactly 1000hz and 996/998 hz .

Do you think This is normal behavior or there’s way to achieve a stable 1000hz ?

Re: Pwm not super stable

Posted: Sat May 16, 2020 5:54 am
by ESP_Sprite
How are you measuring this? Are you sure it's not a glitch in your measuring method?

Re: Pwm not super stable

Posted: Sat May 16, 2020 12:20 pm
by giorgio80
I’m using a simple cheap oscilloscope .

About Being sure it’s not the oscilloscope I can’t obviously be sure , do you think it can be the problem ? Seems btw , that with another non esp32 device I’m using per comparison , I can got the stable 1000hz

Re: Pwm not super stable

Posted: Sun May 17, 2020 7:59 am
by ESP_Sprite
It could be, scopes without a hardware pulse counter can be unreliable as it depends on either how well they can sample the edges or how many samples can fit in sample memory... Given the fact that the LEDC is a hardware device, I'd have a hard time explaining how it would go off every x seconds, to be honest.

Edit: Any chance we can see your code? Chance is that somehow the LEDC isn't set for *exactly* 1KHz, and your scope shows that as frequency jitter.

Re: Pwm not super stable

Posted: Tue Jun 23, 2020 2:29 am
by jgustavoam
Hi,
The LED PWM on ESP32 is incredible stable and has high accuracy! The best I've ever seen!
But you must know how to use correctly.

Example to 1000 Hz.
Setup frequency : 1000 Hz
Select channel : 0 to 15
Setup resolution : 15 (more accuracy) maximum available frequency is 2441 Hz ( 80MHz / 32768)
Setup Duty : 16383 (50%) ===> 0 to (2 ** duty_resolution) - 1

Reference:
https://docs.espressif.com/projects/esp ... /ledc.html