From 82f5a9da9d57ef2ba90e0e5c027d570c7ed2bc73 Mon Sep 17 00:00:00 2001 From: Andrey Gusakov Date: Wed, 26 Apr 2023 22:44:48 +0300 Subject: [PATCH] livedata: show Nernst voltage --- firmware/livedata.cpp | 1 + firmware/livedata.h | 3 ++- firmware/sampling.cpp | 7 +++++++ firmware/sampling.h | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/firmware/livedata.cpp b/firmware/livedata.cpp index ebee1d35..3f86a7e8 100644 --- a/firmware/livedata.cpp +++ b/firmware/livedata.cpp @@ -26,6 +26,7 @@ void SamplingUpdateLiveData() data->temperature = GetSensorTemperature(ch) * 10; data->heaterSupplyVoltage = voltage * 100; data->nernstDc = GetNernstDc(ch) * 1000; + data->nernstV = (int16_t)(GetNernstV(ch) * 1000.0); data->nernstAc = GetNernstAc(ch) * 1000; data->pumpCurrentTarget = GetPumpCurrent(ch); data->pumpCurrentMeasured = GetPumpNominalCurrent(ch); diff --git a/firmware/livedata.h b/firmware/livedata.h index 6d57a203..e5712dc7 100644 --- a/firmware/livedata.h +++ b/firmware/livedata.h @@ -30,7 +30,8 @@ struct livedata_afr_s { float pumpCurrentMeasured; uint16_t heaterDuty; uint16_t heaterEffectiveVoltage; - float esr; + uint16_t esr; + int16_t nernstV; uint8_t fault; // See wbo::Fault uint8_t heaterState; } __attribute__((packed)); diff --git a/firmware/sampling.cpp b/firmware/sampling.cpp index 0a139070..f835434a 100644 --- a/firmware/sampling.cpp +++ b/firmware/sampling.cpp @@ -15,6 +15,7 @@ struct measure_results { float nernstAc; float nernstDc; + float nernstV; float pumpCurrentSenseVoltage; float internalBatteryVoltage; int clamped; @@ -80,6 +81,7 @@ static void SamplingThread(void*) // Compute AC (difference) and DC (average) components float nernstAcLocal = f_abs(r2_opposite_phase - r_2[ch]); res.nernstDc = (r2_opposite_phase + r_2[ch]) / 2; + res.nernstV = result.ch[ch].NernstVoltage; res.nernstAc = (1 - ESR_SENSE_ALPHA) * res.nernstAc + @@ -160,6 +162,11 @@ float GetNernstDc(int ch) return results[ch].nernstDc; } +float GetNernstV(int ch) +{ + return results[ch].nernstV; +} + float GetPumpNominalCurrent(int ch) { // Gain is 10x, then a 61.9 ohm resistor diff --git a/firmware/sampling.h b/firmware/sampling.h index c1415e03..800d5f8a 100644 --- a/firmware/sampling.h +++ b/firmware/sampling.h @@ -6,5 +6,6 @@ float GetNernstAc(int ch); float GetSensorInternalResistance(int ch); float GetSensorTemperature(int ch); float GetNernstDc(int ch); +float GetNernstV(int ch); float GetPumpNominalCurrent(int ch); float GetInternalBatteryVoltage(int ch);