Pwm not super stable

giorgio80
Posts: 5
Joined: Thu Apr 18, 2019 9:29 am

Pwm not super stable

Postby giorgio80 » Fri May 15, 2020 9:43 pm

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 ?

ESP_Sprite
Posts: 9711
Joined: Thu Nov 26, 2015 4:08 am

Re: Pwm not super stable

Postby ESP_Sprite » Sat May 16, 2020 5:54 am

How are you measuring this? Are you sure it's not a glitch in your measuring method?

giorgio80
Posts: 5
Joined: Thu Apr 18, 2019 9:29 am

Re: Pwm not super stable

Postby giorgio80 » Sat May 16, 2020 12:20 pm

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

ESP_Sprite
Posts: 9711
Joined: Thu Nov 26, 2015 4:08 am

Re: Pwm not super stable

Postby ESP_Sprite » Sun May 17, 2020 7:59 am

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.

User avatar
jgustavoam
Posts: 164
Joined: Thu Feb 01, 2018 2:43 pm
Location: Belo Horizonte , Brazil
Contact:

Re: Pwm not super stable

Postby jgustavoam » Tue Jun 23, 2020 2:29 am

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
Retired IBM Brasil
Electronic hobbyist since 1976.

Who is online

Users browsing this forum: Majestic-12 [Bot] and 61 guests