From 33126ca3e5819357f930ac95c3cf9c374290b9c0 Mon Sep 17 00:00:00 2001 From: macphyter Date: Sun, 11 Feb 2024 21:31:29 -0700 Subject: [PATCH] Read vcore properly in GUI --- main/http_server/http_server.c | 2 +- main/system.c | 5 ++++- main/tasks/power_management_task.c | 18 ++++++++++++++++-- main/tasks/power_management_task.h | 2 ++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/main/http_server/http_server.c b/main/http_server/http_server.c index c01e1d85..9d36c63d 100644 --- a/main/http_server/http_server.c +++ b/main/http_server/http_server.c @@ -351,7 +351,7 @@ static esp_err_t GET_system_info(httpd_req_t * req) cJSON_AddNumberToObject(root, "freeHeap", esp_get_free_heap_size()); cJSON_AddNumberToObject(root, "coreVoltage", nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE)); - cJSON_AddNumberToObject(root, "coreVoltageActual", ADC_get_vcore()); + cJSON_AddNumberToObject(root, "coreVoltageActual", Get_vcore()); cJSON_AddNumberToObject(root, "frequency", nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY)); cJSON_AddStringToObject(root, "ssid", ssid); cJSON_AddStringToObject(root, "wifiStatus", GLOBAL_STATE->SYSTEM_MODULE.wifi_status); diff --git a/main/system.c b/main/system.c index 9f867584..f14537b1 100644 --- a/main/system.c +++ b/main/system.c @@ -199,7 +199,10 @@ static void _update_esp32_info(SystemModule * module) { uint32_t free_heap_size = esp_get_free_heap_size(); - uint16_t vcore = ADC_get_vcore(); + //uint16_t vcore = ADC_get_vcore(); + + // Hex board has vcore across three domains + uint16_t vcore = (TPS546_get_vout() * 1000) / 3; if (OLED_status()) { diff --git a/main/tasks/power_management_task.c b/main/tasks/power_management_task.c index 98c77632..be823c63 100644 --- a/main/tasks/power_management_task.c +++ b/main/tasks/power_management_task.c @@ -58,6 +58,18 @@ static void automatic_fan_speed(float chip_temp) EMC2101_set_fan_speed((float) result / 100); } +// Returns the vcore voltage using the appropriate source +uint16_t Get_vcore(void) +{ + // TODO determine which plaform we are on for vcore retrieval + + // Regular bitaxe uses ADC for vcore + //return ADC_get_vcore(); + + // Hex regulator reports measured vcore across all 3 domains + return (TPS546_get_vout() * 1000) / 3; +} + void POWER_MANAGEMENT_task(void * pvParameters) { GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters; @@ -223,8 +235,10 @@ void POWER_MANAGEMENT_HEX_task(void * pvParameters) uint16_t auto_fan_speed = nvs_config_get_u16(NVS_CONFIG_AUTO_FAN_SPEED, 1); // turn on ASIC core voltage (three domains in series) + int want_vcore = nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE); + want_vcore *= 3; // across 3 domains ESP_LOGI(TAG, "---TURNING ON VCORE---"); - TPS546_set_vout(3600); + TPS546_set_vout(want_vcore); vTaskDelay(3000 / portTICK_PERIOD_MS); @@ -242,7 +256,7 @@ void POWER_MANAGEMENT_HEX_task(void * pvParameters) // For reference: // TPS546_get_vin()- board input voltage // we don't have a way to measure board input current - // TPS546_get_out()- core voltage *3 (across all domains) + // TPS546_get_vout()- core voltage *3 (across all domains) // TPS546_get_iout()- Current output of regulator // we don't have a way to measure power, we have to calculate it // but we don't have total board current, so calculate regulator power diff --git a/main/tasks/power_management_task.h b/main/tasks/power_management_task.h index 23a7a83c..32d29808 100644 --- a/main/tasks/power_management_task.h +++ b/main/tasks/power_management_task.h @@ -15,6 +15,8 @@ typedef struct } PowerManagementModule; static void automatic_fan_speed(float chip_temp); + +uint16_t Get_vcore(void); void POWER_MANAGEMENT_task(void * pvParameters); void POWER_MANAGEMENT_HEX_task(void * pvParameters); #endif