power soft start

This commit is contained in:
Ben 2023-06-14 13:31:25 -04:00 committed by johnny9
parent e8f36e89fa
commit 914b926758
4 changed files with 29 additions and 16 deletions

View File

@ -178,7 +178,7 @@ void BM1397_send_hash_frequency(float frequency) {
}
static void _send_init(void) {
static void _send_init(u_int64_t frequency) {
//send serial data
vTaskDelay(SLEEP_TIME / portTICK_RATE_MS);
@ -208,7 +208,7 @@ static void _send_init(void) {
BM1397_set_default_baud();
BM1397_send_hash_frequency(BM1397_FREQUENCY);
BM1397_send_hash_frequency(frequency);
}
@ -236,7 +236,7 @@ static void _send_read_address(void) {
}
void BM1397_init(void) {
void BM1397_init(u_int64_t frequency) {
ESP_LOGI(TAG, "Initializing BM1397");
gpio_pad_select_gpio(BM1397_RST_PIN);
@ -248,7 +248,7 @@ void BM1397_init(void) {
//send the init command
_send_read_address();
_send_init();
_send_init(frequency);
}

View File

@ -65,7 +65,7 @@ struct __attribute__((__packed__)) nonce_response {
uint8_t crc;
};
void BM1397_init(void);
void BM1397_init(u_int64_t frequency);
void BM1397_send_init(void);
void BM1397_send_work(struct job_packet *job);

View File

@ -19,7 +19,11 @@ static GlobalState GLOBAL_STATE = {
.extranonce_str = NULL,
.extranonce_2_len = 0,
.abandon_work = 0,
.version_mask = 0
.version_mask = 0,
.POWER_MANAGEMENT_MODULE = {
.frequency_multiplier = 1,
.frequency_value = BM1397_FREQUENCY/3
}
};
@ -28,6 +32,8 @@ static const char *TAG = "miner";
void app_main(void)
{
ESP_LOGI(TAG, "Welcome to the bitaxe!");
//wait between 0 and 5 seconds for multiple units
vTaskDelay(rand() % 5001 / portTICK_RATE_MS);
ESP_ERROR_CHECK(nvs_flash_init());
//ESP_ERROR_CHECK(esp_netif_init());
//ESP_ERROR_CHECK(esp_event_loop_create_default());
@ -47,7 +53,7 @@ void app_main(void)
SERIAL_init();
BM1397_init();
BM1397_init(GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value);
xTaskCreate(stratum_task, "stratum admin", 8192, (void*)&GLOBAL_STATE, 5, NULL);
xTaskCreate(create_jobs_task, "stratum miner", 8192, (void*)&GLOBAL_STATE, 10, NULL);

View File

@ -30,18 +30,18 @@ static float _fbound(float value, float lower_bound, float upper_bound)
return value;
}
void _power_init(PowerManagementModule * power_management){
power_management->frequency_multiplier = 1;
power_management->frequency_value = BM1397_FREQUENCY;
// void _power_init(PowerManagementModule * power_management){
// power_management->frequency_multiplier = 1;
// power_management->frequency_value = BM1397_FREQUENCY;
}
// }
void POWER_MANAGEMENT_task(void * pvParameters){
GlobalState *GLOBAL_STATE = (GlobalState*)pvParameters;
//bm1397Module * bm1397 = &GLOBAL_STATE->BM1397_MODULE;
PowerManagementModule * power_management = &GLOBAL_STATE->POWER_MANAGEMENT_MODULE;
_power_init(power_management);
// _power_init(power_management);
int last_frequency_increase = 0;
while(1){
@ -73,6 +73,8 @@ void POWER_MANAGEMENT_task(void * pvParameters){
}
}
power_management->frequency_multiplier = lowest_multiplier;
@ -82,6 +84,12 @@ void POWER_MANAGEMENT_task(void * pvParameters){
// TODO: Turn the chip off
}
// reinitialize after coming off some low voltage
if(power_management->frequency_value <= 50 && target_frequency > 50){
power_management->frequency_value = target_frequency;
BM1397_init(target_frequency);
}
if(power_management->frequency_value > target_frequency){
power_management->frequency_value = target_frequency;
@ -90,14 +98,13 @@ void POWER_MANAGEMENT_task(void * pvParameters){
ESP_LOGI(TAG, "target %f, Freq %f, Temp %f, Power %f", target_frequency, power_management->frequency_value, power_management->chip_temp, power_management->power);
}else{
if(
last_frequency_increase > 250 &&
last_frequency_increase > 120 &&
power_management->frequency_value != BM1397_FREQUENCY
){
float add = power_management->frequency_value - (((power_management->frequency_value * 9.0) + target_frequency)/10.0);
power_management->frequency_value += _fbound(add, 2 , 10);
power_management->frequency_value += _fbound(target_frequency, 2 , 15);
BM1397_send_hash_frequency(power_management->frequency_value);
ESP_LOGI(TAG, "target %f, Freq %f, Temp %f, Power %f", target_frequency, power_management->frequency_value, power_management->chip_temp, power_management->power);
last_frequency_increase = 125;
last_frequency_increase = 60;
}else{
last_frequency_increase++;
}