diff --git a/components/esp8266/driver/pwm.c b/components/esp8266/driver/pwm.c index 99680ac6..fe884f40 100644 --- a/components/esp8266/driver/pwm.c +++ b/components/esp8266/driver/pwm.c @@ -26,7 +26,6 @@ #include "esp_heap_caps.h" #include "driver/pwm.h" - #include "driver/gpio.h" // Temporary use the FreeRTOS critical function @@ -61,7 +60,7 @@ static const char *TAG = "pwm"; #define WDEVTSF0TIMER_ENA 0x3ff21098 #define WDEV_TSF0TIMER_ENA BIT(31) -#define PWM_VERSION "PWM v3.0" +#define PWM_VERSION "PWM v3.2" typedef struct { uint32_t duty; /*!< pwm duty for each channel */ @@ -114,16 +113,16 @@ int wDev_MacTimSetFunc(void (*handle)(void)); static void pwm_phase_init(void) { - int16_t time_delay; + int32_t time_delay; uint8_t 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) { - 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) { continue; } 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 { ESP_LOGE(TAG, "channel[%d] phase error %d, valid ramge from (-180,180)\n", i, pwm_obj->pwm_info[i].phase); continue; diff --git a/examples/peripherals/pwm/main/pwm_example_main.c b/examples/peripherals/pwm/main/pwm_example_main.c index d7c04b47..989b4648 100644 --- a/examples/peripherals/pwm/main/pwm_example_main.c +++ b/examples/peripherals/pwm/main/pwm_example_main.c @@ -43,14 +43,14 @@ const uint32_t pin_num[4] = { PWM_3_OUT_IO_NUM }; -// dutys table, (duty/PERIOD)*depth +// duties table, real_duty = duties[x]/PERIOD uint32_t duties[4] = { 250, 250, 250, 250, }; -// phase table, (phase/180)*depth +// phase table, delay = (phase[x]/360)*PERIOD int16_t phase[4] = { - 0, 0, 50, -50, + 0, 0, 90, -90, }; void app_main() @@ -63,8 +63,8 @@ void app_main() while (1) { if (count == 20) { - //channel0, 1 output hight level. - //channel2, 3 output low level. + // channel0, 1 output hight level. + // channel2, 3 output low level. pwm_stop(0x3); ESP_LOGI(TAG, "PWM stop\n"); } else if (count == 30) {