diff --git a/main/TPS546.c b/main/TPS546.c index 7fbb6b236..9d4839aeb 100644 --- a/main/TPS546.c +++ b/main/TPS546.c @@ -317,20 +317,20 @@ static uint16_t float_2_slinear11(float value) * stored in twos-complement * The mantissa occupies the full 16-bits of the value */ -static int ulinear16_2_float(uint16_t value) +static float ulinear16_2_float(uint16_t value) { uint8_t voutmode; int exponent; float result; smb_read_byte(PMBUS_VOUT_MODE, &voutmode); + if (voutmode & 0x10) { // exponent is negative exponent = -1 * ((~voutmode & 0x1F) + 1); } else { exponent = (voutmode & 0x1F); } - result = (value * powf(2.0, exponent)); return result; } @@ -389,9 +389,9 @@ int TPS546_init(void) } /* Make sure power is turned off until commanded */ - ESP_LOGI(TAG, "Verifying power config"); u8_value = ON_OFF_CONFIG_CMD | ON_OFF_CONFIG_PU | ON_OFF_CONFIG_CP | ON_OFF_CONFIG_POLARITY | ON_OFF_CONFIG_DELAY; + ESP_LOGI(TAG, "Power config-ON_OFF_CONFIG: %02x", u8_value); smb_write_byte(PMBUS_ON_OFF_CONFIG, u8_value); /* Read version number and see if it matches */ @@ -419,21 +419,10 @@ int TPS546_init(void) ESP_LOGI(TAG, "-----------VOLTAGE/CURRENT---------------------"); /* Get voltage input (SLINEAR11) */ - //smb_read_word(PMBUS_READ_VIN, &u16_value); - //vin = slinear11_2_float(u16_value); - //ESP_LOGI(TAG, "Vin measured: %2.3f V", vin); TPS546_get_vin(); - /* Get output current (SLINEAR11) */ - //smb_read_word(PMBUS_READ_IOUT, &u16_value); - //iout = slinear11_2_float(u16_value); - //ESP_LOGI(TAG, "Iout measured: %2.3f A", iout); TPS546_get_iout(); - /* Get voltage output (ULINEAR16) */ - //smb_read_word(PMBUS_READ_VOUT, &u16_value); - //vout = ulinear16_2_float(u16_value); - //ESP_LOGI(TAG, "Vout measured: %2.3f V", vout); TPS546_get_vout(); ESP_LOGI(TAG, "-----------TIMING---------------------"); @@ -590,10 +579,8 @@ int TPS546_get_frequency(void) int freq; smb_read_word(PMBUS_FREQUENCY_SWITCH, &value); - ESP_LOGI(TAG, "Read Freq: %04x", value); freq = slinear11_2_int(value); - ESP_LOGI(TAG, "Frequency: %d", freq); return (int)freq; } @@ -604,16 +591,12 @@ void TPS546_set_frequency(int newfreq) ESP_LOGI(TAG, "Writing new frequency: %d", newfreq); value = int_2_slinear11(newfreq); - //value = 0xC999; - ESP_LOGI(TAG, "New value: 0x%04x", value); - //smb_write_word(PMBUS_FREQUENCY_SWITCH, value); - - ESP_LOGI(TAG, "Checking conversion..."); - freq = slinear11_2_int(value); - ESP_LOGI(TAG, "Converted value: %d", freq); + //ESP_LOGI(TAG, "New value: 0x%04x", value); + smb_write_word(PMBUS_FREQUENCY_SWITCH, value); - //ESP_LOGI(TAG, "Frequency: %d", (int)freq); - //return (int)freq; + //ESP_LOGI(TAG, "Checking conversion..."); + //freq = slinear11_2_int(value); + //ESP_LOGI(TAG, "Converted value: %d", freq); } int TPS546_get_temperature(void) @@ -634,7 +617,7 @@ float TPS546_get_vin(void) /* Get voltage input (ULINEAR16) */ smb_read_word(PMBUS_READ_VIN, &u16_value); vin = slinear11_2_float(u16_value); - ESP_LOGI(TAG, "Got Vin: %2.3f V", vin); + //ESP_LOGI(TAG, "Got Vin: %2.3f V", vin); return vin; } @@ -646,7 +629,7 @@ float TPS546_get_iout(void) /* Get current output (SLINEAR11) */ smb_read_word(PMBUS_READ_IOUT, &u16_value); iout = slinear11_2_float(u16_value); - ESP_LOGI(TAG, "Got Iout: %2.3f V", iout); + //ESP_LOGI(TAG, "Got Iout: %2.3f V", iout); return iout; } @@ -658,7 +641,7 @@ float TPS546_get_vout(void) /* Get voltage output (ULINEAR16) */ smb_read_word(PMBUS_READ_VOUT, &u16_value); vout = ulinear16_2_float(u16_value); - ESP_LOGI(TAG, "Got Vout: %2.3f V", vout); + //ESP_LOGI(TAG, "Got Vout: %2.3f V", vout); return vout; } @@ -672,19 +655,20 @@ float TPS546_get_vout(void) void TPS546_set_vout(int millivolts) { uint16_t value; + float volts = millivolts / 1000; - if (millivolts == 0) { + if (volts == 0) { /* turn off output */ smb_write_byte(PMBUS_OPERATION, OPERATION_OFF); } else { /* make sure we're in range */ - if ((millivolts < TPS546_INIT_VOUT_MIN) || (millivolts > TPS546_INIT_VOUT_MAX)) { - ESP_LOGI(TAG, "ERR- Voltage requested is out of range"); + if ((volts < TPS546_INIT_VOUT_MIN) || (volts > TPS546_INIT_VOUT_MAX)) { + ESP_LOGI(TAG, "ERR- Voltage requested (%f) is out of range", volts); } else { /* set the output voltage */ - value = float_2_ulinear16((float)(millivolts / 1000)); + value = float_2_ulinear16(volts); smb_write_word(PMBUS_VOUT_COMMAND, value); - ESP_LOGI(TAG, "Vout changed to %d mV", millivolts); + ESP_LOGI(TAG, "Vout changed to %f mV", volts); /* turn on output */ smb_write_byte(PMBUS_OPERATION, OPERATION_ON); diff --git a/main/main.c b/main/main.c index c7ce4314f..06a270d31 100644 --- a/main/main.c +++ b/main/main.c @@ -114,9 +114,10 @@ void app_main(void) xTaskCreate(USER_INPUT_task, "user input", 8192, (void *) &GLOBAL_STATE, 5, NULL); - if (strcmp(GLOBAL_STATE.board_version, "302") == 0) { + if (GLOBAL_STATE.board_version == 302) { // this is a HEX board ESP_LOGI(TAG, "Starting HEX power management"); + vTaskDelay(2000 / portTICK_PERIOD_MS); xTaskCreate(POWER_MANAGEMENT_HEX_task, "power mangement", 8192, (void *) &GLOBAL_STATE, 10, NULL); } else { // this is NOT a HEX board diff --git a/main/system.c b/main/system.c index c5b1559eb..9f8675844 100644 --- a/main/system.c +++ b/main/system.c @@ -393,6 +393,7 @@ void SYSTEM_task(void * pvParameters) vTaskDelay(5000 / portTICK_PERIOD_MS); } + ESP_LOGI(TAG, "Show the connection screen..."); // show the connection screen while (!module->startup_done) { result = esp_wifi_get_mode(&wifi_mode); @@ -406,6 +407,7 @@ void SYSTEM_task(void * pvParameters) vTaskDelay(100 / portTICK_PERIOD_MS); } + ESP_LOGI(TAG, "Entering System Loop..."); while (1) { _clear_display(); module->screen_page = 0; diff --git a/main/tasks/power_management_task.c b/main/tasks/power_management_task.c index 6f36e7739..089dbe4fd 100644 --- a/main/tasks/power_management_task.c +++ b/main/tasks/power_management_task.c @@ -216,12 +216,6 @@ void POWER_MANAGEMENT_HEX_task(void * pvParameters) power_management->frequency_multiplier = 1; - char * board_version = nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, "unknown"); - power_management->HAS_POWER_EN = - (strcmp(board_version, "202") == 1 || strcmp(board_version, "203") == 1 || strcmp(board_version, "204") == 1); - power_management->HAS_PLUG_SENSE = strcmp(board_version, "204") == 1; - free(board_version); - int last_frequency_increase = 0; uint16_t frequency_target = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY); @@ -229,6 +223,7 @@ 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) + ESP_LOGI(TAG, "---TURNING ON VCORE---"); TPS546_set_vout(3600); vTaskDelay(3000 / portTICK_PERIOD_MS); @@ -250,7 +245,7 @@ void POWER_MANAGEMENT_HEX_task(void * pvParameters) // get regulator internal temperature power_management->chip_temp = (float)TPS546_get_temperature(); - ESP_LOGI(TAG, "TPS546 Temp: %f", power_management->chip_temp); + ESP_LOGI(TAG, "TPS546 Temp: %2f", power_management->chip_temp); // TODO figure out best way to detect overheating on the Hex if (power_management->chip_temp > TPS546_THROTTLE_TEMP && @@ -274,11 +269,9 @@ void POWER_MANAGEMENT_HEX_task(void * pvParameters) // EMC2101_set_fan_speed((float) nvs_config_get_u16(NVS_CONFIG_FAN_SPEED, 100) / 100); //} - ESP_LOGI(TAG, "TPS546 VIN: %f, VOUT: %f, IOUT: %f", TPS546_get_vin(), TPS546_get_vout(), TPS546_get_iout()); + ESP_LOGI(TAG, "VIN: %f, VOUT: %f, IOUT: %f", TPS546_get_vin(), TPS546_get_vout(), TPS546_get_iout()); ESP_LOGI(TAG, "Regulator power: %f mW", power_management->power); - - //ESP_LOGI(TAG, "Frequency target %f, Freq %f", target_frequency, power_management->frequency_value); - ESP_LOGI(TAG, "Frequency %d", TPS546_get_frequency()); + ESP_LOGI(TAG, "TPS546 Frequency %d", TPS546_get_frequency()); vTaskDelay(POLL_RATE / portTICK_PERIOD_MS); }