1

This question is not same as the other one and this is more about employing the pwm signal to drive a CPU fan;

I am trying to follow the answer by Edgar Bonet on the question Need help to set PWM frequency to 25kHz and generate the same 25khz on pin 8 of arduino mega which is controlled by TIMER 4 and use this pwm signal to control the speed of a 4-wire cpu fan(with black, yellow, green and blue wires);

Following is my updated code for generating the pwm signal on timer 4

void analogWrite25k(int value)
{
    OCR4C = value;
}

void setup()
{    
    TCCR4A = 0;
    TCCR4B = 0;
    TCNT4  = 0;        
    TCCR4A = _BV(COM4C1)  // non-inverted PWM on ch. C
          | _BV(WGM41);  // mode 10: phase correct PWM, TOP = ICR4
    TCCR4B = _BV(WGM43)   
         | _BV(CS40);   // prescaler = 1
    ICR4   = 320;      // TOP = 320

    // Set the PWM pin as output.
    pinMode( 8, OUTPUT);
}

void loop()
{
    analogWrite25k(10);
    for (;;) ;  // infinite loop
}

I have connected pin 8 on the mega to the pwm input on the fan(blue wire) but I dont see any variation in fan speed and fan seems to run at full speed;

I dont really have any means or tools to verify if its really generating a 25khz pwm signal but fan speed is not changing or if its not generating a 25khz pwm signal because of which there is no change in the speed of fan;

I am stuck at this point and any help on this would he highly appreciated;

techniche
  • 198
  • 2
  • 12
  • can you fan accepts such a high frequency PWM signal? – dandavis Sep 16 '17 at 20:30
  • yes, its a cpu fan used for intel cpus and the fan datasheet says the signal needs to be ideally 25KHz – techniche Sep 16 '17 at 20:35
  • you should be able to measure duty cycle with a DMM or even an LED; if it's getting adjusted, it would imply operation... – dandavis Sep 16 '17 at 20:43
  • i dont have a DMM, how can it be measured with an LED? and the fan speed should be noticeable ideally since I tried values as low as 5 and 10 for duty cycle and I dont see any variation in fan speed; – techniche Sep 16 '17 at 20:44
  • the LED gets dimmer at low duty-cycle values. make sure to (dramatically) limit current when testing. – dandavis Sep 16 '17 at 20:47
  • okay, thats a bit difficult at the moment since I dont have an LED handy :-( – techniche Sep 16 '17 at 20:48
  • I just added some code to read the RPM of the fan using the green wire which is the sense/tach wire and the RPM does not seem to go low for lower duty cycles; – techniche Sep 16 '17 at 21:13
  • Also, I see that the PWM signal is being generated at 25KHz on pin 8; I verified it by reading the pwm output from pin 8 on pin 9 as if it were coming from the the fan and the code at http://elimelecsarduinoprojects.blogspot.in/2013/06/measure-rpms-arduino.html helps print the frequency in hertz and it looks like approximately 25KHz; – techniche Sep 16 '17 at 21:22
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/65709/discussion-between-techniche-and-dandavis). – techniche Sep 16 '17 at 21:25

1 Answers1

1

I've just tested your setting with older "Alpine 64 GT" CPU Fan and it works as expected. I've just added parsing integers sent from serial monitor, so I don't have to change code anymore.

void analogWrite25k(int value)
{
    OCR4C = value;
}

void setup()
{    
    TCCR4A = 0;
    TCCR4B = 0;
    TCNT4  = 0;

    // Mode 10: phase correct PWM with ICR4 as Top (= F_CPU/2/25000)
    // OC4C as Non-Inverted PWM output
    ICR4   = (F_CPU/25000)/2;
    OCR4C  = ICR4/2;                    // default: about 50:50
    TCCR4A = _BV(COM4C1) | _BV(WGM41);
    TCCR4B = _BV(WGM43) | _BV(CS40);

    Serial.begin(115200);

    // Set the PWM pin as output.
    pinMode( 8, OUTPUT);
}

void loop()
{
    int w = Serial.parseInt();
    if (w>0) {
      analogWrite25k(w);
      Serial.println(w);
    }
}
KIIV
  • 4,272
  • 1
  • 11
  • 21
  • you have connected the pwm line of fan directly to pin 8 of mega right? or is there any additional circuitry? – techniche Sep 17 '17 at 08:59
  • https://www.amazon.in/Terabyte-CPU-Cooler-intel-LGA775/dp/B01BDOI9KE/ref=cm_cd_al_qh_dp_i thats the fan I have; could it be that the fan has 4 wires but is not a pwm fan??? these fans are used as CPU fans so I thought they must definitely respond to pwm; any thoughts? – techniche Sep 17 '17 at 10:11