Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // HP ProLiant Fan Speed Governor
- // Modified By: Joyce Ng
- // Date Modified: 28/4/2019
- #include <avr/wdt.h>
- // Function Prototypes
- void spin_up();
- void read_temp(double temp1, double temp2);
- uint16_t fans[4][2] =
- {
- {A3, 3},
- {A2, 5},
- {A1, 6},
- {A0, 9},
- };
- int bypass = 10;
- double tempA, tempB;
- void setup()
- {
- // Initialize inputs and outputs
- for (int i = 0; i < 4; i++)
- {
- pinMode(fans[i][0], INPUT);
- pinMode(fans[i][1], OUTPUT);
- }
- pinMode(bypass, INPUT_PULLUP);
- Serial.begin(115200);
- delay(100);
- Serial.println();
- Serial.println();
- Serial.println("HP ProLiant Fan Governor");
- Serial.println("-----");
- // Spin up the fans on startup
- spin_up();
- // Configure the watchdog - 4 seconds before reset
- wdt_enable(WDTO_4S);
- }
- void loop()
- {
- uint16_t ana_in;
- double pwm, out;
- uint8_t pwm_out;
- bool bypass = false;
- wdt_reset(); // Feed the dog
- Serial.println("Fan speed settings: ");
- Serial.println();
- for (int i = 0; i < 4; i++)
- {
- ana_in = analogRead(fans[i][0]);
- //5V=1023
- //3.3V=673
- //inverted PWM so 1-
- pwm = (double)(715 - ana_in) / 715;
- if(digitalRead(bypass) == 1)
- {
- out = pwm;
- bypass = true;
- }
- else if (pwm <= 0.20)
- {
- out = pwm; // Let's just follow what iLO says here
- }
- else
- {
- // Let's decide based on temperature readings
- read_temp(tempA, tempB);
- if(tempA > 75 || tempB > 75)
- {
- // Set PWM to 85%
- out = 0.85;
- }
- if(tempA > 65 || tempB > 65)
- {
- // Set PWM to 60%
- out = 0.6;
- }
- else if(tempA > 55 || tempB > 55)
- {
- // Set PWM to 40%
- out = 0.4;
- }
- else if(tempA < 35 || tempB < 35)
- {
- // Set PWM to 20%
- out = 0.20;
- }
- }
- pwm_out = 255 - out * 255;
- analogWrite(fans[i][1], pwm_out);
- Serial.print("Fan ");
- Serial.print(i + 1);
- Serial.print(": iLO: ");
- Serial.print(pwm * 100);
- Serial.print("% Governor: ");
- Serial.print(out * 100);
- Serial.print("% Diff: ");
- Serial.print((pwm - out) * 100);
- Serial.println("%");
- }
- if(bypass == true)
- {
- Serial.println();
- Serial.println("NOTICE: Governor has been bypassed!");
- Serial.println();
- }
- Serial.println();
- Serial.println("System Temperature in °C");
- Serial.println();
- Serial.print("Temperature Sensor 1: ");
- Serial.println(tempA);
- Serial.print("Temperature Sensor 2: ");
- Serial.println(tempB);
- Serial.println();
- Serial.println("-----");
- delay(2000); // wait a bit
- }
- // Spins up the fan during startup
- void spin_up()
- {
- Serial.println("Governor started. Spinning up the fans...");
- Serial.println();
- for (int i = 0; i < 4; i++)
- {
- analogWrite(fans[i][1], 76); // 90% PWM
- }
- delay(6000); // 6 second delay
- }
- // Reads the temperature at various points of the system
- void read_temp(double temp1, double temp2)
- {
- double sense1 = analogRead(A6);
- double sense2 = analogRead(A8);
- // Convert to temperature values in degrees
- temp1 = ((sense1 / 1023.0) * 5000) * 0.1;
- temp2 = ((sense2 / 1023.0) * 5000) * 0.1;
- tempA = temp1;
- tempB = temp2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement