Skip to content

Commit

Permalink
automatic fan speed control
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-wilson committed Nov 15, 2023
1 parent e5009e1 commit fc0e49e
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"idf.flashType": "UART",
"idf.portWin": "COM11",
"idf.portWin": "COM30",
"idf.adapterTargetName": "esp32s3",
"idf.openOcdConfigs": [
"interface/ftdi/esp32_devkitj_v1.cfg",
Expand Down
5 changes: 4 additions & 1 deletion config.cvs.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ asicvoltage,data,u16,1320
asicmodel,data,string,BM1366
devicemodel,data,string,ultra
boardversion,data,string,0.11
flipscreen,data,u16,1
flipscreen,data,u16,1
invertfanpolarity,data,u16,1
autofanspeed,data,u16,1
fanspeed,data,u16,100
Binary file added esp-miner-factory-v2.0.1.bin
Binary file not shown.
24 changes: 24 additions & 0 deletions main/EMC2101.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@
#define EMC2101_FAN_RPM_NUMERATOR 5400000 ///< Conversion unit to convert LSBs to fan RPM
#define _TEMP_LSB 0.125 ///< single bit value for internal temperature readings

#define FAN_LOOKUP_TABLE_T1 0x50
#define FAN_LOOKUP_TABLE_S1 0x51

#define FAN_LOOKUP_TABLE_T2 0x52
#define FAN_LOOKUP_TABLE_S2 0x53

#define FAN_LOOKUP_TABLE_T3 0x54
#define FAN_LOOKUP_TABLE_S3 0x55

#define FAN_LOOKUP_TABLE_T4 0x56
#define FAN_LOOKUP_TABLE_S4 0x57

#define FAN_LOOKUP_TABLE_T5 0x58
#define FAN_LOOKUP_TABLE_S5 0x59

#define FAN_LOOKUP_TABLE_T6 0x5A
#define FAN_LOOKUP_TABLE_S6 0x5B

#define FAN_LOOKUP_TABLE_T7 0x5C
#define FAN_LOOKUP_TABLE_S7 0x5D

#define FAN_LOOKUP_TABLE_T8 0x5E
#define FAN_LOOKUP_TABLE_S8 0x5F

/**
* @brief
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,24 @@ <h2>Settings</h2>
</div>
</ng-container>


<div class="form-group">
<label>Invert Fan Polarity</label>
<input formControlName="invertfanpolarity" type="checkbox">
</div>

<div class="form-group">
<label>Fan Speed {{form.controls['fanspeed'].value}}% <b *ngIf="form.controls['fanspeed'].value < 33"
style="color:red">Danger: Could Cause Overheating</b> <b
*ngIf="form.controls['fanspeed'].value == 100" style="color: #F2A900">S19 Simulator</b></label>
<label>Automatic Fan Control</label>
<input formControlName="autofanspeed" type="checkbox">
</div>


<div class="form-group">
<label>Fan Speed {{form.controls['fanspeed'].value}}% <span
*ngIf="form.controls['autofanspeed'].value == true">(disabled, automatic) </span> <b
*ngIf="form.controls['fanspeed'].value < 33" style="color:red">Danger: Could Cause
Overheating</b> <b *ngIf="form.controls['fanspeed'].value == 100" style="color: #F2A900">S19
Simulator</b></label>
<input formControlName="fanspeed" type="range" [min]="0" [max]="100">
</div>

Expand Down
18 changes: 16 additions & 2 deletions main/http_server/axe-os/src/app/components/edit/edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpErrorResponse, HttpEventType } from '@angular/common/http';
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ToastrService } from 'ngx-toastr';
import { startWith } from 'rxjs';
import { LoadingService } from 'src/app/services/loading.service';
import { SystemService } from 'src/app/services/system.service';
import { eASICModel } from 'src/models/enum/eASICModel';
Expand Down Expand Up @@ -48,10 +49,22 @@ export class EditComponent {
wifiPass: [info.wifiPass, [Validators.required]],
coreVoltage: [info.coreVoltage, [Validators.required]],
frequency: [info.frequency, [Validators.required]],
invertfanpolarity: [info.invertfanpolarity, [Validators.required]],
autofanspeed: [info.autofanspeed == 1, [Validators.required]],
invertfanpolarity: [info.invertfanpolarity == 1, [Validators.required]],
fanspeed: [info.fanspeed, [Validators.required]],
});

this.form.controls['autofanspeed'].valueChanges.pipe(
startWith(this.form.controls['autofanspeed'].value)
).subscribe(autofanspeed => {
if (autofanspeed) {
this.form.controls['fanspeed'].disable();
} else {
this.form.controls['fanspeed'].enable();
}
});
});

}
private checkDevTools = () => {
if (
Expand All @@ -66,7 +79,7 @@ export class EditComponent {

public updateSystem() {

const form = this.form.value;
const form = this.form.getRawValue();

form.frequency = parseInt(form.frequency);
form.coreVoltage = parseInt(form.coreVoltage);
Expand All @@ -75,6 +88,7 @@ export class EditComponent {
form.flipscreen = form.flipscreen == true ? 1 : 0;
form.invertscreen = form.invertscreen == true ? 1 : 0;
form.invertfanpolarity = form.invertfanpolarity == true ? 1 : 0;
form.autofanspeed = form.autofanspeed == true ? 1 : 0;

this.systemService.updateSystem(form)
.pipe(this.loadingService.lockUIUntilComplete())
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/app/services/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class SystemService {
flipscreen: 1,
invertscreen: 0,
invertfanpolarity: 1,
autofanspeed: 1,
fanspeed: 100
}
).pipe(delay(1000));
Expand Down
1 change: 1 addition & 0 deletions main/http_server/axe-os/src/models/ISystemInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export interface ISystemInfo {
frequency: number,
version: string,
invertfanpolarity: number,
autofanspeed: number,
fanspeed: number,
}
4 changes: 3 additions & 1 deletion main/http_server/http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ static esp_err_t PATCH_update_settings(httpd_req_t * req)
uint16_t invert_screen = cJSON_GetObjectItem(root, "invertscreen")->valueint;

uint16_t invert_fan_polarity = cJSON_GetObjectItem(root, "invertfanpolarity")->valueint;
uint16_t auto_fan_speed = cJSON_GetObjectItem(root, "autofanspeed")->valueint;
uint16_t fan_speed = cJSON_GetObjectItem(root, "fanspeed")->valueint;

nvs_config_set_string(NVS_CONFIG_STRATUM_URL, stratumURL);
Expand All @@ -219,8 +220,8 @@ static esp_err_t PATCH_update_settings(httpd_req_t * req)
nvs_config_set_u16(NVS_CONFIG_ASIC_FREQ, frequency);
nvs_config_set_u16(NVS_CONFIG_FLIP_SCREEN, flip_screen);
nvs_config_set_u16(NVS_CONFIG_INVERT_SCREEN, invert_screen);
nvs_config_set_u16(NVS_CONFIG_INVERT_FAN_POLARITY, invert_screen);
nvs_config_set_u16(NVS_CONFIG_INVERT_FAN_POLARITY, invert_fan_polarity);
nvs_config_set_u16(NVS_CONFIG_AUTO_FAN_SPEED, auto_fan_speed);
nvs_config_set_u16(NVS_CONFIG_FAN_SPEED, fan_speed);

cJSON_Delete(root);
Expand Down Expand Up @@ -281,6 +282,7 @@ static esp_err_t GET_system_info(httpd_req_t * req)
cJSON_AddNumberToObject(root, "invertscreen", nvs_config_get_u16(NVS_CONFIG_INVERT_SCREEN, 0));

cJSON_AddNumberToObject(root, "invertfanpolarity", nvs_config_get_u16(NVS_CONFIG_INVERT_FAN_POLARITY, 1));
cJSON_AddNumberToObject(root, "autofanspeed", nvs_config_get_u16(NVS_CONFIG_AUTO_FAN_SPEED, 1));
cJSON_AddNumberToObject(root, "fanspeed", nvs_config_get_u16(NVS_CONFIG_FAN_SPEED, 100));

free(ssid);
Expand Down
1 change: 1 addition & 0 deletions main/nvs_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define NVS_CONFIG_FLIP_SCREEN "flipscreen"
#define NVS_CONFIG_INVERT_SCREEN "invertscreen"
#define NVS_CONFIG_INVERT_FAN_POLARITY "invertfanpolarity"
#define NVS_CONFIG_AUTO_FAN_SPEED "autofanspeed"
#define NVS_CONFIG_FAN_SPEED "fanspeed"
#define NVS_CONFIG_BEST_DIFF "bestdiff"

Expand Down
6 changes: 2 additions & 4 deletions main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ static void _init_system(GlobalState * global_state, SystemModule * module)
// DS4432U tests
DS4432U_set_vcore(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0);

// Fan Tests
EMC2101_init(nvs_config_get_u16(NVS_CONFIG_INVERT_FAN_POLARITY, 1));

EMC2101_set_fan_speed((float) nvs_config_get_u16(NVS_CONFIG_FAN_SPEED, 100) / 100);
EMC2101_set_fan_speed(1);

vTaskDelay(500 / portTICK_PERIOD_MS);

Expand Down Expand Up @@ -277,7 +275,7 @@ static void _check_for_best_diff(SystemModule * module, double diff, uint32_t nb
uint64_t old = module->best_nonce_diff;
module->best_nonce_diff = diff;
// only write to flash if new > old
if(module->best_nonce_diff > old) {
if (module->best_nonce_diff > old) {
nvs_config_set_u64(NVS_CONFIG_BEST_DIFF, module->best_nonce_diff);
}
// make the best_nonce_diff into a string
Expand Down
30 changes: 29 additions & 1 deletion main/tasks/power_management_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void POWER_MANAGEMENT_task(void * pvParameters)

uint16_t frequency_target = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY);

vTaskDelay(2000);
uint16_t auto_fan_speed = nvs_config_get_u16(NVS_CONFIG_AUTO_FAN_SPEED, 1);

vTaskDelay(3000 / portTICK_PERIOD_MS);

while (1) {

Expand Down Expand Up @@ -124,12 +126,38 @@ void POWER_MANAGEMENT_task(void * pvParameters)
ESP_LOGE(TAG, "OVERHEAT");
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, 990);
nvs_config_set_u16(NVS_CONFIG_ASIC_FREQ, 50);
nvs_config_set_u16(NVS_CONFIG_FAN_SPEED, 100);
nvs_config_set_u16(NVS_CONFIG_AUTO_FAN_SPEED, 0);
exit(EXIT_FAILURE);
}
}

if (auto_fan_speed == 1) {
automatic_fan_speed(power_management->chip_temp);
} else {
EMC2101_set_fan_speed((float) nvs_config_get_u16(NVS_CONFIG_FAN_SPEED, 100) / 100);
}
// ESP_LOGI(TAG, "target %f, Freq %f, Volt %f, Power %f", target_frequency, power_management->frequency_value,
// power_management->voltage, power_management->power);
vTaskDelay(POLL_RATE / portTICK_PERIOD_MS);
}
}

// all values input below 60 result in 38 but increases exponentially such that an input of 70 results in 100
static void automatic_fan_speed(float chip_temp)
{
double result = 0.0;
double min_temp = 50.0;

if (chip_temp < min_temp) {
result = 25;
} else if (chip_temp >= THROTTLE_TEMP) {
result = 100;
} else {
double range = THROTTLE_TEMP - min_temp;
result = ((chip_temp - min_temp) / range) * 100;
}

ESP_LOGE(TAG, "Result %f", result);
EMC2101_set_fan_speed((float) result / 100);
}
17 changes: 9 additions & 8 deletions main/tasks/power_management_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

typedef struct
{
uint16_t fan_speed;
float chip_temp;
float voltage;
float frequency_multiplier;
float frequency_value;
float power;
float current;
uint16_t fan_speed;
float chip_temp;
float voltage;
float frequency_multiplier;
float frequency_value;
float power;
float current;
} PowerManagementModule;

void POWER_MANAGEMENT_task(void *pvParameters);
static void automatic_fan_speed(float chip_temp);
void POWER_MANAGEMENT_task(void * pvParameters);

#endif

0 comments on commit fc0e49e

Please sign in to comment.