Latest Forum Posts

Latest News Posts
Coming Soon!
Social
Go Back   Techgage.com > Hardware > Mobile & Small Form-Factor Computing

Mobile & Small Form-Factor Computing Discuss notebooks, PDAs, Smartphones, Cell Phones and all other mobile devices here.

Reply
 
Thread Tools
Old 10-25-2012, 03:08 AM   #31
Tharic-Nar
Techgage Staff
 
Tharic-Nar's Avatar
 
Join Date: Nov 2009
Location: UK
Posts: 1,166
Default

So I ran into complications, (as one does), an incorrect resistor (47Ohm instead of 49K9) and the wrong coefficients derived from an incorrect thermistor model number, plus a lot of mucking around in the Arduino IDE - I managed to (finally) get one of the thermistors reading temps, and very accurately I might add. Using existing code examples gave my either horribly results (600+ or -100C), or failed to compile (I have no clue when it comes to programming). After a few hours of fudging with maths, bad code and an incorrect resistor... I have this!



Yeah, so not that impressive... but I'm getting there. Next step, creating a function and then calling on it for different sensors and configurations and outputting the results simultaneously.

Once I clean up the code, I'll write up what I did.
__________________
PSU: Corsair 1000HX - Case: Thermaltake Xaser VI Full Tower - CPU: Intel Core i7 2600 @3.8GHz - Cooler: Thermaltake FRIO - Motherboard: ASUS P67 Sabertooth - Memory: 16GB Corsair Vengeance LP Arctic 1600 - GPU: 2x AMD Radeon HD 5870 - HDD: WD Caviar Black 1TB 6Gb/s +1TB +2TB storage - Audio: ODAC + O2 Amp, ASUS Xonar DX
K/B: Corsair K90 - Mouse: ROCCAT KONE XTD - Monitor: DELL U2410 - Speakers: Corsair SP2500 - Headphones: Beyerdynamic DT990 - Mic: Blue Yeti USB Microphone

- I need Fiber to fix my Irregular Bandwidth Syndrome -

Last edited by Tharic-Nar; 10-25-2012 at 05:31 AM.
Tharic-Nar is offline   Reply With Quote
Old 10-25-2012, 10:56 AM   #32
Psi*
Tech Monkey
 
Psi*'s Avatar
 
Join Date: Jun 2009
Location: Westport, CT
Posts: 785
Default

Nice work.

That program is compiled on a PC or the RPi? What is the compiler?
Psi* is offline   Reply With Quote
Old 10-25-2012, 04:56 PM   #33
Tharic-Nar
Techgage Staff
 
Tharic-Nar's Avatar
 
Join Date: Nov 2009
Location: UK
Posts: 1,166
Default

At the moment, it's windows because handling all the reference research would be a little too much on the RPi at the moment. However, the Arduino IDE is multi-platform, it doesn't matter where I write the code, it behaves the same - I'll load it up on the RPi and you can see for yourself. The compiler is the IDE too - albeit rather simple in nature.
__________________
PSU: Corsair 1000HX - Case: Thermaltake Xaser VI Full Tower - CPU: Intel Core i7 2600 @3.8GHz - Cooler: Thermaltake FRIO - Motherboard: ASUS P67 Sabertooth - Memory: 16GB Corsair Vengeance LP Arctic 1600 - GPU: 2x AMD Radeon HD 5870 - HDD: WD Caviar Black 1TB 6Gb/s +1TB +2TB storage - Audio: ODAC + O2 Amp, ASUS Xonar DX
K/B: Corsair K90 - Mouse: ROCCAT KONE XTD - Monitor: DELL U2410 - Speakers: Corsair SP2500 - Headphones: Beyerdynamic DT990 - Mic: Blue Yeti USB Microphone

- I need Fiber to fix my Irregular Bandwidth Syndrome -
Tharic-Nar is offline   Reply With Quote
Old 10-25-2012, 06:56 PM   #34
Tharic-Nar
Techgage Staff
 
Tharic-Nar's Avatar
 
Join Date: Nov 2009
Location: UK
Posts: 1,166
Default

For posterity, here's the code I used. It was heavily based on the Thermistor2 Sketch, but extended, plus some help from the Thermistor4 Sketch, as detailed in this new Sketch. It uses the full equation, also changed some of the variables to make them clearer (for me) to understand.

For clarity, "#include math.h" should include < and > around math.h - HTML bug.

Code:
/*
 * Inputs ADC Value from Thermistor and outputs Temperature in Celsius
 *    requires: include math.h
 * Utilizes the full Steinhart-Hart Thermistor Equation:  http://en.wikipedia.org/wiki/Steinhart-Hart_equation
 *    Temperature in Kelvin = 1 / {A + B[ln(R)] + D[ln(R)]3 + C[ln(R)]2}
 *    where A, B, C, and D are the Steinhart-Hart coefficient constants
 *
 * If your thermistor manufacturer does not provide these constants, they can be calculated from http://thermistor.sourceforge.net/
 * You will need at least a basic Resistance/Temperature table for your thermistor (minimum of 3 values).
 * These tables are often found in the datasheet for your particular model.
 * This example uses ATCSemitech SP series Thermistors. Model: 503SP-*050
 *
 * Enter R/T values into the simu.txt file then run coeff.exe to generate the individual coefficients.
 *
 * Thermistor Schematic:
 *   [Ground] -- [fixed resistor] -- | -- [thermistor] -- [Vcc (5 or 3.3v)]
 *                                   |
 *                              Analog Pin 0
 *
 * For best accuracy, measure Voltage and the Fixed Resistor, do not assume values are absolute (5.00V and 50Kohm exactly)
 * To minimise self heating effect, use a higher resistance thermistor.
 * If using a noisy power supply (switcher) decoupling may be required.
 *
 * This Sketch was heavily based on the Thermistor2 sketch by Milan Malesevic and Zoran Stupic
 * http://www.arduino.cc/playground/Com...ib/Thermistor2
 * The full Steinhart-Hart equation, related material and implementation was based on Thermistor4 by MODAT7
 * http://www.arduino.cc/playground/Com...ib/Thermistor4
 *
 */

#include math.h

#define ThermistorPIN A0                 // Analog Pin 0

double InputVoltage = 4.96;              // Measure input voltage for accuracy.
double Rfixed = 49900;                   // Fixed resistor value for voltage divider, measure for accuracy. Stated in ohms
double ThermistorResistance = 50000;     // Thermistor nominal resistance @25C, used for reference and not calculated. Stated in ohms
double BitResolution = pow(2, 10)-1;     // ADC resolution, Arduino = 10bit

// The following are the idividual Steinhart-Hart coefficients used in the equation below, labeled as A, B, C and D
float ShHA = 9.774169450995128e-004;
float ShHB = 2.074316914988221e-004;
float ShHC = 2.991246221052282e-007;
float ShHD = 7.674981852293549e-008;

double Thermistor() {
  double ADCReading;
  double VoltageReading;
  double ResistanceThermistor;
  double Temp;                                                                               // Dual-Purpose variable to save space.
  
  ADCReading = analogRead(ThermistorPIN);                                                    // The reported value of the raw Analog Input.
  VoltageReading = (ADCReading / BitResolution) * InputVoltage;                              // Sets the voltage scale as per ADC resolution.
  ResistanceThermistor = ((InputVoltage * Rfixed) / VoltageReading) - Rfixed;                // Voltage divider, between fixed and thermistor.
  Temp = log(ResistanceThermistor);                                                          // Temporary, so not to calculate it 6 times later.
  Temp = (ShHA + (ShHB * Temp)) + (ShHD * Temp * Temp * Temp) + (ShHC *Temp *Temp);          // Steinhart-Hart Equation.
  Temp = 1.0 / Temp;                                                                         // Inverted equation to provide temperature in Kelvin
  Temp = Temp - 273.15;                                                                      // Convert Kelvin to Celsius                      

  // Uncomment to show Debug Information
  //Serial.print("ADC: "); 
  //Serial.print(ADCReading); 
  //Serial.print("/1024");                           // Print out raw ADC number
  //Serial.print(", vcc: ");
  //Serial.print(InputVoltage,2);                    // Input Voltage
  //Serial.print(", Fixed Resistor: ");
  //Serial.print(Rfixed/1000,3);                     // Value of Fixed Resistor
  //Serial.print(" Kohms, Volts: "); 
  //Serial.print(VoltageReading,3);                  // Voltage across divider
  //Serial.print(", Voltage Divider: "); 
  //Serial.print(ResistanceThermistor);
  //Serial.print(" ohms, ");

  // Uncomment this line for the function to return Fahrenheit instead.
  //temp = (Temp * 9.0)/ 5.0 + 32.0;                // Convert to Fahrenheit
  return Temp;                                      // Return the Temperature
}

void setup() {
  Serial.begin(115200);                             // Display over serial interface at 115200 baud
}

void loop() {
  double temp;
  temp=Thermistor();                                
  Serial.print("Celsius: "); 
  Serial.print(temp,1);                             // display Celsius
  //temp = (temp * 9.0)/ 5.0 + 32.0;                // converts to  Fahrenheit
  //Serial.print(", Fahrenheit: "); 
  //Serial.print(temp,1);                           // display  Fahrenheit
  Serial.println("");                                   
  delay(5000);                                      // Delay in ms
}
__________________
PSU: Corsair 1000HX - Case: Thermaltake Xaser VI Full Tower - CPU: Intel Core i7 2600 @3.8GHz - Cooler: Thermaltake FRIO - Motherboard: ASUS P67 Sabertooth - Memory: 16GB Corsair Vengeance LP Arctic 1600 - GPU: 2x AMD Radeon HD 5870 - HDD: WD Caviar Black 1TB 6Gb/s +1TB +2TB storage - Audio: ODAC + O2 Amp, ASUS Xonar DX
K/B: Corsair K90 - Mouse: ROCCAT KONE XTD - Monitor: DELL U2410 - Speakers: Corsair SP2500 - Headphones: Beyerdynamic DT990 - Mic: Blue Yeti USB Microphone

- I need Fiber to fix my Irregular Bandwidth Syndrome -

Last edited by Tharic-Nar; 10-25-2012 at 07:09 PM.
Tharic-Nar is offline   Reply With Quote
Old 10-25-2012, 06:58 PM   #35
marfig
No ROM battery
 
marfig's Avatar
 
Join Date: May 2011
Posts: 784
Default

Have you confirmed that double and float are same size on the Arduino?
__________________
NOX COOLBAY Side Window Black; NOX Apex 600w Modular; ASUS P7P55D-E Socket 1156, Sata 6Gb/s & USB 3.0;
Intel Quad Core i5 760 2.80 Ghz @ 3.60 Ghz, 8 Mb de cache; Gskill Ripjaws 4 Gb DDR3 1600 Mhz CL8 Dual Channel;
ASUS GEFORCE GTX 560 TI DC II 1024MB GDDR5; Samsung 1 Tb 32 Mb SpinPoint F3; NEC 24x Sata black
Artic Cooling Freezer 7 Pro Rev.2;
2x Samsung SyncMaster S43NW 8000:1 (1440x900)
Logitech K120 Keyboard and Logitech Performance Mouse MX
marfig is offline   Reply With Quote
Old 10-25-2012, 10:58 PM   #36
Tharic-Nar
Techgage Staff
 
Tharic-Nar's Avatar
 
Join Date: Nov 2009
Location: UK
Posts: 1,166
Default

Yes, they are both the same, it's just that floating points in general are technically slower and with only 6-7 digits of precision, so it makes no difference.

http://www.arduino.cc/en/Reference/Float
http://www.arduino.cc/en/Reference/Double

Quote:
Floating-point numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38. They are stored as 32 bits (4 bytes) of information.

Floats have only 6-7 decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point. Unlike other platforms, where you can get more precision by using a double (e.g. up to 15 digits), on the Arduino, double is the same size as float.
There is an exception...
Quote:
On the Arduino Due, doubles have 8-byte (64 bit) precision.
So I might as well switch all values with the coeff to double.
__________________
PSU: Corsair 1000HX - Case: Thermaltake Xaser VI Full Tower - CPU: Intel Core i7 2600 @3.8GHz - Cooler: Thermaltake FRIO - Motherboard: ASUS P67 Sabertooth - Memory: 16GB Corsair Vengeance LP Arctic 1600 - GPU: 2x AMD Radeon HD 5870 - HDD: WD Caviar Black 1TB 6Gb/s +1TB +2TB storage - Audio: ODAC + O2 Amp, ASUS Xonar DX
K/B: Corsair K90 - Mouse: ROCCAT KONE XTD - Monitor: DELL U2410 - Speakers: Corsair SP2500 - Headphones: Beyerdynamic DT990 - Mic: Blue Yeti USB Microphone

- I need Fiber to fix my Irregular Bandwidth Syndrome -

Last edited by Tharic-Nar; 10-25-2012 at 11:06 PM.
Tharic-Nar is offline   Reply With Quote
Old 10-26-2012, 05:48 AM   #37
marfig
No ROM battery
 
marfig's Avatar
 
Join Date: May 2011
Posts: 784
Default

Indeed. Double is a better bet given the circumstances. In fact, with or without the Aruino Due, unless you don't really need the extra precision and you are fine with 7 precision for < 1 and 6 precision for > 1, it's an almost guarantee that future iterations of the Arduino will come sooner or later with proper double precision-floating point.
__________________
NOX COOLBAY Side Window Black; NOX Apex 600w Modular; ASUS P7P55D-E Socket 1156, Sata 6Gb/s & USB 3.0;
Intel Quad Core i5 760 2.80 Ghz @ 3.60 Ghz, 8 Mb de cache; Gskill Ripjaws 4 Gb DDR3 1600 Mhz CL8 Dual Channel;
ASUS GEFORCE GTX 560 TI DC II 1024MB GDDR5; Samsung 1 Tb 32 Mb SpinPoint F3; NEC 24x Sata black
Artic Cooling Freezer 7 Pro Rev.2;
2x Samsung SyncMaster S43NW 8000:1 (1440x900)
Logitech K120 Keyboard and Logitech Performance Mouse MX
marfig is offline   Reply With Quote
Old 10-26-2012, 03:13 PM   #38
Tharic-Nar
Techgage Staff
 
Tharic-Nar's Avatar
 
Join Date: Nov 2009
Location: UK
Posts: 1,166
Default

I've been switching things around on the hardware side. I decided to see the impact of power filtering. It's not a clear cut, but the irregularity of the sensor is noticeable - it can 'scatter' by 0.5 degrees in either direction. With filtering, it's a lot more incremental, steady steps. I then swapped the sensor into a filtered circuit and check, and noticed a steady temperature set. I then swapped the thermistor for a different one to confirm values. There is a 3.0C offset between the filtered and unfiltered, likely the result of a voltage or resistor value inaccuracy. I'll need a larger sample bin though to call it, but those swings in temp are not good...



Actually, looking at it... filtered sensor2 is not that great either... Yeah, I think I need to find a more stable environment. Me being half a meter away is causing the temp to spike in places (damn the thing is sensitive...).
__________________
PSU: Corsair 1000HX - Case: Thermaltake Xaser VI Full Tower - CPU: Intel Core i7 2600 @3.8GHz - Cooler: Thermaltake FRIO - Motherboard: ASUS P67 Sabertooth - Memory: 16GB Corsair Vengeance LP Arctic 1600 - GPU: 2x AMD Radeon HD 5870 - HDD: WD Caviar Black 1TB 6Gb/s +1TB +2TB storage - Audio: ODAC + O2 Amp, ASUS Xonar DX
K/B: Corsair K90 - Mouse: ROCCAT KONE XTD - Monitor: DELL U2410 - Speakers: Corsair SP2500 - Headphones: Beyerdynamic DT990 - Mic: Blue Yeti USB Microphone

- I need Fiber to fix my Irregular Bandwidth Syndrome -

Last edited by Tharic-Nar; 10-26-2012 at 03:16 PM.
Tharic-Nar is offline   Reply With Quote
Old 10-26-2012, 04:16 PM   #39
marfig
No ROM battery
 
marfig's Avatar
 
Join Date: May 2011
Posts: 784
Default

I wonder...

You said a few days ago that one of the reasons you didn't choose the 10KOhm thermistors was because you wouldn't be operating at their 0-30C range. However that's exactly what I'm seeing there. Wouldn't it be better to indeed go with the 10K?

Also, but here I'm not sure... aren't the 50K just a tad bit more power hungry? Wouldn't it affect your readings? I'd expect them to increase temps slightly as opposed to a 10K.
__________________
NOX COOLBAY Side Window Black; NOX Apex 600w Modular; ASUS P7P55D-E Socket 1156, Sata 6Gb/s & USB 3.0;
Intel Quad Core i5 760 2.80 Ghz @ 3.60 Ghz, 8 Mb de cache; Gskill Ripjaws 4 Gb DDR3 1600 Mhz CL8 Dual Channel;
ASUS GEFORCE GTX 560 TI DC II 1024MB GDDR5; Samsung 1 Tb 32 Mb SpinPoint F3; NEC 24x Sata black
Artic Cooling Freezer 7 Pro Rev.2;
2x Samsung SyncMaster S43NW 8000:1 (1440x900)
Logitech K120 Keyboard and Logitech Performance Mouse MX
marfig is offline   Reply With Quote
Old 10-26-2012, 06:24 PM   #40
Tharic-Nar
Techgage Staff
 
Tharic-Nar's Avatar
 
Join Date: Nov 2009
Location: UK
Posts: 1,166
Default

Higher resistance means less power going through the probe (the tighter the valve, the less water that can flow). The sensors I have are 0.2C accurate between 0-70C. I re-read an article to make sure things are fine, and they should be. Its reference 50k probes, going by the graph, are good between 10 - 110C, while a 10k probe is good for -20 - 70C. So my probe should be more than adequate in the room-temperature range. I could get in some 10K sensors too, but I'm likely to see similar results, but with more swing due to the extra sensitivity.

http://www.embeddedrelated.com/showarticle/91.php

I'll retest things later in a more controlled environment (no fans going, closed door) with multiple sensors, and measure the fixed resistor properly on the unregulated board - and run the test longer too. But even if I am in the lower end of the recording accuracy range based on the manufacturer and by that general graph - I still think things should be fine. These sensors will end up in a PC environment, so will likely see temps in the 30-40C ambient range, going up to 60-90C next to the CPU. The variations I'm seeing are in the 0.2-0.5C range (which coincides with natural room fluctuations + sensor error or 0.2). The 3 degree hike on the unregulated board still has my concern, but I need to look into that carefully.

Edit: I should probably just add an averaging system - 10 readings over a couple seconds, then averaged.
__________________
PSU: Corsair 1000HX - Case: Thermaltake Xaser VI Full Tower - CPU: Intel Core i7 2600 @3.8GHz - Cooler: Thermaltake FRIO - Motherboard: ASUS P67 Sabertooth - Memory: 16GB Corsair Vengeance LP Arctic 1600 - GPU: 2x AMD Radeon HD 5870 - HDD: WD Caviar Black 1TB 6Gb/s +1TB +2TB storage - Audio: ODAC + O2 Amp, ASUS Xonar DX
K/B: Corsair K90 - Mouse: ROCCAT KONE XTD - Monitor: DELL U2410 - Speakers: Corsair SP2500 - Headphones: Beyerdynamic DT990 - Mic: Blue Yeti USB Microphone

- I need Fiber to fix my Irregular Bandwidth Syndrome -

Last edited by Tharic-Nar; 10-26-2012 at 06:30 PM.
Tharic-Nar is offline   Reply With Quote
Reply

Thread Tools

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 On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
more Pi (Raspberry Pi) Psi* Mobile & Small Form-Factor Computing 6 10-21-2013 01:59 PM
VIA Announces its Raspberry Pi Competitor, 'APC' Rob Williams General Hardware 1 05-22-2012 07:53 PM


All times are GMT -4. The time now is 06:49 AM.