Ignore:
Timestamp:
Jun 5, 2026, 1:30:00 PM (5 days ago)
Author:
f.jahn
Message:

vor cube code generierung

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/fw_g473rct/SES/src/esr.c

    r55 r71  
    77#include "battery_voltage.h"
    88#include "fast_current.h"
    9 
     9#include "stdio.h"
    1010
    1111
     
    1414
    1515
    16 extern uint16_t adc1Data[SAMPLE_ARRAY_SIZE];
    17 extern uint16_t adc2Data[SAMPLE_ARRAY_SIZE];
    18 extern uint16_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("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     }
     16extern uint32_t adc1Data[SAMPLE_ARRAY_SIZE];
     17extern uint32_t adc2Data[SAMPLE_ARRAY_SIZE];
     18extern 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//    }
    116116
    117117
    118118   
    119   }
    120   return 0;
    121 }
     119//  }
     120//  return 0;
     121//}
    122122
    123123
     
    125125{
    126126 
    127    
     127    printf("esr\r\n");
    128128  static int32_t last_refresh;
    129129  int x;
     
    150150
    151151  //Suche min und max werte
    152   for (x=0; x < SAMPLE_ARRAY_SIZE; x++)
     152  for (x=0; x < SAMPLE_ARRAY_SIZE -1; x++)
    153153  {
    154154     if (adc1Data[x] < minI)  { minI = adc1Data[x]; minIPos  = x; }
    155      if (adc1Data[x] >= maxI) { maxI = adc2Data[x]; maxdIPos = x; } 
     155     if (adc1Data[x] >= maxI) { maxI = adc1Data[x]; maxdIPos = x; } 
    156156     if (adc2Data[x] < minUBatt)  { minUBatt = adc2Data[x]; minUBattPos = x; }
    157157     if (adc2Data[x] > maxUBatt)  { maxUBatt = adc2Data[x]; maxUBattPos = x; }
     
    184184  int32_t min_dI;
    185185  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;
    190190 
    191191  if( abs(dI) < min_dI)
     
    195195  }
    196196
    197   //printf("dI change!\r\n");
     197  printf("2)dI change!\r\n");
    198198
    199199  //if (abs(dU) < min_dU) {
     
    221221
    222222  //ESR berechnen!
    223   sys_data.s.values.esr_fast = ( (double)dUBatt / (double) dI) * 10000;
    224   sys_data.s.values.esr =          ( (double)dUOut  / (double) dI) * 10000;
     223  sys_data.s.values.esr_fast = ( (double)dUBatt / (double) dI) * 1000;
     224  sys_data.s.values.esr =          ( (double)dUOut  / (double) dI) * 1000;
    225225  last_refresh = sys_data.s.values.onTime;
    226226       
Note: See TracChangeset for help on using the changeset viewer.