From 84ecc16632cf3f4ce2655e684636d2033f05d970 Mon Sep 17 00:00:00 2001 From: Skot Date: Thu, 14 Nov 2024 18:02:49 -0500 Subject: [PATCH] added several configs to EMC2101 init --- components/asic/bm1370.c | 5 +++++ main/EMC2101.c | 16 +++++++++++++++- main/EMC2101.h | 5 +++++ main/self_test/self_test.c | 27 +++++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/components/asic/bm1370.c b/components/asic/bm1370.c index 7ab12d506..2e61383f8 100644 --- a/components/asic/bm1370.c +++ b/components/asic/bm1370.c @@ -196,6 +196,11 @@ static void do_frequency_ramp_up(float target_frequency) { float current = 56.25; float step = 6.25; + if (target_frequency == 0) { + ESP_LOGI(TAG, "Skipping frequency ramp"); + return; + } + ESP_LOGI(TAG, "Ramping up frequency from %.2f MHz to %.2f MHz with step %.2f MHz", current, target_frequency, step); BM1370_send_hash_frequency(-1, current, 0.001); diff --git a/main/EMC2101.c b/main/EMC2101.c index daf1237ee..992e8c0c6 100644 --- a/main/EMC2101.c +++ b/main/EMC2101.c @@ -29,6 +29,18 @@ esp_err_t EMC2101_init(bool invertPolarity) { ESP_ERROR_CHECK(i2c_bitaxe_register_write_byte(emc2101_dev_handle, EMC2101_FAN_CONFIG, 0b00100011)); } + //set Ideality Factor + ESP_ERROR_CHECK(i2c_bitaxe_register_write_byte(emc2101_dev_handle, EMC2101_IDEALITY_FACTOR, EMC2101_DEFAULT_IDEALITY)); + + //set Beta Compensation + ESP_ERROR_CHECK(i2c_bitaxe_register_write_byte(emc2101_dev_handle, EMC2101_BETA_COMPENSATION, EMC2101_DEFAULT_BETA)); + + //set filtering + ESP_ERROR_CHECK(i2c_bitaxe_register_write_byte(emc2101_dev_handle, EMC2101_TEMP_FILTER, 0x06)); + + //set conversion rate + ESP_ERROR_CHECK(i2c_bitaxe_register_write_byte(emc2101_dev_handle, EMC2101_REG_DATA_RATE, 0x09)); + return ESP_OK; } @@ -86,8 +98,10 @@ float EMC2101_get_external_temp(void) // Greater than 200C is probably an erroneous reading... if (result > 200){ - return EMC2101_get_internal_temp(); + ESP_LOGE(TAG, "EMC2101 Invalid result: %04X", reading); + result = 0; } + return result; } diff --git a/main/EMC2101.h b/main/EMC2101.h index 00c82a471..fbdbcdfba 100644 --- a/main/EMC2101.h +++ b/main/EMC2101.h @@ -3,6 +3,9 @@ #include "i2c_bitaxe.h" +#define EMC2101_DEFAULT_IDEALITY 0x12 ///< Default ideality factor +#define EMC2101_DEFAULT_BETA 0x00 ///< Default beta compensation + #define EMC2101_I2CADDR_DEFAULT 0x4C ///< EMC2101 default i2c address #define EMC2101_CHIP_ID 0x16 ///< EMC2101 default device id from part id #define EMC2101_ALT_CHIP_ID 0x28 ///< EMC2101 alternate device id from part id @@ -18,6 +21,8 @@ #define EMC2101_REG_CONFIG 0x03 ///< configuration register #define EMC2101_REG_DATA_RATE 0x04 ///< Data rate config #define EMC2101_TEMP_FORCE 0x0C ///< Temp force setting for LUT testing +#define EMC2101_IDEALITY_FACTOR 0x17 ///< Beta Compensation Register +#define EMC2101_BETA_COMPENSATION 0x18 ///< Beta Compensation Register #define EMC2101_TACH_LSB 0x46 ///< Tach RPM data low byte #define EMC2101_TACH_MSB 0x47 ///< Tach RPM data high byte #define EMC2101_TACH_LIMIT_LSB 0x48 ///< Tach low-speed setting low byte. INVERSE OF THE SPEED diff --git a/main/self_test/self_test.c b/main/self_test/self_test.c index 89fcc9d5e..59f6659d8 100644 --- a/main/self_test/self_test.c +++ b/main/self_test/self_test.c @@ -18,8 +18,12 @@ #define POWER_CONSUMPTION_TARGET_GAMMA 11 //watts #define POWER_CONSUMPTION_MARGIN 3 //+/- watts +#define TEMP_CAL_LIMIT 1200 + static const char * TAG = "self_test"; +static void run_temp_cal(void); + bool should_test(GlobalState * GLOBAL_STATE) { bool is_max = GLOBAL_STATE->asic_model == ASIC_BM1397; uint64_t best_diff = nvs_config_get_u64(NVS_CONFIG_BEST_DIFF, 0); @@ -175,7 +179,7 @@ void self_test(void * pvParameters) } uint8_t result = VCORE_init(GLOBAL_STATE); - VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, GLOBAL_STATE); + VCORE_set_voltage(1150 / 1000.0, GLOBAL_STATE); // VCore regulator testing switch (GLOBAL_STATE->device_model) { @@ -222,9 +226,16 @@ void self_test(void * pvParameters) SERIAL_init(); - uint8_t chips_detected = (GLOBAL_STATE->ASIC_functions.init_fn)(GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value, GLOBAL_STATE->asic_count); + uint8_t chips_detected = (GLOBAL_STATE->ASIC_functions.init_fn)(0, GLOBAL_STATE->asic_count); ESP_LOGI(TAG, "%u chips detected, %u expected", chips_detected, GLOBAL_STATE->asic_count); + //turn off vcore + VCORE_set_voltage(0, GLOBAL_STATE); + //delay 1 second to stabilize + vTaskDelay(1000 / portTICK_PERIOD_MS); + run_temp_cal(); + + int baud = (*GLOBAL_STATE->ASIC_functions.set_max_baud_fn)(); vTaskDelay(10 / portTICK_PERIOD_MS); SERIAL_set_baud(baud); @@ -372,3 +383,15 @@ void self_test(void * pvParameters) vTaskDelay(500 / portTICK_PERIOD_MS); } } + +static void run_temp_cal(void) { + float external = 0, internal = 0; + + while (1) { + external = EMC2101_get_external_temp(); + internal = EMC2101_get_internal_temp(); + ESP_LOGI(TAG, "ASIC: %.3f, AIR: %.3f [%.3f]", external, internal, external - internal); + vTaskDelay(500 / portTICK_PERIOD_MS); + } + +}