Changeset 26 for trunk/fw_g473rct/SES/src
- Timestamp:
- Sep 8, 2025, 6:57:30 PM (7 weeks ago)
- Location:
- trunk/fw_g473rct/SES/src
- Files:
-
- 7 edited
-
ah_counter.c (modified) (1 diff)
-
eeprom.c (modified) (16 diffs)
-
esr.c (modified) (4 diffs)
-
fast_current.c (modified) (2 diffs)
-
modbus.c (modified) (3 diffs)
-
sysdata.c (modified) (1 diff)
-
wh_counter.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fw_g473rct/SES/src/ah_counter.c
r20 r26 175 175 sys_data.s.values.mAhCounter = sys_data.s.values.mAsCounter / 3600LL; 176 176 177 static uint16_t lowVoltageCnt; 178 if (sys_data.s.values.batteryVoltage < sys_data.s.values.uBatEmptyTempComp && sys_data.s.values.batteryVoltage > 1000) 179 { 180 lowVoltageCnt++; 181 if ((lowVoltageCnt >= 10) && (startMeasurement == 1)) // 5 Sekunden fest 182 { 183 lowVoltageCnt = 10; //sys_data.s.parameter.tBatFull; 184 185 if ((sys_data.s.values.lastTimeVbatFull >= 3600U) && (sys_data.s.values.lastTimeVbatFull <= 200U * 3600U)) // This line prevents from very high discharge-currents to be used to estimate battery capacity 186 { 187 // This line is not so important anymore, because we do not allow mAh_AutoMode to be greater than zero 188 sys_data.s.values.detectedCapacity = sys_data.s.values.mAh_AutoMode >= 0 ? sys_data.s.values.mAh_AutoMode : -sys_data.s.values.mAh_AutoMode; 189 WH_COUNTER_SetDetectedEnergy(); 190 startMeasurement = 0; 191 EEPROM_storeConfig(&sys_data, 0); // Saving detected values 192 } 193 sys_data.s.values.lastTimeVbatEmpty = 0U; 194 } 195 } 196 else lowVoltageCnt = 0; 197 177 static uint16_t cnt; 178 if (sys_data.s.parameter.batteryEmptyDetectionMode == 0) 179 { 180 if (sys_data.s.values.batteryVoltage < sys_data.s.values.uBatEmptyTempComp && sys_data.s.values.batteryVoltage > 1000) // Verhindert das beim abziehen der Sense ein Batt Empty erkannt wird 181 { 182 cnt++; 183 if ((cnt >= 10) && (startMeasurement == 1)) // 5 Sekunden fest 184 { 185 cnt = 10; //sys_data.s.parameter.tBatFull; 186 187 if ((sys_data.s.values.lastTimeVbatFull >= 3600U) && (sys_data.s.values.lastTimeVbatFull <= 200U * 3600U)) // This line prevents from very high discharge-currents to be used to estimate battery capacity 188 { 189 // This line is not so important anymore, because we do not allow mAh_AutoMode to be greater than zero 190 sys_data.s.values.detectedCapacity = sys_data.s.values.mAh_AutoMode >= 0 ? sys_data.s.values.mAh_AutoMode : -sys_data.s.values.mAh_AutoMode; 191 WH_COUNTER_SetDetectedEnergy(); 192 startMeasurement = 0; 193 } 194 sys_data.s.values.lastTimeVbatEmpty = 0U; 195 } 196 } 197 else 198 { 199 cnt = 0; 200 } 201 } 202 else 203 { 204 // Neuer Modus. Spannungsmessung wird ignoriert. Erkannt wird Batt Leer mit LVP Signal von LiPro 205 // OVP darf nicht ausgehen, sonst handelt es sich um ein Temperaturabschaltung oder ein andere Fehler 206 // 1000mV als Schwelle um sicher vor rauschen um den Nullpunkt zu seinzu sein 207 if ((sys_data.s.values.ovp_sense > 1000) && (sys_data.s.values.lvp_sense < 1000)) 208 { 209 cnt++; 210 if ((cnt >= 10) && (startMeasurement == 1)) // 5 Sekunden fest 211 { 212 cnt = 10; //sys_data.s.parameter.tBatFull; 213 214 if ((sys_data.s.values.lastTimeVbatFull >= 3600U) && (sys_data.s.values.lastTimeVbatFull <= 240U * 3600U)) // This line prevents from very high discharge-currents to be used to estimate battery capacity 215 { 216 // This line is not so important anymore, because we do not allow mAh_AutoMode to be greater than zero 217 sys_data.s.values.detectedCapacity = sys_data.s.values.mAh_AutoMode >= 0 ? sys_data.s.values.mAh_AutoMode : -sys_data.s.values.mAh_AutoMode; 218 WH_COUNTER_SetDetectedEnergy(); 219 startMeasurement = 0; 220 } 221 sys_data.s.values.lastTimeVbatEmpty = 0U; 222 } 223 } 224 else 225 { 226 cnt = 0; 227 } 228 } 198 229 199 230 -
trunk/fw_g473rct/SES/src/eeprom.c
r25 r26 4 4 #include "stdio.h" 5 5 #include "math.h" 6 #include "modbus.h" 6 7 7 8 #define CONCAT(a, b) CONCAT_INNER(a, b) // These three macros … … 57 58 uint32_t currentGain; 58 59 60 int32_t currentOffsetFast; 61 uint32_t currentGainFast; 62 59 63 int64_t mAsCounter; 60 64 int32_t detectedCapacity; … … 97 101 uint16_t cefW; 98 102 99 100 103 } eeprom_data_t; 101 104 … … 136 139 137 140 // Data to store reated defines 138 //#define SIZEOF_DEFAULT_EEPROM_DATA (sizeof(eeprom_new_data_t))141 //#define SIZEOF_DEFAULT_EEPROM_DATA (sizeof(eeprom_new_data_t)) 139 142 #define SIZEOF_CHANGED_EEPROM_DATA (sizeof(eeprom_data_t)) 140 143 #define SIZEOF_DEVICE_INFO (sizeof(device_info_t)) … … 156 159 static uint32_t GetPage(uint32_t Address); 157 160 static HAL_StatusTypeDef getEEPROMData(uint32_t address, uint8_t * data, uint32_t len); 158 159 161 void EEPROM_Read (uint16_t page, uint16_t offset, uint8_t *data, uint16_t size); 160 162 void EEPROM_Write (uint16_t page, uint16_t offset, uint8_t *data, uint16_t size); … … 162 164 163 165 164 165 166 // muss modulo 8 noch hinzufügen wg 8 byte alignement 166 167 static uint8_t eepromData[SIZE_OF_DATA_TO_STORE]; … … 174 175 175 176 /* baudrate */ 19200, // uint32_t baudrate; 176 /* parityMode */ 0,// uint16_t parityMode;177 /* parityMode */ MODBUS_UART_PARITY_EVEN, // uint16_t parityMode; 177 178 /* stopBits */ 1, // uint16_t stopBits; 178 179 /* slave_adress */ 1, // uint16_t slave_adress; … … 202 203 /* currentGain */ 1000000, //uint32_t currentGain; 203 204 205 /* currentOffsetFast */ 0, //int32_t currentOffset; 206 /* currentGainFast */ 1000000, //uint32_t currentGain; 207 204 208 /* mAsCounter */ 0, // mAsCounter 205 209 /* detectedCapacity */ -1, // detectedCapacity … … 212 216 /* cef */ 99, // cef 213 217 /* peukert */ 105, // peukert 214 /* cellCapacity */ 1 00000, // cell Capacity in mAh215 /* cellEnergy */ 2 640000, // cell energy in mWh216 /* iBatFull */ 10, // I-batt full 4% 4A bei 100Ah akku218 /* cellCapacity */ 160000, // cell Capacity in mAh 219 /* cellEnergy */ 2048000, // cell energy in mWh 220 /* iBatFull */ 10, // I-batt full 10%, 10A bei 100Ah akku 217 221 /* tBatFull */ 2, // t-batt full 2 Sekunden 218 /* uBatFull */ 14000, // 14Volt Ubatt full219 /* uBatEmpty */ 12500,// 11,312V Ubatt Empty222 /* uBatFull */ 0, // 14V olt Ubatt full, Neu: Bei 0: Erkung von Lipro LVP als 0% 223 /* uBatEmpty */ -1, // 11,312V Ubatt Empty 220 224 /* socCalcMode */ 1, // SoC calculation mode: 0(default) 221 225 /* cellRatedDischargeTime */ 2, // cell rated current discharge time [C/x]. For example, if 40Ah cell is rated as 0.5c, then rated discharge time is 2 … … 223 227 /* lvpStart */ 12000, // uint16_t lvpStart; Spannung ab der die LOW Voltage Protection aktiv wird in mV 224 228 /* lvpStop */ 12500, // uint16_t lvpStop; Spannung ab der die LOW Voltage Protection wieder inaktiv wird 225 /* ovpStart */ 1 5000, // uint16_t ovpStart; Spannung ab der die OVER Voltage Protection aktiv wird in mV229 /* ovpStart */ 14800, // uint16_t ovpStart; Spannung ab der die OVER Voltage Protection aktiv wird in mV 226 230 /* ovpStop */ 14000, // uint16_t ovpStop; Spannung ab der die OVER Voltage Protection wieder inaktiv wird 227 231 … … 238 242 #error No valid device type 239 243 #endif 240 /* chargeStopHighTemperatureStart */ 7500, // 80°C int16_t chargeStopHighTemperatureStart; Abschalttemperatur Ladung wegen zu hoher Temperatur241 /* chargeStopHighTemperatureStop */ 7000, // 75°C int16_t chargeStopHighTemperatureStop; Wiedereinschalttemperatur242 /* chargeStopLowTemperatureStart */ -3 500, // -35°C int16_t chargeStopLowTemperatureStart; Abschalttemperatur Ladung wegen zu niedriger Temperatur243 /* chargeStopLowTemperatureStop */ - 3000, // -30°C int16_t chargeStopLowTemperatureStop; Wiedereinschalttemperatur244 /* dischargeStopHighTemperatureStart*/ 7500, // 80°C int16_t dischargeStopHighTemperatureStart; Abschalttemperatur Entladung wegen zu hoher Temperatur245 /* dischargeStopHighTemperatureStop */ 7000, // 75°C int16_t dischargeStopHighTemperatureStop; Wiedereinschalttemperatur244 /* chargeStopHighTemperatureStart */ 6000, // 80°C int16_t chargeStopHighTemperatureStart; Abschalttemperatur Ladung wegen zu hoher Temperatur 245 /* chargeStopHighTemperatureStop */ 5500, // 75°C int16_t chargeStopHighTemperatureStop; Wiedereinschalttemperatur 246 /* chargeStopLowTemperatureStart */ -3000, // -35°C int16_t chargeStopLowTemperatureStart; Abschalttemperatur Ladung wegen zu niedriger Temperatur 247 /* chargeStopLowTemperatureStop */ -2500, // -30°C int16_t chargeStopLowTemperatureStop; Wiedereinschalttemperatur 248 /* dischargeStopHighTemperatureStart*/ 6000, // 80°C int16_t dischargeStopHighTemperatureStart; Abschalttemperatur Entladung wegen zu hoher Temperatur 249 /* dischargeStopHighTemperatureStop */ 5500, // 75°C int16_t dischargeStopHighTemperatureStop; Wiedereinschalttemperatur 246 250 /* dischargeStopLowTemperatureStart */ -3500, // -35°C int16_t dischargeStopLowTemperatureStart; Abschalttemperatur EntLadung wegen zu niedriger Temperatur 247 251 /* dischargeStopLowTemperatureStop */ -3000, // -30°C int16_t dischargeStopLowTemperatureStop; Wiedereinschalttemperatur … … 330 334 dataToStore->changedData.currentGain = defaultEepromData.currentGain; 331 335 336 dataToStore->changedData.currentOffsetFast = defaultEepromData.currentOffsetFast; 337 dataToStore->changedData.currentGainFast = defaultEepromData.currentGainFast; 338 332 339 // AH Counter Parameter 333 340 dataToStore->changedData.cef = defaultEepromData.cef; … … 403 410 404 411 // Offset und Gain 405 dataToStore->changedData.currentOffset = data->s.parameter.batteryCurrentOffset;412 406 413 dataToStore->changedData.batteryCurrentOffsetRefTemperatureShunt = data->s.parameter.batteryCurrentOffsetRefTemperatureShunt; 407 414 dataToStore->changedData.batteryCurrentOffsetRefTemperatureChip = data->s.parameter.batteryCurrentOffsetRefTemperatureChip; … … 411 418 dataToStore->changedData.batteryCurrentOffsetTemperatureCalibrationTemperature = data->s.parameter.batteryCurrentOffsetTemperatureCalibrationTemperature; 412 419 dataToStore->changedData.batteryCurrentOffsetTemperatureCompensationFactor = data->s.parameter.batteryCurrentOffsetTemperatureCompensationFactor; 420 dataToStore->changedData.currentOffset = data->s.parameter.batteryCurrentOffset; 413 421 dataToStore->changedData.currentGain = data->s.parameter.batteryCurrentGainCorrectionFaktor; 422 dataToStore->changedData.currentOffsetFast = data->s.parameter.batteryCurrentOffsetFast; 423 dataToStore->changedData.currentGainFast = data->s.parameter.batteryCurrentGainCorrectionFaktorFast; 424 414 425 dataToStore->changedData.batteryCurrentGainRefTempShunt = data->s.parameter.batteryCurrentGainRefTempShunt; 415 426 dataToStore->changedData.batteryCurrentGainRefTempChip = data->s.parameter.batteryCurrentGainRefTempChip; … … 520 531 dataToStore->changedData.currentOffset = data->s.parameter.batteryCurrentOffset; 521 532 dataToStore->changedData.currentGain = data->s.parameter.batteryCurrentGainCorrectionFaktor; 533 534 dataToStore->changedData.currentOffsetFast = data->s.parameter.batteryCurrentOffsetFast; 535 dataToStore->changedData.currentGainFast = data->s.parameter.batteryCurrentGainCorrectionFaktorFast; 536 522 537 523 538 // AH COUNTER Einstellungen … … 616 631 data->s.parameter.batteryCurrentGainCorrectionFaktor = dataToStore->changedData.currentGain; 617 632 633 data->s.parameter.batteryCurrentOffsetFast = dataToStore->changedData.currentOffsetFast; 634 data->s.parameter.batteryCurrentGainCorrectionFaktorFast = dataToStore->changedData.currentGainFast; 635 618 636 //Einstellungenm für AH counter 619 637 data->s.parameter.cef = dataToStore ->changedData.cef; -
trunk/fw_g473rct/SES/src/esr.c
r25 r26 104 104 { 105 105 //ESR berechnen! 106 sys_data.s.values.esr = ( (double)dU / (double) dI) * 1000 ;106 sys_data.s.values.esr = ( (double)dU / (double) dI) * 10000; 107 107 last_refresh = sys_data.s.values.onTime; 108 108 … … 129 129 130 130 //Anzeige vor wieviel Sekunden zuletzt aktualisiert wurd. 131 sys_data.s.values.esrCalcTime = sys_data.s.values.onTime - last_refresh; 131 //Aktuell erfolgt nur die Anze der low speed Methode 132 //sys_data.s.values.esrCalcTime = sys_data.s.values.onTime - last_refresh; 132 133 133 134 … … 153 154 154 155 155 //Suche Zeitpunkt der größten Änderung in I 156 156 157 157 158 //Delta berechnen 158 159 int32_t dI = maxI - minI; 159 int32_t dU = maxU - minU; 160 161 //Nehme nicht mehr die gesamte maximale Differenz der Spannungen, sondern nehme das delt U wo auch das Delta I gemessen wurde 162 //Funktioniert nur bei Synchroner Messug von Strom und Spannung 163 //int32_t dU = maxU - minU; 164 int32_t dU = adc12Data[maxdIPos][1] - adc12Data[minIPos][1]; 160 165 161 166 //Umrechnung in mV / mA 162 dI = dI * (( int64_t) VREF / FAST_CURRENT_SHUNT_RESISTOR / FAST_CURRENT_I_SENSE_GAIN / FAST_CURRENT_ADC_RESOLUTION);167 dI = dI * ((double) VREF / FAST_CURRENT_SHUNT_RESISTOR / FAST_CURRENT_I_SENSE_GAIN / FAST_CURRENT_ADC_RESOLUTION); 163 168 dI = dI * (sys_data.s.parameter.batteryCurrentGainCorrectionFaktor / 1000000.0); 164 169 165 dU = dU * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER / BATTERY_VOLTAGE_ADC_RESOLUTION ;170 dU = dU * (double )VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER / BATTERY_VOLTAGE_ADC_RESOLUTION ; 166 171 167 172 … … 204 209 } 205 210 206 if ((dIMaxPos < 5 ) || (dIMaxPos > (SAMPLE_ARRAY_SIZE-5) ))207 {208 return -3;209 }211 //if ((dIMaxPos < 5 ) || (dIMaxPos > (SAMPLE_ARRAY_SIZE-5) )) 212 //{ 213 // return -3; 214 // } 210 215 211 216 212 217 //ESR berechnen! 213 sys_data.s.values.esr_fast = ( (double)dU / (double) dI) * 1000 ;218 sys_data.s.values.esr_fast = ( (double)dU / (double) dI) * 10000; 214 219 last_refresh = sys_data.s.values.onTime; 215 220 -
trunk/fw_g473rct/SES/src/fast_current.c
r25 r26 32 32 33 33 // --- GLOBALE FUNKTIONEN - bitte in Header dokumentieren------------------------ 34 void CurrentOffsetCal(uint32_t newVal) 35 { 36 sys_data.s.parameter.batteryCurrentOffsetFast = newVal-FAST_CURRENT_ADC_OFFSET; 37 } 34 38 39 void CurrentGainCal(uint32_t newVal) 40 { 41 double correction; 42 double valWithoutGainCorrection; 35 43 44 valWithoutGainCorrection = ((int32_t) newVal - FAST_CURRENT_ADC_OFFSET - sys_data.s.parameter.batteryCurrentOffsetFast) * VREF ; 45 valWithoutGainCorrection = valWithoutGainCorrection / FAST_CURRENT_ADC_RESOLUTION; 46 valWithoutGainCorrection = valWithoutGainCorrection / FAST_CURRENT_I_SENSE_GAIN ; 47 valWithoutGainCorrection = valWithoutGainCorrection / FAST_CURRENT_SHUNT_RESISTOR ; 48 49 correction = (double) sys_data.s.parameter.batteryCurrentGainRefCurrent / valWithoutGainCorrection; 50 sys_data.s.parameter.batteryCurrentGainCorrectionFaktorFast = correction * 1000000; 51 52 } 36 53 void FAST_CURRENT_Exec(uint32_t newVal ) 37 54 { … … 39 56 //Umrechung auf Strom 40 57 double temp_current; 41 temp_current = ((int32_t) newVal - FAST_CURRENT_ADC_OFFSET ) * VREF ;58 temp_current = ((int32_t) newVal - FAST_CURRENT_ADC_OFFSET - sys_data.s.parameter.batteryCurrentOffsetFast) * VREF ; 42 59 temp_current = temp_current / FAST_CURRENT_ADC_RESOLUTION; 43 60 temp_current = temp_current / FAST_CURRENT_I_SENSE_GAIN ; 44 61 temp_current = temp_current / FAST_CURRENT_SHUNT_RESISTOR ; 45 sys_data.s.values.fast_current = temp_current * (sys_data.s.parameter.batteryCurrentGainCorrectionFaktor / 1000000.0);62 sys_data.s.values.fast_current = temp_current * (sys_data.s.parameter.batteryCurrentGainCorrectionFaktorFast / 1000000.0); 46 63 47 64 } -
trunk/fw_g473rct/SES/src/modbus.c
r24 r26 34 34 #define ILLEGAL_DATA_VALUE 0x03 35 35 #define SLAVE_DEVICE_FAILURE 0x04 36 #define SERVER_FAILURE 0x0436 #define SERVER_FAILURE 0x04 37 37 #define ACKNOWLEDGE 0x05 38 38 #define SLAVE_DEVICE_BUSY 0x06 … … 41 41 #define MEMORY_PARITY_ERROR 0x08 42 42 #define GATEWAY_PROBLEM_PATH 0x0A 43 #define GATEWAY_PROBLEM_TARGET 0x0B43 #define GATEWAY_PROBLEM_TARGET 0x0B 44 44 45 45 /* Local Error codes */ … … 185 185 186 186 HAL_UART_EnableReceiverTimeout( usart); 187 HAL_UART_ReceiverTimeout_Config(usart, 3.5 * nrOfBitsPerChar); 187 if (baudrate <= 19200) 188 { 189 HAL_UART_ReceiverTimeout_Config(usart, 3.5 * nrOfBitsPerChar); 190 } 191 else 192 { 193 uint32_t fixedDelayInBitDurations = (FAST_BAUDRATE_INTERFRAME_DELAY_us * baudrate) / 1000000UL + 1UL; 194 HAL_UART_ReceiverTimeout_Config(usart, fixedDelayInBitDurations); 195 } 196 197 188 198 SET_BIT(usart->Instance->CR1, USART_CR1_RTOIE); 189 199 -
trunk/fw_g473rct/SES/src/sysdata.c
r25 r26 13 13 // Gertetyp angeben 14 14 #if (DEVICETYPE == 500) 15 sys_data.s.parameter.device_type = 5 10;15 sys_data.s.parameter.device_type = 520; 16 16 #elif (DEVICETYPE == 250) 17 sys_data.s.parameter.device_type = 5 11;17 sys_data.s.parameter.device_type = 521; 18 18 #elif (DEVICETYPE == 125) 19 sys_data.s.parameter.device_type = 5 12;19 sys_data.s.parameter.device_type = 522; 20 20 #else 21 21 #error "No valid device type" -
trunk/fw_g473rct/SES/src/wh_counter.c
r20 r26 78 78 sys_data.s.values.mWhCounter = sys_data.s.values.mWsCounter / 3600LL; 79 79 80 81 82 83 80 // Counting Total Power 84 81 if (sys_data.s.values.batteryPower < 0) 85 82 { 86 83 totalDischarge += -sys_data.s.values.batteryPower; 87 sys_data.s.values.dischargeTotalWh = totalDischarge / 3600000; //Umrechnung von mWs auf Wh 88 89 90 sys_data.s.values.fullCyclesCnt = (uint16_t) ((sys_data.s.values.dischargeTotalAh * 1000) / sys_data.s.parameter.cellCapacity); 84 sys_data.s.values.dischargeTotalWh = totalDischarge / 3600000; //Umrechnung von mWs auf Wh 91 85 } 92 86 else … … 95 89 sys_data.s.values.chargeTotalWh = totalCharge / 3600000; //Umrechnung von mWs auf Wh 96 90 } 97 98 99 100 91 } 101 92
Note: See TracChangeset
for help on using the changeset viewer.
