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)

Committer:
andrewklmn
Date:
Tue Oct 06 08:17:06 2020 +0000
Revision:
58:70930f201f97
Parent:
55:3378972851fd
Child:
59:0c6f3541beda
min temp changed to +5C

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewklmn 38:a0753c2a4497 1 #include "temp_controller.h"
andrewklmn 38:a0753c2a4497 2
andrewklmn 38:a0753c2a4497 3 extern Serial pc;
andrewklmn 38:a0753c2a4497 4 extern Watchdog wd;
andrewklmn 38:a0753c2a4497 5 extern DigitalOut myled;
andrewklmn 39:aa5f95061409 6 extern DigitalOut pomp_OFF;
andrewklmn 39:aa5f95061409 7 extern DigitalOut heater_OFF;
andrewklmn 49:f9f65a2fc92f 8 extern EventQueue queue;
andrewklmn 39:aa5f95061409 9
andrewklmn 38:a0753c2a4497 10 extern unsigned int eeprom_config_value;
andrewklmn 38:a0753c2a4497 11
andrewklmn 58:70930f201f97 12 // here we define default working temps for standart mode if eeprom is not initialized
andrewklmn 58:70930f201f97 13 #define MIN_MEBEL_TEMP 15
andrewklmn 58:70930f201f97 14 #define MIN_LITOS_TEMP 10
andrewklmn 38:a0753c2a4497 15 #define MIN_BACK_WATER_TEMP 10
andrewklmn 58:70930f201f97 16 #define MAX_HOT_WATER_TEMP 35
andrewklmn 58:70930f201f97 17
andrewklmn 58:70930f201f97 18 // here we define default working temps for ECO mode
andrewklmn 58:70930f201f97 19 #define ECO_MIN_MEBEL_TEMP 5
andrewklmn 58:70930f201f97 20 #define ECO_MIN_LITOS_TEMP 5
andrewklmn 58:70930f201f97 21 #define ECO_MIN_BACK_WATER_TEMP 5
andrewklmn 58:70930f201f97 22 #define ECO_MAX_HOT_WATER_TEMP 25
andrewklmn 58:70930f201f97 23
andrewklmn 58:70930f201f97 24
andrewklmn 58:70930f201f97 25 #define HYSTERESIS 0.2
andrewklmn 38:a0753c2a4497 26
andrewklmn 38:a0753c2a4497 27 //unsigned int epprom_config_value = 0x0F0A0A23;
andrewklmn 38:a0753c2a4497 28 /*
andrewklmn 38:a0753c2a4497 29 epprom_config_value:
andrewklmn 38:a0753c2a4497 30 1 unsigned char - Min mebel temp (default +15)
andrewklmn 38:a0753c2a4497 31 2 unsigned char Min litos temp (default +10)
andrewklmn 38:a0753c2a4497 32 3 unsigned char Min back water temp (default +10)
andrewklmn 38:a0753c2a4497 33 4 unsigned char Max hot water temp (default +35)
andrewklmn 38:a0753c2a4497 34 */
andrewklmn 38:a0753c2a4497 35
andrewklmn 52:20d6bf661fd6 36 float current_temp[5] = {
andrewklmn 52:20d6bf661fd6 37 // current work temperature is maximum
andrewklmn 52:20d6bf661fd6 38 85, // OUTDOOR
andrewklmn 52:20d6bf661fd6 39 85, // LITOS
andrewklmn 52:20d6bf661fd6 40 85, // MEBEL
andrewklmn 52:20d6bf661fd6 41 85, // HOT WATER
andrewklmn 52:20d6bf661fd6 42 85 // BACK WATER
andrewklmn 52:20d6bf661fd6 43 };
andrewklmn 52:20d6bf661fd6 44
andrewklmn 52:20d6bf661fd6 45
andrewklmn 38:a0753c2a4497 46 float temp[5] = {
andrewklmn 39:aa5f95061409 47 // initial temperature is maximum
andrewklmn 39:aa5f95061409 48 85, // OUTDOOR
andrewklmn 39:aa5f95061409 49 85, // LITOS
andrewklmn 39:aa5f95061409 50 85, // MEBEL
andrewklmn 39:aa5f95061409 51 85, // HOT WATER
andrewklmn 39:aa5f95061409 52 85 // BACK WATER
andrewklmn 39:aa5f95061409 53 };
andrewklmn 39:aa5f95061409 54
andrewklmn 39:aa5f95061409 55 float simulated_temp[5] = {
andrewklmn 39:aa5f95061409 56 // initial temperature for simulator
andrewklmn 39:aa5f95061409 57 7, // OUTDOOR
andrewklmn 39:aa5f95061409 58 10, // LITOS
andrewklmn 39:aa5f95061409 59 14, // MEBEL
andrewklmn 39:aa5f95061409 60 33, // HOT WATER
andrewklmn 39:aa5f95061409 61 18 // BACK WATER
andrewklmn 38:a0753c2a4497 62 };
andrewklmn 38:a0753c2a4497 63
andrewklmn 38:a0753c2a4497 64 int temp_error[5] = {
andrewklmn 39:aa5f95061409 65 1,1,1,1,1 // initial state is no sensors
andrewklmn 39:aa5f95061409 66 // 0 - sensor present
andrewklmn 39:aa5f95061409 67 // 1 - no sensor
andrewklmn 39:aa5f95061409 68 // 2 - sensor CRC error
andrewklmn 39:aa5f95061409 69 };
andrewklmn 38:a0753c2a4497 70
andrewklmn 38:a0753c2a4497 71 string labels[5] = {
andrewklmn 38:a0753c2a4497 72 "OUTDOOR",
andrewklmn 38:a0753c2a4497 73 "LITOS",
andrewklmn 38:a0753c2a4497 74 "MEBEL",
andrewklmn 38:a0753c2a4497 75 "HOT WATER",
andrewklmn 38:a0753c2a4497 76 "BACK WATER"
andrewklmn 38:a0753c2a4497 77 };
andrewklmn 38:a0753c2a4497 78
andrewklmn 38:a0753c2a4497 79 DS1820 ds1820[5] = {
andrewklmn 39:aa5f95061409 80 DS1820(PA_9), // substitute PA_9 with actual mbed pin name connected to the OUTDOOR
andrewklmn 39:aa5f95061409 81 DS1820(PA_8), // substitute PA_8 with actual mbed pin name connected to the INDOOR LITOS
andrewklmn 39:aa5f95061409 82 DS1820(PA_7), // substitute PA_7 with actual mbed pin name connected to the INDOOR MEBEL
andrewklmn 39:aa5f95061409 83 DS1820(PA_6), // substitute PA_6 with actual mbed pin name connected to the HOT WATER
andrewklmn 39:aa5f95061409 84 DS1820(PA_5) // substitute PA_6 with actual mbed pin name connected to the HOT WATER
andrewklmn 39:aa5f95061409 85 };
andrewklmn 52:20d6bf661fd6 86
andrewklmn 52:20d6bf661fd6 87 int error_count = 0; // counts temp sensor errors
andrewklmn 38:a0753c2a4497 88
andrewklmn 39:aa5f95061409 89 unsigned char working_mode = 1; // default mode after powerup is ECO
andrewklmn 39:aa5f95061409 90 // 0 - OFF - heating off, pomp and heater are OFF
andrewklmn 39:aa5f95061409 91 // 1 - ECO - eco heating
andrewklmn 39:aa5f95061409 92 // 2 - STANDART - standart heating
andrewklmn 49:f9f65a2fc92f 93 // 3 - ECO SIMULATOR - eco simulator mode - work on eco simulated_temp
andrewklmn 49:f9f65a2fc92f 94 // 4 - SIMULATOR - simulator mode - work on simulated_temp
andrewklmn 49:f9f65a2fc92f 95 // 5 - POMP - pomp is ON, heater is OFF
andrewklmn 49:f9f65a2fc92f 96 // 6 - EMERGENCY - pomp and heater are ON
andrewklmn 49:f9f65a2fc92f 97
andrewklmn 49:f9f65a2fc92f 98 char pomp_was_delayed = 0;
andrewklmn 49:f9f65a2fc92f 99
andrewklmn 49:f9f65a2fc92f 100 void delayed_pomp_off(){
andrewklmn 49:f9f65a2fc92f 101 if (pomp_was_delayed == 1) {
andrewklmn 49:f9f65a2fc92f 102 pomp_OFF = 1;
andrewklmn 49:f9f65a2fc92f 103 };
andrewklmn 49:f9f65a2fc92f 104 pomp_was_delayed = 0;
andrewklmn 49:f9f65a2fc92f 105 //pc.printf("delayed_pomp_off\r\n");
andrewklmn 49:f9f65a2fc92f 106 };
andrewklmn 38:a0753c2a4497 107
andrewklmn 38:a0753c2a4497 108 void start_temp(){
andrewklmn 38:a0753c2a4497 109
andrewklmn 38:a0753c2a4497 110 __disable_irq();
andrewklmn 38:a0753c2a4497 111
andrewklmn 38:a0753c2a4497 112 for ( int j=0; j < 5; j++ ) {
andrewklmn 38:a0753c2a4497 113 if(ds1820[j].begin()) {
andrewklmn 38:a0753c2a4497 114 ds1820[j].startConversion();
andrewklmn 39:aa5f95061409 115 //pc.printf("%s sensor present!\r\n", labels[j].c_str());
andrewklmn 39:aa5f95061409 116 };// else {
andrewklmn 39:aa5f95061409 117 //pc.printf("No %s sensor found!\r\n", labels[j].c_str());
andrewklmn 39:aa5f95061409 118 //};
andrewklmn 38:a0753c2a4497 119 };
andrewklmn 38:a0753c2a4497 120 __enable_irq();
andrewklmn 38:a0753c2a4497 121
andrewklmn 38:a0753c2a4497 122 };
andrewklmn 38:a0753c2a4497 123
andrewklmn 38:a0753c2a4497 124 void check_temp(){
andrewklmn 38:a0753c2a4497 125
andrewklmn 49:f9f65a2fc92f 126 int error_flag = 0;
andrewklmn 38:a0753c2a4497 127 myled = 0; // turn the LED on
andrewklmn 38:a0753c2a4497 128
andrewklmn 38:a0753c2a4497 129 // kick the watchdog
andrewklmn 38:a0753c2a4497 130 wd.Service();
andrewklmn 38:a0753c2a4497 131
andrewklmn 38:a0753c2a4497 132 __disable_irq();
andrewklmn 38:a0753c2a4497 133
andrewklmn 38:a0753c2a4497 134 for ( int j=0; j < 5; j++ ) {
andrewklmn 52:20d6bf661fd6 135 temp_error[j] = ds1820[j].read(current_temp[j]); // read temperature from DS1820 and perform cyclic redundancy check (CRC)
andrewklmn 52:20d6bf661fd6 136 if ( temp_error[j] == 0 ) {
andrewklmn 52:20d6bf661fd6 137 temp[j] = current_temp[j];
andrewklmn 52:20d6bf661fd6 138 } else {
andrewklmn 52:20d6bf661fd6 139 error_flag++;
andrewklmn 52:20d6bf661fd6 140 };
andrewklmn 41:978c2d85a0e7 141 ds1820[j].startConversion(); // start temperature conversion from analog to digital before next reading
andrewklmn 39:aa5f95061409 142 };
andrewklmn 38:a0753c2a4497 143
andrewklmn 49:f9f65a2fc92f 144 if (error_flag > 0 && ( working_mode==1 || working_mode==2 ) ){
andrewklmn 52:20d6bf661fd6 145 error_count++;
andrewklmn 52:20d6bf661fd6 146 if ( error_count > 10 ) {
andrewklmn 52:20d6bf661fd6 147 // if sensor reading error repeats more than 10 times - EMERGENCY MODE
andrewklmn 55:3378972851fd 148 //============================================================================================DEVELOPMENT
andrewklmn 55:3378972851fd 149 //working_mode = 6;
andrewklmn 52:20d6bf661fd6 150 };
andrewklmn 52:20d6bf661fd6 151 } else if ( error_flag == 0 ) {
andrewklmn 52:20d6bf661fd6 152 // if all sensors are readable set no errors
andrewklmn 52:20d6bf661fd6 153 error_count = 0;
andrewklmn 49:f9f65a2fc92f 154 };
andrewklmn 49:f9f65a2fc92f 155
andrewklmn 38:a0753c2a4497 156
andrewklmn 38:a0753c2a4497 157 // save new config if it was changed
andrewklmn 50:94730b99ea41 158 if (readEEPROMWord(0) != eeprom_config_value ||
andrewklmn 50:94730b99ea41 159 readEEPROMWord(4) != (unsigned int)working_mode) {
andrewklmn 39:aa5f95061409 160 save_new_config();
andrewklmn 50:94730b99ea41 161 //pc.printf("Tram=%x Teeprom=%x\r\n", readEEPROMWord(0), eeprom_config_value);
andrewklmn 50:94730b99ea41 162 //pc.printf("Mram=%x Meeprom=%x\r\n", readEEPROMWord(4), working_mode);
andrewklmn 38:a0753c2a4497 163 };
andrewklmn 38:a0753c2a4497 164
andrewklmn 38:a0753c2a4497 165
andrewklmn 38:a0753c2a4497 166
andrewklmn 38:a0753c2a4497 167 __enable_irq();
andrewklmn 38:a0753c2a4497 168
andrewklmn 38:a0753c2a4497 169 myled = 1; // turn the LED off
andrewklmn 38:a0753c2a4497 170 };
andrewklmn 38:a0753c2a4497 171
andrewklmn 39:aa5f95061409 172
andrewklmn 39:aa5f95061409 173 void process_temp() {
andrewklmn 45:abc682827659 174
andrewklmn 39:aa5f95061409 175 switch(working_mode) {
andrewklmn 39:aa5f95061409 176 case 0:
andrewklmn 39:aa5f95061409 177 // 0 - OFF - heating off, pomp and heater are OFF
andrewklmn 39:aa5f95061409 178 pomp_OFF = 1;
andrewklmn 39:aa5f95061409 179 heater_OFF = 1;
andrewklmn 39:aa5f95061409 180 break;
andrewklmn 39:aa5f95061409 181 case 1:
andrewklmn 39:aa5f95061409 182 // 1 - ECO - eco heating
andrewklmn 58:70930f201f97 183 set_pomp_and_heater_by(
andrewklmn 58:70930f201f97 184 temp,
andrewklmn 58:70930f201f97 185 ECO_MIN_MEBEL_TEMP,
andrewklmn 58:70930f201f97 186 ECO_MIN_LITOS_TEMP,
andrewklmn 58:70930f201f97 187 ECO_MIN_BACK_WATER_TEMP,
andrewklmn 58:70930f201f97 188 ECO_MAX_HOT_WATER_TEMP
andrewklmn 58:70930f201f97 189 ); // temp,min_mebel_temp, min_litos_temp,min_back_water_temp,max_hot_water_temp
andrewklmn 39:aa5f95061409 190 break;
andrewklmn 39:aa5f95061409 191 case 2:
andrewklmn 39:aa5f95061409 192 // 2 - STANDART - standart heating
andrewklmn 58:70930f201f97 193 set_pomp_and_heater_by( temp,
andrewklmn 58:70930f201f97 194 eeprom_config_value >> 24,
andrewklmn 58:70930f201f97 195 (0x00FF0000 & eeprom_config_value) >> 16,
andrewklmn 58:70930f201f97 196 (0x0000FF00 & eeprom_config_value) >> 8,
andrewklmn 58:70930f201f97 197 0x000000FF & eeprom_config_value
andrewklmn 58:70930f201f97 198 );
andrewklmn 39:aa5f95061409 199 break;
andrewklmn 39:aa5f95061409 200 case 3:
andrewklmn 46:0d60fbcfb245 201 // 3 - ECO SIMULATOR - simulator mode - work on simulated_temp
andrewklmn 58:70930f201f97 202 set_pomp_and_heater_by( simulated_temp, 10, 7, 7, 26);
andrewklmn 39:aa5f95061409 203 break;
andrewklmn 39:aa5f95061409 204 case 4:
andrewklmn 46:0d60fbcfb245 205 // 4 - SIMULATOR - simulator mode - work on simulated_temp
andrewklmn 58:70930f201f97 206 set_pomp_and_heater_by( simulated_temp,
andrewklmn 58:70930f201f97 207 eeprom_config_value >> 24,
andrewklmn 58:70930f201f97 208 (0x00FF0000 & eeprom_config_value) >> 16,
andrewklmn 58:70930f201f97 209 (0x0000FF00 & eeprom_config_value) >> 8,
andrewklmn 58:70930f201f97 210 0x000000FF & eeprom_config_value
andrewklmn 58:70930f201f97 211 );
andrewklmn 58:70930f201f97 212
andrewklmn 46:0d60fbcfb245 213 break;
andrewklmn 46:0d60fbcfb245 214 case 5:
andrewklmn 46:0d60fbcfb245 215 // 5 - POMP - pomp is ON, heater is OFF
andrewklmn 40:6168609574d0 216 pomp_OFF = 0;
andrewklmn 39:aa5f95061409 217 heater_OFF = 1;
andrewklmn 39:aa5f95061409 218 break;
andrewklmn 46:0d60fbcfb245 219 case 6:
andrewklmn 46:0d60fbcfb245 220 // 6 - FULL - pomp and heater are ON
andrewklmn 41:978c2d85a0e7 221 pomp_OFF = 0;
andrewklmn 41:978c2d85a0e7 222 heater_OFF = 0;
andrewklmn 39:aa5f95061409 223 break;
andrewklmn 39:aa5f95061409 224 default:
andrewklmn 39:aa5f95061409 225 pomp_OFF = 1;
andrewklmn 39:aa5f95061409 226 heater_OFF = 1;
andrewklmn 39:aa5f95061409 227 };
andrewklmn 39:aa5f95061409 228
andrewklmn 39:aa5f95061409 229 };
andrewklmn 39:aa5f95061409 230
andrewklmn 39:aa5f95061409 231
andrewklmn 39:aa5f95061409 232 void save_new_config() {
andrewklmn 39:aa5f95061409 233
andrewklmn 39:aa5f95061409 234 enableEEPROMWriting();
andrewklmn 39:aa5f95061409 235 writeEEPROMWord(0,eeprom_config_value);
andrewklmn 50:94730b99ea41 236 writeEEPROMWord(4,(unsigned int)working_mode);
andrewklmn 39:aa5f95061409 237 disableEEPROMWriting();
andrewklmn 39:aa5f95061409 238
andrewklmn 39:aa5f95061409 239 };
andrewklmn 39:aa5f95061409 240
andrewklmn 39:aa5f95061409 241
andrewklmn 38:a0753c2a4497 242 unsigned int get_temp_config_value(){
andrewklmn 38:a0753c2a4497 243
andrewklmn 38:a0753c2a4497 244 unsigned int v = readEEPROMWord(0);
andrewklmn 38:a0753c2a4497 245 if ( v == 0xFFFFFFFF ) {
andrewklmn 38:a0753c2a4497 246 // if eeprom config value is not initialized
andrewklmn 38:a0753c2a4497 247 // set default value 0x0F0A0A23;
andrewklmn 38:a0753c2a4497 248 v = MIN_MEBEL_TEMP;
andrewklmn 38:a0753c2a4497 249 v = ( v << 8 ) | MIN_LITOS_TEMP;
andrewklmn 38:a0753c2a4497 250 v = ( v << 8 ) | MIN_BACK_WATER_TEMP;
andrewklmn 38:a0753c2a4497 251 v = ( v << 8 ) | MAX_HOT_WATER_TEMP;
andrewklmn 38:a0753c2a4497 252 };
andrewklmn 38:a0753c2a4497 253 return v;
andrewklmn 45:abc682827659 254 };
andrewklmn 45:abc682827659 255
andrewklmn 50:94730b99ea41 256
andrewklmn 50:94730b99ea41 257
andrewklmn 50:94730b99ea41 258 unsigned int get_mode_config_value(){
andrewklmn 50:94730b99ea41 259
andrewklmn 50:94730b99ea41 260 unsigned int v = readEEPROMWord(4);
andrewklmn 50:94730b99ea41 261 if ( v > 6 ) {
andrewklmn 50:94730b99ea41 262 // if eeprom mode value is not initialized
andrewklmn 50:94730b99ea41 263 // set default value 0x01; ECO mode
andrewklmn 50:94730b99ea41 264 v = 1;
andrewklmn 50:94730b99ea41 265 };
andrewklmn 50:94730b99ea41 266 return v;
andrewklmn 50:94730b99ea41 267 };
andrewklmn 50:94730b99ea41 268
andrewklmn 58:70930f201f97 269
andrewklmn 58:70930f201f97 270
andrewklmn 58:70930f201f97 271 void set_pomp_and_heater_by(float * work_temp,
andrewklmn 58:70930f201f97 272 unsigned char min_mebel_temp,
andrewklmn 58:70930f201f97 273 unsigned char min_litos_temp,
andrewklmn 58:70930f201f97 274 unsigned char min_back_water_temp,
andrewklmn 58:70930f201f97 275 unsigned char max_hot_water_temp)
andrewklmn 58:70930f201f97 276 {
andrewklmn 45:abc682827659 277 // temp config array = outdoor|litos|mebel|hot_water|back_water
andrewklmn 45:abc682827659 278 /*
andrewklmn 45:abc682827659 279 eeprom_config_value:
andrewklmn 45:abc682827659 280 1 unsigned char - Min mebel temp (default +15)
andrewklmn 45:abc682827659 281 2 unsigned char Min litos temp (default +10)
andrewklmn 45:abc682827659 282 3 unsigned char Min back water temp (default +10)
andrewklmn 45:abc682827659 283 4 unsigned char Max hot water temp (default +35)
andrewklmn 45:abc682827659 284 */
andrewklmn 58:70930f201f97 285
andrewklmn 45:abc682827659 286 float outdoor = *(work_temp);
andrewklmn 45:abc682827659 287 float litos = *(work_temp + 1);
andrewklmn 45:abc682827659 288 float mebel = *(work_temp + 2);
andrewklmn 45:abc682827659 289 float hot_water = *(work_temp + 3);
andrewklmn 45:abc682827659 290 float back_water = *(work_temp + 4);
andrewklmn 45:abc682827659 291
andrewklmn 48:4ec055c066b4 292 if (outdoor > min_litos_temp) {
andrewklmn 45:abc682827659 293 // ============================================= SUMMER MODE
andrewklmn 45:abc682827659 294 // system off
andrewklmn 49:f9f65a2fc92f 295 if ( heater_OFF == 0 ) {
andrewklmn 58:70930f201f97 296 heater_OFF = 1;
andrewklmn 58:70930f201f97 297 //pomp_OFF = 1;
andrewklmn 49:f9f65a2fc92f 298 queue.call_in( 10000, delayed_pomp_off );
andrewklmn 49:f9f65a2fc92f 299 pomp_was_delayed = 1;
andrewklmn 49:f9f65a2fc92f 300 } else {
andrewklmn 49:f9f65a2fc92f 301 if ( pomp_was_delayed == 0 ) {
andrewklmn 49:f9f65a2fc92f 302 pomp_OFF = 1;
andrewklmn 49:f9f65a2fc92f 303 };
andrewklmn 49:f9f65a2fc92f 304 };
andrewklmn 58:70930f201f97 305 } else if ( outdoor < 2) {
andrewklmn 45:abc682827659 306 // ============================================== WINTER MODE
andrewklmn 58:70930f201f97 307 // pomp is always on
andrewklmn 45:abc682827659 308 pomp_OFF = 0;
andrewklmn 45:abc682827659 309
andrewklmn 58:70930f201f97 310 //heater state definition
andrewklmn 58:70930f201f97 311 if (mebel < min_mebel_temp || litos < min_litos_temp || back_water < min_back_water_temp)
andrewklmn 58:70930f201f97 312 { // somewhere is colder then it must be
andrewklmn 58:70930f201f97 313 if (hot_water > max_hot_water_temp) {
andrewklmn 58:70930f201f97 314 heater_OFF = 1;
andrewklmn 58:70930f201f97 315 } else {
andrewklmn 58:70930f201f97 316 if (hot_water < (max_hot_water_temp - 8)) {
andrewklmn 58:70930f201f97 317 heater_OFF = 0;
andrewklmn 45:abc682827659 318 };
andrewklmn 58:70930f201f97 319 };
andrewklmn 58:70930f201f97 320 } else if (mebel > (min_mebel_temp + HYSTERESIS) &&
andrewklmn 58:70930f201f97 321 litos > (min_litos_temp + HYSTERESIS) &&
andrewklmn 58:70930f201f97 322 back_water > (min_back_water_temp + HYSTERESIS))
andrewklmn 58:70930f201f97 323 {
andrewklmn 58:70930f201f97 324 // warm is everywhere
andrewklmn 45:abc682827659 325 heater_OFF = 1;
andrewklmn 58:70930f201f97 326 } else {
andrewklmn 58:70930f201f97 327 if (hot_water > max_hot_water_temp) {
andrewklmn 58:70930f201f97 328 heater_OFF = 1;
andrewklmn 58:70930f201f97 329 };
andrewklmn 45:abc682827659 330 };
andrewklmn 45:abc682827659 331 } else {
andrewklmn 45:abc682827659 332 // ======================================== DEMI SEASON MODE
andrewklmn 58:70930f201f97 333 //heater state definition
andrewklmn 58:70930f201f97 334 if (mebel < min_mebel_temp || litos < min_litos_temp || back_water < min_back_water_temp)
andrewklmn 58:70930f201f97 335 { // somewhere is colder than it must be
andrewklmn 58:70930f201f97 336 pomp_OFF = 0;
andrewklmn 58:70930f201f97 337 if (hot_water > max_hot_water_temp - 4) {
andrewklmn 58:70930f201f97 338 heater_OFF = 1;
andrewklmn 58:70930f201f97 339 } else {
andrewklmn 58:70930f201f97 340 if (hot_water < (max_hot_water_temp - 12)) {
andrewklmn 58:70930f201f97 341 heater_OFF = 0;
andrewklmn 45:abc682827659 342 };
andrewklmn 58:70930f201f97 343 };
andrewklmn 58:70930f201f97 344 } else if (mebel > (min_mebel_temp + HYSTERESIS) &&
andrewklmn 58:70930f201f97 345 litos > (min_litos_temp + HYSTERESIS) &&
andrewklmn 58:70930f201f97 346 back_water > (min_back_water_temp + HYSTERESIS))
andrewklmn 58:70930f201f97 347 {
andrewklmn 58:70930f201f97 348 // warm is everywhere
andrewklmn 45:abc682827659 349 heater_OFF = 1;
andrewklmn 58:70930f201f97 350 if ( hot_water > (back_water + 3) ) {
andrewklmn 45:abc682827659 351 pomp_OFF = 0;
andrewklmn 45:abc682827659 352 } else {
andrewklmn 45:abc682827659 353 pomp_OFF = 1;
andrewklmn 45:abc682827659 354 };
andrewklmn 49:f9f65a2fc92f 355 } else {
andrewklmn 58:70930f201f97 356 //printf("====demi==== ");
andrewklmn 58:70930f201f97 357 if (hot_water > max_hot_water_temp - 4) {
andrewklmn 58:70930f201f97 358 heater_OFF = 1;
andrewklmn 58:70930f201f97 359 };
andrewklmn 49:f9f65a2fc92f 360 };
andrewklmn 46:0d60fbcfb245 361 };
andrewklmn 58:70930f201f97 362 };