summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIhorNehrutsa <Ihor.Nehrutsa@gmail.com>2022-01-25 17:07:24 +0200
committerDamien George <damien@micropython.org>2022-02-01 16:46:55 +1100
commita5e64c209f2d76cb0cc903df875d87e8ca009507 (patch)
treebe5256360a9f2a0faf7e1aca889ae451e5d20d4f
parenta5003ba40719a3da70586bb79856ec635db1076d (diff)
esp32/machine_pwm: Fix PWM not allowing frequencies < 611 Hz.
Fixes issue #8189.
-rwxr-xr-x[-rw-r--r--]ports/esp32/machine_pwm.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/ports/esp32/machine_pwm.c b/ports/esp32/machine_pwm.c
index 43d44249d..9d5d9595e 100644..100755
--- a/ports/esp32/machine_pwm.c
+++ b/ports/esp32/machine_pwm.c
@@ -85,10 +85,10 @@ STATIC ledc_timer_config_t timers[PWM_TIMER_MAX];
// duty_u16() and duty_ns() use 16-bit resolution or less
// Possible highest resolution in device
-#if (LEDC_TIMER_BIT_MAX - 1) < LEDC_TIMER_16_BIT
-#define HIGHEST_PWM_RES (LEDC_TIMER_BIT_MAX - 1)
-#else
+#if CONFIG_IDF_TARGET_ESP32
#define HIGHEST_PWM_RES (LEDC_TIMER_16_BIT) // 20 bit for ESP32, but 16 bit is used
+#else
+#define HIGHEST_PWM_RES (LEDC_TIMER_BIT_MAX - 1) // 14 bit is used
#endif
// Duty resolution of user interface in `duty_u16()` and `duty_u16` parameter in constructor/initializer
#define UI_RES_16_BIT (16)
@@ -300,7 +300,7 @@ STATIC uint32_t get_duty_u16(machine_pwm_obj_t *self) {
}
STATIC uint32_t get_duty_u10(machine_pwm_obj_t *self) {
- return get_duty_u16(self) >> (HIGHEST_PWM_RES - PWRES);
+ return get_duty_u16(self) >> (UI_RES_16_BIT - LEDC_TIMER_10_BIT);
}
STATIC uint32_t get_duty_ns(machine_pwm_obj_t *self) {