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:
- 52:20d6bf661fd6
- Parent:
- 50:94730b99ea41
- Child:
- 55:3378972851fd
diff -r 881a30217532 -r 20d6bf661fd6 temp_controller/temp_controller.cpp --- a/temp_controller/temp_controller.cpp Mon Sep 24 14:57:38 2018 +0000 +++ b/temp_controller/temp_controller.cpp Sat Sep 29 06:53:19 2018 +0000 @@ -23,6 +23,16 @@ 4 unsigned char Max hot water temp (default +35) */ +float current_temp[5] = { + // current work temperature is maximum + 85, // OUTDOOR + 85, // LITOS + 85, // MEBEL + 85, // HOT WATER + 85 // BACK WATER + }; + + float temp[5] = { // initial temperature is maximum 85, // OUTDOOR @@ -63,6 +73,8 @@ DS1820(PA_6), // substitute PA_6 with actual mbed pin name connected to the HOT WATER DS1820(PA_5) // substitute PA_6 with actual mbed pin name connected to the HOT WATER }; + +int error_count = 0; // counts temp sensor errors unsigned char working_mode = 1; // default mode after powerup is ECO // 0 - OFF - heating off, pomp and heater are OFF @@ -110,14 +122,24 @@ __disable_irq(); for ( int j=0; j < 5; j++ ) { - temp_error[j] = ds1820[j].read(temp[j]); // read temperature from DS1820 and perform cyclic redundancy check (CRC) - error_flag += temp_error[j]; + temp_error[j] = ds1820[j].read(current_temp[j]); // read temperature from DS1820 and perform cyclic redundancy check (CRC) + if ( temp_error[j] == 0 ) { + temp[j] = current_temp[j]; + } else { + error_flag++; + }; ds1820[j].startConversion(); // start temperature conversion from analog to digital before next reading }; if (error_flag > 0 && ( working_mode==1 || working_mode==2 ) ){ - // set EMERGENCY mode - pomp and heater are ON if sensors are bad - working_mode = 6; + error_count++; + if ( error_count > 10 ) { + // if sensor reading error repeats more than 10 times - EMERGENCY MODE + working_mode = 6; + }; + } else if ( error_flag == 0 ) { + // if all sensors are readable set no errors + error_count = 0; };