Go Down

Topic: Using an array to smooth double variable types? (Read 534 times) previous topic - next topic

Rosscopico0

Hi All,
I am reading from a thermocouple with the MAX31855 chip using double variable type for greater precision.
I want to smooth the readings coming from the thermocouple.
I found Smooth & digitalSmooth functions in the playground to do this, but it seems these have been written for int variable types only (ie- reading analog sensor)

When I change the sensor reading variable to a double (in order to read the thermocouple with precision), the smoothing by the array results in integers.

Is there a way to make the array work with double variable types, or is there a different function that I have not yet discovered?

pylon

The MAX31855 has a 14-bit resolution, an integer has 16 bits. How do you wanna get more precision than the chip is able to provide?

MichaelMeissner

#2
Nov 20, 2012, 08:42 pm Last Edit: Nov 20, 2012, 08:44 pm by MichaelMeissner Reason: 1

Hi All,
I am reading from a thermocouple with the MAX31855 chip using double variable type for greater precision.

Ummm, doubles on Arduinos (except for the Due) are actually 32-bits, which gives you 24 bits of precision in the mantissa for numbers in the normal range of precision.  I would imagine giving the posting by pylon that says the MAX31855 only has 14 bits of integer precision means even a float may give you more precision than the device returns (though if you are doing extensive calculations on the value, you may want some extra bits to prevent unintended round-off).

Another thing to consider is floating point is done entirely in software in the Arduinos (both the AVR based ones and the Due).  If you are running into performance bottlenecks, you probably should consider using int/long variables instead of double.

dhenry

Try this:

Code: [Select]

  temp = alpha * temp + (1-alpha) * max38155_read();


where alpha is [0, 1]: higher alpha means longer memory (smoother changers but slower reaction).

alpha can be fractions if you wish to use fixed point math.

robtillaart

Quote
The MAX31855 has a 14-bit resolution, an integer has 16 bits. How do you wanna get more precision than the chip is able to provide?

oversampling,
rule of thumb for every 4x measurements you can gain 1 bit precision (but be aware that you first must reduce noise, often 2 bits)
4 samples => 15 bit
16 samples => 16 bit
64 samples => 17 bit
etc

You can also check - http://www.arduino.cc/playground/Main/runningAverage - which take more measurements into account.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Rosscopico0

Thank you all!
I think runningAverage will suit my purposes.

Go Up