Go Down

### Topic: Modelling Temperature Sensor Delay (Read 2076 times)previous topic - next topic

#### TotalNovice

##### Oct 21, 2012, 02:13 pm
Hi all,
I'm incredibly new to programming and trying to figure out how to compensate for temperature sensor delay in my program.
My problem is that I don't know how to store the previous reading and recall it for use in the equation.

where Temperature is a proposed temperature, TempRead is the current reading and TempPrev is the previous reading.

Can anyone help point me in the right direction?

#### robtillaart

#1
##### Oct 21, 2012, 02:38 pm
this?
Code: [Select]
`setup(){  TempPrev = getTemp(); // function that wraps the reading of the temperature}loop(){  TempRead = getTemp();  Temperature = TempRead + TempRead - TempPrev;  TempPrev = TempRead;  ...}`
Rob Tillaart

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

#### michinyon

#2
##### Oct 21, 2012, 03:45 pm
That code will do what you asked for,   but what you asked for doesn't seem to actually make sense.

What exactly are you trying to calculate with that equation ?

#### TotalNovice

#3
##### Oct 21, 2012, 03:49 pm
Robtillaart - thanks so much for your help!

It's part of a larger system, I'm just trying to minimise the delay of the temperature sensor by predicting what the temperature actually is.

#### michinyon

#4
##### Oct 21, 2012, 03:54 pm
So you are adding an estimate of the rate of temperature change,  to the latest reading ?  To try to predict what the following reading will be ?

At the rate at which a microcontroller would be reading the temperature,   that hardly seems necessary.   You may end up simply confusing yourself by amplifying the "noise" which will be present in the temperature readings.

#### marco_c

#5
##### Oct 22, 2012, 01:25 amLast Edit: Oct 22, 2012, 04:16 am by marco_c Reason: 1
Temperatures are slow moving inputs compared to the speed of any control devices, so the issue is not generally to predict the temperature changes but to smooth out any of the noise that happens on the input from the sensor. This is usually done by taking an average of a number of values over a set period of time and calling that the 'tempertaure'.
Arduino Libraries https://github.com/MajicDesigns?tab=Repositories
Parola for Arduino https://github.com/MajicDesigns/Parola
Arduino++ blog https://arduinoplusplus.wordpress.com

#### dhenry

#6
##### Oct 22, 2012, 02:15 am
Quote

Code: [Select]
`unsigned short Temperature(void) {  static unsigned short TempPrev=0;  unsigned short TempRead = getTemp(); //read the temperature  unsigned short tmp = TempRead + (TempRead - TempPrev);  TempPrev = TempRead;  return tmp;}`

All if wrap'd in the function call.

#### TotalNovice

#7
##### Oct 22, 2012, 04:21 am

It's for a uni project where they specifically want the temperature change to be predicted in the equation I gave, otherwise I would do what you guys are suggesting

#### pwillard

#8
##### Oct 22, 2012, 12:58 pm
This is where things like the PID library can also come in handy.

http://www.arduino.cc/playground/Code/PIDLibrary

#### michinyon

#9
##### Nov 01, 2012, 07:23 am
"It's for a uni project where they specifically want the temperature change to be predicted in the equation"

It seems to me that this equation does not
(a)  estimate the actual temperature
(b)  estimate the temperature delta since the last reading
(c)  estimate the rate of change of the temperature
(d)  make a useful prediction of the temperature.

It doesn't seem to do any of those things.

Just because "they" want something,  doesn't make it right.

#### dhenry

#10
##### Nov 01, 2012, 03:36 pm
Quote

it is a crude form of forward error estimation. What it does is to say that the same "error", as defined by TempRead - TempPrev, will persist for the next read, which is generally true and helpful for slow-moving measurements, like temperature.

However, in cases of very high gain (very frequent temperature readings), this approach will yield unstable readings - it is essentially the D in a pid controller.

A different from of it would go like this:

Temperature = TempRead + (( TempRead - TempPrev ) - (TempPrev - TempPrev2)); where TempPrev2 is the temperature two readings ago.

Go Up