08-15-14, 12:42 PM | #11 |
Master EcoRenovator
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
|
I don't mean to step on toes!
Only way I can understand someones code is to start messing with it. My changes: some time names & blocking_delay >= on delays Check my changes for being correct? Ormston_Rev02 Code:
#include <Thermistor.h> //Got tired of counting zeros #define One_Sec 1000 #define Half_Min 30000 #define One_Min 60000 #define Two_Min 120000 #define Five_Min 300000 #define Ten_Min 600000 #define Thirty_Min 1800000 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 blocking_Time; // Delay Time unsigned long hpStart_Time; // Time HP cycle started unsigned long hpStop_Time; // 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 (One_Sec); //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); blocking_Time = millis(); } void loop() { readTemps(); readFlows(); demand = digitalRead(demandPin); unsigned long current_Time = millis(); if ((demand == true) && (blocking_Time >= (current_Time - Two_Min))) //Wait 2 min. { if (runHP == false) hpStart_Time = current_Time; runHP = true; } else { if (runHP == true) hpStop_Time = current_Time; runHP = false; } //*****HP startup cycle******** if (runHP == true) runInPump = true; if ((runHP == true) && (hpStart_Time >= (current_Time - Half_Min) //Delay compressor start 30s && (HpLPM > minLPM))) //after starting in pump runCompressor = true; if ((runHP == true) && (hpStart_Time >= (current_Time - One_Min))) { 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) && (hpStop_Time >= (current_Time - Two_Min))) runInPump = false; if ((runHP == false) && (hpStop_Time >= (current_Time - Five_Min))) //delay 5 min. { runOutPump = false; blocking_Time = current_Time; 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) hpStop_Time = current_Time; blocking_Time = (current_Time + Ten_Min); //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) hpStop_Time = current_Time; blocking_Time = (current_Time + Thirty_Min); //prevent cycle restart for 30m runHP = false; } digitalWrite(led, ledState); digitalWrite(comp, runCompressor); digitalWrite(inPump, runInPump); digitalWrite(outPump, runOutPump); } Last edited by buffalobillpatrick; 08-15-14 at 01:21 PM.. |
|
|