PWM glitches and bad frequency

Pato
Posts: 31
Joined: Sat Mar 24, 2018 12:52 am

PWM glitches and bad frequency

Postby Pato » Tue Jun 26, 2018 6:35 pm

Hey folks,

Now I'm playing with the PWM API on a ESP-WROOM-02. I can get a PWM output on the pin, but the signal is quite dirty:
    - Each cycle is preceeded by a glitch
    - The period is longer than the one set in the code, probably because of this glitch
    - It occures with different duty cycles and period.

Here is what I get with the code below (500Hz, duty cylce 50%) with the code attached. Do you now why I get this and how to fix it ?
Thanks !

[Image

Code: Select all

#include "ets_sys.h"
#include "osapi.h"
#include "pwm.h"
#include "os_type.h"

#define NB_PWM_CHANNELS  1u          // Nb of PWM channel to be active

void user_init()
{   
    uint32 period = 2000;                      // PWM period in microsec (mini is 1000, max 10000)
    uint32 nbChannels = NB_PWM_CHANNELS;       // Nb of PWM channel to be active
    uint32 duty[NB_PWM_CHANNELS] = {22222};    // Duty cycle, in number of step of 45ns
    uint32 pinParams[NB_PWM_CHANNELS][3] = {{PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, 14u}};
   
    pwm_init(period, duty, nbChannels, pinParams);
    pwm_start();
}

AgentSmithers
Posts: 123
Joined: Sat Apr 01, 2017 1:21 am
Contact:

Re: PWM glitches and bad frequency

Postby AgentSmithers » Wed Jun 27, 2018 6:41 am

Pato wrote:Hey folks,

Now I'm playing with the PWM API on a ESP-WROOM-02. I can get a PWM output on the pin, but the signal is quite dirty:
    - Each cycle is preceeded by a glitch
    - The period is longer than the one set in the code, probably because of this glitch
    - It occures with different duty cycles and period.

Here is what I get with the code below (500Hz, duty cylce 50%) with the code attached. Do you now why I get this and how to fix it ?
Thanks !

[Image

Code: Select all

#include "ets_sys.h"
#include "osapi.h"
#include "pwm.h"
#include "os_type.h"

#define NB_PWM_CHANNELS  1u          // Nb of PWM channel to be active

void user_init()
{   
    uint32 period = 2000;                      // PWM period in microsec (mini is 1000, max 10000)
    uint32 nbChannels = NB_PWM_CHANNELS;       // Nb of PWM channel to be active
    uint32 duty[NB_PWM_CHANNELS] = {22222};    // Duty cycle, in number of step of 45ns
    uint32 pinParams[NB_PWM_CHANNELS][3] = {{PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, 14u}};
   
    pwm_init(period, duty, nbChannels, pinParams);
    pwm_start();
}


That's interesting, What SDK version are you on. Can you safely snapshot (if its a VM) and move to the next neighboring major version?

Pato
Posts: 31
Joined: Sat Mar 24, 2018 12:52 am

Re: PWM glitches and bad frequency

Postby Pato » Thu Jun 28, 2018 3:30 pm

I'm using NONOS-SDK-2.2.0, built with esp-open-sdk toolchain.
I'll try the previous SDK in few days if I have a little free time...

AgentSmithers
Posts: 123
Joined: Sat Apr 01, 2017 1:21 am
Contact:

Re: PWM glitches and bad frequency

Postby AgentSmithers » Wed Jul 04, 2018 6:30 am

Pato wrote:I'm using NONOS-SDK-2.2.0, built with esp-open-sdk toolchain.
I'll try the previous SDK in few days if I have a little free time...


Yea post back here and let us know if its any different, I'm watching this thread so I'll get a notification when you post back. One more thing. With your PyTool if you don't do it already, do a "erase" on the rom to make sure its clean and reflash your 2.2.0 as well. See if that gives you anything different.

Pato
Posts: 31
Joined: Sat Mar 24, 2018 12:52 am

Re: PWM glitches and bad frequency

Postby Pato » Mon Jul 09, 2018 5:10 pm

So I erased the flash with "esptool.py erase_flash", and then as he ESP was bricked with error "rf_cal[0] !=0x05,is 0xFF", I re-flashed all the blank.bin, eagle.irom0.bin and so to init the ROM and re-flashed my software. I got the same glitches and frequency offset on my PWM.

I also added the user_rf_cal_sector_set() function that I did not implemented until now, but the result is the same on the PWM...
But thank you for this suggestion.


NB: Because of the wrong frequency, I assumed it's a software issue and not a hardware issue. But I also tried on an Adafruit Huzzah board with a ESP-12 module and I got the exact same behavior, so it's definitively on the software side :( (after reset, reflash, etc)

AgentSmithers
Posts: 123
Joined: Sat Apr 01, 2017 1:21 am
Contact:

Re: PWM glitches and bad frequency

Postby AgentSmithers » Tue Jul 10, 2018 12:57 am

Are you writing custom firmware from NONOS SDK or using that ATfirmware portion?

Pato
Posts: 31
Joined: Sat Mar 24, 2018 12:52 am

Re: PWM glitches and bad frequency

Postby Pato » Tue Jul 10, 2018 3:25 pm

It's a custom firmware written in C (I also test with the few lines of code above) built with NON-OS SDK (esp-open-sdk).

I just hacked the SDKto enable the modf() functions (https://bbs.espressif.com/viewtopic.php?f=7&t=9432)... Maybe PWM is somehow linked to modudulus functions ant that breaks it...

Jake9879
Posts: 1
Joined: Fri Oct 12, 2018 7:30 am

Re: PWM glitches and bad frequency

Postby Jake9879 » Fri Oct 12, 2018 7:34 am

Check out this post about the problems with the included pwm driver from espressif:

https://lurchi.wordpress.com/2016/06/29 ... plemented/

And try this pwm driver from the same guy who wrote that post (worked great for me):

https://github.com/StefanBruens/ESP8266_new_pwm

Who is online

Users browsing this forum: No registered users and 15 guests