Fan simulation with Arduino Mega

Hi
I want to simulating a 12v 4 pin fan with my Arduino mega for reading pwm from a hardware that has sensor for temperature and sending tacho signal back to board.
how can I do this ?
thanks in advance

From what I've read about 4-pin fans the tach signal generates 2 pulses for every rotation. You could set up a timer and toggle a digital output. I have used the TimerOne library for outputting signals in which case you just tell it to configure the timer with the desired frequency. There may be better libraries but this has worked for me.

To measure the PWM input you could use pulseIn() to time the HIGH and LOW pulse length of the input to determine frequency and duty cycle, however you can't do anything while pulseIn() waits for the signal to change. Alternatively you could use pin interrupts to measure the length of the input pulses if you don't want to stall your program while waiting.

Thank you for your response I Write a sample test code by reading several post on forum , that read pwm from computer main board fan but tach signal doesn't show RPM on system info software of main board .

//assume that pin 18 is receiving PWM input
#define PWM_PIN 18
#define TACH_PIN 2
int pulse_time;
//micros when the pin goes HIGH
volatile unsigned long timer_start;
volatile int last_interrupt_time; //calcSignal is the interrupt handler
void calcSignal()
{
//record the interrupt time so that we can tell if the receiver has a signal from the transmitter
last_interrupt_time = micros();
//if the pin has gone HIGH, record the microseconds since the Arduino started up
if(digitalRead(PWM_PIN) == HIGH)
{
timer_start = micros();
}
//otherwise, the pin has gone LOW
else
{
if(timer_start != 0)
{
//record the pulse time
pulse_time = ((volatile int)micros() - timer_start);
//restart the timer
timer_start = 0;
}
}
}

void setup()
{
pinMode(TACH_PIN, OUTPUT);
timer_start = 0;
attachInterrupt(5, calcSignal, CHANGE);
Serial.begin(9600);
}

void loop()
{
Serial.println(pulse_time);

delay(100);
analogWrite(TACH_PIN, 120);
delay(100);

}

does calcSignal() need to be any more than

void calcSignal()
{
    if(digitalRead(PWM_PIN) == HIGH)
        timer_start = micros();
    else
        pulse_time  = micros() - timer_start;
}

won't pulse_time be incorrect just once if the first interrupt catches the falling edge?

With respect to the tach signal:

  1. The tach signals on these fans are an open collector output. You will need a transistor to simulate that.
  2. PWM pins on the Mega are 490Hz. Assuming wiring is correct then the RPM at the main board would be interpreted as 490*60/2 = 14,700. Doesn't seem a reasonable RPM.

With respect to the PWM it looks like it should be around 25kHz. The way you have it programmed you will be getting 50 interrupts per millisecond.

I'm grateful for your response dear ToddL1962. could you tell which Transistor I need and how to connect it and about the Code that I wrote in earlier was for just testing and not very good if you have any suggestion for code please write a example for using timer and generating tach signal.
Also I see this page in github

and

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.