EcoRenovator  

Go Back   EcoRenovator > Improvements > Geothermal & Heat Pumps
Advanced Search
 


Blog 60+ Home Energy Saving Tips Recent Posts


Reply
 
Thread Tools Display Modes
Old 11-19-14, 11:00 AM   #281
buffalobillpatrick
Master EcoRenovator
 
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
Default

My thermistor code defines address:

Code:
                                 //define Digital output pins for MUX 
                                 // multiplexer address select lines (A/B/C/D)
const byte mux_address_A       = 7;
const byte mux_address_B       = 8; 
const byte mux_address_C       = 9; 
const byte mux_address_D       = 10; 
const byte mux_enable          = 12;  // multiplexer enable


#define mux_analog_in                 A0  //multiplexer to Arduino analog in pin       


              //analog signals into MUX, these are NOT analog pins on Arduino
#define COND_IN_sensor               0 
#define COND_OUT_sensor              1 

#define HIGH_SIDE_IHX_OUT_sensor     2 

#define EVAP_IN_sensor               3 
                                        //4 & 5 dead on mux
#define EVAP_OUT_sensor              6                        

#define LOW_SIDE_IHX_OUT_sensor      7 

#define ESWT_sensor                  8              
#define XSWT_sensor                  9  

#define ELWT_sensor                 10
                                        //11 & 12 dead on mux
#define XLWT_sensor                 13



void setup(void)       //Start Setup
  {       
  pinMode (mux_analog_in, INPUT);  //MUX DATA INPUT
  pinMode (mux_address_A, OUTPUT); // multiplexer address select lines (A/B/C/D)
  pinMode (mux_address_B, OUTPUT); 
  pinMode (mux_address_C, OUTPUT); 
  pinMode (mux_address_D, OUTPUT); 
  pinMode (mux_enable,    OUTPUT); // multiplexer enable
  }



//Example of reading sensor
     
  Sensor_Data         =  (Read_10K_NTC (COND_IN_sensor));                  
  lcd.clear();
  lcd.home (); // go home
  lcd.print(F("COND_IN="));
  lcd.print(Sensor_Data);




//function that reads thermistors

int Read_10K_NTC (const byte which_sensor)
  {   
  #define sample_cnt 23                    //takes 254 MS
  
  float alpha =   0.9;     // factor to tune
  float average = 0.0;
  
  int I;
 
  float steinhart;

// 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



//  T1 = millis();



  digitalWrite (mux_enable, HIGH); //disable
  delay(10);

  // select correct MUX channel
  digitalWrite (mux_address_A, (which_sensor & 1) ? HIGH : LOW);
  digitalWrite (mux_address_B, (which_sensor & 2) ? HIGH : LOW);
  digitalWrite (mux_address_C, (which_sensor & 4) ? HIGH : LOW);
  digitalWrite (mux_address_D, (which_sensor & 8) ? HIGH : LOW);

  digitalWrite (mux_enable, LOW); //enable
  delay(10);


  
  for (I=0; I< sample_cnt; I++) 
  {  
  average =  alpha * analogRead(mux_analog_in) + (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  

/*
  T2 = millis();

  TT = T2 - T1;
  
  lcd.clear();
  lcd.home (); // go home
  lcd.print(TT); 
  delay(10000); 
*/           
  }  // end of Read_10K_NTC


Last edited by buffalobillpatrick; 11-19-14 at 11:27 AM..
buffalobillpatrick is offline   Reply With Quote
The Following User Says Thank You to buffalobillpatrick For This Useful Post:
jeff5may (11-19-14)
Old 11-19-14, 04:49 PM   #282
jeff5may
Supreme EcoRenovator
 
Join Date: Jan 2010
Location: elizabethtown, ky, USA
Posts: 2,428
Thanks: 431
Thanked 619 Times in 517 Posts
Send a message via Yahoo to jeff5may
Default

I'm guessing my temperature reading routine will not be so precise. My goal is more towards operation and ease of connection. It will be something like this, taken straight off hacktronics:

Code:
double Thermister(int RawADC) {
  double Temp;
  // See http://en.wikipedia.org/wiki/Thermistor for explanation of formula
  Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
  Temp = Temp - 273.15;           // Convert Kelvin to Celcius
  return Temp;
}
If utmost accuracy is your goal, a thermistor might not be the best means. I don't plan on using thermistors forever... Once I sort out how the unit will do what it does with 1wire sensors, I may not even use thermistors in my unit. Of course, the pins and code will be there if you want to connect a thermistor (or linear sensor) in your unit. The key here is flexibility and support.
jeff5may is offline   Reply With Quote
The Following User Says Thank You to jeff5may For This Useful Post:
buffalobillpatrick (11-19-14)
Old 11-19-14, 05:31 PM   #283
buffalobillpatrick
Master EcoRenovator
 
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
Default

Hi Jeff,

Arduino compiles double float, but really don't execute double precision floating point arithemitic operations.

I find thermistors to be very repeatable & accurate.

I can scan 16 thermistors & print out their temperatures in a continuous loop.

As room temperature moves up or down over a 12 hr. period

They all report the same temperature +- 1*F

No bouncing around, no noise problems, no addressing problems.

Last edited by buffalobillpatrick; 11-19-14 at 05:33 PM..
buffalobillpatrick is offline   Reply With Quote
The Following User Says Thank You to buffalobillpatrick For This Useful Post:
jeff5may (11-19-14)
Old 11-19-14, 06:09 PM   #284
jeff5may
Supreme EcoRenovator
 
Join Date: Jan 2010
Location: elizabethtown, ky, USA
Posts: 2,428
Thanks: 431
Thanked 619 Times in 517 Posts
Send a message via Yahoo to jeff5may
Default

Quote:
Originally Posted by buffalobillpatrick View Post
Hi Jeff,

Arduino compiles double float, but really don't execute double precision floating point arithemitic operations.

I find thermistors to be very repeatable & accurate.

I can scan 16 thermistors & print out their temperatures in a continuous loop.

As room temperature moves up or down over a 12 hr. period

They all report the same temperature +- 1*F

No bouncing around, no noise problems, no addressing problems.
Good to know this ahead of time. I may end up pointing to your code for others to use, or robbing it myself, in the future.

I grabbed this example from the same website I found working libraries for onewire and the dallas sensors. I will probably just use floats in the real thing.

The problem with thermistors is like the wizard was eluding to: to get total accuracy, you have to calibrate for each individual sensor. I know this level of accuracy will be outside the scope of this project, but there are many different mfrs and brands of 10k thermistors. I'm not so sure that a sensor is a sensor is a sensor.

For instance, a sensor existing in a 10 year old repurposed unit may not read exactly the same as a brand new one bought from sparkfun. If both are run through the same algorithm, they may not yield the same result. For what it's worth, I DON"T CARE. As long as both sensors read something somewhat close to what exists in reality, that's good enough for my monster. It may not be good enough for what someone else is planning on doing, though.

Last edited by jeff5may; 11-19-14 at 06:13 PM..
jeff5may is offline   Reply With Quote
Old 11-19-14, 06:32 PM   #285
jeff5may
Supreme EcoRenovator
 
Join Date: Jan 2010
Location: elizabethtown, ky, USA
Posts: 2,428
Thanks: 431
Thanked 619 Times in 517 Posts
Send a message via Yahoo to jeff5may
Default

Quote:
Originally Posted by RB855 View Post
Have been following this for a while now (just in case my chinese heatpump waterheater controller ever failed), and while working on a window shaker the other day something occurred to me. The unit I was repairing had a failed relay board. This board contains all in one many of the components mentioned early on in the thread. It has 3x 25amp relays, 4x 3amp relays, 5v filtered regulated power supply (minus off board transformer), relays are opto-isolated, has a little piezo beeper, and 3 removable temp sensors (1x tube sensors, 2x air temp) with onboard filtering. And this whole board as it sits only costs about 22$ Now, as I mentioned this board had failed, but the 6 I have here in front of me, every single one only has a bad filter capacitor on the 5v supply, an easy fix! The boards I have on hand are Amana 30132023 , which lack 1 of the 3amp relays, but the 30132033 has the most relays, and actually costs less... Since these are all warranty change outs and were heading for the trash, if there is interest in toying with one of these, pay the post and its yours!

I should mention, originally the 4 small relays were for reversing valve, low-med-high fan speed. The large relays, 2 were used for the heat as a redundancy and 100% isolation from mains, and one for the compressor (the top pin on this relay supplies L1 to the board through a 3.15a fuse, L2 is on the board itself, that has a pinout for the xfmr and runs the fan/rvalve outputs). One of the air temp sensors was inlet, one was outlet, and depending on the model the tube sensor was mounted to evap or condenser. There is a model board out there with both, but i forgot which one it is.
Also note worthy, Amana 30132030 has a 5th 3amp relay used for vent swing motor, and uses 4 sensors, and uses a different form factor, otherwise the same as above.
Do these boards also have the relay driver IC on them? If so, they will work as the brawn that will slave directly off of the uno's brain! I got my uno board working my beige-box window unit using one of these power boards. The only other stuff I used was some pieces out of the starter kit package (a dinky proto-board, a few jumper wires, and a chopped up usb cable) I ordered with my uno board. For someone building a "mutt" unit, the power boards could save lots of time, effort, trial and error.

PM me if you haven't gotten any takers. I'd pay you something more than just shipping for them.
jeff5may is offline   Reply With Quote
Old 11-19-14, 06:37 PM   #286
theoldwizard1
Apprentice EcoRenovator
 
Join Date: Oct 2014
Location: SE MI
Posts: 105
Thanks: 3
Thanked 12 Times in 9 Posts
Default

Arduino Une and Mega chip (ATmega328) does not have a "native" floating point processor. Floating point is done via compiler libraries, which can be very slow.

IMHO, float should be avoided at all costs. There are "tricks" you can use, especially if the compiler properly handles long (32 bit) and long long (64 bits) that will give you all the range and accuracy that you could need and will actually execute faster than most floating point processors.

Last edited by theoldwizard1; 11-19-14 at 06:54 PM..
theoldwizard1 is offline   Reply With Quote
The Following 2 Users Say Thank You to theoldwizard1 For This Useful Post:
buffalobillpatrick (11-19-14), jeff5may (11-19-14)
Old 11-19-14, 06:53 PM   #287
theoldwizard1
Apprentice EcoRenovator
 
Join Date: Oct 2014
Location: SE MI
Posts: 105
Thanks: 3
Thanked 12 Times in 9 Posts
Default

Quote:
Originally Posted by buffalobillpatrick View Post
I find thermistors to be very repeatable & accurate.
Yep ! Their only issue is "accuracy" at the extremes of their range.

Below is a "typical" thermistor "transfer function".



At lower and higher temperatures, the function curves and approaches each axis. The area of the curve in the is more "linear" which is highly desirable.
theoldwizard1 is offline   Reply With Quote
The Following User Says Thank You to theoldwizard1 For This Useful Post:
buffalobillpatrick (11-19-14)
Old 11-19-14, 07:07 PM   #288
buffalobillpatrick
Master EcoRenovator
 
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
Default

No long long, so sorry!

theoldwizard1, I'm glad you are on board & contributing, actual experience is hard to come by!

Floats work fine on Arduino acording to all that I have read.
Time is used up for sure!

My 23X sample loops take about 11ms each, the actual analogRead takes about 100us, so most of the rest is floating point math.

Jeff,
Your math is difficult for me to translate from that Wikipedia page.

I don't see in your math where the Beta-coefficient of the thermistor is used?
This is important and is specified with each batch of thermistors.

in mine you would change the #define

// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3892


Also your example don't average & smooth out possible anomilas readings.
Long sensor wires are susceptible to noise.

Last edited by buffalobillpatrick; 11-19-14 at 07:31 PM..
buffalobillpatrick is offline   Reply With Quote
Old 11-19-14, 07:59 PM   #289
theoldwizard1
Apprentice EcoRenovator
 
Join Date: Oct 2014
Location: SE MI
Posts: 105
Thanks: 3
Thanked 12 Times in 9 Posts
Default

Quote:
Originally Posted by buffalobillpatrick View Post
No long long, so sorry!
Bummer, but not a job stopper !

I would still stay away from float. The big problem with integer arithmetic is multiplication and division. A 32x32 multiplication (could) result in a 64 bit result. You would really like to be able to do a 64 by 32 bit divide.


Quote:
theoldwizard1, I'm glad you are on board & contributing, actual experience is hard to come by!
Hopefully I haven't forgotten too much !!
theoldwizard1 is offline   Reply With Quote
Old 11-19-14, 09:03 PM   #290
jeff5may
Supreme EcoRenovator
 
Join Date: Jan 2010
Location: elizabethtown, ky, USA
Posts: 2,428
Thanks: 431
Thanked 619 Times in 517 Posts
Send a message via Yahoo to jeff5may
Default

In this project, we are not guiding sidewinder or patriot missiles to a quickly moving target. I'm not overly concerned whether a calculation takes 15 clock cycles or 600 to compute. The temperatures are not going to change that fast. Clock cycles and loop times are only relevant to gathering user input via key presses. If the cpu is busy running slow routines, it could take a couple of key presses to get a response.

I am, however, concerned about extra or buggy lines of code that eat memory or force huge piles on the stack and data registers. This is one reason I'm trying to use global variables and few libraries. If at all possible, I would like not to have to resort to adding any extra shields to the basic controller to gain memory for comm buffers and the like. I have a feeling this will be a challenge given the severely limited amount of onboard program memory and RAM.

jeff5may is offline   Reply With Quote
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 09:59 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Ad Management by RedTyger
Inactive Reminders By Icora Web Design