espressif / ESP8266_RTOS_SDK

Latest ESP8266 SDK based on FreeRTOS, esp-idf style.
http://bbs.espressif.com
Apache License 2.0
3.33k stars 1.57k forks source link

PWM doesn't work. I use Nodemocu (GIT8266O-536) #959

Open ElecTroMagicX opened 4 years ago

ElecTroMagicX commented 4 years ago

I've almost completely copied this

"esp/ESP8266_RTOS_SDK/examples/peripherals/pwm/main/pwm_example_main.c"

And the compilation was successful

but still has no output and is always low level.

main.c

#include "f_s_pwm.h"

static const char *TAG = "main";

void app_main()
{
   usr_pwm_init();
   usr_pwm_start();

   int cnt = 0;

   while (1)
   {
      vTaskDelay(5000 / portTICK_PERIOD_MS);
      ESP_LOGI(TAG, "cnt: %d\n", cnt++);
   }
}

f_s_pwm.c

#include "f_s_pwm.h"

//pwm_init(uint32_t period, uint32_t *duties, uint8_t channel_num, const uint32_t *pin_num);

#define PWM_PERIOD    (1000)

uint8_t channel_num = 1;
uint32_t duties[1] = {500};
const uint32_t pin_num[1] = {4};    //NodeMCU----D2

int16_t phase[1] = {0};

void usr_pwm_init()
{
    esp_err_t pwminit = pwm_init(PWM_PERIOD, duties, 1, pin_num);
    pwm_set_phases(phase);
    ESP_LOGI("PWM", "PWM_INIT: %d/n", pwminit);
}

void usr_pwm_start()
{
    esp_err_t pwmstart = pwm_start();
    ESP_LOGI("PWM", "PWM_START: %d/n", pwmstart);
}

f_s_pwm.h

#ifndef __F_S_PWM_H_
#define __F_S_PWM_H_

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#include "esp_log.h"

#include "driver/pwm.h"

void usr_pwm_init();
void usr_pwm_start();

#endif
colesnicov commented 3 years ago

I have this problem too