Index: trunk/fw_g473rct/SES/src/battery_voltage.c
===================================================================
--- trunk/fw_g473rct/SES/src/battery_voltage.c	(revision 70)
+++ trunk/fw_g473rct/SES/src/battery_voltage.c	(revision 71)
@@ -13,5 +13,7 @@
 #include "main.h"
 #include "sysdata.h"
-#include <stdio.h>
+#include "stdlib.h"
+#include "stdio.h"
+
 //	--- EXTERNE VARIABLEN --------------------------------------------------------
 
@@ -24,9 +26,10 @@
 
 //	--- DEFINITIONEN GLOBALER VARIABLEN - Bitte in Header dokumentieren ----------
-
+extern ADC_HandleTypeDef hadc2;
 //	--- LOKALE VARIABLEN - bitte hier dokumentieren ------------------------------
-
+ int32_t BATTERY_VOLTAGE_adc_offset =0;
+ int32_t last_adc_value = 0 ;
 //	--- LOKALE FUNKTIONS PROTOTYPEN ----------------------------------------------
-
+void ADC2_SetOffset(uint32_t channel, int16_t offset);
 //	--- LOKALE FUNKTIONEN - bitte hier dokumentieren -----------------------------
 
@@ -39,11 +42,12 @@
   static unsigned long avgSum = 0;
   int32_t avgVal;
+  last_adc_value = newVal;
   if (measCounter < INT32_MAX) measCounter++;
 
 
   // Filterlängen in 2er-Potenzen --> Compiler optimiert
-  avgSum -= avgSum / BATTERY_VOLTAGE_FILTER;
-  avgSum += newVal;
-  avgVal =  avgSum / BATTERY_VOLTAGE_FILTER;
+  //avgSum -= avgSum / BATTERY_VOLTAGE_FILTER;
+  //avgSum += newVal;
+  //avgVal =  avgSum / BATTERY_VOLTAGE_FILTER;
 
   
@@ -51,5 +55,5 @@
 
   //Umrechung auf Eingangsspannung am Gerät mit Teiler
-  sys_data.s.values.batteryVoltage = ((avgVal-BATTERY_VOLTAGE_ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / BATTERY_VOLTAGE_ADC_RESOLUTION;
+  sys_data.s.values.batteryVoltage = ((newVal-BATTERY_VOLTAGE_ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / BATTERY_VOLTAGE_ADC_RESOLUTION;
 
   
@@ -73,5 +77,5 @@
   //Berechnung schnelle Wert ohne Glättung:
   //Umrechung auf Eingangsspannung am Gerät mit Teiler
-  sys_data.s.values.fast_voltage = ((newVal-BATTERY_VOLTAGE_ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / BATTERY_VOLTAGE_ADC_RESOLUTION;
+  //sys_data.s.values.fast_voltage = ((newVal-BATTERY_VOLTAGE_ADC_OFFSET) * VREF * BATTERY_VOLTAGE_VOLTAGE_DIVIDER ) / BATTERY_VOLTAGE_ADC_RESOLUTION;
 
 
@@ -79,3 +83,39 @@
 }
 
+    ADC_ChannelConfTypeDef sConfig = {0};
+
+void BATTERY_VOLTAGE_ZeroCal(void)
+{
+  BATTERY_VOLTAGE_adc_offset = last_adc_value - BATTERY_VOLTAGE_ADC_OFFSET;
+  
+
+
+
+
+    // 1. ADC2 stoppen und sicherstellen, dass er deaktiviert ist
+    HAL_ADC_Stop(&hadc2);
+
+  uint16_t offset_value = abs(BATTERY_VOLTAGE_adc_offset);
+
+  if (BATTERY_VOLTAGE_adc_offset < 0 )
+  {
+   ADC2->OFR1 = (ADC_OFR1_OFFSET1_EN | 
+                 (3 << ADC_OFR1_OFFSET1_CH_Pos) | 
+				 (1 << ADC_OFR1_OFFSETPOS_Pos) |
+                 (offset_value  ));
+  }
+  else 
+  {
+   ADC2->OFR1 = (ADC_OFR1_OFFSET1_EN | 
+                 (3 << ADC_OFR1_OFFSET1_CH_Pos) | 
+				 (0 << ADC_OFR1_OFFSETPOS_Pos) |
+                 (offset_value  ));
+  }
+
+  // 5. ADC2 wieder für die Wandlung starten
+  HAL_ADC_Start(&hadc2);
+}
+
+
+
 /*************************** End of file ****************************/
Index: trunk/fw_g473rct/SES/src/esr.c
===================================================================
--- trunk/fw_g473rct/SES/src/esr.c	(revision 70)
+++ trunk/fw_g473rct/SES/src/esr.c	(revision 71)
@@ -7,5 +7,5 @@
 #include "battery_voltage.h"
 #include "fast_current.h"
-
+#include "stdio.h"
 
 
@@ -14,110 +14,110 @@
 
 
-extern uint16_t adc1Data[SAMPLE_ARRAY_SIZE];
-extern uint16_t adc2Data[SAMPLE_ARRAY_SIZE];
-extern uint16_t adc4Data[SAMPLE_ARRAY_SIZE];
-
-
-int16_t ESR_Exec(void)
-{
- 
-
-  static int32_t last_refresh;
-  int x;
-
-  //Anzeige vor wieviel Sekunden zuletzt aktualisiert wurd.
-  sys_data.s.values.esrCalcTime = sys_data.s.values.onTime - last_refresh;
-
-  for (x=SAMPLE_ARRAY_SIZE-1; x>0; x--)
-  {
-    current_buffer[x] = current_buffer[x-1];
-    voltage_buffer[x] = voltage_buffer[x-1];
-  }
-
-  // Neue Werte ins array aufnehmen
-  current_buffer[0] = sys_data.s.values.batteryCurrent;
-  voltage_buffer[0] = sys_data.s.values.batteryVoltage;
-
-
-  //Suche Min und max werte im Array
-  int32_t minU=INT32_MAX;
-  int32_t maxU=0;
-  int32_t minI=INT32_MAX;
-  int32_t maxI=0;
-  int32_t minIPos = -1;
-  int32_t maxdIPos = -1;
-  int32_t minUPos = -1;
-  int32_t maxUPos = -1;
-
-  //Suche min und max werte
-  for (x=0; x < SAMPLE_ARRAY_SIZE; x++)
-  {
-     if (abs(current_buffer[x]) < minI)  { minI = abs(current_buffer[x]); minIPos  = x; }
-     if (abs(current_buffer[x]) >= maxI) { maxI = abs(current_buffer[x]); maxdIPos = x; } 
-     if (abs(voltage_buffer[x]) < minU)  { minU = abs(voltage_buffer[x]); minUPos = x; }
-     if (abs(voltage_buffer[x]) > maxU)  { maxU = abs(voltage_buffer[x]); maxUPos = x; }
-  }
-
-  
-  //Suche Zeitpunkt der größten Änderung in I
-
-  //Delta berechnen
-  int32_t dI = abs (maxI - minI);
-  int32_t dU = abs (maxU - minU);
-
-  //Minimale Belastung Prüfen ob es genügent Änderungen gab
-  // 1/20 des Nennstroms
-  // Bei 100Ah Batterie mit 0,5 Std discharge --> 50A --> /20 =2,5 A
-  int32_t min_dI;
-  min_dI = sys_data.s.parameter.cellCapacity /  sys_data.s.parameter.cellRatedDischargeTime; //Nennlaststrom  in mA
-  min_dI = min_dI / 20 ;
-
-  int32_t min_dU = 25;
-  
-  if( dI < min_dI)
-  {
-  
-    return -1;
-  }
-
-  //printf("dI change!\r\n");
-
-  if (dU < min_dU) {
-    return -2;
-  }
-
-  //printf("dU change!\r\n");
-
- 
-  int32_t dIMax=-1;
-  int32_t dIx=-1;;
-  int32_t dIMaxPos=-1;
- 
-  for (x=0; x < (SAMPLE_ARRAY_SIZE-1); x++)
-  {
-    dIx = abs(current_buffer[x+1] - current_buffer[x]); 
-    if (dIx > dIMax) { dIMax = dIx; dIMaxPos = x; } 
-  }
-
-
-
-  if (dIMaxPos == SAMPLE_ARRAY_SIZE / 2)
-  {
-    //ESR berechnen!
-    sys_data.s.values.esr = ( (double)dU / (double) dI) * 10000;
-    last_refresh = sys_data.s.values.onTime;
-
-
-    for (x=0; x < SAMPLE_ARRAY_SIZE; x++)
-    {
-      sys_data.s.values.current_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc1Data[x];
-      sys_data.s.values.voltage_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc2Data[x];
-    }
+extern uint32_t adc1Data[SAMPLE_ARRAY_SIZE];
+extern uint32_t adc2Data[SAMPLE_ARRAY_SIZE];
+extern uint32_t adc4Data[SAMPLE_ARRAY_SIZE];
+
+
+//int16_t ESR_Exec(void)
+//{
+ 
+
+//  static int32_t last_refresh;
+//  int x;
+
+//  //Anzeige vor wieviel Sekunden zuletzt aktualisiert wurd.
+//  sys_data.s.values.esrCalcTime = sys_data.s.values.onTime - last_refresh;
+
+//  for (x=SAMPLE_ARRAY_SIZE-1; x>0; x--)
+//  {
+//    current_buffer[x] = current_buffer[x-1];
+//    voltage_buffer[x] = voltage_buffer[x-1];
+//  }
+
+//  // Neue Werte ins array aufnehmen
+//  current_buffer[0] = sys_data.s.values.batteryCurrent;
+//  voltage_buffer[0] = sys_data.s.values.batteryVoltage;
+
+
+//  //Suche Min und max werte im Array
+//  int32_t minU=INT32_MAX;
+//  int32_t maxU=0;
+//  int32_t minI=INT32_MAX;
+//  int32_t maxI=0;
+//  int32_t minIPos = -1;
+//  int32_t maxdIPos = -1;
+//  int32_t minUPos = -1;
+//  int32_t maxUPos = -1;
+
+//  //Suche min und max werte
+//  for (x=0; x < SAMPLE_ARRAY_SIZE; x++)
+//  {
+//     if (abs(current_buffer[x]) < minI)  { minI = abs(current_buffer[x]); minIPos  = x; }
+//     if (abs(current_buffer[x]) >= maxI) { maxI = abs(current_buffer[x]); maxdIPos = x; } 
+//     if (abs(voltage_buffer[x]) < minU)  { minU = abs(voltage_buffer[x]); minUPos = x; }
+//     if (abs(voltage_buffer[x]) > maxU)  { maxU = abs(voltage_buffer[x]); maxUPos = x; }
+//  }
+
+  
+//  //Suche Zeitpunkt der größten Änderung in I
+
+//  //Delta berechnen
+//  int32_t dI = abs (maxI - minI);
+//  int32_t dU = abs (maxU - minU);
+
+//  //Minimale Belastung Prüfen ob es genügent Änderungen gab
+//  // 1/20 des Nennstroms
+//  // Bei 100Ah Batterie mit 0,5 Std discharge --> 50A --> /20 =2,5 A
+//  int32_t min_dI;
+//  min_dI = sys_data.s.parameter.cellCapacity /  sys_data.s.parameter.cellRatedDischargeTime; //Nennlaststrom  in mA
+//  min_dI = min_dI / 20 ;
+
+//  int32_t min_dU = 25;
+  
+//  if( dI < min_dI)
+//  {
+  
+//    return -1;
+//  }
+
+//  printf("1)dI change!\r\n");
+
+//  if (dU < min_dU) {
+//    return -2;
+//  }
+
+//  //printf("dU change!\r\n");
+
+ 
+//  int32_t dIMax=-1;
+//  int32_t dIx=-1;;
+//  int32_t dIMaxPos=-1;
+ 
+//  for (x=0; x < (SAMPLE_ARRAY_SIZE-1); x++)
+//  {
+//    dIx = abs(current_buffer[x+1] - current_buffer[x]); 
+//    if (dIx > dIMax) { dIMax = dIx; dIMaxPos = x; } 
+//  }
+
+
+
+//  if (dIMaxPos == SAMPLE_ARRAY_SIZE / 2)
+//  {
+//    //ESR berechnen!
+//    sys_data.s.values.esr = ( (double)dU / (double) dI) * 1000;
+//    last_refresh = sys_data.s.values.onTime;
+
+
+//    for (x=0; x < SAMPLE_ARRAY_SIZE; x++)
+//    {
+//      sys_data.s.values.current_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc1Data[x];
+//      sys_data.s.values.voltage_buffer[(SAMPLE_ARRAY_SIZE-1)-x] = adc2Data[x];
+//    }
 
 
     
-  }
-  return 0;
-}
+//  }
+//  return 0;
+//}
 
 
@@ -125,5 +125,5 @@
 {
  
-    
+    printf("esr\r\n");
   static int32_t last_refresh;
   int x;
@@ -150,8 +150,8 @@
 
   //Suche min und max werte
-  for (x=0; x < SAMPLE_ARRAY_SIZE; x++)
+  for (x=0; x < SAMPLE_ARRAY_SIZE -1; x++)
   {
      if (adc1Data[x] < minI)  { minI = adc1Data[x]; minIPos  = x; }
-     if (adc1Data[x] >= maxI) { maxI = adc2Data[x]; maxdIPos = x; }  
+     if (adc1Data[x] >= maxI) { maxI = adc1Data[x]; maxdIPos = x; }  
      if (adc2Data[x] < minUBatt)  { minUBatt = adc2Data[x]; minUBattPos = x; }
      if (adc2Data[x] > maxUBatt)  { maxUBatt = adc2Data[x]; maxUBattPos = x; }
@@ -184,8 +184,8 @@
   int32_t min_dI;
   min_dI = sys_data.s.parameter.cellCapacity /  sys_data.s.parameter.cellRatedDischargeTime; //Nennlaststrom  in mA
-  min_dI = min_dI / 10 ;
- 
-
-  int32_t min_dU = 10;
+  min_dI = min_dI / 100 ;
+ 
+
+ // int32_t min_dU = 10;
   
   if( abs(dI) < min_dI)
@@ -195,5 +195,5 @@
   }
 
-  //printf("dI change!\r\n");
+  printf("2)dI change!\r\n");
 
   //if (abs(dU) < min_dU) {
@@ -221,6 +221,6 @@
 
   //ESR berechnen!
-  sys_data.s.values.esr_fast = ( (double)dUBatt / (double) dI) * 10000;
-  sys_data.s.values.esr =	   ( (double)dUOut  / (double) dI) * 10000;
+  sys_data.s.values.esr_fast = ( (double)dUBatt / (double) dI) * 1000;
+  sys_data.s.values.esr =	   ( (double)dUOut  / (double) dI) * 1000;
   last_refresh = sys_data.s.values.onTime;
 	
Index: trunk/fw_g473rct/SES/src/ltc_current.c
===================================================================
--- trunk/fw_g473rct/SES/src/ltc_current.c	(revision 70)
+++ trunk/fw_g473rct/SES/src/ltc_current.c	(revision 71)
@@ -45,12 +45,21 @@
 
 
-  //Umrechnung in °C mit LM61 Sensor
+  #if DEVICETYPE == 125
   temp1 = temp1 * 600; //6 / 20 / 0.0005; 
   temp2 = temp2 * 600; //6 / 20 / 0.0005;
+  #elif DEVICETYPE == 250
+  temp1 = temp1 /  20;
+  temp1 = temp1 * 6;
+  temp1 = temp1 / 0.000250;
+  temp2 = temp2 /  20;
+  temp2 = temp2 * 6;
+  temp2 = temp2 / 0.000250;
+  #endif
 
-  //2Nackommastellen
-  //milli grad in grad * 100 /festkomma
-  sys_data.s.values.ltc_discharge_current = temp1; 
-  sys_data.s.values.ltc_charge_current = temp2; 
+
+  //Nur Amperere
+  //
+  sys_data.s.values.ltc_discharge_current = temp1/1000; 
+  sys_data.s.values.ltc_charge_current = temp2/1000; 
 
 
