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:
Sat Sep 29 06:53:19 2018 +0000
Revision:
52:20d6bf661fd6
Parent:
50:94730b99ea41
Child:
55:3378972851fd
currnet temp error checker added

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