even softer start & smarter low voltage recovery

This commit is contained in:
Ben 2023-06-14 15:10:37 -04:00 committed by johnny9
parent 914b926758
commit 700db06f5a
4 changed files with 21 additions and 8 deletions

View File

@ -206,7 +206,7 @@ static void _send_init(u_int64_t frequency) {
unsigned char init6[9] = {0x00, FAST_UART_CONFIGURATION, 0x06, 0x00, 0x00, 0x0F}; //init6 - fast_uart_configuration
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init6, 6, false);
BM1397_set_default_baud();
//BM1397_set_default_baud();
BM1397_send_hash_frequency(frequency);
}
@ -259,10 +259,11 @@ void BM1397_init(u_int64_t frequency) {
// Baud formula = 25M/((denominator+1)*8)
// The denominator is 5 bits found in the misc_control (bits 9-13)
void BM1397_set_default_baud(void){
int BM1397_set_default_baud(void){
//default divider of 26 (11010) for 115,749
unsigned char baudrate[9] = {0x00, MISC_CONTROL, 0x00, 0x00, 0b01111010, 0b00110001}; //baudrate - misc_control
_send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), baudrate, 6, false);
return 115749;
}
int BM1397_set_max_baud(void){

View File

@ -71,7 +71,7 @@ void BM1397_send_init(void);
void BM1397_send_work(struct job_packet *job);
void BM1397_set_job_difficulty_mask(int);
int BM1397_set_max_baud(void);
void BM1397_set_default_baud(void);
int BM1397_set_default_baud(void);
void BM1397_send_hash_frequency(float frequency);
#endif /* BM1397_H_ */

View File

@ -22,7 +22,7 @@ static GlobalState GLOBAL_STATE = {
.version_mask = 0,
.POWER_MANAGEMENT_MODULE = {
.frequency_multiplier = 1,
.frequency_value = BM1397_FREQUENCY/3
.frequency_value = 50
}
};

View File

@ -8,6 +8,7 @@
#include "EMC2101.h"
#include "INA260.h"
#include "math.h"
#include "serial.h"
#define POLL_RATE 1000/60
#define MAX_TEMP 90.0
@ -84,10 +85,20 @@ 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;
// chip is coming back from a low/no voltage event
if(power_management->frequency_value < 50 && target_frequency > 50){
// The chip could have reset to the default baud OR not
// if chip is not default baud, set to default
int baud = BM1397_set_default_baud();
// then set esp32 baud to default
SERIAL_set_baud(baud);
// init the chip
BM1397_init(target_frequency);
// set asic and esp32 to max baud again
baud = BM1397_set_max_baud();
SERIAL_set_baud(baud);
power_management->frequency_value = target_frequency;
}
@ -101,7 +112,8 @@ void POWER_MANAGEMENT_task(void * pvParameters){
last_frequency_increase > 120 &&
power_management->frequency_value != BM1397_FREQUENCY
){
power_management->frequency_value += _fbound(target_frequency, 2 , 15);
float add = (target_frequency + power_management->frequency_value) / 2;
power_management->frequency_value += _fbound(add, 2 , 20);
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 = 60;