Central Heating controller using the real time clock, PHY module for internet, 1-wire interface for temperature sensors, a system log and a configuration file

Dependencies:   net 1-wire lpc1768 crypto clock web fram log

/media/uploads/andrewboyson/heating.sch

/media/uploads/andrewboyson/heating.brd

/media/uploads/andrewboyson/eagle.epf

Committer:
andrewboyson
Date:
Fri Sep 27 11:33:30 2019 +0000
Revision:
76:3ef2a46c8b1e
Parent:
57:72c1c1357861
Child:
95:97621bfbedfa
Updated libraries

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 0:3c04f4b47041 1 #include <stdint.h>
andrewboyson 0:3c04f4b47041 2 #include <string.h>
andrewboyson 0:3c04f4b47041 3 #include <stdbool.h>
andrewboyson 48:6eac12df3ad5 4 #include <stdint.h>
andrewboyson 0:3c04f4b47041 5
andrewboyson 35:bb8a6d1c034c 6 #include "gpio.h"
andrewboyson 35:bb8a6d1c034c 7 #include "program.h"
andrewboyson 35:bb8a6d1c034c 8 #include "ds18b20.h"
andrewboyson 35:bb8a6d1c034c 9 #include "fram.h"
andrewboyson 0:3c04f4b47041 10 #include "radiator.h"
andrewboyson 35:bb8a6d1c034c 11 #include "led.h"
andrewboyson 5:82197a6997fd 12
andrewboyson 5:82197a6997fd 13
andrewboyson 5:82197a6997fd 14 #define RADIATOR_PUMP_DIR FIO2DIR(03) // P2.03 == p23;
andrewboyson 5:82197a6997fd 15 #define RADIATOR_PUMP_PIN FIO2PIN(03)
andrewboyson 5:82197a6997fd 16 #define RADIATOR_PUMP_SET FIO2SET(03)
andrewboyson 5:82197a6997fd 17 #define RADIATOR_PUMP_CLR FIO2CLR(03)
andrewboyson 0:3c04f4b47041 18
andrewboyson 57:72c1c1357861 19 static char htgWinter; static int iWinter;
andrewboyson 0:3c04f4b47041 20 static char htgOverride; static int iOverride;
andrewboyson 48:6eac12df3ad5 21 static char* hallRom; static int iHallRom;
andrewboyson 0:3c04f4b47041 22 static int32_t nightTemperature; static int iNightTemperature;
andrewboyson 0:3c04f4b47041 23 static int32_t frostTemperature; static int iFrostTemperature;
andrewboyson 0:3c04f4b47041 24
andrewboyson 57:72c1c1357861 25 bool RadiatorGetWinter (){ return (bool)htgWinter; }
andrewboyson 48:6eac12df3ad5 26 bool RadiatorGetOverride (){ return (bool)htgOverride; }
andrewboyson 48:6eac12df3ad5 27 uint16_t RadiatorGetHallDS18B20Value(){ return DS18B20ValueFromRom(hallRom); }
andrewboyson 48:6eac12df3ad5 28 int RadiatorGetNightTemperature(){ return (int)nightTemperature; }
andrewboyson 48:6eac12df3ad5 29 int RadiatorGetFrostTemperature(){ return (int)frostTemperature; }
andrewboyson 0:3c04f4b47041 30
andrewboyson 57:72c1c1357861 31 static void setWinter ( bool value) { htgWinter = (char)value; FramWrite(iWinter, 1, &htgWinter ); }
andrewboyson 0:3c04f4b47041 32 static void setOverride ( bool value) { htgOverride = (char)value; FramWrite(iOverride, 1, &htgOverride ); }
andrewboyson 48:6eac12df3ad5 33 static void setHallRom (char* value) { memcpy(hallRom, value, 8); FramWrite(iHallRom, 8, hallRom ); }
andrewboyson 0:3c04f4b47041 34 void RadiatorSetNightTemperature ( int value) { nightTemperature = (int32_t)value; FramWrite(iNightTemperature, 4, &nightTemperature); }
andrewboyson 0:3c04f4b47041 35 void RadiatorSetFrostTemperature ( int value) { frostTemperature = (int32_t)value; FramWrite(iFrostTemperature, 4, &frostTemperature); }
andrewboyson 0:3c04f4b47041 36
andrewboyson 0:3c04f4b47041 37 static bool outputBeforeOverride = false;
andrewboyson 0:3c04f4b47041 38 static void makeOutputBeforeOverride()
andrewboyson 0:3c04f4b47041 39 {
andrewboyson 0:3c04f4b47041 40 //See if the temperature is too low
andrewboyson 0:3c04f4b47041 41 int hallTemp16ths = DS18B20ValueFromRom(hallRom);
andrewboyson 0:3c04f4b47041 42 int nightTemp16ths = nightTemperature << 4;
andrewboyson 0:3c04f4b47041 43 int frostTemp16ths = frostTemperature << 4;
andrewboyson 0:3c04f4b47041 44
andrewboyson 0:3c04f4b47041 45 static bool tooCold = false; //This is static to ride through invalid temperature reads
andrewboyson 0:3c04f4b47041 46 if (DS18B20IsValidValue(hallTemp16ths))
andrewboyson 0:3c04f4b47041 47 {
andrewboyson 0:3c04f4b47041 48 tooCold = hallTemp16ths < frostTemp16ths;
andrewboyson 57:72c1c1357861 49 if (htgWinter) tooCold |= hallTemp16ths < nightTemp16ths;
andrewboyson 0:3c04f4b47041 50 }
andrewboyson 0:3c04f4b47041 51
andrewboyson 76:3ef2a46c8b1e 52 outputBeforeOverride = (htgWinter && ProgramTimerOutput) || tooCold;
andrewboyson 0:3c04f4b47041 53 }
andrewboyson 0:3c04f4b47041 54 static void adjustOverride()
andrewboyson 0:3c04f4b47041 55 {
andrewboyson 0:3c04f4b47041 56 static bool previousOutput = false;
andrewboyson 0:3c04f4b47041 57 if (previousOutput != outputBeforeOverride) setOverride(false);
andrewboyson 0:3c04f4b47041 58 previousOutput = outputBeforeOverride;
andrewboyson 0:3c04f4b47041 59 }
andrewboyson 0:3c04f4b47041 60 bool RadiatorPump = false;
andrewboyson 0:3c04f4b47041 61 static void makeOutputWithOverride()
andrewboyson 0:3c04f4b47041 62 {
andrewboyson 0:3c04f4b47041 63 RadiatorPump = htgOverride ? !outputBeforeOverride : outputBeforeOverride ;
andrewboyson 0:3c04f4b47041 64 }
andrewboyson 0:3c04f4b47041 65
andrewboyson 57:72c1c1357861 66 void RadiatorSetWinter(bool value) //Summer is false, Winter is true
andrewboyson 0:3c04f4b47041 67 {
andrewboyson 57:72c1c1357861 68 if (htgWinter == (char)value) return; //Ignore no change
andrewboyson 57:72c1c1357861 69 setWinter(value); //Change to the new value
andrewboyson 0:3c04f4b47041 70
andrewboyson 0:3c04f4b47041 71 bool prevOutputBeforeOverride = outputBeforeOverride;
andrewboyson 0:3c04f4b47041 72 makeOutputBeforeOverride();
andrewboyson 0:3c04f4b47041 73
andrewboyson 0:3c04f4b47041 74 if (htgOverride) //Only deal with an override that is already set; if it wasn't set don't change it
andrewboyson 0:3c04f4b47041 75 {
andrewboyson 57:72c1c1357861 76 if (htgWinter) //Summer -> Winter
andrewboyson 0:3c04f4b47041 77 {
andrewboyson 0:3c04f4b47041 78 if (outputBeforeOverride != prevOutputBeforeOverride) setOverride(0); //Adjust the override to leave the heat as it was - off or on.
andrewboyson 0:3c04f4b47041 79 }
andrewboyson 0:3c04f4b47041 80 else //Winter -> Summer
andrewboyson 0:3c04f4b47041 81 {
andrewboyson 0:3c04f4b47041 82 setOverride(0); //turn off the heat.
andrewboyson 0:3c04f4b47041 83 }
andrewboyson 0:3c04f4b47041 84 }
andrewboyson 0:3c04f4b47041 85
andrewboyson 0:3c04f4b47041 86 makeOutputWithOverride();
andrewboyson 0:3c04f4b47041 87 }
andrewboyson 0:3c04f4b47041 88 void RadiatorSetOverride(bool value)
andrewboyson 0:3c04f4b47041 89 {
andrewboyson 0:3c04f4b47041 90 setOverride(value);
andrewboyson 0:3c04f4b47041 91 makeOutputBeforeOverride();
andrewboyson 0:3c04f4b47041 92 makeOutputWithOverride(); }
andrewboyson 0:3c04f4b47041 93
andrewboyson 57:72c1c1357861 94 void RadiatorChgWinter (){ RadiatorSetWinter (!RadiatorGetWinter ()); }
andrewboyson 0:3c04f4b47041 95 void RadiatorChgOverride(){ RadiatorSetOverride(!RadiatorGetOverride()); }
andrewboyson 0:3c04f4b47041 96
andrewboyson 0:3c04f4b47041 97 int RadiatorInit()
andrewboyson 0:3c04f4b47041 98 {
andrewboyson 48:6eac12df3ad5 99 hallRom = DS18B20Roms + 8 * DS18B20RomCount;
andrewboyson 48:6eac12df3ad5 100 DS18B20RomSetters[DS18B20RomCount] = setHallRom;
andrewboyson 48:6eac12df3ad5 101 DS18B20RomNames[DS18B20RomCount] = "Hall";
andrewboyson 48:6eac12df3ad5 102 DS18B20RomCount++;
andrewboyson 48:6eac12df3ad5 103
andrewboyson 0:3c04f4b47041 104 int address;
andrewboyson 0:3c04f4b47041 105 char def1;
andrewboyson 0:3c04f4b47041 106 int32_t def4;
andrewboyson 57:72c1c1357861 107 def1 = 0; address = FramLoad( 1, &htgWinter, &def1); if (address < 0) return -1; iWinter = address;
andrewboyson 0:3c04f4b47041 108 def1 = 0; address = FramLoad( 1, &htgOverride, &def1); if (address < 0) return -1; iOverride = address;
andrewboyson 0:3c04f4b47041 109 address = FramLoad( 8, hallRom, 0); if (address < 0) return -1; iHallRom = address;
andrewboyson 0:3c04f4b47041 110 def4 = 15; address = FramLoad( 4, &nightTemperature, &def4); if (address < 0) return -1; iNightTemperature = address;
andrewboyson 0:3c04f4b47041 111 def4 = 8; address = FramLoad( 4, &frostTemperature, &def4); if (address < 0) return -1; iFrostTemperature = address;
andrewboyson 0:3c04f4b47041 112
andrewboyson 5:82197a6997fd 113 RADIATOR_PUMP_DIR = 1; //Set the direction to 1 == output
andrewboyson 0:3c04f4b47041 114
andrewboyson 0:3c04f4b47041 115 return 0;
andrewboyson 0:3c04f4b47041 116 }
andrewboyson 0:3c04f4b47041 117 void RadiatorMain()
andrewboyson 0:3c04f4b47041 118 {
andrewboyson 0:3c04f4b47041 119 //Make the radiator output
andrewboyson 0:3c04f4b47041 120 makeOutputBeforeOverride();
andrewboyson 0:3c04f4b47041 121 adjustOverride();
andrewboyson 0:3c04f4b47041 122 makeOutputWithOverride();
andrewboyson 0:3c04f4b47041 123
andrewboyson 0:3c04f4b47041 124 //Pump output
andrewboyson 5:82197a6997fd 125 if (RadiatorPump) RADIATOR_PUMP_SET;
andrewboyson 5:82197a6997fd 126 else RADIATOR_PUMP_CLR;
andrewboyson 0:3c04f4b47041 127
andrewboyson 0:3c04f4b47041 128 }