STM32F103C8T6_WIFI_Heating_system

Dependencies:   mbed mbed-STM32F103C8T6 eeprom_flash Watchdog PinDetect DS1820

  1. Bluepill STM32F103C8T6 Heating system
    1. _This project is core part of bigger heating system project!_

Features - Reading temperature from four DS18B20 sensors - Making a decision about switching on/off heater and pomp - Executing simple user commands from UART - Storing state parameters to program memory (EEPROM emulation)

Revision:
49:f9f65a2fc92f
Parent:
48:4ec055c066b4
Child:
50:94730b99ea41
diff -r 4ec055c066b4 -r f9f65a2fc92f temp_controller/temp_controller.cpp
--- a/temp_controller/temp_controller.cpp	Sun Sep 23 18:54:12 2018 +0000
+++ b/temp_controller/temp_controller.cpp	Sun Sep 23 19:59:48 2018 +0000
@@ -5,6 +5,7 @@
 extern DigitalOut myled; 
 extern DigitalOut pomp_OFF;
 extern DigitalOut heater_OFF;
+extern EventQueue queue;
 
 extern unsigned int eeprom_config_value;
 
@@ -67,9 +68,20 @@
                                 // 0 - OFF - heating off, pomp and heater are OFF
                                 // 1 - ECO - eco heating
                                 // 2 - STANDART - standart heating
-                                // 3 - SIMULATOR - simulator mode - work on simulated_temp
-                                // 4 - POMP - pomp is ON, heater is OFF
-                                // 5 - FULL - pomp and heater are ON
+                                // 3 - ECO SIMULATOR - eco simulator mode - work on eco simulated_temp
+                                // 4 - SIMULATOR - simulator mode - work on simulated_temp
+                                // 5 - POMP - pomp is ON, heater is OFF
+                                // 6 - EMERGENCY - pomp and heater are ON
+                                
+char pomp_was_delayed = 0;
+                                
+void delayed_pomp_off(){
+    if (pomp_was_delayed == 1) {
+        pomp_OFF = 1;
+    };
+    pomp_was_delayed = 0;
+    //pc.printf("delayed_pomp_off\r\n"); 
+};
 
 void start_temp(){
     
@@ -89,6 +101,7 @@
 
 void check_temp(){
   
+       int error_flag = 0;
        myled = 0; // turn the LED on
        
        // kick the watchdog
@@ -97,11 +110,16 @@
        __disable_irq();
        
        for ( int j=0; j < 5; j++ ) {
-            
             temp_error[j] = ds1820[j].read(temp[j]); // read temperature from DS1820 and perform cyclic redundancy check (CRC)
+            error_flag += temp_error[j];
             ds1820[j].startConversion();            // start temperature conversion from analog to digital before next reading
         };        
         
+        if (error_flag > 0 && ( working_mode==1 || working_mode==2 ) ){
+            // set EMERGENCY mode - pomp and heater are ON if sensors are bad
+            working_mode = 6;
+        };
+        
         
         // save new config if it was changed
         if (readEEPROMWord(0)!= eeprom_config_value) {
@@ -214,7 +232,14 @@
     if (outdoor > min_litos_temp) {
         // ============================================= SUMMER MODE
         // system off
-        pomp_OFF = 1;
+        if ( heater_OFF == 0 ) {
+            queue.call_in( 10000, delayed_pomp_off );
+            pomp_was_delayed = 1;
+        } else {
+            if ( pomp_was_delayed == 0 ) {
+                pomp_OFF = 1;    
+            };  
+        };
         heater_OFF = 1;
         
     } else if ( outdoor < 3) {
@@ -295,8 +320,15 @@
     if (outdoor > min_litos_temp) {
         //============================================ summer mode   
         // system off
-        pomp_OFF = 1;
-        heater_OFF = 1; 
+        if ( heater_OFF == 0 ) {
+            queue.call_in( 10000, delayed_pomp_off );
+            pomp_was_delayed = 1;
+        } else {
+            if ( pomp_was_delayed == 0 ) {
+                pomp_OFF = 1;    
+            };  
+        };
+        heater_OFF = 1;
         
     } else if (outdoor < 3) {
         //============================================ winter mode