Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.66 KB | None | 0 0
  1. /*
  2. Disclaimer:
  3. Use it as it is, completely and entirely at YOUR OWN RISK.
  4. YOU CAN DAMAGE YOUR HARDWARE WITHOUT PROPER COOLING, LEAVE THE THERMAL SHUTDOWN ON!
  5.  
  6. Generic CPU fan tachometer signal emulator for 4 wire pwm fans.
  7.  
  8. Tuned for Delta AFB1212SH, 0 - 3400 RPM (found in HP Microserver Gen 8)
  9.  
  10. The fan will send 2 pulses per revolution, with a duration of 1/4 rev.
  11.  
  12. ->  1 RPM  -> 1 rotation / 60 seconds -> 1 Hz
  13. 2 pulses per rotation -> 2 Hz signal freq. -> 500 miliseconds per pulse ( 250ms UP and 250ms DOWN )
  14.  
  15. -> 3400 RPN -> 3400 rotations / 60 seconds -> ~56.7 Hz
  16. 2 pulses per rotation -> 2x56.7 -> ~113.4 Hz -> ~8.8 miliseconds per pulse (4.4ms UP and 4.4ms DOWN )
  17.  
  18.  
  19. -> 1000 RPM -> 1000 rotations / 60 seconds -> 16.7 Hz
  20. 4 pulses per rotation -> 4x16.7 -> ~66.7 Hz -> ~15 milliseconds per pulse(7.5 UP and 7.5 DOWN)
  21.  
  22. -> 14000RPM -> 14000 rotations / 60 seconds -> ~233.3 Hz
  23. 4 pulses per rotation -> 4x233.3 -> ~933.2 Hz -> 1.1 milliseconds per pulse( 0.55 UP and 0.55 DOWN )
  24.  
  25. After computing the above ( min, max rpm ) put them in the voltage to pulse duration mapping in the loop() function
  26.  
  27. pFreq = map(Voltage, 0, 1023, 500.0, 8.8235);
  28.  
  29. Volatage = voltage read from the motherboard pwm driving pin by the ADC
  30. (10 bit resolution, means 0-5V will return 0-1023)
  31.  
  32. Voltage range - 0, 1023
  33. Ms pulse range - 500.0 - 8.8235  
  34.  
  35. Hardware:
  36. Tested on Arduino Pro Mini 5V/16Mhz - ( ~10$)
  37. Programmer - FTDI Basic Breakout - 5V - ( ~15$)
  38.  
  39. Software:
  40. Adruino IDE 1.0.5-r2
  41. Arduino Timer Library - http://playground.arduino.cc/Code/Timer#.UxdUPfS1a7M
  42.  
  43. Pin A0 connected to the motherboard PWM pin
  44. Pin 3 connected to the tach. signal on the motherboard
  45. GND to GNDs (see fan connector gnd loop)
  46.  
  47.  
  48.  
  49.  
  50. */
  51.  
  52.  
  53. // Timer lib
  54. #include "Timer.h";
  55.  
  56. // Timer
  57. Timer t;
  58. // Pulse output pin
  59. int pPin = 3;
  60. // Pulse freq.
  61. float pFreq;
  62. // Voltage measure pin
  63. int iPin = A0;
  64. // Voltage
  65. int Voltage;
  66. // Led pin - alive blink
  67. int ledPin = 13;
  68.  
  69.  
  70. void setup()
  71. {
  72.   //Initial config
  73.  
  74.   //IO Pins
  75.   pinMode(ledPin, OUTPUT);
  76.   pinMode(pPin, OUTPUT);
  77.   digitalWrite(pPin, LOW);
  78.   pinMode(iPin, INPUT);
  79.  
  80.   //Timers
  81.   t.every(pFreq, sendPulse);
  82.   t.every(100, readIV);
  83.   t.oscillate(ledPin,1500,HIGH);
  84. }
  85.  
  86. void loop()
  87. {
  88.   // Map V to Pulse Freq
  89.   //pFreq = map(Voltage, 0, 1023, 500.0, 8.8235);
  90.   pFreq = map(Voltage, 0, 1023, 16.7, 1.1);
  91.   // Update timers
  92.   t.update();
  93. }
  94.  
  95. void sendPulse()
  96. {
  97.     // Half period on
  98.     digitalWrite(pPin, HIGH);
  99.     delay(pFreq/2);
  100.  
  101.     // Half period off
  102.     digitalWrite(pPin, LOW);
  103.     delay(pFreq/2);
  104. }
  105.  
  106. void readIV()
  107. {
  108.   //Analog voltage read - little bit imprecise but works
  109.   Voltage =  analogRead(iPin);
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement