Skip to content

Commit

Permalink
added TPS546 static power offset. Increased delay for power_managemen…
Browse files Browse the repository at this point in the history
…t_task.c to start
  • Loading branch information
skot committed Aug 17, 2024
1 parent 7a07460 commit be1242e
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 85 deletions.
4 changes: 2 additions & 2 deletions components/asic/include/bm1370.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#define BM1370_INITIAL_DIFFICULTY 256

#define BM1370_SERIALTX_DEBUG true
#define BM1370_SERIALRX_DEBUG true
#define BM1370_SERIALTX_DEBUG false
#define BM1370_SERIALRX_DEBUG false
#define BM1370_DEBUG_WORK false //causes insane amount of debug output

static const uint64_t BM1370_CORE_COUNT = 128;
Expand Down
4 changes: 2 additions & 2 deletions main/EMC2101.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ float EMC2101_get_external_temp(void)
reading >>= 5;

if (reading == EMC2101_TEMP_FAULT_OPEN_CIRCUIT) {
ESP_LOGE(TAG, "EMC2101 TEMP_FAULT_OPEN_CIRCUIT");
ESP_LOGE(TAG, "EMC2101 TEMP_FAULT_OPEN_CIRCUIT: %04X", reading);
}
if (reading == EMC2101_TEMP_FAULT_SHORT) {
ESP_LOGE(TAG, "EMC2101 TEMP_FAULT_SHORT");
ESP_LOGE(TAG, "EMC2101 TEMP_FAULT_SHORT: %04X", reading);
}

float result = (float) reading / 8.0;
Expand Down
1 change: 0 additions & 1 deletion main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ void app_main(void)

xTaskCreate(USER_INPUT_task, "user input", 8192, (void *) &GLOBAL_STATE, 5, NULL);


if (GLOBAL_STATE.ASIC_functions.init_fn != NULL) {
wifi_softap_off();

Expand Down
160 changes: 80 additions & 80 deletions main/tasks/power_management_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
#define TPS546_THROTTLE_TEMP 105.0
#define TPS546_MAX_TEMP 145.0

#define SUPRA_POWER_OFFSET 5
#define GAMMA_POWER_OFFSET 5

static const char * TAG = "power_management";

static float _fbound(float value, float lower_bound, float upper_bound)
Expand Down Expand Up @@ -115,7 +118,7 @@ void POWER_MANAGEMENT_task(void * pvParameters)
default:
}

vTaskDelay(3000 / portTICK_PERIOD_MS);
vTaskDelay(4000 / portTICK_PERIOD_MS);

while (1) {

Expand All @@ -128,6 +131,8 @@ void POWER_MANAGEMENT_task(void * pvParameters)
power_management->current = TPS546_get_iout() * 1000;
// calculate regulator power (in milliwatts)
power_management->power = (TPS546_get_vout() * power_management->current) / 1000;
// The power reading from the TPS546 is only it's output power. So the rest of the Bitaxe power is not accounted for.
power_management->power += SUPRA_POWER_OFFSET; // Add offset for the rest of the Bitaxe power. TODO: this better.
} else if (INA260_installed() == true) {
power_management->voltage = INA260_read_voltage();
power_management->current = INA260_read_current();
Expand All @@ -140,106 +145,101 @@ void POWER_MANAGEMENT_task(void * pvParameters)
power_management->current = TPS546_get_iout() * 1000;
// calculate regulator power (in milliwatts)
power_management->power = (TPS546_get_vout() * power_management->current) / 1000;
// The power reading from the TPS546 is only it's output power. So the rest of the Bitaxe power is not accounted for.
power_management->power += GAMMA_POWER_OFFSET; // Add offset for the rest of the Bitaxe power. TODO: this better.
break;
default:
}

power_management->fan_rpm = EMC2101_get_fan_speed();

if (GLOBAL_STATE->asic_model == ASIC_BM1397) {
switch (GLOBAL_STATE->device_model) {
case DEVICE_MAX:
power_management->chip_temp_avg = EMC2101_get_external_temp();

switch (GLOBAL_STATE->device_model) {
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:
case DEVICE_GAMMA:
if ((power_management->chip_temp_avg > THROTTLE_TEMP) &&
(power_management->frequency_value > 50 || power_management->voltage > 1000)) {
ESP_LOGE(TAG, "OVERHEAT ASIC %fC", power_management->chip_temp_avg );

EMC2101_set_fan_speed(1);
if (power_management->HAS_POWER_EN) {
gpio_set_level(GPIO_NUM_10, 1);
}
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, 1000);
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);
}
break;
case DEVICE_ULTRA:
case DEVICE_SUPRA:

if (GLOBAL_STATE->board_version == 402) {
power_management->chip_temp_avg = EMC2101_get_external_temp();
power_management->vr_temp = (float)TPS546_get_temperature();
} else {
power_management->chip_temp_avg = EMC2101_get_internal_temp() + 5;
power_management->vr_temp = 0.0;
}

if ((power_management->chip_temp_avg > THROTTLE_TEMP) &&
(power_management->frequency_value > 50 || power_management->voltage > 1000)) {
ESP_LOGE(TAG, "OVERHEAT ASIC %fC", power_management->chip_temp_avg );

EMC2101_set_fan_speed(1);
if (power_management->HAS_POWER_EN) {
gpio_set_level(GPIO_NUM_10, 1);
}
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, 1000);
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);
}
// EMC2101 will give bad readings if the ASIC is turned off
if(power_management->voltage < TPS546_INIT_VOUT_MIN){
break;
}

default:
}
} else if (GLOBAL_STATE->asic_model == ASIC_BM1366 || GLOBAL_STATE->asic_model == ASIC_BM1368 || GLOBAL_STATE->asic_model == ASIC_BM1370) {
switch (GLOBAL_STATE->device_model) {
case DEVICE_MAX:
case DEVICE_ULTRA:
case DEVICE_SUPRA:

if (GLOBAL_STATE->board_version == 402) {
power_management->chip_temp_avg = EMC2101_get_external_temp();
power_management->vr_temp = (float)TPS546_get_temperature();
} else {
power_management->chip_temp_avg = EMC2101_get_internal_temp() + 5;
power_management->vr_temp = 0.0;
}

// EMC2101 will give bad readings if the ASIC is turned off
if(power_management->voltage < TPS546_INIT_VOUT_MIN){
break;
//overheat mode if the voltage regulator or ASIC is too hot
if ((power_management->vr_temp > TPS546_THROTTLE_TEMP || power_management->chip_temp_avg > THROTTLE_TEMP) &&
(power_management->frequency_value > 50 || power_management->voltage > 1000)) {
ESP_LOGE(TAG, "OVERHEAT! VR: %fC ASIC %fC", power_management->vr_temp, power_management->chip_temp_avg );

EMC2101_set_fan_speed(1);
if (GLOBAL_STATE->board_version == 402) {
// Turn off core voltage
VCORE_set_voltage(0.0, GLOBAL_STATE);
} else if (power_management->HAS_POWER_EN) {
gpio_set_level(GPIO_NUM_10, 1);
}
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, 1000);
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);
nvs_config_set_u16(NVS_CONFIG_OVERHEAT_MODE, 1);
exit(EXIT_FAILURE);
}

if ((power_management->vr_temp > TPS546_THROTTLE_TEMP || power_management->chip_temp_avg > THROTTLE_TEMP) &&
(power_management->frequency_value > 50 || power_management->voltage > 1000)) {
ESP_LOGE(TAG, "OVERHEAT VR: %fC ASIC %fC", power_management->vr_temp, power_management->chip_temp_avg );

EMC2101_set_fan_speed(1);
if (GLOBAL_STATE->board_version == 402) {
// Turn off core voltage
VCORE_set_voltage(0.0, GLOBAL_STATE);
} else if (power_management->HAS_POWER_EN) {
gpio_set_level(GPIO_NUM_10, 1);
}
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, 1000);
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);
}
break;
case DEVICE_GAMMA:
power_management->chip_temp_avg = EMC2101_get_external_temp();
power_management->vr_temp = (float)TPS546_get_temperature();

// EMC2101 will give bad readings if the ASIC is turned off
if(power_management->voltage < TPS546_INIT_VOUT_MIN){
break;
case DEVICE_GAMMA:
power_management->chip_temp_avg = EMC2101_get_external_temp();
power_management->vr_temp = (float)TPS546_get_temperature();

// EMC2101 will give bad readings if the ASIC is turned off
if(power_management->voltage < TPS546_INIT_VOUT_MIN){
break;
}
}

if ((power_management->vr_temp > TPS546_THROTTLE_TEMP || power_management->chip_temp_avg > THROTTLE_TEMP) &&
(power_management->frequency_value > 50 || power_management->voltage > 1000)) {
ESP_LOGE(TAG, "OVERHEAT VR: %fC ASIC %fC", power_management->vr_temp, power_management->chip_temp_avg );
//overheat mode if the voltage regulator or ASIC is too hot
if ((power_management->vr_temp > TPS546_THROTTLE_TEMP || power_management->chip_temp_avg > THROTTLE_TEMP) &&
(power_management->frequency_value > 50 || power_management->voltage > 1000)) {
ESP_LOGE(TAG, "OVERHEAT! VR: %fC ASIC %fC", power_management->vr_temp, power_management->chip_temp_avg );

EMC2101_set_fan_speed(1);
EMC2101_set_fan_speed(1);

// Turn off core voltage
VCORE_set_voltage(0.0, GLOBAL_STATE);
// Turn off core voltage
VCORE_set_voltage(0.0, GLOBAL_STATE);

nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, 1000);
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);
}
break;
default:
}
nvs_config_set_u16(NVS_CONFIG_ASIC_VOLTAGE, 1000);
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);
nvs_config_set_u16(NVS_CONFIG_OVERHEAT_MODE, 1);
exit(EXIT_FAILURE);
}
break;
default:
}


if (auto_fan_speed == 1) {

power_management->fan_perc = (float)automatic_fan_speed(power_management->chip_temp_avg, GLOBAL_STATE);
Expand Down

0 comments on commit be1242e

Please sign in to comment.