reprappro / Marlin

Reprap FW with look ahead. SDcard and LCD support. It works on Gen6, Ultimaker, RAMPS and Sanguinololu
46 stars 66 forks source link

Fix the annoying high-pitched fan PWM sound. #3

Open ambrop72 opened 11 years ago

ambrop72 commented 11 years ago

I find the PWM noise from the fan incredibly annoying; the noise is much worse for powerful fans. Software PWM which is already used for heaters is more appropriate than the current hardware PWM, as is uses a much lower frequency. I've patched RRP-Marlin to do this (based on code in upstream Marlin). Additionally, I've added an option to allow increasing the frequency of the software PWM (because the fan is then annoying due to the very low frequency). By multiplying the software PWM frequency by 4, the PWM noise is almost inaudiable (but I'd be reluctant to make this the default due to possible impact on the bed/extruder heater mosfets).

https://github.com/ambrop72/Marlin-rrp/commit/590fe6c95ce2b9fe35b4a4076ef567ba4ad62aac

ambrop72 commented 11 years ago

Unfortunately switching to software PWM for fan triggers a problem where the fan speed will be adjusted when the g-code is received/processed and not when it's supposed to be adjusted. This commit fixes this (on top of the already mentioned commit):

https://github.com/ambrop72/Marlin-rrp/commit/1af198b2676e54df09dadab7481ee82c5d602063

It's based mostly on upstream Marlin code (planner.cpp), except that it's also fixed to work for software PWM, not just hardware PWM (via the introduction of the FanSpeedSoftPwm variable).

ambrop72 commented 11 years ago

I'll try changing the PWM code so that only the fan frequency would be increased and not the heater or bed frequency, to avoid possible damage to the mosfets; will send a pull request once it's working properly.