11-19-14, 12:00 PM | #281 |
Master EcoRenovator
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
|
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 12:27 PM.. |
The Following User Says Thank You to buffalobillpatrick For This Useful Post: | jeff5may (11-19-14) |
11-19-14, 05:49 PM | #282 |
Supreme EcoRenovator
|
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; } |
The Following User Says Thank You to jeff5may For This Useful Post: | buffalobillpatrick (11-19-14) |
11-19-14, 06:31 PM | #283 |
Master EcoRenovator
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
|
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 06:33 PM.. |
The Following User Says Thank You to buffalobillpatrick For This Useful Post: | jeff5may (11-19-14) |
11-19-14, 07:09 PM | #284 | |
Supreme EcoRenovator
|
Quote:
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 07:13 PM.. |
|
11-19-14, 07:32 PM | #285 | |
Supreme EcoRenovator
|
Quote:
PM me if you haven't gotten any takers. I'd pay you something more than just shipping for them. |
|
11-19-14, 07:37 PM | #286 |
Apprentice EcoRenovator
Join Date: Oct 2014
Location: SE MI
Posts: 105
Thanks: 3
Thanked 12 Times in 9 Posts
|
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 07:54 PM.. |
The Following 2 Users Say Thank You to theoldwizard1 For This Useful Post: |
11-19-14, 07:53 PM | #287 |
Apprentice EcoRenovator
Join Date: Oct 2014
Location: SE MI
Posts: 105
Thanks: 3
Thanked 12 Times in 9 Posts
|
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. |
The Following User Says Thank You to theoldwizard1 For This Useful Post: | buffalobillpatrick (11-19-14) |
11-19-14, 08:07 PM | #288 |
Master EcoRenovator
Join Date: Mar 2014
Location: Florissant, Colorado
Posts: 599
Thanks: 814
Thanked 59 Times in 55 Posts
|
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 08:31 PM.. |
11-19-14, 08:59 PM | #289 | |
Apprentice EcoRenovator
Join Date: Oct 2014
Location: SE MI
Posts: 105
Thanks: 3
Thanked 12 Times in 9 Posts
|
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:
|
|
11-19-14, 10:03 PM | #290 |
Supreme EcoRenovator
|
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. |
|
|