Take a pain-free break from head smashing and watch my videos #14 (part 1) and #15 (part 2) all about PWM. Part two specifically uses a computer cooling type fan which may be of interest to you. URL for my videos in the signature of this post. Enjoy!
On your specific issue, using a 3-wire fan may be the issue - PWM works by modulating the 'on' time so 3 wires are not (normally) required - just the +ve and -ve of your fan. The third wire is (usually) a speed sensor wire so your PC knows to alert you if it stops. Check your connections here!
fwiw, using pwm on fan power is really just a hack. You can get 4 wire computer fan that has a dedicated pwm pin for speed control and works on 3.3v or 5v. The PWM frequency must be about 25khz, otherwise there will be an audible whine.
I connect pwm direct to fan pwm pin, fan tach pin to a pullup resistor connected to a pin with interrupt enabled. The 12v power to fan is controlled by an npn + p channel mosfet circuit so I can completely shut off the fan.
Seems that P-Channel fets are used, and that they are normally 'on'.
So the fan should run at full speed when nothing is connected to the input of the board.
A 'high' from the Arduino pin should turn the fet 'off', and stop the fan.
Your map function should be 0, 1024, 255, 0. Or better 0, 1024, 255, 100.
Fans need a minimum voltage to work.
Leo..
redcx:
Yes, i am using only + and gnd wire on the fan.
Watched the videos, but did not get it working.
Is it something to do with the mosfets on the board?
Well, those are not logic-level (5v gate) MOSFETs so will not switch on fully with the 5v output from an Arduino GPIO pin. The clue is in the name (IRF as opposed to IRL).
Maybe that's the issue here?