Gain vs loss confusion (#304)

This commit is contained in:
Andrey G 2023-12-10 14:53:56 +03:00 committed by GitHub
parent 72d5a0dc06
commit 94f2377bca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 12 additions and 12 deletions

View File

@ -45,7 +45,7 @@ AnalogResult AnalogSample()
.ch = .ch =
{ {
{ {
.NernstVoltage = AverageSamples(adcBuffer, 0) * NERNST_INPUT_GAIN, .NernstVoltage = AverageSamples(adcBuffer, 0) * (1.0 / NERNST_INPUT_GAIN),
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1), .PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
.BatteryVoltage = 0, .BatteryVoltage = 0,
}, },

View File

@ -9,7 +9,7 @@
// ******************************* // *******************************
// Nernst voltage & ESR sense // Nernst voltage & ESR sense
// ******************************* // *******************************
#define NERNST_INPUT_GAIN (1 / 2.7f) #define NERNST_INPUT_GAIN (2.7f)
#define AFR_CHANNELS 1 #define AFR_CHANNELS 1

View File

@ -109,13 +109,13 @@ AnalogResult AnalogSample()
.ch = { .ch = {
{ {
/* left */ /* left */
.NernstVoltage = AverageSamples(adcBuffer, 3) * NERNST_INPUT_GAIN, .NernstVoltage = AverageSamples(adcBuffer, 3) * (1.0 / NERNST_INPUT_GAIN),
.PumpCurrentVoltage = AverageSamples(adcBuffer, 2), .PumpCurrentVoltage = AverageSamples(adcBuffer, 2),
.BatteryVoltage = l_heater_voltage, .BatteryVoltage = l_heater_voltage,
}, },
{ {
/* right */ /* right */
.NernstVoltage = AverageSamples(adcBuffer, 1) * NERNST_INPUT_GAIN, .NernstVoltage = AverageSamples(adcBuffer, 1) * (1.0 / NERNST_INPUT_GAIN),
.PumpCurrentVoltage = AverageSamples(adcBuffer, 0), .PumpCurrentVoltage = AverageSamples(adcBuffer, 0),
.BatteryVoltage = r_heater_voltage, .BatteryVoltage = r_heater_voltage,
}, },

View File

@ -16,7 +16,7 @@
// ******************************* // *******************************
// Nernst voltage & ESR sense // Nernst voltage & ESR sense
// ******************************* // *******************************
#define NERNST_INPUT_GAIN (1 / 3.0f) #define NERNST_INPUT_GAIN (3.0f)
// ******************************* // *******************************
// Battery Sensing // Battery Sensing

View File

@ -127,7 +127,7 @@ AnalogResult AnalogSample()
float NernstRaw = AverageSamples(adcBuffer, (i == 0) ? 3 : 1); float NernstRaw = AverageSamples(adcBuffer, (i == 0) ? 3 : 1);
if ((NernstRaw > 0.01) && (NernstRaw < (3.3 - 0.01))) { if ((NernstRaw > 0.01) && (NernstRaw < (3.3 - 0.01))) {
/* not clamped */ /* not clamped */
res.ch[i].NernstVoltage = (NernstRaw - NERNST_INPUT_OFFSET) * NERNST_INPUT_GAIN; res.ch[i].NernstVoltage = (NernstRaw - NERNST_INPUT_OFFSET) * (1.0 / NERNST_INPUT_GAIN);
} else { } else {
/* Clamped, use ungained input */ /* Clamped, use ungained input */
res.ch[i].NernstVoltage = AverageSamples(adcBuffer, (i == 0) ? 9 : 8) - HALF_VCC; res.ch[i].NernstVoltage = AverageSamples(adcBuffer, (i == 0) ? 9 : 8) - HALF_VCC;

View File

@ -20,7 +20,7 @@
// ******************************* // *******************************
// Nernst voltage & ESR sense // Nernst voltage & ESR sense
// ******************************* // *******************************
#define NERNST_INPUT_GAIN (1 / 3.15f) #define NERNST_INPUT_GAIN (3.15f)
#define NERNST_INPUT_OFFSET (0.247) #define NERNST_INPUT_OFFSET (0.247)
// ******************************* // *******************************

View File

@ -62,7 +62,7 @@ AnalogResult AnalogSample()
{ {
.ch = { .ch = {
{ {
.NernstVoltage = AverageSamples(adcBuffer, 2) * NERNST_INPUT_GAIN, .NernstVoltage = AverageSamples(adcBuffer, 2) * (1.0 / NERNST_INPUT_GAIN),
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1), .PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
/* We also can measure output virtual ground voltage for diagnostic purposes */ /* We also can measure output virtual ground voltage for diagnostic purposes */
//.VirtualGroundVoltageExt = AverageSamples(adcBuffer, 0) / VM_INPUT_DIVIDER, //.VirtualGroundVoltageExt = AverageSamples(adcBuffer, 0) / VM_INPUT_DIVIDER,

View File

@ -12,7 +12,7 @@
// ******************************* // *******************************
// Nernst voltage & ESR sense // Nernst voltage & ESR sense
// ******************************* // *******************************
#define NERNST_INPUT_GAIN (1 / 3.0f) #define NERNST_INPUT_GAIN (3.0f)
// ******************************* // *******************************
// Battery Sensing // Battery Sensing

View File

@ -59,7 +59,7 @@ AnalogResult AnalogSample()
{ {
.ch = { .ch = {
{ {
.NernstVoltage = AverageSamples(adcBuffer, 2) * NERNST_INPUT_GAIN, .NernstVoltage = AverageSamples(adcBuffer, 2) * (1.0 / NERNST_INPUT_GAIN),
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1), .PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
/* We also can measure output virtual ground voltage for diagnostic purposes */ /* We also can measure output virtual ground voltage for diagnostic purposes */
//.VirtualGroundVoltageExt = AverageSamples(adcBuffer, 0) / VM_INPUT_DIVIDER, //.VirtualGroundVoltageExt = AverageSamples(adcBuffer, 0) / VM_INPUT_DIVIDER,

View File

@ -12,7 +12,7 @@
// ******************************* // *******************************
// Nernst voltage & ESR sense // Nernst voltage & ESR sense
// ******************************* // *******************************
#define NERNST_INPUT_GAIN (1 / 3.0f) #define NERNST_INPUT_GAIN (3.0f)
// ******************************* // *******************************
// Battery Sensing // Battery Sensing

View File

@ -9,7 +9,7 @@
// ******************************* // *******************************
// Nernst voltage & ESR sense // Nernst voltage & ESR sense
// ******************************* // *******************************
#define NERNST_INPUT_GAIN (1 / 2.7f) #define NERNST_INPUT_GAIN (2.7f)
#define AFR_CHANNELS 1 #define AFR_CHANNELS 1