Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I had a potential out-of-boundary bug on an esp8266 device when setting the PWM duty value to control fan speed (negative value or >1023). On esp8266 the
machine.PWM
bounds the duty value:micropython/ports/esp8266/esppwm.c
Lines 230 to 236 in 203e1d2
...so I didn't notice it. The PWM behaviour was normal, just bounded to 0 and 1023.
When I switched my code to an esp32, the fan behaviour was really strange, because the PWM duty value is only binary ANDed:
micropython/ports/esp32/machine_pwm.c
Line 270 in 4eaebc1
Negative values may be higher and bigger values lower. Combined with issue #5737 I thought first about a hardware problem...
This PR solves the problem and makes the esp32 PWM to have the same behaviour as esp8266/stm32 (AFAIK), by bounding the duty value between 0 and max PWM resolution. My previous buggy code works again :)