mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-07-15 08:32:42 +08:00
bugfix(pwm): fix pwm error phase
Fixes https://github.com/espressif/ESP8266_RTOS_SDK/issues/528 Fixes https://github.com/espressif/ESP8266_RTOS_SDK/issues/527
This commit is contained in:
@ -26,7 +26,6 @@
|
|||||||
#include "esp_heap_caps.h"
|
#include "esp_heap_caps.h"
|
||||||
|
|
||||||
#include "driver/pwm.h"
|
#include "driver/pwm.h"
|
||||||
|
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
|
||||||
// Temporary use the FreeRTOS critical function
|
// Temporary use the FreeRTOS critical function
|
||||||
@ -61,7 +60,7 @@ static const char *TAG = "pwm";
|
|||||||
#define WDEVTSF0TIMER_ENA 0x3ff21098
|
#define WDEVTSF0TIMER_ENA 0x3ff21098
|
||||||
#define WDEV_TSF0TIMER_ENA BIT(31)
|
#define WDEV_TSF0TIMER_ENA BIT(31)
|
||||||
|
|
||||||
#define PWM_VERSION "PWM v3.0"
|
#define PWM_VERSION "PWM v3.2"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t duty; /*!< pwm duty for each channel */
|
uint32_t duty; /*!< pwm duty for each channel */
|
||||||
@ -114,16 +113,16 @@ int wDev_MacTimSetFunc(void (*handle)(void));
|
|||||||
|
|
||||||
static void pwm_phase_init(void)
|
static void pwm_phase_init(void)
|
||||||
{
|
{
|
||||||
int16_t time_delay;
|
int32_t time_delay;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
for (i = 0; i < pwm_obj->channel_num; i++) {
|
for (i = 0; i < pwm_obj->channel_num; i++) {
|
||||||
if (-180 < pwm_obj->pwm_info[i].phase && pwm_obj->pwm_info[i].phase < 0) {
|
if (-180 < pwm_obj->pwm_info[i].phase && pwm_obj->pwm_info[i].phase < 0) {
|
||||||
time_delay = 0 - ((0 - pwm_obj->pwm_info[i].phase) * pwm_obj->depth / 180);
|
time_delay = 0 - ((0 - pwm_obj->pwm_info[i].phase) * pwm_obj->depth / 360);
|
||||||
} else if (pwm_obj->pwm_info[i].phase == 0) {
|
} else if (pwm_obj->pwm_info[i].phase == 0) {
|
||||||
continue;
|
continue;
|
||||||
} else if (180 > pwm_obj->pwm_info[i].phase && pwm_obj->pwm_info[i].phase > 0) {
|
} else if (180 > pwm_obj->pwm_info[i].phase && pwm_obj->pwm_info[i].phase > 0) {
|
||||||
time_delay = pwm_obj->pwm_info[i].phase * pwm_obj->depth / 180;
|
time_delay = pwm_obj->pwm_info[i].phase * pwm_obj->depth / 360;
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "channel[%d] phase error %d, valid ramge from (-180,180)\n", i, pwm_obj->pwm_info[i].phase);
|
ESP_LOGE(TAG, "channel[%d] phase error %d, valid ramge from (-180,180)\n", i, pwm_obj->pwm_info[i].phase);
|
||||||
continue;
|
continue;
|
||||||
|
@ -43,14 +43,14 @@ const uint32_t pin_num[4] = {
|
|||||||
PWM_3_OUT_IO_NUM
|
PWM_3_OUT_IO_NUM
|
||||||
};
|
};
|
||||||
|
|
||||||
// dutys table, (duty/PERIOD)*depth
|
// duties table, real_duty = duties[x]/PERIOD
|
||||||
uint32_t duties[4] = {
|
uint32_t duties[4] = {
|
||||||
250, 250, 250, 250,
|
250, 250, 250, 250,
|
||||||
};
|
};
|
||||||
|
|
||||||
// phase table, (phase/180)*depth
|
// phase table, delay = (phase[x]/360)*PERIOD
|
||||||
int16_t phase[4] = {
|
int16_t phase[4] = {
|
||||||
0, 0, 50, -50,
|
0, 0, 90, -90,
|
||||||
};
|
};
|
||||||
|
|
||||||
void app_main()
|
void app_main()
|
||||||
@ -63,8 +63,8 @@ void app_main()
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (count == 20) {
|
if (count == 20) {
|
||||||
//channel0, 1 output hight level.
|
// channel0, 1 output hight level.
|
||||||
//channel2, 3 output low level.
|
// channel2, 3 output low level.
|
||||||
pwm_stop(0x3);
|
pwm_stop(0x3);
|
||||||
ESP_LOGI(TAG, "PWM stop\n");
|
ESP_LOGI(TAG, "PWM stop\n");
|
||||||
} else if (count == 30) {
|
} else if (count == 30) {
|
||||||
|
Reference in New Issue
Block a user