Changeset 71 for trunk/fw_g473rct/SES/src/esr.c
- Timestamp:
- Jun 5, 2026, 1:30:00 PM (5 days ago)
- File:
-
- 1 edited
-
trunk/fw_g473rct/SES/src/esr.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/fw_g473rct/SES/src/esr.c
r55 r71 7 7 #include "battery_voltage.h" 8 8 #include "fast_current.h" 9 9 #include "stdio.h" 10 10 11 11 … … 14 14 15 15 16 extern uint 16_t adc1Data[SAMPLE_ARRAY_SIZE];17 extern uint 16_t adc2Data[SAMPLE_ARRAY_SIZE];18 extern uint 16_t adc4Data[SAMPLE_ARRAY_SIZE];19 20 21 int16_t ESR_Exec(void)22 {23 24 25 static int32_t last_refresh;26 int x;27 28 //Anzeige vor wieviel Sekunden zuletzt aktualisiert wurd.29 sys_data.s.values.esrCalcTime = sys_data.s.values.onTime - last_refresh;30 31 for (x=SAMPLE_ARRAY_SIZE-1; x>0; x--)32 {33 current_buffer[x] = current_buffer[x-1];34 voltage_buffer[x] = voltage_buffer[x-1];35 }36 37 // Neue Werte ins array aufnehmen38 current_buffer[0] = sys_data.s.values.batteryCurrent;39 voltage_buffer[0] = sys_data.s.values.batteryVoltage;40 41 42 //Suche Min und max werte im Array43 int32_t minU=INT32_MAX;44 int32_t maxU=0;45 int32_t minI=INT32_MAX;46 int32_t maxI=0;47 int32_t minIPos = -1;48 int32_t maxdIPos = -1;49 int32_t minUPos = -1;50 int32_t maxUPos = -1;51 52 //Suche min und max werte53 for (x=0; x < SAMPLE_ARRAY_SIZE; x++)54 {55 if (abs(current_buffer[x]) < minI) { minI = abs(current_buffer[x]); minIPos = x; }56 if (abs(current_buffer[x]) >= maxI) { maxI = abs(current_buffer[x]); maxdIPos = x; }57 if (abs(voltage_buffer[x]) < minU) { minU = abs(voltage_buffer[x]); minUPos = x; }58 if (abs(voltage_buffer[x]) > maxU) { maxU = abs(voltage_buffer[x]); maxUPos = x; }59 }60 61 62 //Suche Zeitpunkt der größten Änderung in I63 64 //Delta berechnen65 int32_t dI = abs (maxI - minI);66 int32_t dU = abs (maxU - minU);67 68 //Minimale Belastung Prüfen ob es genügent Änderungen gab69 // 1/20 des Nennstroms70 // Bei 100Ah Batterie mit 0,5 Std discharge --> 50A --> /20 =2,5 A71 int32_t min_dI;72 min_dI = sys_data.s.parameter.cellCapacity / sys_data.s.parameter.cellRatedDischargeTime; //Nennlaststrom in mA73 min_dI = min_dI / 20 ;74 75 int32_t min_dU = 25;76 77 if( dI < min_dI)78 {79 80 return -1;81 }82 83 //printf("dI change!\r\n");84 85 if (dU < min_dU) {86 return -2;87 }88 89 //printf("dU change!\r\n");90 91 92 int32_t dIMax=-1;93 int32_t dIx=-1;;94 int32_t dIMaxPos=-1;95 96 for (x=0; x < (SAMPLE_ARRAY_SIZE-1); x++)97 {98 dIx = abs(current_buffer[x+1] - current_buffer[x]);99 if (dIx > dIMax) { dIMax = dIx; dIMaxPos = x; }100 }101 102 103 104 if (dIMaxPos == SAMPLE_ARRAY_SIZE / 2)105 {106 //ESR berechnen!107 sys_data.s.values.esr = ( (double)dU / (double) dI) * 10000;108 last_refresh = sys_data.s.values.onTime;109 110 111 for (x=0; x < SAMPLE_ARRAY_SIZE; x++)112 {113 sys_data.s.values.current_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc1Data[x];114 sys_data.s.values.voltage_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc2Data[x];115 }16 extern uint32_t adc1Data[SAMPLE_ARRAY_SIZE]; 17 extern uint32_t adc2Data[SAMPLE_ARRAY_SIZE]; 18 extern uint32_t adc4Data[SAMPLE_ARRAY_SIZE]; 19 20 21 //int16_t ESR_Exec(void) 22 //{ 23 24 25 // static int32_t last_refresh; 26 // int x; 27 28 // //Anzeige vor wieviel Sekunden zuletzt aktualisiert wurd. 29 // sys_data.s.values.esrCalcTime = sys_data.s.values.onTime - last_refresh; 30 31 // for (x=SAMPLE_ARRAY_SIZE-1; x>0; x--) 32 // { 33 // current_buffer[x] = current_buffer[x-1]; 34 // voltage_buffer[x] = voltage_buffer[x-1]; 35 // } 36 37 // // Neue Werte ins array aufnehmen 38 // current_buffer[0] = sys_data.s.values.batteryCurrent; 39 // voltage_buffer[0] = sys_data.s.values.batteryVoltage; 40 41 42 // //Suche Min und max werte im Array 43 // int32_t minU=INT32_MAX; 44 // int32_t maxU=0; 45 // int32_t minI=INT32_MAX; 46 // int32_t maxI=0; 47 // int32_t minIPos = -1; 48 // int32_t maxdIPos = -1; 49 // int32_t minUPos = -1; 50 // int32_t maxUPos = -1; 51 52 // //Suche min und max werte 53 // for (x=0; x < SAMPLE_ARRAY_SIZE; x++) 54 // { 55 // if (abs(current_buffer[x]) < minI) { minI = abs(current_buffer[x]); minIPos = x; } 56 // if (abs(current_buffer[x]) >= maxI) { maxI = abs(current_buffer[x]); maxdIPos = x; } 57 // if (abs(voltage_buffer[x]) < minU) { minU = abs(voltage_buffer[x]); minUPos = x; } 58 // if (abs(voltage_buffer[x]) > maxU) { maxU = abs(voltage_buffer[x]); maxUPos = x; } 59 // } 60 61 62 // //Suche Zeitpunkt der größten Änderung in I 63 64 // //Delta berechnen 65 // int32_t dI = abs (maxI - minI); 66 // int32_t dU = abs (maxU - minU); 67 68 // //Minimale Belastung Prüfen ob es genügent Änderungen gab 69 // // 1/20 des Nennstroms 70 // // Bei 100Ah Batterie mit 0,5 Std discharge --> 50A --> /20 =2,5 A 71 // int32_t min_dI; 72 // min_dI = sys_data.s.parameter.cellCapacity / sys_data.s.parameter.cellRatedDischargeTime; //Nennlaststrom in mA 73 // min_dI = min_dI / 20 ; 74 75 // int32_t min_dU = 25; 76 77 // if( dI < min_dI) 78 // { 79 80 // return -1; 81 // } 82 83 // printf("1)dI change!\r\n"); 84 85 // if (dU < min_dU) { 86 // return -2; 87 // } 88 89 // //printf("dU change!\r\n"); 90 91 92 // int32_t dIMax=-1; 93 // int32_t dIx=-1;; 94 // int32_t dIMaxPos=-1; 95 96 // for (x=0; x < (SAMPLE_ARRAY_SIZE-1); x++) 97 // { 98 // dIx = abs(current_buffer[x+1] - current_buffer[x]); 99 // if (dIx > dIMax) { dIMax = dIx; dIMaxPos = x; } 100 // } 101 102 103 104 // if (dIMaxPos == SAMPLE_ARRAY_SIZE / 2) 105 // { 106 // //ESR berechnen! 107 // sys_data.s.values.esr = ( (double)dU / (double) dI) * 1000; 108 // last_refresh = sys_data.s.values.onTime; 109 110 111 // for (x=0; x < SAMPLE_ARRAY_SIZE; x++) 112 // { 113 // sys_data.s.values.current_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc1Data[x]; 114 // sys_data.s.values.voltage_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc2Data[x]; 115 // } 116 116 117 117 118 118 119 }120 return 0;121 }119 // } 120 // return 0; 121 //} 122 122 123 123 … … 125 125 { 126 126 127 127 printf("esr\r\n"); 128 128 static int32_t last_refresh; 129 129 int x; … … 150 150 151 151 //Suche min und max werte 152 for (x=0; x < SAMPLE_ARRAY_SIZE ; x++)152 for (x=0; x < SAMPLE_ARRAY_SIZE -1; x++) 153 153 { 154 154 if (adc1Data[x] < minI) { minI = adc1Data[x]; minIPos = x; } 155 if (adc1Data[x] >= maxI) { maxI = adc 2Data[x]; maxdIPos = x; }155 if (adc1Data[x] >= maxI) { maxI = adc1Data[x]; maxdIPos = x; } 156 156 if (adc2Data[x] < minUBatt) { minUBatt = adc2Data[x]; minUBattPos = x; } 157 157 if (adc2Data[x] > maxUBatt) { maxUBatt = adc2Data[x]; maxUBattPos = x; } … … 184 184 int32_t min_dI; 185 185 min_dI = sys_data.s.parameter.cellCapacity / sys_data.s.parameter.cellRatedDischargeTime; //Nennlaststrom in mA 186 min_dI = min_dI / 10 ;187 188 189 int32_t min_dU = 10;186 min_dI = min_dI / 100 ; 187 188 189 // int32_t min_dU = 10; 190 190 191 191 if( abs(dI) < min_dI) … … 195 195 } 196 196 197 //printf("dI change!\r\n");197 printf("2)dI change!\r\n"); 198 198 199 199 //if (abs(dU) < min_dU) { … … 221 221 222 222 //ESR berechnen! 223 sys_data.s.values.esr_fast = ( (double)dUBatt / (double) dI) * 1000 0;224 sys_data.s.values.esr = ( (double)dUOut / (double) dI) * 1000 0;223 sys_data.s.values.esr_fast = ( (double)dUBatt / (double) dI) * 1000; 224 sys_data.s.values.esr = ( (double)dUOut / (double) dI) * 1000; 225 225 last_refresh = sys_data.s.values.onTime; 226 226
Note:
See TracChangeset
for help on using the changeset viewer.
