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
Diff: heating/boiler.c
- Revision:
- 35:bb8a6d1c034c
- Parent:
- 13:2ca12dd42e91
- Child:
- 41:6413522ed343
--- a/heating/boiler.c Thu Feb 28 16:21:15 2019 +0000 +++ b/heating/boiler.c Thu Mar 07 15:17:26 2019 +0000 @@ -2,10 +2,10 @@ #include <stdint.h> #include <stdbool.h> -#include "gpio.h" -#include "clktime.h" +#include "gpio.h" +#include "mstimer.h" #include "ds18b20.h" -#include "fram.h" +#include "fram.h" #define BOILER_PUMP_DIR FIO2DIR(4) // P2.4 == p22 #define BOILER_PUMP_PIN FIO2PIN(4) @@ -21,7 +21,6 @@ static char outputRom[8]; static int iOutputRom; static char returnRom[8]; static int iReturnRom; - static int32_t tankSetPoint; static int iTankSetPoint; static int32_t tankHysteresis; static int iTankHysteresis; static int32_t runOnResidual; static int iRunOnResidual; @@ -43,7 +42,6 @@ void BoilerSetRunOnResidual (int value) { runOnResidual = (int32_t)value; FramWrite(iRunOnResidual, 4, &runOnResidual ); } void BoilerSetRunOnTime (int value) { runOnTime = (int32_t)value; FramWrite(iRunOnTime, 4, &runOnTime ); } - int BoilerInit() { int address; @@ -61,12 +59,9 @@ return 0; } -bool BoilerPump = false; bool BoilerCall = false; - -void BoilerMain() +static void controlBoilerCall() { - //Control boiler call int tankTemp16ths = DS18B20ValueFromRom(tankRom); if (DS18B20IsValidValue(tankTemp16ths)) //Ignore values which are likely to be wrong { @@ -77,32 +72,34 @@ if (tankTemp16ths >= tankUpper16ths) BoilerCall = false; if (tankTemp16ths <= tankLower16ths) BoilerCall = true; } - if (BoilerCall) BOILER_CALL_SET; - else BOILER_CALL_CLR; - - //Control boiler circulation pump +} +bool BoilerPump = false; +static void controlBoilerPump() +{ int boilerOutput16ths = DS18B20ValueFromRom(outputRom); int boilerReturn16ths = DS18B20ValueFromRom(returnRom); int boilerResidual16ths = boilerOutput16ths - boilerReturn16ths; int boilerTempsAreValid = DS18B20IsValidValue(boilerOutput16ths) && DS18B20IsValidValue(boilerReturn16ths); - static int64_t offTicks; + static uint32_t msTimerBoilerPumpRunOn = 0; if (BoilerCall) { BoilerPump = true; - offTicks = ClkTimeGet(); + msTimerBoilerPumpRunOn = MsTimerCount; } else { - int secondsSinceBoilerOff = (ClkTimeGet() - offTicks) >> CLK_TIME_ONE_SECOND_SHIFT; - if (secondsSinceBoilerOff > runOnTime) BoilerPump = false; - if (boilerTempsAreValid) - { - int boilerStillSupplyingHeat = boilerResidual16ths > runOnResidual; - if (!boilerStillSupplyingHeat) BoilerPump = false; - } + if (MsTimerHasElapsed(msTimerBoilerPumpRunOn, runOnTime * 1000)) BoilerPump = false; + if (boilerTempsAreValid && boilerResidual16ths < runOnResidual << 4) BoilerPump = false; } +} +void BoilerMain() +{ + controlBoilerCall(); + if (BoilerCall) BOILER_CALL_SET; + else BOILER_CALL_CLR; + controlBoilerPump(); if (BoilerPump) BOILER_PUMP_SET; else BOILER_PUMP_CLR;