diff options
| author | Damien George <damien@micropython.org> | 2022-09-25 22:12:29 +1000 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-09-26 00:11:42 +1000 |
| commit | dd9dcb594c577cb818c336db59a884fd329c3840 (patch) | |
| tree | 29697fd1809d48f85c7751162fc57d9763881efb | |
| parent | 3abcfb9aecd567c4c74fd3c99703f23c372b7445 (diff) | |
esp32/machine_pwm: Don't use LEDC_USE_REF_TICK on ESP32-C3 variants.
Because it's not supported by this particular MCU (since IDF v4.4.2).
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/esp32/machine_pwm.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/ports/esp32/machine_pwm.c b/ports/esp32/machine_pwm.c index 0107187a8..2a456c71c 100644 --- a/ports/esp32/machine_pwm.c +++ b/ports/esp32/machine_pwm.c @@ -97,8 +97,10 @@ STATIC ledc_timer_config_t timers[PWM_TIMER_MAX]; // How much to shift from the HIGHEST_PWM_RES duty resolution to the user interface duty resolution UI_RES_16_BIT #define UI_RES_SHIFT (UI_RES_16_BIT - HIGHEST_PWM_RES) // 0 for ESP32, 2 for S2, S3, C3 +#if SOC_LEDC_SUPPORT_REF_TICK // If the PWM frequency is less than EMPIRIC_FREQ, then LEDC_REF_CLK_HZ(1 MHz) source is used, else LEDC_APB_CLK_HZ(80 MHz) source is used #define EMPIRIC_FREQ (10) // Hz +#endif // Config of timer upon which we run all PWM'ed GPIO pins STATIC bool pwm_inited = false; @@ -208,9 +210,11 @@ STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf if (freq != timer->freq_hz) { // Find the highest bit resolution for the requested frequency unsigned int i = LEDC_APB_CLK_HZ; // 80 MHz + #if SOC_LEDC_SUPPORT_REF_TICK if (freq < EMPIRIC_FREQ) { i = LEDC_REF_CLK_HZ; // 1 MHz } + #endif #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) // original code @@ -243,9 +247,11 @@ STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf timer->duty_resolution = res; timer->freq_hz = freq; timer->clk_cfg = LEDC_USE_APB_CLK; + #if SOC_LEDC_SUPPORT_REF_TICK if (freq < EMPIRIC_FREQ) { timer->clk_cfg = LEDC_USE_REF_TICK; } + #endif // Set frequency esp_err_t err = ledc_timer_config(timer); |
