070914

Dependencies:   FreescaleIAP MODSERIAL mbed monitor timer0

Fork of 17_PT1000 by Temp27

Revision:
4:46365f765d30
Parent:
3:72a65324d50d
Child:
5:7c6fbe5d62e5
--- a/main.cpp	Wed Jul 30 15:04:59 2014 +0000
+++ b/main.cpp	Sat Aug 02 14:42:22 2014 +0000
@@ -11,6 +11,11 @@
 
 #define CR 13
 
+#define SOLL_WERT 27.0
+#define R_TEMP_MAX 40.0
+
+InterruptIn tropfen(PTA5);
+
 SDFileSystem sd(PTD2, PTD3, PTC5, PTD0, "sd");  // The pinout (MOSI, MISO, SCLK, CS)
 timer0 down_timer;                              // Zeitsteuerung
 Serial pc(USBTX, USBRX);                        // tx, rx
@@ -26,7 +31,7 @@
 
 DigitalOut led1(LED1);
 //DigitalOut LED2(PTA2);
-DigitalOut LED5(PTA5);
+DigitalOut LED5(PTA4);
 DigitalOut LED_4(PTA12);
 
 // Schalter 4051
@@ -70,9 +75,9 @@
 uint16_t temp_word;
 uint8_t n, y, status, ds1820_status;
 
-
+int tropfen_anz = 0;
 
-float temp_float, temp_diff, temp_alt, temp_neu;
+float temp_float, temp_diff, temp_neu, esum, temp_soll;
 
 ConfigFile cfg;
 char value[BUFSIZ];
@@ -82,6 +87,12 @@
 float offset = 0.0;
 
 //------------------------------------------------------------------------------
+// Interruptroutine wird bei jedem Tropfen aufgerufen
+void tropfen_handler(){
+    tropfen_anz++;
+    }
+    
+//------------------------------------------------------------------------------
 // Interruptroutine wird bei jedem ankommenden Zeichen aufgerufen
 void rx_handler(void)
 {
@@ -147,8 +158,9 @@
     
     heizung.period(0.020);          //  requires a 20ms period
     heizung.pulsewidth(0.005);
-    temp_alt = 0.0;
+    esum = 0.0;
     
+    tropfen.fall(&tropfen_handler);
     
     //------------------------------------------------------------------------------
     // RS232 Schnittstellt welche auf den CMSIS-DAP (USB Port) weitergeleitet wird
@@ -321,43 +333,50 @@
             // 16 mal den Eingang fuer eine bessere Mittelung lesen
             //
            
+           temp_word = read_mw(1);
+           temp_soll = (temp_word - 28510);
+           temp_soll /= 113;
+           
             temp_word = read_mw(0);
-            temp_float = (temp_word - 28500);
+            temp_float = (temp_word - 28510); //27100
             
             //pc.printf("%d;",temp_word);
+            pc.printf("Soll %2.2f;",temp_soll);
             
-            temp_float /= 116;
-            pc.printf("%0.2f; ",temp_float);                     // Rohdaten ausgeben
+            temp_float /= 113;  //112.3
+            pc.printf("Temp-R %0.2f; ",temp_float);                     // Rohdaten ausgeben
 
-            temp_diff = 40 - temp_float;
+            temp_diff = (SOLL_WERT - temp_soll);
             
             
+            if(temp_diff > SOLL_WERT)temp_diff = SOLL_WERT;
+                
+            //temp_neu = ((temp_diff*0.0005) + (temp_alt*0.9));
   
-            temp_neu = ((temp_diff*0.0005) + (temp_alt*0.9));
+            if(temp_diff < 3){
+                esum += temp_diff * 0.00001;
+                }
+            
+            temp_neu = (temp_diff*0.0005) + esum;
             
             if(temp_neu > 0.02){
                 temp_neu = 0.02;
             }            
-            //if(temp_neu < -0.001){
-            //    temp_neu = -0.001;
-            //}
-            if(temp_float > 40){
+        
+            if(temp_soll > SOLL_WERT){
                 temp_neu = 0.0;
-                }
+                esum = 0.0;
+            }
+            
+            if(temp_float > R_TEMP_MAX){
+                temp_neu = 0.0;
+                esum = 0.0;
+            }
             
             heizung.pulsewidth(0.0001 + temp_neu);
-            pc.printf("%0.4f;",temp_alt);
+            //pc.printf("%0.4f;",temp_alt);
             pc.printf("%0.4f \n",temp_neu);
-            
-            temp_alt = temp_neu;
-
-            temp_word = read_mw(1);
-            temp_float = (temp_word - 17210);
-            temp_float /= 70;
-            // pc.printf("%0.2f\n",temp_float);                      // Rohdaten ausgeben
-
-            
-             
+                   
        
             //------------------------------------------------------
             // one wire Daten lesen und ausgeben