Go Down

Topic: Help needed for a computer fan PWM control project (Read 1 time) previous topic - next topic


Sep 01, 2011, 02:09 am Last Edit: Sep 09, 2011, 12:48 am by ashi1 Reason: 1
Thanks for the replies!

@Bobnova, yeah, the fan does have a fairly wide PWM frequency range and it's just recommended to be 25kHz. So it's not that crucial to have the frequency set to be exactly 25k, I just think it'll be nice to set it to the recommended value and to have it work. If it takes other PWM frequency to have my project working, I will be fine with it, too.

@PaulS, thanks for the detailed explanation, those are very helpful! I recognize individual fans are different and did some measurements that indicates the speed fluctuation is within 2% which is acceptable for my project so at least I don't have to mess around with bit-bang PWM for now I guess?

However, I did encounter a couple of problems.

I modified the code from robtillaart a little bit and it works all great except when I change the duty cycle to be 100% (dc=100), rather than going up to highest speed, it ramped down to a very low speed. I searched for the reason and found from this post http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1191976081 that delayMicroseconds(0) would delay for 1023 us rather than execute the next line instantly. And delay() doesn't seem to have this problem. Also I want to make sure I'm correct about this: delayMicroseconds won't take fraction numbers like 0.5 or 1.2 (although from the linked post it says delayMicroseconds has a resolution of 0.25 us but I tried those numbers and didn't receive expected result) but delay() will and delay(0) would go onto the next line instantly?

Currently I use another code to turn everything high instead of change to 100% duty cycle in this code (attached). Wondering is there a way to implement 100% into this code as well or I have to use separate code just for 100% case? (self-correct from what I said earlier about the pin correspondence with ports. The correspondence in this post is correct)


unsigned int dc = 80;   // % duty cycle that you can set yourself.

unsigned int t = 0;    
unsigned int period = 40;  // Unit is "us", gives 25kHz PWM output.
void setup() {
 for (int i=2; i< 14; i++) pinMode(i, OUTPUT);
 t = (40 * dc) / 100;    // This returns an integer between 0 and 40.

void loop()
 PORTE |= B00111000;  // Turn on pins 3,2,5 (fan 2,1,4)
 PORTH |= B01111000;  // Turn on pins 9,8,7,6 (fan 8,7,6,5)
 PORTB |= B11110000;  // Turn on pins 13,12,11,10 (fan 10,9)
 PORTG |= B00100000;  // Turn on pin 4 (fan 3)
 PORTE &= B11000111;  // Turn off pins 3,2,5
 PORTH &= B10000111;  // Turn off pins 9,8,7,6
 PORTB &= B00001111;  // Turn off pins 13,12,11,10
 PORTG &= B11011111;  // Turn off pin 4
 delayMicroseconds(40 - t);

Also I started thinking about part 2) of my project (to have 10 fans at different set speed). Since the % duty cycle can be different for each fan, this is what I wrote.. It looks stupid and didn't work because the loop takes too long to run so the % duty cycle is no long correct. I tried to increase the period (even tried to change delaymicroseconds to delay) but neither would give me anything close to they duty cycle I wanted.. Because each fan can be with different duty cycles (t1..t10 can be different integers), I don't know if there is an elegant way to put them together rather than running them individually and then loop the whole thing to output the right (more reasonable) speed for the fans.  :smiley-sad-blue:


purged. found the way to do part 2) by using analogWrite function on PWM pins.


Oh, there is another problem I had is that if I increase the percentage duty cycle say from 0 to 80%, the fan will speed up to a pretty high rpm (in my case, about 4400). After it's stable, then upload the code of 80% again, the rpm of the fan is about 4600 rpm after it's stable. Same thing happens with other percentage duty cycle as long as the jump is high. For other duty cycles, the difference between going up slowly (e.g. from 70% to 80% or upload same code twice) and direct big jump is about 100 to 200 rpm. I'm using delta PFC1212DE-F00 fans so I want to know if it's the problem with the fan, microcontroller, power supply (Antec 650W for 10 fans) or there is an ET somewhere hiding at my place messing around with me.. Anyone had similar issues before?

Go Up