Skip to content

Commit

Permalink
🔧 Group FAST_PWM_FAN.options (#23331)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
robbycandra and thinkyhead authored Dec 23, 2021
1 parent da67deb commit 3e737cb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
3 changes: 0 additions & 3 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -2841,9 +2841,6 @@
// :[1,2,3,4,5,6,7,8]
//#define NUM_M106_FANS 1

// Increase the FAN PWM frequency. Removes the PWM noise but increases heating in the FET/Arduino
//#define FAST_PWM_FAN

// Use software PWM to drive the fan, as for the heaters. This uses a very low frequency
// which is not as annoying as with the hardware PWM. On the other hand, if this frequency
// is too low, you should also increment SOFT_PWM_SCALE.
Expand Down
29 changes: 20 additions & 9 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -549,18 +549,21 @@
//#define FAN_MAX_PWM 128

/**
* FAST PWM FAN Settings
* Fan Fast PWM
*
* Use to change the FAST FAN PWM frequency (if enabled in Configuration.h)
* Combinations of PWM Modes, prescale values and TOP resolutions are used internally to produce a
* frequency as close as possible to the desired frequency.
* Combinations of PWM Modes, prescale values and TOP resolutions are used internally
* to produce a frequency as close as possible to the desired frequency.
*
* FAST_PWM_FAN_FREQUENCY [undefined by default]
* FAST_PWM_FAN_FREQUENCY
* Set this to your desired frequency.
* If left undefined this defaults to F = F_CPU/(2*255*1)
* i.e., F = 31.4kHz on 16MHz microcontrollers or F = 39.2kHz on 20MHz microcontrollers.
* These defaults are the same as with the old FAST_PWM_FAN implementation - no migration is required
* For AVR, if left undefined this defaults to F = F_CPU/(2*255*1)
* i.e., F = 31.4kHz on 16MHz microcontrollers or F = 39.2kHz on 20MHz microcontrollers.
* For non AVR, if left undefined this defaults to F = 1Khz.
* This F value is only to protect the hardware from an absence of configuration
* and not to complete it when users are not aware that the frequency must be specifically set to support the target board.
*
* NOTE: Setting very low frequencies (< 10 Hz) may result in unexpected timer behavior.
* Setting very high frequencies can damage your hardware.
*
* USE_OCR2A_AS_TOP [undefined by default]
* Boards that use TIMER2 for PWM have limitations resulting in only a few possible frequencies on TIMER2:
Expand All @@ -570,9 +573,17 @@
* PWM on pin OC2A. Only use this option if you don't need PWM on 0C2A. (Check your schematic.)
* USE_OCR2A_AS_TOP sacrifices duty cycle control resolution to achieve this broader range of frequencies.
*/
//#define FAST_PWM_FAN // Increase the fan PWM frequency. Removes the PWM noise but increases heating in the FET/Arduino
#if ENABLED(FAST_PWM_FAN)
//#define FAST_PWM_FAN_FREQUENCY 31400
//#define FAST_PWM_FAN_FREQUENCY 31400 // Define here to override the defaults below
//#define USE_OCR2A_AS_TOP
#ifndef FAST_PWM_FAN_FREQUENCY
#ifdef __AVR__
#define FAST_PWM_FAN_FREQUENCY ((F_CPU) / (2 * 255 * 1))
#else
#define FAST_PWM_FAN_FREQUENCY 1000U
#endif
#endif
#endif

/**
Expand Down
11 changes: 0 additions & 11 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2667,17 +2667,6 @@
#error "FAN_OFF_PWM must be less than or equal to FAN_MIN_PWM."
#endif

/**
* FAST PWM FAN default PWM frequency
*/
#if !defined(FAST_PWM_FAN_FREQUENCY) && ENABLED(FAST_PWM_FAN)
#ifdef __AVR__
#define FAST_PWM_FAN_FREQUENCY ((F_CPU) / (2 * 255 * 1))
#else
#define FAST_PWM_FAN_FREQUENCY 1000U
#endif
#endif

/**
* Controller Fan Settings
*/
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
#define FAN_MAX_PWM 255
#else
#define FAST_PWM_FAN // STM32 Variant allow TIMER2 Hardware PWM
#define FAST_PWM_FAN_FREQUENCY 31400 // This frequency allow a good range, fan starts at 3%, half noise at 50%
#define FAN_MIN_PWM 5
#define FAN_MAX_PWM 255
#endif
Expand Down

0 comments on commit 3e737cb

Please sign in to comment.