8000 esp32/machine_pwm: Don't use LEDC_USE_REF_TICK on ESP32-C3 variants. · micropython/micropython@dd9dcb5 · GitHub
[go: up one dir, main page]

Skip to content

Commit dd9dcb5

Browse files
committed
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>
1 parent 3abcfb9 commit dd9dcb5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ports/esp32/machine_pwm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ STATIC ledc_timer_config_t timers[PWM_TIMER_MAX];
9797
// How much to shift from the HIGHEST_PWM_RES duty resolution to the user interface duty resolution UI_RES_16_BIT
9898
#define UI_RES_SHIFT (UI_RES_16_BIT - HIGHEST_PWM_RES) // 0 for ESP32, 2 for S2, S3, C3
9999

100+
#if SOC_LEDC_SUPPORT_REF_TICK
100101
// 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
101102
#define EMPIRIC_FREQ (10) // Hz
103+
#endif
102104

103105
// Config of timer upon which we run all PWM'ed GPIO pins
104106
STATIC bool pwm_inited = false;
@@ -208,9 +210,11 @@ STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf
208210
if (freq != timer->freq_hz) {
209211
// Find the highest bit resolution for the requested frequency
210212
unsigned int i = LEDC_APB_CLK_HZ; // 80 MHz
213+
#if SOC_LEDC_SUPPORT_REF_TICK
211214
if (freq < EMPIRIC_FREQ) {
212215
i = LEDC_REF_CLK_HZ; // 1 MHz
213216
}
217+
#endif
214218

215219
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
216220
// original code
@@ -243,9 +247,11 @@ STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf
243247
timer->duty_resolution = res;
244248
timer->freq_hz = freq;
245249
timer->clk_cfg = LEDC_USE_APB_CLK;
250+
#if SOC_LEDC_SUPPORT_REF_TICK
246251
if (freq < EMPIRIC_FREQ) {
247252
timer->clk_cfg = LEDC_USE_REF_TICK;
248253
}
254+
#endif
249255

250256
// Set frequency
251257
esp_err_t err = ledc_timer_config(timer);

0 commit comments

Comments
 (0)
0