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)
Diff: temp_controller/temp_controller.cpp
- Revision:
- 45:abc682827659
- Parent:
- 42:03cbc2a6f63b
- Child:
- 46:0d60fbcfb245
diff -r e6efa8be1f9e -r abc682827659 temp_controller/temp_controller.cpp --- a/temp_controller/temp_controller.cpp Sat Sep 22 17:33:14 2018 +0000 +++ b/temp_controller/temp_controller.cpp Sun Sep 23 15:04:46 2018 +0000 @@ -117,6 +117,7 @@ void process_temp() { + switch(working_mode) { case 0: // 0 - OFF - heating off, pomp and heater are OFF @@ -125,6 +126,9 @@ break; case 1: // 1 - ECO - eco heating + + set_pomp_and_heater_by(temp); + //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)); @@ -133,14 +137,15 @@ heater_OFF = !heater_OFF; break; case 2: + + set_pomp_and_heater_by(temp); // 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; + set_pomp_and_heater_by(simulated_temp); break; case 4: // 4 - POMP - pomp is ON, heater is OFF @@ -181,4 +186,97 @@ v = ( v << 8 ) | MAX_HOT_WATER_TEMP; }; return v; -}; \ No newline at end of file +}; + +void set_pomp_and_heater_by(float * work_temp) { + // temp config array = outdoor|litos|mebel|hot_water|back_water + + /* + eeprom_config_value: + 1 unsigned char - Min mebel temp (default +15) + 2 unsigned char Min litos temp (default +10) + 3 unsigned char Min back water temp (default +10) + 4 unsigned char Max hot water temp (default +35) + */ + unsigned char min_mebel_temp = eeprom_config_value >> 24; + unsigned char min_litos_temp = ( 0x00FF0000 & eeprom_config_value) >> 16; + unsigned char min_back_water_temp = ( 0x0000FF00 & eeprom_config_value) >> 8; + unsigned char max_hot_water_temp = 0x000000FF & eeprom_config_value; + + //__disable_irq(); + //pc.printf("Level %d|%d|%d|%d\r\n", min_mebel_temp, min_litos_temp, min_back_water_temp, max_hot_water_temp); + //__enable_irq(); + + float outdoor = *(work_temp); + float litos = *(work_temp + 1); + float mebel = *(work_temp + 2); + float hot_water = *(work_temp + 3); + float back_water = *(work_temp + 4); + + if (outdoor > litos) { + // ============================================= SUMMER MODE + // system off + pomp_OFF = 1; + heater_OFF = 1; + + } else if ( outdoor < 3) { + // ============================================== WINTER MODE + // pomp is always on + pomp_OFF = 0; + + if (mebel < min_mebel_temp || + litos < min_litos_temp || + back_water < min_back_water_temp) { + // when if somewhere is colder than it must be + if (hot_water > max_hot_water_temp) { + heater_OFF = 1; + } else { + if ( heater_OFF == 1 ) { + if (hot_water < (max_hot_water_temp - 10)) { + heater_OFF = 0; + } else { + heater_OFF = 1; + }; + } else { + heater_OFF = 0; + }; + }; + } else { + heater_OFF = 1; + }; + + } else { + // ======================================== DEMI SEASON MODE + + if (mebel < min_mebel_temp || + litos < min_litos_temp || + back_water < min_back_water_temp) { + // when if somewhere is colder than it must be + pomp_OFF = 0; + if ( hot_water > (max_hot_water_temp-10) ) { + heater_OFF = 1; + } else { + if ( heater_OFF == 1 ) { + if ( hot_water < (min_back_water_temp + 2) ) { + heater_OFF = 0; + } else { + heater_OFF = 1; + }; + } else { + heater_OFF = 0; + }; + }; + } else { + heater_OFF = 1; + if ( hot_water > min_back_water_temp ) { + pomp_OFF = 0; + } else { + pomp_OFF = 1; + }; + }; + }; + + //__disable_irq(); + //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) ); + //__enable_irq(); +}; \ No newline at end of file