|
02-18-15, 04:45 PM | #1 |
Master EcoRenovator
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
|
Arduino Subcooling code
Subcooling only code:
Code:
/******************************************************** * * ARDUINO R290 Calculate Subcooling * * Note: REQUIRED SENSOR * High Pressure Sensor: 0-300PSI with output of .5 -> 4.5vdc * * If in DEBUG mode, values are forced to test code function * * In Void Loop: * * , read Hi Side Pressure Transducer * * , if RAW_ADC is in bounds: * , convert Raw_ADC to PSI * , calc_R290_Saturated_Temp * , read Subcooling_Temp_sensor (analog NTC thermistor) * , calc Subcooling * * , if RAW_ADC is out of bounds, Hang Forever * * Repeat Void loop * * * Change History: * 02/18/15 Coded, BBP * * * ********************************************************/ #if defined(ARDUINO) && ARDUINO >= 100 #include "Arduino.h" #else #include "WProgram.h" #endif #include <Wire.h> #include <LCD.h> #include <LiquidCrystal_I2C.h> #define DEBUG 1 //#define DEBUG 0 #define I2C_ADDR 0x3F // <<----- Add your address here. Find it from I2C Scanner //D3 #define BACKLIGHT_PIN 3 //define LCD digital pins #define En_pin 2 #define Rw_pin 1 //can't use D0 & D1 Tx, Rx #define Rs_pin 0 #define D4_pin 4 #define D5_pin 5 //can use D2 -> D12 below in code #define D6_pin 6 #define D7_pin 7 LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); #define SDA A4 //RESERVE I2C for LCD #define SCL A5 // pinMode(A0, OUTPUT); //This works acording // http://arduino.cc/en/Tutorial/AnalogInputPins // digitalWrite(A0, HIGH); // #define Subcooling_Temp_sensor_pin A0 #define Hi_Side_Pressure_Transducer_pin A1 #define ADC_Low_Limit 102.0 //ADC of .5v #define ADC_Hi_Limit 921.0 //ADC of 4.5v #define PSI_min 0.0 #define PSI_max 300.0 float Raw_ADC, Hi_Side_PSI, Subcooling_T, Subcooling, Saturated_Temp; int Y; void setup(void) //Start Setup { pinMode (Subcooling_Temp_sensor_pin, INPUT); pinMode (Hi_Side_Pressure_Transducer_pin, INPUT); // Serial.begin(9600); // start serial communication // delay(10000); //time to enable monitor window // Serial.println(F("........Hello world!.......")); // delay(100); lcd.begin (16,2); // <<----- My LCD is 16x2 lcd.clear(); //Switch on the backlight lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); lcd.setBacklight(HIGH); lcd.clear(); lcd.home (); // go home lcd.print(F("R290_SUBCOOL_3")); delay(10000); if(DEBUG) { lcd.clear(); lcd.home (); // go home lcd.print(F("DEBUG = ON")); delay(10000); } else { lcd.clear(); lcd.home (); // go home lcd.print(F("DEBUG = OFF")); delay(10000); } } //end setup void loop () { Raw_ADC = analogRead(Hi_Side_Pressure_Transducer_pin); //read Hi Side pressure if(DEBUG){ Raw_ADC = 921;} //Raw_ADC Bounds check if ((Raw_ADC >= ADC_Low_Limit) && (Raw_ADC <= ADC_Hi_Limit)) { // in bounds, convert Raw_ADC to PSI Hi_Side_PSI = mapfloat(Raw_ADC, ADC_Low_Limit, ADC_Hi_Limit, PSI_min, PSI_max); lcd.clear(); lcd.home (); // go home lcd.print(F("SUBCOL_PSI=")); lcd.print(Hi_Side_PSI); delay(10000); Saturated_Temp = calc_R290_Saturated_Temp(Hi_Side_PSI); lcd.clear(); lcd.home (); // go home lcd.print(F("SAT_T=")); lcd.print(Saturated_Temp); lcd.print(F("*F")); delay(10000); //read Subcooling Temp sensor Subcooling_T = (Read_10K_NTC (Subcooling_Temp_sensor_pin)); if(DEBUG){ Subcooling_T = 150;} lcd.clear(); lcd.home (); // go home lcd.print(F("SUBCOL_T=")); lcd.print(Subcooling_T); lcd.print(F("*F")); delay(10000); Subcooling = Subcooling_T - Saturated_Temp; //calc Subcooling lcd.clear(); lcd.home (); // go home lcd.print(F("SUBCOOL=")); lcd.print(Subcooling); lcd.print(F("*F")); delay(10000); } //end if in bounds else //ADC out of bounds { lcd.clear(); lcd.home (); // go home lcd.print(F("RAW_PSI_NG")); lcd.setCursor(0,1); lcd.print(F("HANG_FOREVER_1")); do{Y = Y;} while (Y == Y); //hang forever } } //end forever loop float mapfloat(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } float calc_R290_Saturated_Temp(float psi) { //MMF Model: y=(a*b+c*x^d)/(b+x^d) //Coefficient Data: float a = -6.63511955666E+001; float b = 6.30623048298E+001; float c = 7.72874234743E+002; float d = 5.32503085812E-001; float p; p = pow(psi,d); return (((a * b) + (c * p)) / (b + p )); } int Read_10K_NTC (int which_sensor) { #define sample_cnt 30 float alpha = 0.9; // factor to tune float average = 0.0; float steinhart; int I; // resistance at 25 degrees C #define THERMISTORNOMINAL 10000 // TEMP. for nominal resistance (almost always 25 C) #define TEMPERATURENOMINAL 25 // The beta coefficient of the thermistor (usually 3000-4000) #define BCOEFFICIENT 3892 // the value of the series resistor #define SERIESRESISTOR 10000 for (I=0; I< sample_cnt; I++) { average = alpha * analogRead(which_sensor) + (1-alpha) * average; delay(10); } // convert the value to resistance average = 1023 / average - 1; average = SERIESRESISTOR / average; steinhart = average / THERMISTORNOMINAL; // (R/Ro) steinhart = log(steinhart); // ln(R/Ro) steinhart /= BCOEFFICIENT; // 1/B * ln(R/Ro) steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) steinhart = 1.0 / steinhart; // Invert steinhart -= 273.15; // convert to C return (round(steinhart * 1.8) + 32); // round to whole number // & convert to F } // end of Read_10K_NTC Last edited by buffalobillpatrick; 02-19-15 at 08:11 PM.. Reason: improved function: calc_R290_Saturated_Temp |
02-19-15, 02:03 AM | #2 |
Supreme EcoRenovator
Join Date: Oct 2008
Location: Austin, TX
Posts: 1,154
Thanks: 14
Thanked 257 Times in 241 Posts
|
Just as with superheat, two temperature sensors are all you need to calculate subcooling. But unlike superheat, it's not quite as straightforward to find the point that tracks the discharge pressure. I suggest checking along the condenser after the system has been running in steady state for a few minutes. You'll find a large section that's basically the same temperature and it corresponds well to the actual high side pressure. Put the temperature sensor in the middle of the section and you're good to go.
BTW, in my experience, the subcooling measurement isn't really used for control but rather just to check that all is well.
__________________
To my surprise, shortly after Naomi Wu gave me a bit of fame for making good use of solar power, Allie Moore got really jealous of her... |
The Following User Says Thank You to NiHaoMike For This Useful Post: | buffalobillpatrick (02-19-15) |
02-19-15, 11:40 AM | #3 |
Master EcoRenovator
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
|
NiHaoMike, thanks. Mikesolar wanted Subcooling only for EEV
|
02-19-15, 05:25 PM | #4 |
Master EcoRenovator
Join Date: Aug 2012
Location: Toronto
Posts: 958
Thanks: 40
Thanked 158 Times in 150 Posts
|
I will hook it to a MEGA when it comes in the mail. I had one but seem to have blown most of the output pins with wrong resistors values. I have a relay board so I should be able to run the 12vdc stepper and see how it works. It is important that the limits of the valve travel are known to the control so it doesn't try to drive it past its limits. Also, the valve needs to open a bit before starting the pot.
|
The Following User Says Thank You to Mikesolar For This Useful Post: | buffalobillpatrick (02-19-15) |
02-19-15, 08:07 PM | #5 |
Master EcoRenovator
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
|
Good Luck Mike, keep us posted. I have no clue as to stepper motor control. I bet some Arduino users have some code you can borrow.
|
02-19-15, 09:03 PM | #6 |
Master EcoRenovator
Join Date: Aug 2012
Location: Toronto
Posts: 958
Thanks: 40
Thanked 158 Times in 150 Posts
|
I thought arduino was your forte?
|
02-20-15, 12:29 PM | #7 |
Master EcoRenovator
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
|
I dabble in Arduino & C programming, not an expert.
When I want to do something that may fit an Arduino, I google something like: "arduino stepper motor" & start reading. Like: stepper_oneRevolution.tiff Or: http://arduino.cc/en/Reference/Stepper I poke around in the hits & try to learn & see what code exists that I can steal & modify. Try to find info on the stepper moror type that you have. I have never asked a question on the official Arduino site from the true experts. I don't know their very specific format & rules. They really beat-up people why don't follow their rules. They remind me of the Jerry Seinfeld show "Soup Nazi" Last edited by buffalobillpatrick; 02-20-15 at 01:02 PM.. |
02-20-15, 12:40 PM | #8 |
Master EcoRenovator
Join Date: Aug 2012
Location: Toronto
Posts: 958
Thanks: 40
Thanked 158 Times in 150 Posts
|
The one I have is bipolar, 12vdc and 2500 steps full travel.
I don't know what other equipment info is needed to create a program. I guess just an order of operations (if this, than that, etc) |
02-20-15, 03:03 PM | #9 |
Master EcoRenovator
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
|
http://www.solarbotics.net/library/p..._steppers.html
http://library.solarbotics.net/pdflib/pdf/motorbas.pdf http://www.tigoe.com/pcomp/code/circ...tepper-motors/ Arduino - StepperBipolarCircuit 2 or 4 pins? Arduino - StepperConstructor http://arduino.cc/en/Reference/StepperSetSpeed http://arduino.cc/en/Reference/StepperStep |
02-20-15, 03:52 PM | #10 |
Master EcoRenovator
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
|
Some good info from pro's:
http://forum.arduino.cc/index.php?topic=284828.0 http://www.lucidtronix.com/tutorials/24 |
|
|