View Single Post
Old 08-13-14, 05:02 PM   #181
Ormston
Apprentice EcoRenovator
 
Join Date: Mar 2013
Location: UK
Posts: 131
Thanks: 13
Thanked 35 Times in 32 Posts
Default

After a PM conversation with AC yesterday i agreed to write some code to hopefully get the GPHP controller started.

Below is a first draft, it compiles fine but i haven't had time to set up any hardware to test it.

Flow sensors on D2 and D3 (input flow and output flow), have used this code before should it should work fine. Calibrated for 3/4" version of the flow meters AC showed, i think the calibration should be the same.

D4 is input from thermostat, tank stat or whatever your heating. +5v to call for heat.
D4, D5 and D4 are outputs to compressor, input pump and output pump.

Thermistors on A0 and A1, this is untested code to me. Used thermistor library found here: Tutorial: Using NTC Thermistors With Arduino - GarageLab (arduino, electronics, robotics, hacking)
A0 is evaporator temp (water return to loop field in GSHP)
A1 is condensor temp, return from water tank or radiant floor.

Please try it and tell me what doesn't work. This really is a first draft with much testing and many more features required.

Steve

AC I will start a thread on my system when i get chance.

Code:
#include <Thermistor.h>


double evaporator, condensor;  //Variables for temperatures from thermistors
float HpLPM;                   //Flow rate from flow meter in L/m
float HpLPM1;                   //Flow rate from flow meter in L/m
int minLPM = 3;                //Minimum flowrate to run HP
int minEv = 2;                //Minimum evaporator temp
int maxCon = 65;              //Maximum condensor temp
byte runHP = false;
byte runCompressor = false;
byte runOutPump = false;       // pump to circulate water to house/tank
byte runInPump = false;        //fan in case of ASHP
const int demandPin = 4;       // input connected to external thermostat to request heat
byte demand = false;               // variable for reading if heat required from thermostat
unsigned long compLR;          // Time compressor was last run
unsigned long hpStarted;        // Time HP cycle started
unsigned long hpStopped;        // Time HP cycle stopped
volatile int NbTopsFan; //measuring the rising edges of the signal
volatile int NbTopsFan1; //measuring the rising edges of the signal
int hallsensor = 2; //The pin location of the sensor
int hallsensor1 = 3; //The pin location of the sensor
byte led = 13;
byte ledState = false;
byte comp = 5;
byte inPump = 6;
byte outPump = 7;
unsigned long prevMillis = 0;        //used for led blinking
Thermistor temp(0);
Thermistor temp1(1);

// ********************Temperature measurement starts here**************
void readTemps() { //read all temperatures from thermistors
  evaporator = temp.getTemp();
  condensor = temp1.getTemp();
  }

// ********************Temperature measurement ends here**************

// ********************Flow meter reading starts here**************

void hpFlow () //This is the function that the interupt calls
{
  NbTopsFan++;  //This function measures the rising and falling edge of the hall effect sensors signal
}

void hpFlow1 () //This is the function that the interupt calls
{
  NbTopsFan1++;  //This function measures the rising and falling edge of the hall effect sensors signal
}

void readFlows()
{
  NbTopsFan = 0; //Set NbTops to 0 ready for calculations
  NbTopsFan1 = 0; //Set NbTops to 0 ready for calculations
  interrupts(); //Enables interrupts
  delay (1000); //Wait 1 second
  noInterrupts(); //Disable interrupts
  HpLPM = (NbTopsFan / 2.75);
  HpLPM = (NbTopsFan1 / 2.75);
}
// ********************Flow meter reading ends here**************


void setup() {
  pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input
  pinMode(hallsensor1, INPUT); //initializes digital pin 3 as an input
  attachInterrupt(0, hpFlow, RISING); //and the interrupt is attached (1 for Leonardo 0 for mega/uno)
  attachInterrupt(1, hpFlow1, RISING); //and the interrupt is attached (0 for Leonardo 1 for mega/uno)
  pinMode(led, OUTPUT);
  pinMode(comp, OUTPUT);
  pinMode(inPump, OUTPUT);
  pinMode(outPump, OUTPUT);
  pinMode(demandPin, INPUT); 
  compLR = millis();

}

void loop() {
  readTemps();
  readFlows();
  demand = digitalRead(demandPin);

  unsigned long tm = millis();
  if ((demand == true) && (compLR <= (tm - 120000))) {
    if (runHP == false) hpStarted = tm;
    runHP = true;
  }
  else {
    if (runHP == true) hpStopped = tm;
    runHP = false;
  }

  //*****HP startup cycle********
  if (runHP == true) runInPump = true;
  if ((runHP == true) && (hpStarted <= (tm - 30000) && (HpLPM > minLPM))) runCompressor = true; //Delay compressor start 30s after starting in pump
  if ((runHP == true) && (hpStarted <= (tm - 60000))) {
    runOutPump = true; //Delay out pump start 60s after starting in pump
    ledState = true; ///turn on pin 13 led after startup of HP
  }
  
  //*****HP shutdown cycle********
  if (runHP == false) runCompressor = false;
  if ((runHP == false) && (hpStopped <= (tm - 120000))) runInPump = false;
  if ((runHP == false) && (hpStopped <= (tm - 300000))) {
    runOutPump = false;
    compLR = tm;
    ledState = false; ///turn off pin 13 led after shutdown of HP
  }
  
  //***Check flow rates above min***
  if (HpLPM < minLPM || HpLPM1 < minLPM) {
    runCompressor = false;
    if (runHP == true) hpStopped = tm;
    compLR = (tm + 600000); //prevent cycle restart for 10m
    runHP = false;
  }

 //***Check evaporator/condensor above/below limits*** not intended for defrost purposes, halts system for 30m
  if (evaporator < minEv || condensor > maxCon) {
    runCompressor = false;
    if (runHP == true) hpStopped = tm;
    compLR = (tm + 1800000); //prevent cycle restart for 30m
    runHP = false;
  }
    
  
  digitalWrite(led, ledState);
  digitalWrite(comp, runCompressor);
  digitalWrite(inPump, runInPump);
  digitalWrite(outPump, runOutPump);


}

Ormston is offline   Reply With Quote
The Following 2 Users Say Thank You to Ormston For This Useful Post:
AC_Hacker (08-13-14), buffalobillpatrick (08-13-14)