mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ledc: Fix the usage of ledc_ls_timer_update and ledc_timer_rst
ledc_ls_timer_update is required only when CLK_DIV and DUTY_RES bits are changed. Calling ledc_timer_rst while re-configure PWM frequency through ledc_set_freq can cause glitch in the signal
This commit is contained in:
parent
bcb34ca7ae
commit
0445c87459
@ -276,7 +276,6 @@ esp_err_t ledc_timer_rst(ledc_mode_t speed_mode, ledc_timer_t timer_sel)
|
||||
LEDC_CHECK(p_ledc_obj[speed_mode] != NULL, LEDC_NOT_INIT, ESP_ERR_INVALID_STATE);
|
||||
portENTER_CRITICAL(&ledc_spinlock);
|
||||
ledc_hal_timer_rst(&(p_ledc_obj[speed_mode]->ledc_hal), timer_sel);
|
||||
ledc_ls_timer_update(speed_mode, timer_sel);
|
||||
portEXIT_CRITICAL(&ledc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -288,7 +287,6 @@ esp_err_t ledc_timer_pause(ledc_mode_t speed_mode, ledc_timer_t timer_sel)
|
||||
LEDC_CHECK(p_ledc_obj[speed_mode] != NULL, LEDC_NOT_INIT, ESP_ERR_INVALID_STATE);
|
||||
portENTER_CRITICAL(&ledc_spinlock);
|
||||
ledc_hal_timer_pause(&(p_ledc_obj[speed_mode]->ledc_hal), timer_sel);
|
||||
ledc_ls_timer_update(speed_mode, timer_sel);
|
||||
portEXIT_CRITICAL(&ledc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -300,7 +298,6 @@ esp_err_t ledc_timer_resume(ledc_mode_t speed_mode, ledc_timer_t timer_sel)
|
||||
LEDC_CHECK(p_ledc_obj[speed_mode] != NULL, LEDC_NOT_INIT, ESP_ERR_INVALID_STATE);
|
||||
portENTER_CRITICAL(&ledc_spinlock);
|
||||
ledc_hal_timer_resume(&(p_ledc_obj[speed_mode]->ledc_hal), timer_sel);
|
||||
ledc_ls_timer_update(speed_mode, timer_sel);
|
||||
portEXIT_CRITICAL(&ledc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -581,9 +578,6 @@ static esp_err_t ledc_set_timer_div(ledc_mode_t speed_mode, ledc_timer_t timer_n
|
||||
|
||||
/* The divisor is correct, we can write in the hardware. */
|
||||
ledc_timer_set(speed_mode, timer_num, div_param, duty_resolution, timer_clk_src);
|
||||
|
||||
/* Reset the timer. */
|
||||
ledc_timer_rst(speed_mode, timer_num);
|
||||
return ESP_OK;
|
||||
|
||||
error:
|
||||
@ -618,7 +612,12 @@ esp_err_t ledc_timer_config(const ledc_timer_config_t *timer_conf)
|
||||
ledc_hal_init(&(p_ledc_obj[speed_mode]->ledc_hal), speed_mode);
|
||||
}
|
||||
|
||||
return ledc_set_timer_div(speed_mode, timer_num, timer_conf->clk_cfg, freq_hz, duty_resolution);
|
||||
esp_err_t ret = ledc_set_timer_div(speed_mode, timer_num, timer_conf->clk_cfg, freq_hz, duty_resolution);
|
||||
if (ret == ESP_OK) {
|
||||
/* Reset the timer. */
|
||||
ledc_timer_rst(speed_mode, timer_num);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t ledc_set_pin(int gpio_num, ledc_mode_t speed_mode, ledc_channel_t ledc_channel)
|
||||
|
@ -611,6 +611,7 @@ TEST_CASE("LEDC timer pause and resume", "[ledc]")
|
||||
printf("reset ledc timer\n");
|
||||
TEST_ESP_OK(ledc_timer_rst(test_speed_mode, LEDC_TIMER_0));
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
count = wave_count(1000);
|
||||
TEST_ASSERT_UINT32_WITHIN(5, count, 5000);
|
||||
tear_testbench();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user