-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve BM1370 die temp reading accuracy and stability. #483
Conversation
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be removed and replaced by proper sign handling:
float EMC2101_get_external_temp(void)
{
uint8_t temp_msb, temp_lsb;
uint16_t reading;
ESP_ERROR_CHECK(i2c_bitaxe_register_read(emc2101_dev_handle, EMC2101_EXTERNAL_TEMP_MSB, &temp_msb, 1));
ESP_ERROR_CHECK(i2c_bitaxe_register_read(emc2101_dev_handle, EMC2101_EXTERNAL_TEMP_LSB, &temp_lsb, 1));
// Combine MSB and LSB, and then right shift to get 11 bits
reading = (temp_msb << 8) | temp_lsb;
reading >>= 5; // Now, `reading` contains an 11-bit signed value
// Cast `reading` to a signed 16-bit integer
int16_t signed_reading = (int16_t)reading;
// If the 11th bit (sign bit in 11-bit data) is set, extend the sign
if (signed_reading & 0x0400) {
signed_reading |= 0xF800; // Set upper bits to extend the sign
}
if (signed_reading == EMC2101_TEMP_FAULT_OPEN_CIRCUIT) {
ESP_LOGE(TAG, "EMC2101 TEMP_FAULT_OPEN_CIRCUIT: %04X", signed_reading);
}
if (signed_reading == EMC2101_TEMP_FAULT_SHORT) {
ESP_LOGE(TAG, "EMC2101 TEMP_FAULT_SHORT: %04X", signed_reading);
}
// Convert the signed reading to temperature in Celsius
float result = (float)signed_reading / 8.0;
return result;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right shifting a signed int should properly sign extend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For whatever reason it does not but I confirmed the above code does.
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only be for BM1370 and not all chips
Enhance the home chart with temperature display and line fills
* Redo swarm Redo swarm to use network scanning and local storage rather than storing the set of IP's on device. * auto refresh --------- Co-authored-by: Benjamin Wilson <[email protected]>
…into skot_emc2101_tests
…into skot_emc2101_tests
Borked this up - see new pull |
The correct setting for the BM1370 "Analog Mux" register 0x54 has changed from 0x03 to 0x02. This makes temperature reading much more stable.
Setting the EMC2101 external temp sensor to manual beta compensation (0.11) and changing the ideality from 1.008 to 1.0319 makes the die temperature much more accurate.