temperature monitoring of 10k ntc
This commit is contained in:
parent
eb9ad3c75a
commit
df42d18944
@ -16,6 +16,7 @@
|
||||
#include "timeconst.h"
|
||||
#include "drivers/nerd-nos/bm1397.h"
|
||||
#include "drivers/nerd-nos/serial.h"
|
||||
#include "drivers/nerd-nos/adc.h"
|
||||
|
||||
#ifdef NERD_NOS
|
||||
#include "mining_nerdnos.h"
|
||||
@ -147,6 +148,7 @@ void setup()
|
||||
#endif
|
||||
|
||||
#ifdef NERD_NOS
|
||||
nerdnos_adc_init();
|
||||
SERIAL_init();
|
||||
int chips = BM1397_init(200, 1);
|
||||
Serial.printf("found bm1397: %d\n", chips);
|
||||
|
@ -65,9 +65,13 @@ void tDisplay_MinerScreen(unsigned long mElapsed)
|
||||
|
||||
// Print background screen
|
||||
background.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen);
|
||||
|
||||
#ifdef NERD_NOS
|
||||
Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s GH/s, %s °C\n",
|
||||
data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str(), data.currentTemperature.c_str());
|
||||
#else
|
||||
Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n",
|
||||
data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str());
|
||||
#endif
|
||||
|
||||
// Hashrate
|
||||
render.setFontSize(35);
|
||||
|
48
src/drivers/nerd-nos/adc.cpp
Normal file
48
src/drivers/nerd-nos/adc.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include "driver/adc.h"
|
||||
#include "esp_adc_cal.h"
|
||||
|
||||
#define ADC_CHANNEL ADC1_CHANNEL_1 // GPIO2 corresponds to ADC1 channel 1 on ESP32-S3
|
||||
#define BETA 3380 // Beta value of the thermistor
|
||||
#define R0 10000 // Resistance at 25°C (10kΩ)
|
||||
#define ADC_MAX 4095 // Max ADC value for 12-bit resolution
|
||||
#define DEFAULT_VREF 1100 // Default VREF in millivolts for ESP32 ADC
|
||||
|
||||
// ADC Calibration characteristics
|
||||
static esp_adc_cal_characteristics_t adc1_chars;
|
||||
|
||||
void nerdnos_adc_init() {
|
||||
// Configure the ADC
|
||||
adc1_config_width(ADC_WIDTH_BIT_12); // Set ADC width (12-bit)
|
||||
adc1_config_channel_atten(ADC_CHANNEL, ADC_ATTEN_DB_11); // Set attenuation to read the full range of 0 to 3.3V
|
||||
|
||||
// Characterize ADC at given attenuation
|
||||
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, 0, &adc1_chars);
|
||||
}
|
||||
|
||||
float nerdnos_get_temperature() {
|
||||
// Convert the raw ADC value to a voltage using esp_adc_cal
|
||||
uint32_t voltage_mv = esp_adc_cal_raw_to_voltage(adc1_get_raw(ADC_CHANNEL), &adc1_chars); // Voltage in millivolts
|
||||
|
||||
// Convert millivolts to volts
|
||||
float voltage = voltage_mv / 1000.0;
|
||||
|
||||
// Ensure the voltage is within a valid range
|
||||
if (voltage <= 0) {
|
||||
printf("Error: Invalid voltage reading.\n");
|
||||
return -273.15; // Return a clearly invalid temperature to indicate an error
|
||||
}
|
||||
|
||||
// Calculate the thermistor resistance using the voltage divider formula
|
||||
// R_T = R0 * (Vout / (VREF - Vout))
|
||||
float thermistor_resistance = R0 * (voltage / (3.3 - voltage));
|
||||
|
||||
// Use the Beta parameter equation to calculate the temperature in Kelvin
|
||||
float temperature_kelvin = (float)(BETA / (log(thermistor_resistance / R0) + (BETA / 298.15)));
|
||||
|
||||
// Convert the temperature to Celsius
|
||||
float temperature_celsius = temperature_kelvin - 273.15;
|
||||
|
||||
return temperature_celsius;
|
||||
}
|
4
src/drivers/nerd-nos/adc.h
Normal file
4
src/drivers/nerd-nos/adc.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void nerdnos_adc_init();
|
||||
float nerdnos_get_temperature();
|
@ -63,8 +63,8 @@ static void _send_BM1397(uint8_t header, uint8_t *data, uint8_t data_len, bool d
|
||||
packet_type_t packet_type = (header & TYPE_JOB) ? JOB_PACKET : CMD_PACKET;
|
||||
uint8_t total_length = (packet_type == JOB_PACKET) ? (data_len + 6) : (data_len + 5);
|
||||
|
||||
// allocate memory for buffer
|
||||
unsigned char *buf = (unsigned char *)malloc(total_length);
|
||||
// memory for buffer
|
||||
uint8_t buf[total_length];
|
||||
|
||||
// add the preamble
|
||||
buf[0] = 0x55;
|
||||
@ -93,8 +93,6 @@ static void _send_BM1397(uint8_t header, uint8_t *data, uint8_t data_len, bool d
|
||||
|
||||
// send serial data
|
||||
SERIAL_send(buf, total_length, debug);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
static void _send_read_address(void)
|
||||
|
@ -129,7 +129,6 @@ void nerdnos_create_job(mining_subscribe *mWorker, mining_job *job, bm_job_t *ne
|
||||
calculate_merkle_root_hash(coinbase_tx.c_str(), job, merkle_root);
|
||||
|
||||
//Serial.printf("asic merkle root: %s\n", merkle_root);
|
||||
// we need malloc because we will save it in the job array
|
||||
construct_bm_job(job, merkle_root, 0x1fffe000, next_job);
|
||||
|
||||
next_job->jobid = strdup(job->job_id.c_str());
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#ifdef NERD_NOS
|
||||
#include "mining_nerdnos.h"
|
||||
#include "drivers/nerd-nos/adc.h"
|
||||
#endif
|
||||
|
||||
extern uint32_t templates;
|
||||
@ -243,11 +244,19 @@ String getCurrentHashRate(unsigned long mElapsed) {
|
||||
// we have too little space for 2 digits after the decimal point
|
||||
return String(nerdnos_get_avg_hashrate(), 1);
|
||||
}
|
||||
|
||||
String getCurrentTemperature() {
|
||||
return String(nerdnos_get_temperature(), 2);
|
||||
}
|
||||
#else
|
||||
String getCurrentHashRate(unsigned long mElapsed)
|
||||
{
|
||||
return String((1.0 * (elapsedKHs * 1000)) / mElapsed, 2);
|
||||
}
|
||||
|
||||
String getCurrentTemperature() {
|
||||
return String(0.0, 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
mining_data getMiningData(unsigned long mElapsed)
|
||||
@ -269,6 +278,7 @@ mining_data getMiningData(unsigned long mElapsed)
|
||||
data.totalMHashes = Mhashes;
|
||||
data.totalKHashes = totalKHashes;
|
||||
data.currentHashRate = getCurrentHashRate(mElapsed);
|
||||
data.currentTemperature = getCurrentTemperature();
|
||||
data.templates = templates;
|
||||
data.bestDiff = best_diff_string;
|
||||
data.timeMining = timeMining;
|
||||
|
@ -73,6 +73,7 @@ typedef struct {
|
||||
String valids;
|
||||
String temp;
|
||||
String currentTime;
|
||||
String currentTemperature;
|
||||
}mining_data;
|
||||
|
||||
typedef struct {
|
||||
|
Loading…
Reference in New Issue
Block a user