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

vor cube code generierung

Location:
trunk/fw_g473rct/SES/src
Files:
3 edited

Legend:

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

    r38 r71  
    1313#include "main.h"
    1414#include "sysdata.h"
    15 #include <stdio.h>
     15#include "stdlib.h"
     16#include "stdio.h"
     17
    1618//      --- EXTERNE VARIABLEN --------------------------------------------------------
    1719
     
    2426
    2527//      --- DEFINITIONEN GLOBALER VARIABLEN - Bitte in Header dokumentieren ----------
    26 
     28extern ADC_HandleTypeDef hadc2;
    2729//      --- LOKALE VARIABLEN - bitte hier dokumentieren ------------------------------
    28 
     30 int32_t BATTERY_VOLTAGE_adc_offset =0;
     31 int32_t last_adc_value = 0 ;
    2932//      --- LOKALE FUNKTIONS PROTOTYPEN ----------------------------------------------
    30 
     33void ADC2_SetOffset(uint32_t channel, int16_t offset);
    3134//      --- LOKALE FUNKTIONEN - bitte hier dokumentieren -----------------------------
    3235
     
    3942  static unsigned long avgSum = 0;
    4043  int32_t avgVal;
     44  last_adc_value = newVal;
    4145  if (measCounter < INT32_MAX) measCounter++;
    4246
    4347
    4448  // Filterlängen in 2er-Potenzen --> Compiler optimiert
    45   avgSum -= avgSum / BATTERY_VOLTAGE_FILTER;
    46   avgSum += newVal;
    47   avgVal =  avgSum / BATTERY_VOLTAGE_FILTER;
     49  //avgSum -= avgSum / BATTERY_VOLTAGE_FILTER;
     50  //avgSum += newVal;
     51  //avgVal =  avgSum / BATTERY_VOLTAGE_FILTER;
    4852
    4953 
     
    5155
    5256  //Umrechung auf Eingangsspannung am Gerät mit Teiler
    53   sys_data.s.values.batteryVoltage = ((avgVal-BATTERY_VOLTAGE_ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / BATTERY_VOLTAGE_ADC_RESOLUTION;
     57  sys_data.s.values.batteryVoltage = ((newVal-BATTERY_VOLTAGE_ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / BATTERY_VOLTAGE_ADC_RESOLUTION;
    5458
    5559 
     
    7377  //Berechnung schnelle Wert ohne Glättung:
    7478  //Umrechung auf Eingangsspannung am Gerät mit Teiler
    75   sys_data.s.values.fast_voltage = ((newVal-BATTERY_VOLTAGE_ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / BATTERY_VOLTAGE_ADC_RESOLUTION;
     79  //sys_data.s.values.fast_voltage = ((newVal-BATTERY_VOLTAGE_ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / BATTERY_VOLTAGE_ADC_RESOLUTION;
    7680
    7781
     
    7983}
    8084
     85    ADC_ChannelConfTypeDef sConfig = {0};
     86
     87void BATTERY_VOLTAGE_ZeroCal(void)
     88{
     89  BATTERY_VOLTAGE_adc_offset = last_adc_value - BATTERY_VOLTAGE_ADC_OFFSET;
     90 
     91
     92
     93
     94
     95    // 1. ADC2 stoppen und sicherstellen, dass er deaktiviert ist
     96    HAL_ADC_Stop(&hadc2);
     97
     98  uint16_t offset_value = abs(BATTERY_VOLTAGE_adc_offset);
     99
     100  if (BATTERY_VOLTAGE_adc_offset < 0 )
     101  {
     102   ADC2->OFR1 = (ADC_OFR1_OFFSET1_EN |
     103                 (3 << ADC_OFR1_OFFSET1_CH_Pos) |
     104                                 (1 << ADC_OFR1_OFFSETPOS_Pos) |
     105                 (offset_value  ));
     106  }
     107  else
     108  {
     109   ADC2->OFR1 = (ADC_OFR1_OFFSET1_EN |
     110                 (3 << ADC_OFR1_OFFSET1_CH_Pos) |
     111                                 (0 << ADC_OFR1_OFFSETPOS_Pos) |
     112                 (offset_value  ));
     113  }
     114
     115  // 5. ADC2 wieder für die Wandlung starten
     116  HAL_ADC_Start(&hadc2);
     117}
     118
     119
     120
    81121/*************************** End of file ****************************/
  • 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       
  • trunk/fw_g473rct/SES/src/ltc_current.c

    r63 r71  
    4545
    4646
    47   //Umrechnung in °C mit LM61 Sensor
     47  #if DEVICETYPE == 125
    4848  temp1 = temp1 * 600; //6 / 20 / 0.0005;
    4949  temp2 = temp2 * 600; //6 / 20 / 0.0005;
     50  #elif DEVICETYPE == 250
     51  temp1 = temp1 /  20;
     52  temp1 = temp1 * 6;
     53  temp1 = temp1 / 0.000250;
     54  temp2 = temp2 /  20;
     55  temp2 = temp2 * 6;
     56  temp2 = temp2 / 0.000250;
     57  #endif
    5058
    51   //2Nackommastellen
    52   //milli grad in grad * 100 /festkomma
    53   sys_data.s.values.ltc_discharge_current = temp1;
    54   sys_data.s.values.ltc_charge_current = temp2;
     59
     60  //Nur Amperere
     61  //
     62  sys_data.s.values.ltc_discharge_current = temp1/1000;
     63  sys_data.s.values.ltc_charge_current = temp2/1000;
    5564
    5665
Note: See TracChangeset for help on using the changeset viewer.