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:
39:aa5f95061409
Parent:
38:a0753c2a4497
Child:
40:6168609574d0
--- a/temp_controller/temp_controller.cpp	Tue Sep 18 20:49:05 2018 +0000
+++ b/temp_controller/temp_controller.cpp	Fri Sep 21 17:56:25 2018 +0000
@@ -3,6 +3,9 @@
 extern Serial pc;
 extern Watchdog wd;
 extern DigitalOut myled; 
+extern DigitalOut pomp_OFF;
+extern DigitalOut heater_OFF;
+
 extern unsigned int eeprom_config_value;
 
 #define MIN_MEBEL_TEMP 15 
@@ -20,12 +23,29 @@
 */
 
 float temp[5] = {
-                    85,85,85,85,85  // initial temperature
+                    // initial temperature is maximum
+                    85, // OUTDOOR
+                    85, // LITOS
+                    85, // MEBEL
+                    85, // HOT WATER
+                    85  // BACK WATER
+                };
+                
+float simulated_temp[5] = {
+                    // initial temperature for simulator
+                    7,  // OUTDOOR
+                    10, // LITOS
+                    14, // MEBEL
+                    33, // HOT WATER
+                    18  // BACK WATER
                 };
                 
 int temp_error[5] = {
-                    0,0,0,0,0       // initial state
-                };
+                        1,1,1,1,1       // initial state is no sensors
+                                        // 0 - sensor present
+                                        // 1 - no sensor
+                                        // 2 - sensor CRC error
+                    };
                         
 string labels[5] = {
                         "OUTDOOR", 
@@ -36,13 +56,20 @@
                     };
     
 DS1820  ds1820[5] = { 
-                            DS1820(PA_9), // substitute PA_9 with actual mbed pin name connected to the OUTDOOR
-                            DS1820(PA_8), // substitute PA_8 with actual mbed pin name connected to the INDOOR LITOS    
-                            DS1820(PA_7), // substitute PA_7 with actual mbed pin name connected to the INDOOR MEBEL
-                            DS1820(PA_6), // substitute PA_6 with actual mbed pin name connected to the HOT WATER
-                            DS1820(PA_5)  // substitute PA_6 with actual mbed pin name connected to the HOT WATER
-                        };
+                        DS1820(PA_9), // substitute PA_9 with actual mbed pin name connected to the OUTDOOR
+                        DS1820(PA_8), // substitute PA_8 with actual mbed pin name connected to the INDOOR LITOS    
+                        DS1820(PA_7), // substitute PA_7 with actual mbed pin name connected to the INDOOR MEBEL
+                        DS1820(PA_6), // substitute PA_6 with actual mbed pin name connected to the HOT WATER
+                        DS1820(PA_5)  // substitute PA_6 with actual mbed pin name connected to the HOT WATER
+                    };
                         
+unsigned char working_mode = 1; // default mode after powerup is ECO
+                                // 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
 
 void start_temp(){
     
@@ -51,10 +78,10 @@
     for ( int j=0; j < 5; j++ ) {
         if(ds1820[j].begin()) { 
             ds1820[j].startConversion();
-            pc.printf("%s sensor present!\r\n", labels[j].c_str()); 
-        } else {
-            pc.printf("No %s sensor found!\r\n", labels[j].c_str());         
-        };
+            //pc.printf("%s sensor present!\r\n", labels[j].c_str()); 
+        };// else {
+            //pc.printf("No %s sensor found!\r\n", labels[j].c_str());         
+        //};
     };
     __enable_irq(); 
         
@@ -73,31 +100,28 @@
             
             temp_error[j] = ds1820[j].read(temp[j]); // read temperature from DS1820 and perform cyclic redundancy check (CRC)
             
+            /*
             switch(temp_error[j]) {
-            case 0:    // no errors -> 'temp' contains the value of measured temperature
-                pc.printf("%s = %3.1fC \r\n", labels[j].c_str() , temp[j]);
-                break;
-            case 1:    // no sensor present -> 'temp' is not updated
-                pc.printf("no %s sensor present \r\n", labels[j].c_str() );
-                break;
-            case 2:    // CRC error -> 'temp' is not updated
-                pc.printf("%s sensor CRC error \r\n", labels[j].c_str() );
+                case 0:    // no errors -> 'temp' contains the value of measured temperature
+                    //pc.printf("%s = %3.1fC \r\n", labels[j].c_str() , temp[j]);
+                    break;
+                case 1:    // no sensor present -> 'temp' is not updated
+                    //pc.printf("no %s sensor present \r\n", labels[j].c_str() );
+                    break;
+                case 2:    // CRC error -> 'temp' is not updated
+                    //pc.printf("%s sensor CRC error \r\n", labels[j].c_str() );
+                default:
+                    
             };
-            // start temperature conversion from analog to digital
+            */
+            // start temperature conversion from analog to digital before next reading
             ds1820[j].startConversion();             
-        };
-       
-        pc.printf("State %d|%d|%d|%d|%d\r\n", temp_error[0], temp_error[1], temp_error[2], temp_error[3], temp_error[4] );
-        pc.printf("Temp %3.1f|%3.1f|%3.1f|%3.1f|%3.1f\r\n", temp[0], temp[1], temp[2], temp[3], temp[4] );
-        pc.printf("RAM_config=%X, FLASH_config=%X\r\n", eeprom_config_value ,readEEPROMWord(0));
-        pc.printf("=======================================");
+        };        
         
         
         // save new config if it was changed
         if (readEEPROMWord(0)!= eeprom_config_value) {
-            enableEEPROMWriting();
-            writeEEPROMWord(0,eeprom_config_value);    
-            disableEEPROMWriting();        
+            save_new_config();
         };
         
         
@@ -107,6 +131,60 @@
         myled = 1;      // turn the LED off
 };
 
+
+void process_temp() {    
+        switch(working_mode) {
+            case 0:
+                // 0 - OFF - heating off, pomp and heater are OFF
+                pomp_OFF = 1;
+                heater_OFF = 1;
+                break;
+            case 1:
+                // 1 - ECO - eco heating
+                pc.printf("State %d|%d|%d|%d|%d\r\n", temp_error[0], temp_error[1], temp_error[2], temp_error[3], temp_error[4] );
+                pc.printf("Temp %3.1f|%3.1f|%3.1f|%3.1f|%3.1f\r\n", temp[0], temp[1], temp[2], temp[3], temp[4] );
+                pc.printf("RAM_config=%X, FLASH_config=%X\r\n", eeprom_config_value ,readEEPROMWord(0));
+                pc.printf("=======================================");
+                pomp_OFF = !pomp_OFF;
+                heater_OFF = !heater_OFF;
+                break; 
+            case 2:
+                // 2 - STANDART - standart heating
+                pomp_OFF = 1;
+                heater_OFF = 1;
+                break; 
+            case 3:
+                // 3 - SIMULATOR - simulator mode - work on simulated_temp
+                pomp_OFF = 1;
+                heater_OFF = 1;
+                break; 
+            case 4:
+                // 4 - POMP - pomp is ON, heater is OFF
+                pomp_OFF = 0
+                heater_OFF = 1;
+                break; 
+            case 5:
+                // 5 - FULL - pomp and heater are ON
+                pomp_OFF = 1;
+                heater_OFF = 1;
+                break;                 
+            default:
+                pomp_OFF = 1;
+                heater_OFF = 1;
+        };
+
+};
+
+
+void save_new_config() {
+    
+    enableEEPROMWriting();
+    writeEEPROMWord(0,eeprom_config_value);    
+    disableEEPROMWriting();        
+                  
+};
+
+
 unsigned int get_temp_config_value(){
     
     unsigned int v = readEEPROMWord(0);