Skip to content

Commit

Permalink
added several configs to EMC2101 init
Browse files Browse the repository at this point in the history
  • Loading branch information
skot committed Nov 14, 2024
1 parent da93d79 commit 84ecc16
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
5 changes: 5 additions & 0 deletions components/asic/bm1370.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 15 additions & 1 deletion main/EMC2101.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 5 additions & 0 deletions main/EMC2101.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
27 changes: 25 additions & 2 deletions main/self_test/self_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

}

0 comments on commit 84ecc16

Please sign in to comment.