MarlinFirmware / Marlin

Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
https://marlinfw.org
GNU General Public License v3.0
16.18k stars 19.21k forks source link

[FR] Improve PWM Performance for Magnetic Heatbeds #18137

Open SimGas opened 4 years ago

SimGas commented 4 years ago

Description

Hi, I've recently bought a MK52 heatbed, which is used in Prusa printers MK2.5 and in a 24V version also in MK3. I connected the heatbed to my Anycubic i3 Mega and technically, everything works fine with it. However, the heatbed copper traces form some kind of a coil and together with the embedded strong magnets, they act as a loudspeaker. You can clearly hear the ~8Hz PWM switching frequency. https://github.com/prusa3d/Prusa-Firmware/issues/1862#issuecomment-505302336 While adjusting the soft pwm frequency helps to quieten the noise a bit, it never really gets silent.

This "Issue" was already adressed at the Prusa firmware repository here on github. As the prusa firmware is originally based on Marlin, I think their issue should be portable to Marlin 2.0 relatively easily.

From the heatbed_pwm.cpp file from prusa (version 3.8.0)

// All this is about silencing the heat bed, as it behaves like a loudspeaker. // Basically, we want the PWM heating switched at 30Hz (or so) which is a well ballanced // frequency for both power supply units (i.e. both PSUs are reasonably silent). // The only trouble is the rising or falling edge of bed heating - that creates an audible click. // This audible click may be suppressed by making the rising or falling edge NOT sharp. // Of course, making non-sharp edges in digital technology is not easy, but there is a solution. // It is possible to do a fast PWM sequence with duty starting from 0 to 255. // Doing this at higher frequency than the bed "loudspeaker" can handle makes the click barely audible. // Technically: // timer0 is set to fast PWM mode at 62.5kHz (timer0 is linked to the bed heating pin) (zero prescaler) // To keep the bed switching at 30Hz - we don't want the PWM running at 62kHz all the time // since it would burn the heatbed's MOSFET: // 16MHz/256 levels of PWM duty gives us 62.5kHz // 62.5kHz/256 gives ~244Hz, that is still too fast - 244/8 gives ~30Hz, that's what we need // So the automaton runs atop of inner 8 (or 16) cycles. // The finite automaton is running in the ISR(TIMER0_OVF_vect)

I would really appreciate if someone looks into this :)

Best, Simon

Additional Information

Original Implementation by Prusa: https://github.com/prusa3d/Prusa-Firmware/blob/v3.8.0-RC1/Firmware/heatbed_pwm.cpp Fix of the original implementation to relax PSU strain(?): https://github.com/prusa3d/Prusa-Firmware/pull/2129/files

MikeEitel commented 4 years ago

The "usual" way is using rc snubber filters over the load...