Ignore:
Timestamp:
Sep 7, 2025, 3:51:43 PM (7 weeks ago)
Author:
f.jahn
Message:

RTC implementiert

File:
1 edited

Legend:

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

    r20 r25  
    44#include "esr.h"
    55#include <stdlib.h>
    6 #include <stdio.h>
     6#include "main.h"
     7#include "battery_voltage.h"
     8#include "fast_current.h"
     9
    710
    811
    912int32_t current_buffer[SAMPLE_ARRAY_SIZE]; 
    1013int32_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
     17extern uint16_t adc12Data[SAMPLE_ARRAY_SIZE][2];
    1318
    1419
     
    105110    for (x=0; x < SAMPLE_ARRAY_SIZE; x++)
    106111    {
    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];
    109114    }
    110115
     
    126131  sys_data.s.values.esrCalcTime = sys_data.s.values.onTime - last_refresh;
    127132
    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 aufnehmen
    135   current_buffer_fast[0] = sys_data.s.values.fast_current;
    136   voltage_buffer_fast[0] = sys_data.s.values.shuntVoltage;
    137133
    138134
     
    150146  for (x=0; x < SAMPLE_ARRAY_SIZE; x++)
    151147  {
    152      if (abs(current_buffer_fast[x]) < minI)  { minI = abs(current_buffer_fast[x]); minIPos  = x; }
    153      if (abs(current_buffer_fast[x]) >= maxI) { maxI = abs(current_buffer_fast[x]); maxdIPos = x; } 
    154      if (abs(voltage_buffer_fast[x]) < minU)  { minU = abs(voltage_buffer_fast[x]); minUPos = x; }
    155      if (abs(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; }
    156152  }
    157153
     
    160156
    161157  //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 
    164167
    165168  //Minimale Belastung Prüfen ob es genügent Änderungen gab
     
    168171  int32_t min_dI;
    169172  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)
    175179  {
    176180 
     
    180184  //printf("dI change!\r\n");
    181185
    182   if (dU < min_dU) {
     186  if (abs(dU) < min_dU) {
    183187    return -2;
    184188  }
     
    191195  int32_t dIMaxPos=-1;
    192196 
     197
     198
     199  //Finde Position der flanke
    193200  for (x=0; x < (SAMPLE_ARRAY_SIZE-1); x++)
    194201  {
    195     dIx = abs(current_buffer_fast[x+1] - current_buffer_fast[x]);
     202    dIx = adc12Data[x+1][0] - adc12Data[x][0];
    196203    if (dIx > dIMax) { dIMax = dIx; dIMaxPos = x; }
    197204  }
    198205
    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 
    218227  return 0;   
    219228}
Note: See TracChangeset for help on using the changeset viewer.