Changeset 25 for trunk/fw_g473rct/SES/src/esr.c
- Timestamp:
- Sep 7, 2025, 3:51:43 PM (7 weeks ago)
- File:
-
- 1 edited
-
trunk/fw_g473rct/SES/src/esr.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fw_g473rct/SES/src/esr.c
r20 r25 4 4 #include "esr.h" 5 5 #include <stdlib.h> 6 #include <stdio.h> 6 #include "main.h" 7 #include "battery_voltage.h" 8 #include "fast_current.h" 9 7 10 8 11 9 12 int32_t current_buffer[SAMPLE_ARRAY_SIZE]; 10 13 int32_t voltage_buffer[SAMPLE_ARRAY_SIZE]; 11 int32_t current_buffer_fast[SAMPLE_ARRAY_SIZE]; 12 int32_t voltage_buffer_fast[SAMPLE_ARRAY_SIZE]; 14 //int32_t current_buffer_fast[SAMPLE_ARRAY_SIZE]; 15 //int32_t voltage_buffer_fast[SAMPLE_ARRAY_SIZE]; 16 17 extern uint16_t adc12Data[SAMPLE_ARRAY_SIZE][2]; 13 18 14 19 … … 105 110 for (x=0; x < SAMPLE_ARRAY_SIZE; x++) 106 111 { 107 sys_data.s.values.current_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = current_buffer[x];108 sys_data.s.values.voltage_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = voltage_buffer[x];112 sys_data.s.values.current_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc12Data[x][0]; 113 sys_data.s.values.voltage_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc12Data[x][1]; 109 114 } 110 115 … … 126 131 sys_data.s.values.esrCalcTime = sys_data.s.values.onTime - last_refresh; 127 132 128 for (x=SAMPLE_ARRAY_SIZE-1; x>0; x--)129 {130 current_buffer_fast[x] = current_buffer_fast[x-1];131 voltage_buffer_fast[x] = voltage_buffer_fast[x-1];132 }133 134 // Neue Werte ins array aufnehmen135 current_buffer_fast[0] = sys_data.s.values.fast_current;136 voltage_buffer_fast[0] = sys_data.s.values.shuntVoltage;137 133 138 134 … … 150 146 for (x=0; x < SAMPLE_ARRAY_SIZE; x++) 151 147 { 152 if (a bs(current_buffer_fast[x]) < minI) { minI = abs(current_buffer_fast[x]); minIPos = x; }153 if (a bs(current_buffer_fast[x]) >= maxI) { maxI = abs(current_buffer_fast[x]); maxdIPos = x; }154 if (a bs(voltage_buffer_fast[x]) < minU) { minU = abs(voltage_buffer_fast[x]); minUPos = x; }155 if (a bs(voltage_buffer_fast[x]) > maxU) { maxU = abs(voltage_buffer_fast[x]); maxUPos = x; }148 if (adc12Data[x][0] < minI) { minI = adc12Data[x][0]; minIPos = x; } 149 if (adc12Data[x][0] >= maxI) { maxI = adc12Data[x][0]; maxdIPos = x; } 150 if (adc12Data[x][1] < minU) { minU = adc12Data[x][1]; minUPos = x; } 151 if (adc12Data[x][1] > maxU) { maxU = adc12Data[x][1]; maxUPos = x; } 156 152 } 157 153 … … 160 156 161 157 //Delta berechnen 162 int32_t dI = abs (maxI - minI); 163 int32_t dU = abs (maxU - minU); 158 int32_t dI = maxI - minI; 159 int32_t dU = maxU - minU; 160 161 //Umrechnung in mV / mA 162 dI = dI * ((int64_t) VREF / FAST_CURRENT_SHUNT_RESISTOR / FAST_CURRENT_I_SENSE_GAIN / FAST_CURRENT_ADC_RESOLUTION); 163 dI = dI * (sys_data.s.parameter.batteryCurrentGainCorrectionFaktor / 1000000.0); 164 165 dU = dU * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER / BATTERY_VOLTAGE_ADC_RESOLUTION ; 166 164 167 165 168 //Minimale Belastung Prüfen ob es genügent Änderungen gab … … 168 171 int32_t min_dI; 169 172 min_dI = sys_data.s.parameter.cellCapacity / sys_data.s.parameter.cellRatedDischargeTime; //Nennlaststrom in mA 170 min_dI = min_dI / 4 ; 171 172 int32_t min_dU = 100; 173 174 if( dI < min_dI) 173 min_dI = min_dI / 10 ; 174 175 176 int32_t min_dU = 10; 177 178 if( abs(dI) < min_dI) 175 179 { 176 180 … … 180 184 //printf("dI change!\r\n"); 181 185 182 if ( dU< min_dU) {186 if (abs(dU) < min_dU) { 183 187 return -2; 184 188 } … … 191 195 int32_t dIMaxPos=-1; 192 196 197 198 199 //Finde Position der flanke 193 200 for (x=0; x < (SAMPLE_ARRAY_SIZE-1); x++) 194 201 { 195 dIx = a bs(current_buffer_fast[x+1] - current_buffer_fast[x]);202 dIx = adc12Data[x+1][0] - adc12Data[x][0]; 196 203 if (dIx > dIMax) { dIMax = dIx; dIMaxPos = x; } 197 204 } 198 205 199 200 201 if (dIMaxPos == SAMPLE_ARRAY_SIZE / 2) 202 { 203 //ESR berechnen! 204 sys_data.s.values.esr_fast = ( (double)dU / (double) dI) * 1000; 205 last_refresh = sys_data.s.values.onTime; 206 207 208 for (x=0; x < SAMPLE_ARRAY_SIZE; x++) 209 { 210 sys_data.s.values.current_buffer_fast[(SAMPLE_ARRAY_SIZE-1)-x] = current_buffer_fast[x]; 211 sys_data.s.values.voltage_buffer_fast[(SAMPLE_ARRAY_SIZE-1)-x] = voltage_buffer_fast[x]; 212 } 213 214 215 216 217 } 206 if ((dIMaxPos < 5 ) || (dIMaxPos > (SAMPLE_ARRAY_SIZE-5) )) 207 { 208 return -3; 209 } 210 211 212 //ESR berechnen! 213 sys_data.s.values.esr_fast = ( (double)dU / (double) dI) * 1000; 214 last_refresh = sys_data.s.values.onTime; 215 216 217 for (x=0; x < SAMPLE_ARRAY_SIZE; x++) 218 { 219 sys_data.s.values.current_buffer_fast[x] = (int32_t) adc12Data[x][0] - FAST_CURRENT_ADC_OFFSET ; 220 sys_data.s.values.voltage_buffer_fast[x] = (int32_t) adc12Data[x][1] - BATTERY_VOLTAGE_ADC_OFFSET ; 221 } 222 223 224 225 226 218 227 return 0; 219 228 }
Note: See TracChangeset
for help on using the changeset viewer.
