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:
- 58:70930f201f97
- Parent:
- 55:3378972851fd
- Child:
- 59:0c6f3541beda
diff -r 9bf4c8142958 -r 70930f201f97 temp_controller/temp_controller.cpp --- a/temp_controller/temp_controller.cpp Sun Oct 07 08:36:56 2018 +0000 +++ b/temp_controller/temp_controller.cpp Tue Oct 06 08:17:06 2020 +0000 @@ -9,10 +9,20 @@ extern unsigned int eeprom_config_value; -#define MIN_MEBEL_TEMP 15 -#define MIN_LITOS_TEMP 10 +// here we define default working temps for standart mode if eeprom is not initialized +#define MIN_MEBEL_TEMP 15 +#define MIN_LITOS_TEMP 10 #define MIN_BACK_WATER_TEMP 10 -#define MAX_HOT_WATER_TEMP 35 +#define MAX_HOT_WATER_TEMP 35 + +// here we define default working temps for ECO mode +#define ECO_MIN_MEBEL_TEMP 5 +#define ECO_MIN_LITOS_TEMP 5 +#define ECO_MIN_BACK_WATER_TEMP 5 +#define ECO_MAX_HOT_WATER_TEMP 25 + + +#define HYSTERESIS 0.2 //unsigned int epprom_config_value = 0x0F0A0A23; /* @@ -162,11 +172,6 @@ void process_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)); - //pc.printf("======================================="); - switch(working_mode) { case 0: // 0 - OFF - heating off, pomp and heater are OFF @@ -175,19 +180,36 @@ break; case 1: // 1 - ECO - eco heating - set_pomp_and_heater_eco_mode(temp); + set_pomp_and_heater_by( + temp, + ECO_MIN_MEBEL_TEMP, + ECO_MIN_LITOS_TEMP, + ECO_MIN_BACK_WATER_TEMP, + ECO_MAX_HOT_WATER_TEMP + ); // temp,min_mebel_temp, min_litos_temp,min_back_water_temp,max_hot_water_temp break; case 2: // 2 - STANDART - standart heating - set_pomp_and_heater_by(temp); + set_pomp_and_heater_by( temp, + eeprom_config_value >> 24, + (0x00FF0000 & eeprom_config_value) >> 16, + (0x0000FF00 & eeprom_config_value) >> 8, + 0x000000FF & eeprom_config_value + ); break; case 3: // 3 - ECO SIMULATOR - simulator mode - work on simulated_temp - set_pomp_and_heater_eco_mode(simulated_temp); + set_pomp_and_heater_by( simulated_temp, 10, 7, 7, 26); break; case 4: // 4 - SIMULATOR - simulator mode - work on simulated_temp - set_pomp_and_heater_by(simulated_temp); + set_pomp_and_heater_by( simulated_temp, + eeprom_config_value >> 24, + (0x00FF0000 & eeprom_config_value) >> 16, + (0x0000FF00 & eeprom_config_value) >> 8, + 0x000000FF & eeprom_config_value + ); + break; case 5: // 5 - POMP - pomp is ON, heater is OFF @@ -244,9 +266,15 @@ return v; }; -void set_pomp_and_heater_by(float * work_temp) { + + +void set_pomp_and_heater_by(float * work_temp, + unsigned char min_mebel_temp, + unsigned char min_litos_temp, + unsigned char min_back_water_temp, + unsigned char max_hot_water_temp) +{ // temp config array = outdoor|litos|mebel|hot_water|back_water - /* eeprom_config_value: 1 unsigned char - Min mebel temp (default +15) @@ -254,15 +282,7 @@ 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); @@ -273,6 +293,8 @@ // ============================================= SUMMER MODE // system off if ( heater_OFF == 0 ) { + heater_OFF = 1; + //pomp_OFF = 1; queue.call_in( 10000, delayed_pomp_off ); pomp_was_delayed = 1; } else { @@ -280,148 +302,61 @@ pomp_OFF = 1; }; }; - heater_OFF = 1; - - } else if ( outdoor < 3) { + } else if ( outdoor < 2) { // ============================================== WINTER MODE - // pomp is always on + // 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; - }; + //heater state definition + if (mebel < min_mebel_temp || litos < min_litos_temp || back_water < min_back_water_temp) + { // somewhere is colder then it must be + if (hot_water > max_hot_water_temp) { + heater_OFF = 1; + } else { + if (hot_water < (max_hot_water_temp - 8)) { + heater_OFF = 0; }; - } else { + }; + } else if (mebel > (min_mebel_temp + HYSTERESIS) && + litos > (min_litos_temp + HYSTERESIS) && + back_water > (min_back_water_temp + HYSTERESIS)) + { + // warm is everywhere heater_OFF = 1; + } else { + if (hot_water > max_hot_water_temp) { + 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; - }; + //heater state definition + if (mebel < min_mebel_temp || litos < min_litos_temp || back_water < min_back_water_temp) + { // somewhere is colder than it must be + pomp_OFF = 0; + if (hot_water > max_hot_water_temp - 4) { + heater_OFF = 1; + } else { + if (hot_water < (max_hot_water_temp - 12)) { + heater_OFF = 0; }; - } else { + }; + } else if (mebel > (min_mebel_temp + HYSTERESIS) && + litos > (min_litos_temp + HYSTERESIS) && + back_water > (min_back_water_temp + HYSTERESIS)) + { + // warm is everywhere heater_OFF = 1; - if ( hot_water > min_back_water_temp ) { + if ( hot_water > (back_water + 3) ) { 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(); -}; - -void set_pomp_and_heater_eco_mode(float * work_temp){ - - unsigned char min_mebel_temp = 10; - unsigned char min_litos_temp = 7; - unsigned char min_back_water_temp = 7; - unsigned char max_hot_water_temp = 25; - - 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 > min_litos_temp) { - //============================================ summer mode - // system off - if ( heater_OFF == 0 ) { - queue.call_in( 10000, delayed_pomp_off ); - pomp_was_delayed = 1; } else { - if ( pomp_was_delayed == 0 ) { - pomp_OFF = 1; - }; + //printf("====demi==== "); + if (hot_water > max_hot_water_temp - 4) { + heater_OFF = 1; + }; }; - heater_OFF = 1; - - } else if (outdoor < 3) { - //============================================ winter mode - 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 - 5) ) { - heater_OFF = 1; - } else { - if ( heater_OFF == 1 ) { - if ( hot_water < (min_back_water_temp + 3) ) { - 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; - }; - }; - }; -}; \ No newline at end of file +}; \ No newline at end of file