Welcome! Log In Create A New Profile

Advanced

USE_CONTROLLER_FAN with hardware PWM fan

Posted by Reven 
USE_CONTROLLER_FAN with hardware PWM fan
January 31, 2019 03:29PM
I've come across something weird and wanted to make sure I'm not doing anything stupid before adding an issue on Github.

I'm using an MKS Gen 1.4 board flashed with Marlin-bugfix-2.0. I'm trying to use a 4-wire PWM computer case fan as a fan for the controller case to keep the drivers cool because I was getting overtemp warnings.

I've attached the yellow and black wires to the 12V rail directly and I thought that connecting the blue wire (which is PWM) to the board would give me control over the fan without needing to use a mosfet and softPWM.

In Configuration_adv.h I've set the following:
#define USE_CONTROLLER_FAN
#if ENABLED(USE_CONTROLLER_FAN)
  #define CONTROLLER_FAN_PIN 2           // Set a custom pin for the controller fan
  #define CONTROLLERFAN_SECS 60          // Duration in seconds for the fan to run after all motors are disabled
  #define CONTROLLERFAN_SPEED 100        // 255 == full speed
#endif

But the fan just blows at full speed the second I turn on the board and it doesn't go down again. Ideally it would be off all the time and only turn on when the motor drivers are on.

In addition I've got the extruder cooling fan set to automatic and that works fine, but that's also the reason I don't have any more mosfet outputs on the board.

I just wanted to check that I'm not doing anything that's impossible. Or that I'm using a pin reserved for something else. Or that I have to define the pin somewhere else, like in the pins definition or board definition file. Because the PWM implementation from each manufacturer is different, it might just be that my fan (an Arctic fan) does 100% rpm when the PWM signal is 0; I've seen this before, but wanted to be sure the firmware side is ok before I tackle that.
Re: USE_CONTROLLER_FAN with hardware PWM fan
January 31, 2019 09:00PM
This is not a firmware issue but an understanding issue

Marlin controls speed by PWM the power lines , it has no support for an actual 3 or 4 wire fan, it only supports 2 wire fans
the PWM on a fan requires 25kHz PWM signal...
Re: USE_CONTROLLER_FAN with hardware PWM fan
January 31, 2019 09:40PM
Of course! I had completely overlooked that!! Ok, that's good news. At least I'm not going crazy. smiling smiley

I've seen somewhere else that Marlin's default PWM frequency is 1kHz. On a simple test sketch I've done a proof of concept and the default Arduino Mega frequency does drive the fan, though the fan does complain a little, so I took for granted it would just work, even though I was aware that the PWM is normally used on the power.

I've found a couple of sketches where the timer is set at 25kHz, so theoretically it could work, but it's probably a bit overkill and could possibly screw up some other timer critical for actually printing. So I guess I'll just get a mosfet and drive the power line, like everybody else.

Thanks!
Sorry, only registered users may post in this forum.

Click here to login