SOFT_PWM: Implement dithering if SOFT_PWM_SCALE is 1 or more

If dithering is enabled, the remainder of the soft_pwm_X duty value at
turnoff time is added to the next cycle. If e.g. the duty is set to 9 and
SCALE is set to 2, the PWM will be active for 8 counts for 3 cycles and
12 counts on each fourth cycle, i.e. the average is 9 cycles.

This compensates the resolution loss at higher scales and allows running
fans with SOFT_PWM with significantly reduced noise.

Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
This commit is contained in:
Stefan Brüns
2017-03-12 06:00:26 +01:00
committed by Scott Lahteine
parent 2aed66a955
commit 35a55d5757
2 changed files with 32 additions and 18 deletions

View File

@ -1424,6 +1424,12 @@
// at zero value, there are 128 effective control positions.
#define SOFT_PWM_SCALE 0
// If SOFT_PWM_SCALE is set to a value higher than 0, dithering can
// be used to mitigate the associated resolution loss. If enabled,
// some of the PWM cycles are stretched so on average the wanted
// duty cycle is attained.
//#define SOFT_PWM_DITHER
// Temperature status LEDs that display the hotend and bed temperature.
// If all hotends and bed temperature and temperature setpoint are < 54C then the BLUE led is on.
// Otherwise the RED led is on. There is 1C hysteresis.