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