Index: trunk/firmware_v2/SES/src/chip_temperature.c
===================================================================
--- trunk/firmware_v2/SES/src/chip_temperature.c	(revision 22)
+++ trunk/firmware_v2/SES/src/chip_temperature.c	(revision 23)
@@ -24,12 +24,10 @@
 //	--- LOKALE VARIABLEN - bitte hier dokumentieren ------------------------------
 uint32_t calTemperatureSensor30Value;  // Kalibrierungswert für den Temperatursensor auf dem STM32G0 (Werksmäßig im SCB Bereich gespeichert wird beim Programmstart ausgelesen)
-uint32_t calTemperatureSensor130Value; // Kalibrierungswert für den Temperatursensor auf dem STM32G0 (Werksmäßig im SCB Bereich gespeichert wird beim Programmstart ausgelesen)
-uint32_t calTemperatureSensorDiff;     // Differenz calTemperatureSensor130Value und calTemperatureSensor30Value wird für die Kalibrierung des internen Temperatursensors bentigt
-                                                              // Daten Temperaturanzeige µProzessor
+                                                 // Daten Temperaturanzeige µProzessor
 
 //	--- LOKALE FUNKTIONS PROTOTYPEN ----------------------------------------------
 
 void calc_temp_compensation(void);
-int16_t y(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x);
+
 
 //	--- LOKALE FUNKTIONEN - bitte hier dokumentieren -----------------------------
@@ -52,39 +50,23 @@
   calibrationData30  = * pCalibrationData;
 
-
   //Berechnung Spannung in mV bei CAL Punk 30°C
   //Kalbibrierung wurde mit 12 Bit und 3000mV Vref durchgeführt
   calibrationData30 = calibrationData30 / 4096;
   calTemperatureSensor30Value = calibrationData30 * 3000 ;      // jetzt haben wir die Kalibrierungsspannung in mVolt bei 30°C;
-
-  //pCalibrationData = (uint16_t *)TEMPSENSOR_CAL2_ADDR;
-  //calibrationData130  = * pCalibrationData;
-  calibrationData130  = calibrationData30 + 343;
-
-  //Berechnung Spannung in mV bei CAL Punk 130°C
-  //Kalbibrierung wurde mit 12 Bit und 3000mV Vref durchgeführt
-  calibrationData130 = calibrationData130 / 4096;
-  calTemperatureSensor130Value = calibrationData130 * 3000;      // jetzt haben wir die Kalibrierungsspannung in mV bei 130°C;
-
-  // Spannungsdifferenz bei 100 Kelvin Temperatureunterschied
-  calTemperatureSensorDiff = (calTemperatureSensor130Value - calTemperatureSensor30Value);
 }
 
-void CHIP_TEMPERATURE_Exec(uint32_t chiptemperature)
+int CHIP_TEMPERATURE_Exec(uint32_t chiptemperature)
 {
-    int32_t voltage;
+    int32_t temp;
     //Aktuelle Spannung am Temp Sensor
-    voltage = (3300 * (uint32_t)chiptemperature) / 65536;
+    temp = (3300 * (uint32_t)chiptemperature) / 65536;
 
 
-    voltage = voltage - (calTemperatureSensor30Value);
+    temp = temp - (calTemperatureSensor30Value);
 
-    voltage = voltage / 2.530; //2,53mV/°C
-    voltage = voltage + 25; //30000 da Erste Kalibrierpunkt bei 25°C --> 25
-
+    temp = temp / 2.530; //2,53mV/°C
+    temp = temp + 25; //30000 da Erste Kalibrierpunkt bei 25°C --> 25
+	return temp;
     //Durch 10 teilen, damit es in 16 Bit signed modbus register passt
-
-
-	
 }
 
Index: trunk/firmware_v2/SES/src/main.c
===================================================================
--- trunk/firmware_v2/SES/src/main.c	(revision 22)
+++ trunk/firmware_v2/SES/src/main.c	(revision 23)
@@ -85,5 +85,8 @@
 
   /* USER CODE BEGIN 1 */
-
+  int temperature = 0;
+  unsigned pwm = 0U;
+  uint32_t uin = 0;
+  uint32_t uout = 0;
   /* USER CODE END 1 */
 
@@ -108,5 +111,5 @@
   MX_DMA_Init();
   MX_ADC1_Init();
-  MX_TIM3_Init();
+  MX_TIM16_Init();
   MX_TIM17_Init();
  // MX_USART1_UART_Init();
@@ -163,13 +166,75 @@
 	{
 	  msCounter = 0;
-      CHIP_TEMPERATURE_Exec( adcData[4]);
+      temperature = CHIP_TEMPERATURE_Exec(adcData[4]);
 	  
-	  static unsigned pwm = 100U;
+	  if (temperature > 50)
+	  {  
+		  pwm++;
+		  if (pwm > 100U) pwm = 100U;	
+		  
+	  }
+	  if (temperature < 50)
+	  {
+		if (pwm > 0) pwm--;
+	  }
+	  SetFANSpeed(pwm);
+
+
+	  if (temperature > 80)
+	  {
+		  
+          
+          BUTTON_SetModeOff(); //Damit nicht von alleine wieder eingeschaltet wird
+		  LEDS_GN_Off();
+          LEDS_RT_BlinkCode_Start(BLINK_CODE_ERROR_TEMP, LED_RT_ON_TIME_WARN_TEMP, LED_RT_OFF_TIME, LED_RT_OFF_TIME *5); //Fehler Anzeigen
+          printf("Temperature too high!\n");
+          
+	  }
+
+	  // Starting measuring frequency of the FAN tacho output
+	  static unsigned stage;
+	  extern uint32_t freq, ic_overflows;
+
+	  switch (stage)
+	  {
+		  case 0:
+			  ic_overflows = 0U;
+			  __HAL_TIM_SetCounter(&htim16, 0U);
+			  HAL_TIM_Base_Start_IT(&htim16);
+			  HAL_TIM_IC_Start_IT(&htim16, TIM_CHANNEL_1);
+			  //printf("IC started\n");
+			  stage++;
+			  break;
+		  
+		  case 1: stage++; break;
+		  case 2: stage++; break;
+		  case 3: stage++; break;
+		  case 4: stage++; break;
+		  case 5: stage++; break;
+		  case 6:
+			  //printf("F = %u\n", freq);
+			  if (!freq)
+			  {
+				  static unsigned zeroFreqCnt;
+
+				  zeroFreqCnt++;
+				  // Checking if we set last time non-zero FAN-speed, but
+				  // tacho-sensor signal is absent more than 15 sec.
+				  if (zeroFreqCnt > 3U && GetLastSpeed())
+				  {
+					  SetFANSpeed(0U);
+					  // ACHTUNG! Der Lüfter ist kaputt!
+				  }
+			  }
+			  stage = 0;
+			  break;
+	  }
+
+	  uin = VOLTAGE_MEAS_GetUin();
+	  uout = VOLTAGE_MEAS_GetUout();
+	  printf("uin= %d, uout=%d, temp=%d, pwm=%d, fan=%d\r\n", uin, uout, temperature,pwm,freq);
 	  
-	  SetFANSpeed(pwm);
-
-	  pwm++;
-	  if (pwm > 300U) pwm = 300U;	// 30.0%
-	}
+	  
+	} //endsecond tick
 
 
@@ -190,5 +255,5 @@
 
 	  case MODE_MAINSWITCH_LVP_OVP:
-        MODE_LVP_OVP_Exec();
+     //   MODE_LVP_OVP_Exec();
       break;
 
Index: trunk/firmware_v2/SES/src/voltage_meas.c
===================================================================
--- trunk/firmware_v2/SES/src/voltage_meas.c	(revision 22)
+++ trunk/firmware_v2/SES/src/voltage_meas.c	(revision 23)
@@ -7,7 +7,7 @@
 
 
-uint32_t voltageUin;
-uint32_t voltageUout;
-uint32_t voltageDrop;
+static uint32_t voltageUin;
+static uint32_t voltageUout;
+static uint32_t voltageDrop;
 
 #define	VOLTAGE_DIVIDER_12V		6
@@ -24,5 +24,5 @@
   vuin = adcValUin * VREF;
   vuin = vuin / 65635;
-  vuin = vuin * VOLTAGE_DIVIDER_12V; //Divider ür 12V Version
+  vuin = vuin * VOLTAGE_DIVIDER_12V; //Divider für 12V Version
   voltageUin = vuin;
 
@@ -31,5 +31,5 @@
   vuout = adcValUout * VREF;
   vuout = vuout / 65635;
-  vuout = vuout * VOLTAGE_DIVIDER_12V; //Divider ür 12V Version
+  vuout = vuout * VOLTAGE_DIVIDER_12V; //Divider für 12V Version
   voltageUout = vuout;
   
@@ -64,3 +64,14 @@
   dropLimitCounter = 0;
 	
-  }
+}
+
+uint32_t VOLTAGE_MEAS_GetUin(void)
+{
+  return voltageUin;
+	
+}
+
+uint32_t VOLTAGE_MEAS_GetUout(void)
+{
+  return voltageUout;	
+}
