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 !
[

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();
}