@@ -97,8 +97,10 @@ STATIC ledc_timer_config_t timers[PWM_TIMER_MAX];
97
97
// How much to shift from the HIGHEST_PWM_RES duty resolution to the user interface duty resolution UI_RES_16_BIT
98
98
#define UI_RES_SHIFT (UI_RES_16_BIT - HIGHEST_PWM_RES) // 0 for ESP32, 2 for S2, S3, C3
99
99
100
+ #if SOC_LEDC_SUPPORT_REF_TICK
100
101
// 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
101
102
#define EMPIRIC_FREQ (10) // Hz
103
+ #endif
102
104
103
105
// Config of timer upon which we run all PWM'ed GPIO pins
104
106
STATIC bool pwm_inited = false;
@@ -208,9 +210,11 @@ STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf
208
210
if (freq != timer -> freq_hz ) {
209
211
// Find the highest bit resolution for the requested frequency
210
212
unsigned int i = LEDC_APB_CLK_HZ ; // 80 MHz
213
+ #if SOC_LEDC_SUPPORT_REF_TICK
211
214
if (freq < EMPIRIC_FREQ ) {
212
215
i = LEDC_REF_CLK_HZ ; // 1 MHz
213
216
}
217
+ #endif
214
218
215
219
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL (5 , 0 , 0 )
216
220
// original code
@@ -243,9 +247,11 @@ STATIC void set_freq(machine_pwm_obj_t *self, unsigned int freq, ledc_timer_conf
243
247
timer -> duty_resolution = res ;
244
248
timer -> freq_hz = freq ;
245
249
timer -> clk_cfg = LEDC_USE_APB_CLK ;
250
+ #if SOC_LEDC_SUPPORT_REF_TICK
246
251
if (freq < EMPIRIC_FREQ ) {
247
252
timer -> clk_cfg = LEDC_USE_REF_TICK ;
248
253
}
254
+ #endif
249
255
250
256
// Set frequency
251
257
esp_err_t err = ledc_timer_config (timer );
0 commit comments