1 | /*! |
---|
2 | * \file : sysdata.h |
---|
3 | * \brief : Header for sysdata.c file. |
---|
4 | * This file contains the common defines of the application. |
---|
5 | * |
---|
6 | */ |
---|
7 | |
---|
8 | #ifndef __SYS_DATA_H |
---|
9 | #define __SYS_DATA_H |
---|
10 | |
---|
11 | #ifdef __cplusplus |
---|
12 | extern "C" { |
---|
13 | #endif |
---|
14 | |
---|
15 | #include "stdint.h" |
---|
16 | |
---|
17 | #define CONCAT(a, b) CONCAT_INNER(a, b) // These three macros |
---|
18 | #define CONCAT_INNER(a, b) a ## b // generate unique variables |
---|
19 | #define UNIQUE_NAME(base) CONCAT(base, __COUNTER__) // according to template "baseX", like "base1", "base2" and etc. |
---|
20 | |
---|
21 | #define SAMPLE_ARRAY_SIZE 32 |
---|
22 | |
---|
23 | //------------------------------------------------------------------------------ |
---|
24 | |
---|
25 | typedef union |
---|
26 | { |
---|
27 | uint16_t w; |
---|
28 | int16_t sw; |
---|
29 | uint8_t b[2]; |
---|
30 | int8_t sb[2]; |
---|
31 | } bword_t; |
---|
32 | |
---|
33 | //------------------------------------------------------------------------------ |
---|
34 | // This structure must be aligned to 4-byte address |
---|
35 | typedef struct |
---|
36 | { |
---|
37 | // Device spezifisch / Einstellungsbereich |
---|
38 | uint16_t device_type; // 0 ECS interne Gertetyp Kennung (IHP 500 -> daher wird angedacht die Gerätekennung 500 zu nehmen) |
---|
39 | uint16_t UNIQUE_NAME(reserved); // 1 Reserviert wg Alignement |
---|
40 | uint32_t sn; // 2-3 Seriennummer Teil 1 -> wird bei der Produktion geschrieben |
---|
41 | |
---|
42 | uint16_t fw_revision_major; // 4 Firmware Revision Major -> wird bei einer neuen Gertegeneration hochgezhlt |
---|
43 | uint16_t fw_revision_minor; // 5 Firmware Revision Minor -> wird hochegezhlt, wenn nderungen in der Firmware auch nderungen in der Bedienungsanleitung zur Folge haben |
---|
44 | |
---|
45 | uint16_t fw_revision_revision; // 6 Firmware Revision Revision -> wird bei jeder nderung der Firmware hochgezhlt |
---|
46 | uint16_t UNIQUE_NAME(reserved); // 7 Reserviert wg Alignement |
---|
47 | |
---|
48 | uint32_t baudrate; // 8-9 Die Modbus Baudrate (default 19200 Bit/s). Gltig im Bereich von 50 Bit/s bis 1000 000 Bit/s |
---|
49 | |
---|
50 | uint16_t parityMode; // 10 UART Parity Mode (default EVEN) mgliche Werte 0=EVEN, 1=ODD, 2=NONE |
---|
51 | uint16_t stopBit; // 11 UART Stop Bit Reserviert, Aktuell automatisch selektiert nach Modbus standart Bei Parity EVEN oder ODD 1, bei NONE werden 2 stopbits genutzt |
---|
52 | |
---|
53 | uint16_t slave_address; // 12 Modbus Slave Adresse (default 1) mgliche Werte von 1 bis 247 |
---|
54 | uint16_t command; // 13 Kommando Word, das Schreiben bestimmter Werte in dieses Register fhrt bestimmte Aktionen aus |
---|
55 | |
---|
56 | uint16_t ibn_day; // 14 Inbetriebnahme Datum: Tag |
---|
57 | uint16_t ibn_month; // 15 Inbetriebnahme Datum: Monat |
---|
58 | uint16_t ibn_year; // 16 Inbetriebnahme Datum: Jahr |
---|
59 | uint16_t user_id; // 17 Freies Feld für eine Kunden ID oder ähnlich |
---|
60 | uint16_t UNIQUE_NAME(reserved)[8]; // 18-25 RESERVIERT |
---|
61 | |
---|
62 | //--- Konfiguration Schaltausgänge --- |
---|
63 | uint16_t lvpStart; // 26 Spannung ab der die LOW Voltage Protection aktiv wird in [mV] |
---|
64 | uint16_t lvpStop; // 27 Spannung ab der die LOW Voltage Protection wieder inaktiv wird [mV] |
---|
65 | |
---|
66 | uint16_t ovpStart; // 28 Spannung ab der die OVER Voltage Protection aktiv wird in [mV] |
---|
67 | uint16_t ovpStop; // 29 Spannung ab der die OVER Voltage Protection wieder inaktiv wird [mV] |
---|
68 | |
---|
69 | int16_t loadCurrentLimit; // 30 maximaler Laststrom in A wenn der Strom grer ist als der eingestelle Wert dann wird die Laststrom Protection aktiv, darf nicht unsigned sein, da Entladestrom mit Minus angegeben [A] Default -500 A |
---|
70 | int16_t chargeCurrentLimit; // 31 maximaler Ladestrom in A wenn der Strom grer ist als der eingestelle Wert dann wird die Ladestrom Protection aktiv [A] Default:500A |
---|
71 | |
---|
72 | |
---|
73 | int16_t chargeStopHighTemperatureStart; // 32 Abschalttemperatur Ladung wegen zu hoher Temperatur [C * 100] |
---|
74 | int16_t chargeStopHighTemperatureStop; // 33 Wiedereinschalttemperatur [C * 100] |
---|
75 | |
---|
76 | int16_t chargeStopLowTemperatureStart; // 34 Abschalttemperatur Ladung wegen zu niedriger Temperatur [C * 100] |
---|
77 | int16_t chargeStopLowTemperatureStop; // 35 Wiedereinschalttemperatur [C * 100] |
---|
78 | |
---|
79 | int16_t dischargeStopHighTemperatureStart; // 36 Abschalttemperatur Entladung wegen zu hoher Temperatur [C * 100] |
---|
80 | int16_t dischargeStopHighTemperatureStop; // 37 Wiedereinschalttemperatur[C * 100] |
---|
81 | |
---|
82 | int16_t dischargeStopLowTemperatureStart; // 38 Abschalttemperatur EntLadung wegen zu niedriger Temperatur |
---|
83 | int16_t dischargeStopLowTemperatureStop; // 39 Wiedereinschalttemperatur |
---|
84 | |
---|
85 | |
---|
86 | //ah-Counter |
---|
87 | uint16_t peukert; // 40 Peukert Faktor (Wert für den Exponent) * 100 |
---|
88 | uint16_t cef; // 41 Ladeeffektivitätsfaktor in % |
---|
89 | |
---|
90 | uint16_t iBatFull; // 42 Strom in % ab dem die Zellen als voll erkannt werden (Strom muss für die Zeit timeBatFull unter den Wert fallen) |
---|
91 | uint16_t tBatFull; // 43 Zeit in Sekunden ab dem die Zellen als voll erkannt werden (Strom muss unter dem Wert iBattFull liegen) |
---|
92 | |
---|
93 | uint16_t uBatFull; // 44 Spannung für Erkennung Battery voll in [mV] |
---|
94 | uint16_t uBatEmpty; // 45 Reserviert |
---|
95 | uint32_t cellCapacity; // 46-47 Die Zellkapazität in mAh (bei parallel geschalteten Zellen wird die Kapazitt der Zellen addiert) |
---|
96 | uint32_t battEnergy; // 48-49 Die Zellkapazität in mWh (Wh = mAh * Vnom) |
---|
97 | uint16_t socCalcMode; // 50 SoC calculation method: 0 (simple - default) - based on Ah values; 1 (advanced) - based on Wh values |
---|
98 | uint16_t UNIQUE_NAME(reserved); // 51 RESERVIERT |
---|
99 | uint16_t cellRatedDischargeTime; // 52 Standard discharge time in h |
---|
100 | int16_t uBatEmptyCompStartTemp; // 53 We start calculating uBatEmpty compensations only when cell temperature is lower than this value |
---|
101 | int16_t uBatEmptyCompStopTemp; // 54 We stop calculating uBatEmpty compensations when cell temperature is lower than this value |
---|
102 | uint16_t uBatEmptyCompStopVolt; // 55 uBatEmpty Voltage at temperatures lower than lvpCompStopTemp |
---|
103 | int16_t extraDischargeStrom_mA; // 56 |
---|
104 | uint16_t cefW; // 57 CeF for Wh calculations |
---|
105 | uint16_t lvpMode; // 58-59 RESERVIERT |
---|
106 | uint16_t ovpMode; // 58-59 RESERVIERT |
---|
107 | |
---|
108 | // ------- Calibration Parameter ----- |
---|
109 | int32_t batteryCurrentOffset; // 60-61 Offset bei Raumtemperatur ADC Schritte |
---|
110 | int16_t batteryCurrentOffsetRefTemperatureShunt; // 62 gesicherte Shunt Temperatur zum Zeitpunkt der Kalibrierung |
---|
111 | int16_t batteryCurrentOffsetRefTemperatureChip; // 63 gesicherte Chip Temperatur zum Zeitpunkt der Kalibrierung |
---|
112 | int32_t batteryCurrentOffsetRefshuntVoltage; // 64-65 gesicherte Shunt Spannung zum Zeitpunkt der Kalibrierung |
---|
113 | |
---|
114 | int32_t batteryCurrentOffsetCommonModeCalibrationVoltage; // 66-67 gesicherte Spannuung am Shunt für Common Mode Error Compensation |
---|
115 | int32_t batteryCurrentOffsetCommonModeCompensationFactor; // 68-69 Common Mode Error Compensation Faktor Faktor pro mV Shuntspannungsnderung * 1000 |
---|
116 | |
---|
117 | int16_t batteryCurrentOffsetTemperatureCalibrationTemperature; // 70 gesicherte Temperatur zum Zeitput der Offset Temperatur Kompensation |
---|
118 | int16_t UNIQUE_NAME(reserved); // 71 reserviert |
---|
119 | int32_t batteryCurrentOffsetTemperatureCompensationFactor; // 72-73 Berechnete Temperatur Kompensation für Strom Offset |
---|
120 | |
---|
121 | int32_t batteryCurrentGainCorrectionFaktor; // 74-75 Gain Korrektur Faktor * 1000000 |
---|
122 | int16_t batteryCurrentGainRefTempShunt; // 76 Gesicherte Temperatur Shunts bei Gain Kallibrierung |
---|
123 | int16_t batteryCurrentGainRefTempChip; // 77 Gesicherte Temperatur Chip bei Gain Kallibrierung |
---|
124 | int32_t batteryCurrentGainRefCurrent; // 78-79 Referenz Strom für die Gain Kalibrierung, muss vor dem Start des Kal. Befehls hier eingegeben werden |
---|
125 | |
---|
126 | int16_t batteryCurrentGainTemperatureCalibrationShuntTemperature; // 80 Gesicherte Shunt Temperatur bei Start der Gain Temperatur Kompensation |
---|
127 | int16_t UNIQUE_NAME(reserved); // 81 reserviert |
---|
128 | int32_t batteryCurrentGainTemperatureCompensationShuntFactor; // 82-83 Berechneter Faktor für Gain Temperatur kompensation. Pro 1/100 C * 1000000000 |
---|
129 | int16_t batteryCurrentGainTemperatureCalibrationChipTemperature; // 84 Gesicherte Chip Temperatur bei Start der Gain Temperatur Kompensation |
---|
130 | int16_t UNIQUE_NAME(reserved); // 85 reserviert |
---|
131 | int32_t batteryCurrentGainTemperatureCompensationChipFactor; // 86-87 zustzlicher Kalibrierungsfaktor, nicht in Verwendung |
---|
132 | |
---|
133 | uint32_t UNIQUE_NAME(reserved)[6]; |
---|
134 | |
---|
135 | } device_parameter_t; |
---|
136 | |
---|
137 | //------------------------------------------------------------------------------ |
---|
138 | // This structure must be aligned to 4-byte address |
---|
139 | typedef struct |
---|
140 | { /*offset 0*/ |
---|
141 | /* 2 of 8 */ uint16_t voltageVref; // 100 Aktuelle Spannung der Referenzspannungsquelle des ADS1260 gemessen von dem STM32G0 [mV] |
---|
142 | /* 4 of 8 */ uint16_t realVdd; // 101 Aktuelle Umrechnung von gemessene externe RefSpannung auf ADC Ref Spannung = Vdd, Vdd ist die Referenz des internen ADC. Diese wird jetzt als Referenz für die interne ADC Messungen verwendet [mV] |
---|
143 | /* 6 of 8 */ int16_t chipTemperature; // 102 Chiptemperatur gemessen auf dem STM32G0 [C * 100] |
---|
144 | /* 8 of 8 */ int16_t shuntTemperature; // 103 Gemessene Shunt Temperatur [C * 100] |
---|
145 | /* 2 of 8 */ int16_t shuntTemperatureMax; // 104 Höchste Shunttemperatur seit Programmstart, kann durch Schreiben von Int16-Min (-32.768) in das Register zurückgesetzt werden |
---|
146 | /* 4 of 8 */ int16_t shuntTemperatureMin; // 105 Niedrigste Shunttemperatur seit Programmstart, kann durch Schreiben von Int16_Max (+32.767) in das Register zurückgesetzt werden |
---|
147 | /* 8 of 8 */ uint32_t shuntVoltage; // 106-107 Shuntspannung in mV (Common Mode Voltage) gemessen von dem STM32G0. Spannung zwischen Shunt B und GND Versorgung |
---|
148 | /* 4 of 8 */ int32_t batteryVoltage; // 108-109! Gemessenen Batteriespannung in mV. Es kann in beide Richtungen gemessen werden (mindestens von -60V bis +60V). Es muss darauf geachtet werden, dass die gemessen Spannung positiv ist (+ an Batterieplus und - an Batterieminus) |
---|
149 | /* 8 of 8 */ int32_t batteryVoltageMax; // 110-111 Hchster Spannungswert in mV (Batteriespannung) seit Programmstart. Kann durch schreiben von int32-Min (-2,147,483,648) in das Register zurckgesetzt werden |
---|
150 | /* 4 of 8 */ int32_t batteryVoltageMin; // 112-113 Niedrigster Spannungswert in mV (Batteriespannung) seit Programmstart. Kann durch Schreiben von int32-Max (2,147,483,647) in das Register zurckgesetzt werden |
---|
151 | /* 8 of 8 */ int32_t batteryCurrent; // 114-115! Gemessener Batteriestrom in mA. Es kann in beide Richtungen gemessen werden, es muss darauf geachtet werden, dass der Stromsensor so eingebaut wird, dass der Ladestrom positiv gemessen wird und der Laststrom negativ, ansonsten falsche SOC Berechnung |
---|
152 | /* 4 of 8 */ int32_t batteryCurrentMax; // 116-117 Hchster Batteriestrom seit Programmstart in mA. Kann durch Schreiben von Int32-Min (-2,147,483,648) in das Register zurückgesetzt werden |
---|
153 | /* 8 of 8 */ int32_t batteryCurrentMin; // 118-119 Niedrigster Batteriestrom seit Programmstart in mA. Kkann durch Schreiben von Int32-Max (2,147,483,647) in das Register zurückgesetzt werden |
---|
154 | /* 4 of 8 */ int32_t batteryCurrentCorrected; // 120-121! Gemessener Batteriestrom mit berücksichtitgten Peukert Faktor in mA |
---|
155 | /* 8 of 8 */ int32_t mAhCounter; // 122-123 Kapazitätszähler in [mAh] umgerechnet von mAsCounter |
---|
156 | /* 8 of 8 */ int64_t mAsCounter; // 124-127! Kapazitätszähler in mAhs, zählt den gemessenen Strom, positiv für Ladeströme und negativ für Lastströme (Mit Peukert und CEF) |
---|
157 | /* 4 of 8 */ int32_t soc; // 128-129! State of Charge in % * 1000 |
---|
158 | /* 6 of 8 */ int16_t ovpState; // 130 Zustand Schaltausgang OVP |
---|
159 | /* 8 of 8 */ int16_t lvpState; // 131 Zustand Schaltausgang LVP |
---|
160 | /* 4 of 8 */ int32_t batteryPower; // 132-133! Leistung Batterie[mW] |
---|
161 | /* 8 of 8 */ int32_t detectedCapacity; // 134-135 Festgestellte Kapazität [mAh] |
---|
162 | /* 4 of 8 */ int32_t detectedEnergy; // 136-137 [mWh] |
---|
163 | /* 6 of 8 */ int16_t SoH; // 138 [%] |
---|
164 | /* 8 of 8 */ int16_t efficiency; // 139 [%] |
---|
165 | /* 2 of 8 */ int16_t selfDischarge; // 140 [mA] |
---|
166 | /* 4 of 8 */ int16_t selfDischargeAvg; // 141 [mA] |
---|
167 | /* 6 of 8 */ int16_t esr; // 142 [mOhm] |
---|
168 | /* 8 of 8 */ int16_t esr_fast; // 143 [mOhm] |
---|
169 | /* 6 of 8 */ uint32_t lastTimeVbatFull; // 144-145 [s] |
---|
170 | /* 8 of 8 */ uint32_t lastTimeVbatEmpty; // 146-147 [s] |
---|
171 | /* 4 of 8 */ uint32_t onTime; // 148-149 [s] Runtime Zähler zum speichern der Statistik Werte im EEPROM und als Betriebszeitzähler |
---|
172 | /* 8 of 8 */ uint32_t dischargeTotalAh; // 150-151 [mAs] |
---|
173 | /* 4 of 8 */ uint32_t chargeTotalAh; // 152-153 [mAs] |
---|
174 | /* 8 of 8 */ uint32_t dischargeTotalWh; // 154-155 [mAs] |
---|
175 | /* 4 of 8 */ uint32_t chargeTotalWh; // 156-157 [mAs] |
---|
176 | /* 6 of 8 */ uint16_t fullCyclesCnt; // 158 |
---|
177 | /* 8 of 8 */ uint16_t UNIQUE_NAME(reserved); // 159 |
---|
178 | /* 8 of 8 */ int64_t mAs_AutoMode; // 160-163 |
---|
179 | /* 8 of 8 */ int64_t mWs_AutoMode; // 164-167 |
---|
180 | /* 2 of 8 */ uint16_t ovp_sense; // 168 |
---|
181 | /* 4 of 8 */ uint16_t lvp_sense; // 169 |
---|
182 | /* 6 of 8 */ uint16_t UNIQUE_NAME(reserved); // 170 |
---|
183 | /* 8 of 8 */ uint16_t UNIQUE_NAME(reserved); // 171 |
---|
184 | /* 2 of 8 */ uint16_t UNIQUE_NAME(reserved); // 172 |
---|
185 | /* 4 of 8 */ uint16_t UNIQUE_NAME(reserved); // 173 |
---|
186 | /* 6 of 8 */ uint16_t UNIQUE_NAME(reserved); // 174 |
---|
187 | /* 8 of 8 */ uint16_t UNIQUE_NAME(reserved); // 175 |
---|
188 | /* 2 of 8 */ uint16_t UNIQUE_NAME(reserved); // 176 |
---|
189 | /* 4 of 8 */ uint16_t UNIQUE_NAME(reserved); // 177 |
---|
190 | /* 6 of 8 */ uint16_t UNIQUE_NAME(reserved); // 178 |
---|
191 | /* 8 of 8 */ uint16_t UNIQUE_NAME(reserved); // 179 |
---|
192 | |
---|
193 | // --- DEBUG WERTE |
---|
194 | /* 4 of 8 */ int32_t mAh_AutoMode; // 180-181 [mWh] |
---|
195 | /* 8 of 8 */ int32_t mWh_AutoMode; // 182-183 [mWh] |
---|
196 | /* 8 of 8 */ int64_t mWsCounter; // 184-187 [mWs] |
---|
197 | /* 4 of 8 */ int32_t mWhCounter; // 188-189 [mWh] |
---|
198 | /* 8 of 8 */ int32_t correctedStromForChargeWhCnt; // 190-191 Reserviert |
---|
199 | /* 2 of 8 */ uint16_t uBatEmptyTempComp; // 192 [mV] |
---|
200 | /* 4 of 8 */ uint16_t adc_restarts; // 193 |
---|
201 | /* 6 of 8 */ int16_t UNIQUE_NAME(reserved); // 194 Reserviert |
---|
202 | /* 8 of 8 */ int16_t UNIQUE_NAME(reserved); // 195 Reserviert |
---|
203 | /* 4 of 8 */ int32_t battryCurrentRaw; // 196-197 Gemessener Strom in ADC Schritte Ohne Korrekturen |
---|
204 | /* 8 of 8 */ int32_t batteryCurrentOffsetCommonModeCorrectionADCSteps; // 198-199 Offset Korrektur Wert aufgrund Common Mode Error |
---|
205 | /* 4 of 8 */ int32_t fast_current; // 200-201 |
---|
206 | /* 6 of 8 */ int32_t fast_voltage; // 202-203 |
---|
207 | /* 8 of 8 */ int16_t esrCalcStatus; // 204 |
---|
208 | /* 2 of 8 */ uint16_t esrCalcTime; // 205 |
---|
209 | /* 4 of 8 */ int16_t selfDischargeStatus; // 206 |
---|
210 | /* 6 of 8 */ uint16_t selfDischargeTime; // 207 |
---|
211 | /* 8 of 8 */ uint8_t message[24]; // 208-219 ASCII-char message, limited to 8 letters |
---|
212 | /* 4 of 8 */ int32_t current_buffer[SAMPLE_ARRAY_SIZE]; // 220-283 |
---|
213 | /* 8 of 8 */ int32_t voltage_buffer[SAMPLE_ARRAY_SIZE]; // 284-347 |
---|
214 | /* 4 of 8 */ int32_t current_buffer_fast[SAMPLE_ARRAY_SIZE]; // 348-411 |
---|
215 | /* 8 of 8 */ int32_t voltage_buffer_fast[SAMPLE_ARRAY_SIZE]; // 412-475 |
---|
216 | |
---|
217 | } device_values_t; |
---|
218 | |
---|
219 | //------------------------------------------------------------------------------ |
---|
220 | |
---|
221 | typedef struct |
---|
222 | { |
---|
223 | device_parameter_t parameter; // 0-99 |
---|
224 | device_values_t values; // 100 |
---|
225 | } sys_data_struct_t; |
---|
226 | |
---|
227 | //------------------------------------------------------------------------------ |
---|
228 | typedef volatile union |
---|
229 | { |
---|
230 | sys_data_struct_t s; |
---|
231 | bword_t mb[sizeof(sys_data_struct_t) / 2]; |
---|
232 | } sys_data_t; |
---|
233 | |
---|
234 | //------------------------------------------------------------------------------ |
---|
235 | |
---|
236 | extern sys_data_t sys_data; |
---|
237 | |
---|
238 | //------------------------------------------------------------------------------ |
---|
239 | |
---|
240 | void SYS_DATA_Init(void); |
---|
241 | |
---|
242 | #ifdef __cplusplus |
---|
243 | } |
---|
244 | #endif |
---|
245 | |
---|
246 | #endif // __SYS_DATA_H |
---|