From 8f82dc78fb7062a371645d6b32593a073197e42f Mon Sep 17 00:00:00 2001 From: Jochen Steinmann Date: Tue, 7 Mar 2023 09:40:26 +0100 Subject: [PATCH 01/72] added calculation of the offset amplifier --- firmware/calculations/offset_amplifier.py | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 firmware/calculations/offset_amplifier.py diff --git a/firmware/calculations/offset_amplifier.py b/firmware/calculations/offset_amplifier.py new file mode 100644 index 0000000..0c6bf1d --- /dev/null +++ b/firmware/calculations/offset_amplifier.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +""" + +""" +from sympy import Symbol, symbols, solve, pprint, Eq + +Up, Un = symbols("U_+, U_-") + + +Uout = Symbol("U_out") +Ubias = Symbol("U_bias") + +R1, R2 = symbols("R_1, R_2") + +I_R1R2 = (Uout - Ubias) / (R1 + R2) + +Un = I_R1R2 * R2 + Ubias + +eq1 = Eq( Up , Un ) +pprint(eq1) + +Uin = symbols("U_in") +eq1 = eq1.subs(Up, Uin) +pprint(eq1) + +sol = solve(eq1, Uout)[0].factor() +pprint(sol) + From 156bffd10065d01354b9df86ea723d700000db9e Mon Sep 17 00:00:00 2001 From: Jochen Steinmann Date: Tue, 7 Mar 2023 11:04:08 +0100 Subject: [PATCH 02/72] added calculation for voltage before bias amplifier --- firmware/Inc/utils.h | 1 + firmware/Src/utils.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/firmware/Inc/utils.h b/firmware/Inc/utils.h index 5b7e7b3..044cbb1 100644 --- a/firmware/Inc/utils.h +++ b/firmware/Inc/utils.h @@ -25,5 +25,6 @@ uint8_t upper(uint16_t val); uint8_t lower(uint16_t val); float convertPT100_R2T(float resistance); +float getVoltageBeforeAmplifier(float Uadc, float Ubias, float R1, float R2); #endif //__UTILS_H__ diff --git a/firmware/Src/utils.c b/firmware/Src/utils.c index 153507d..dab8dca 100644 --- a/firmware/Src/utils.c +++ b/firmware/Src/utils.c @@ -19,3 +19,14 @@ float convertPT100_R2T(float resistance){ const float R0 = 100; return (resistance - R0)/(R0 * A); } + +/** + * calculate the voltage before the biases amplifier + * @param Ubias bias voltage + * @param Uadc measured voltage of the ADC (amplifier output) + * @param R1 gain setting resistor (upper) + * @param R2 gain setting resistor (lower) + */ +float getVoltageBeforeAmplifier(float Uadc, float Ubias, float R1, float R2){ + return (R1 * Ubias + R2 * Uadc)/(R1 + R2); +} From c69e269e6e8b4b63557ed33793a25cdcdfc38298 Mon Sep 17 00:00:00 2001 From: Jochen Steinmann Date: Tue, 7 Mar 2023 11:54:16 +0100 Subject: [PATCH 03/72] moved #define of PCB version to own header file --- firmware/Inc/config.h | 2 +- firmware/Inc/pcb_version.h | 30 ++++++++++++++++++++++++++++++ firmware/Src/main.c | 30 ++---------------------------- 3 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 firmware/Inc/pcb_version.h diff --git a/firmware/Inc/config.h b/firmware/Inc/config.h index ae3c35d..a9d4a30 100644 --- a/firmware/Inc/config.h +++ b/firmware/Inc/config.h @@ -6,7 +6,7 @@ extern "C" { #endif #include - +#include "pcb_version.h" #include "pid.h" #define ISATURATION_LSB 3970 diff --git a/firmware/Inc/pcb_version.h b/firmware/Inc/pcb_version.h new file mode 100644 index 0000000..aee34f6 --- /dev/null +++ b/firmware/Inc/pcb_version.h @@ -0,0 +1,30 @@ +#pragma once + +/** + * PCB v1 compatibility mode + */ +#define PCB_V1 +/******************************************************************************/ +/** + * PCB v2 compatibility mode + * enables: + * - dual gain ADC readout + * - I2C sensor readout + */ +//#define PCB_V2 +#if defined(PCB_V2) +#undef PCB_V1 +#endif +/******************************************************************************/ +/** + * PCB v3 compatibility mode + * enables: + * - dual gain ADC readout + * - offset for ADC / differential amplifier + * - I2C sensor readout + */ +//#define PCB_V3 +#if defined(PCB_V3) +#undef PCB_V1 +#undef PCB_V2 +#endif diff --git a/firmware/Src/main.c b/firmware/Src/main.c index 3e84ad6..d2e806f 100644 --- a/firmware/Src/main.c +++ b/firmware/Src/main.c @@ -30,6 +30,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "pcb_version.h" #include "syscalls.h" #include "utils.h" #include "i2c_scanner.h" @@ -57,34 +58,7 @@ //#define PRINT_UART_ADC // print the ADC data //#define PRINT_UART_CALC_TEMP // print the calculated temperatures /******************************************************************************/ -/** - * PCB v1 compatibility mode - */ -#define PCB_V1 -/******************************************************************************/ -/** - * PCB v2 compatibility mode - * enables: - * - dual gain ADC readout - * - I2C sensor readout - */ -//#define PCB_V2 -#if defined(PCB_V2) -#undef PCB_V1 -#define I2C_SENSOR_READOUT -#endif -/******************************************************************************/ -/** - * PCB v3 compatibility mode - * enables: - * - dual gain ADC readout - * - offset for ADC / differential amplifier - * - I2C sensor readout - */ -//#define PCB_V3 -#if defined(PCB_V3) -#undef PCB_V1 -#undef PCB_V2 +#if defined(PCB_V2) || defined(PCB_V3) #define I2C_SENSOR_READOUT #endif /******************************************************************************/ From e108ae944cb7b01dbd50163b8067ecf2a3a3ce3f Mon Sep 17 00:00:00 2001 From: Jochen Steinmann Date: Tue, 7 Mar 2023 11:54:50 +0100 Subject: [PATCH 04/72] use gain config only for PCB v2 --- firmware/Inc/config.h | 2 ++ firmware/Src/config.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/firmware/Inc/config.h b/firmware/Inc/config.h index a9d4a30..3f38f3a 100644 --- a/firmware/Inc/config.h +++ b/firmware/Inc/config.h @@ -83,7 +83,9 @@ typedef struct { * only the high gain is stored here, the lower gain is always 1 * @{ */ +#if defined(PCB_V2) gain_config_t GAIN[2]; +#endif /** @}*/ diff --git a/firmware/Src/config.c b/firmware/Src/config.c index d341e26..8c36e9c 100644 --- a/firmware/Src/config.c +++ b/firmware/Src/config.c @@ -39,6 +39,7 @@ void generateDefaultCFG(config_t *cfg){ cfg->PID_flags.PID0_active = 0; cfg->PID_flags.PID1_active = 0; +#if defined(PCB_V2) // gain settings from calculations / optimisation cfg->GAIN[0].Igain = 1 + 47.0e3 / 5.6e3; cfg->GAIN[0].Ugain = 1 + 33.0e3 / 5.6e3; @@ -49,6 +50,8 @@ void generateDefaultCFG(config_t *cfg){ cfg->GAIN[1].Ugain = 1 + 33.0e3 / 5.6e3; cfg->GAIN[1].Ibias = 0.12; cfg->GAIN[1].Ubias = 0.01; +#endif + } /** @@ -69,6 +72,7 @@ void printCfg(config_t *cfg){ printf("SMOO: %d\r\n", cfg->SMOO); printf("SMOOMAX: %d\r\n", cfg->SMOO_MAX); +#if defined(PCB_V2) printf("\r\n"); printf("Gain:"); printf(" CH0 I %f U%f\r\n", cfg->GAIN[0].Igain, cfg->GAIN[0].Ugain); @@ -76,6 +80,7 @@ void printCfg(config_t *cfg){ printf("Offset:"); printf(" CH0 I %f U%f\r\n", cfg->GAIN[0].Ibias, cfg->GAIN[0].Ubias); printf(" CH1 I %f U%f\r\n", cfg->GAIN[1].Ibias, cfg->GAIN[1].Ubias); +#endif printf("\r\n"); printf("PID 0: (%d)\r\n", cfg->PID_flags.PID0_active); From 022e8059f05d3594813d22512bdc69a30834d86f Mon Sep 17 00:00:00 2001 From: Jochen Steinmann Date: Tue, 7 Mar 2023 11:55:29 +0100 Subject: [PATCH 05/72] for PCBv1 use a much simpler calculation There is no need to match add an additional bias --- firmware/Src/main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/firmware/Src/main.c b/firmware/Src/main.c index d2e806f..cf4d8e7 100644 --- a/firmware/Src/main.c +++ b/firmware/Src/main.c @@ -373,8 +373,13 @@ int main(void) // calculate coarse current and voltage for each channel for(int i=0; i<2; i++){ +#if defined(PCB_V1) + current[i] = (*avr_current[i][0] * LSB2I); + voltage[i] = (*avr_voltage[i][0] * LSB2U); +#else current[i] = (*avr_current[i][0] * LSB2I) + cfg.GAIN[i].Ibias/1000.; voltage[i] = (*avr_voltage[i][0] * LSB2U) + cfg.GAIN[i].Ubias; +#endif } #if defined(PCB_V2) From e56d75200e0a765549c8840a07b8864086be8a53 Mon Sep 17 00:00:00 2001 From: Jochen Steinmann Date: Tue, 7 Mar 2023 11:56:06 +0100 Subject: [PATCH 06/72] change Uout with Uadc and solve to Uin --- firmware/calculations/offset_amplifier.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/calculations/offset_amplifier.py b/firmware/calculations/offset_amplifier.py index 0c6bf1d..a64f835 100644 --- a/firmware/calculations/offset_amplifier.py +++ b/firmware/calculations/offset_amplifier.py @@ -7,12 +7,12 @@ Up, Un = symbols("U_+, U_-") -Uout = Symbol("U_out") +Uadc = Symbol("U_adc") Ubias = Symbol("U_bias") R1, R2 = symbols("R_1, R_2") -I_R1R2 = (Uout - Ubias) / (R1 + R2) +I_R1R2 = (Uadc - Ubias) / (R1 + R2) Un = I_R1R2 * R2 + Ubias @@ -23,6 +23,6 @@ eq1 = eq1.subs(Up, Uin) pprint(eq1) -sol = solve(eq1, Uout)[0].factor() +sol = solve(eq1, Uin)[0].factor() pprint(sol) From 443b38a101f23a6f2ac96a3b91c3e664e6fadae6 Mon Sep 17 00:00:00 2001 From: Jochen Steinmann Date: Tue, 7 Mar 2023 14:09:53 +0100 Subject: [PATCH 07/72] created build settings for each PCB revision (and added them to ignore) --- .gitignore | 1 + firmware/.cproject | 269 ++++++++++++++++++++++++++++++++++++- firmware/Inc/pcb_version.h | 2 +- 3 files changed, 270 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7ea2a23..7d15608 100644 --- a/.gitignore +++ b/.gitignore @@ -71,6 +71,7 @@ software/FlowMeasurement/*.png firmware/.settings/*.prefs firmware/.project firmware/Debug/* +firmware/Debug* firmware/Release/* *.launch diff --git a/firmware/.cproject b/firmware/.cproject index 7edf440..95cd6f3 100644 --- a/firmware/.cproject +++ b/firmware/.cproject @@ -25,7 +25,7 @@