Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. // HP ProLiant Fan Speed Governor
  2. // Modified By: Joyce Ng
  3. // Date Modified: 28/4/2019
  4.  
  5. #include <avr/wdt.h>
  6.  
  7. // Function Prototypes
  8. void spin_up();
  9. void read_temp(double temp1, double temp2);
  10.  
  11.  
  12. uint16_t fans[4][2] =
  13. {
  14. {A3, 3},
  15. {A2, 5},
  16. {A1, 6},
  17. {A0, 9},
  18. };
  19.  
  20. int bypass = 10;
  21. double tempA, tempB;
  22.  
  23.  
  24. void setup()
  25. {
  26.  
  27. // Initialize inputs and outputs
  28. for (int i = 0; i < 4; i++)
  29. {
  30. pinMode(fans[i][0], INPUT);
  31. pinMode(fans[i][1], OUTPUT);
  32. }
  33.  
  34. pinMode(bypass, INPUT_PULLUP);
  35.  
  36.  
  37. Serial.begin(115200);
  38. delay(100);
  39. Serial.println();
  40. Serial.println();
  41. Serial.println("HP ProLiant Fan Governor");
  42. Serial.println("-----");
  43.  
  44. // Spin up the fans on startup
  45. spin_up();
  46.  
  47. // Configure the watchdog - 4 seconds before reset
  48. wdt_enable(WDTO_4S);
  49.  
  50.  
  51. }
  52.  
  53.  
  54. void loop()
  55. {
  56.  
  57. uint16_t ana_in;
  58. double pwm, out;
  59. uint8_t pwm_out;
  60. bool bypass = false;
  61.  
  62. wdt_reset(); // Feed the dog
  63.  
  64.  
  65. Serial.println("Fan speed settings: ");
  66. Serial.println();
  67.  
  68. for (int i = 0; i < 4; i++)
  69. {
  70. ana_in = analogRead(fans[i][0]);
  71. //5V=1023
  72. //3.3V=673
  73. //inverted PWM so 1-
  74. pwm = (double)(715 - ana_in) / 715;
  75.  
  76.  
  77. if(digitalRead(bypass) == 1)
  78. {
  79. out = pwm;
  80. bypass = true;
  81.  
  82. }
  83. else if (pwm <= 0.20)
  84. {
  85. out = pwm; // Let's just follow what iLO says here
  86. }
  87. else
  88. {
  89. // Let's decide based on temperature readings
  90. read_temp(tempA, tempB);
  91.  
  92. if(tempA > 75 || tempB > 75)
  93. {
  94. // Set PWM to 85%
  95. out = 0.85;
  96. }
  97. if(tempA > 65 || tempB > 65)
  98. {
  99. // Set PWM to 60%
  100. out = 0.6;
  101. }
  102. else if(tempA > 55 || tempB > 55)
  103. {
  104. // Set PWM to 40%
  105. out = 0.4;
  106. }
  107. else if(tempA < 35 || tempB < 35)
  108. {
  109. // Set PWM to 20%
  110. out = 0.20;
  111. }
  112. }
  113.  
  114. pwm_out = 255 - out * 255;
  115. analogWrite(fans[i][1], pwm_out);
  116.  
  117.  
  118. Serial.print("Fan ");
  119. Serial.print(i + 1);
  120. Serial.print(": iLO: ");
  121. Serial.print(pwm * 100);
  122. Serial.print("% Governor: ");
  123. Serial.print(out * 100);
  124. Serial.print("% Diff: ");
  125. Serial.print((pwm - out) * 100);
  126. Serial.println("%");
  127.  
  128.  
  129. }
  130.  
  131. if(bypass == true)
  132. {
  133. Serial.println();
  134. Serial.println("NOTICE: Governor has been bypassed!");
  135. Serial.println();
  136. }
  137.  
  138. Serial.println();
  139. Serial.println("System Temperature in °C");
  140. Serial.println();
  141. Serial.print("Temperature Sensor 1: ");
  142. Serial.println(tempA);
  143. Serial.print("Temperature Sensor 2: ");
  144. Serial.println(tempB);
  145. Serial.println();
  146. Serial.println("-----");
  147.  
  148. delay(2000); // wait a bit
  149. }
  150.  
  151.  
  152. // Spins up the fan during startup
  153. void spin_up()
  154. {
  155. Serial.println("Governor started. Spinning up the fans...");
  156. Serial.println();
  157.  
  158. for (int i = 0; i < 4; i++)
  159. {
  160. analogWrite(fans[i][1], 76); // 90% PWM
  161. }
  162.  
  163. delay(6000); // 6 second delay
  164. }
  165.  
  166.  
  167. // Reads the temperature at various points of the system
  168. void read_temp(double temp1, double temp2)
  169. {
  170. double sense1 = analogRead(A6);
  171. double sense2 = analogRead(A8);
  172.  
  173. // Convert to temperature values in degrees
  174. temp1 = ((sense1 / 1023.0) * 5000) * 0.1;
  175. temp2 = ((sense2 / 1023.0) * 5000) * 0.1;
  176.  
  177. tempA = temp1;
  178. tempB = temp2;
  179.  
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement