Hysteresis in float value for temperature display

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
585
1. I am measuring temperature of PT100 whose value is calculated in float inside the code, but on display only integer value is displayed. Now what happens is when 31.9 or 32.0, display fluctuates between 31 & 32 very rapidly.

2. I tried used round off from maths library, but again display fluctuates at 34.5 and 34.4. display keep fluctuates at 34 & 35.

3. how to add some hysteresis to this float value so that:
a) temperature keep on showing 31 if temperature goes from 31 to 31.9
b) at 32.0, it shows 32 only
c) but when now temperature falls to 31.9, it don't fall back to 31 on display, but keep it showing 32 until temperature falls below 31.5 ?
d) is there any math function for it in library?
 

MrChips

Joined Oct 2, 2009
24,143
You will always have this problem. It does not matter if you use integers or floats, rounding or truncation.
You will always have this 0+1 jitter at the transition.
What you need to do is compute a running average to reduce the noise.
 

nsaspook

Joined Aug 27, 2009
8,653
Metastability (Metastable is a Greek word meaning "in between.") is a inherent characteristic of asynchronous data capture with digital encoding system. The classical method is to first smooth the random 0-1 transitions with averaging or to use synchronizers for digital signals before display processing.
 

ElectricSpidey

Joined Dec 2, 2017
1,796
If I had the horsepower I would use "if" statements.

For example:

if temp is between X and Y display Z
if temp is between A and B display C

Place it in a function...call it every so often, polled or timer interrupt allowing the processor to do other things.

Sorry if I'm way off base...I'm only a coding newbie. ;)
 

BobaMosfet

Joined Jul 1, 2009
1,848
1. I am measuring temperature of PT100 whose value is calculated in float inside the code, but on display only integer value is displayed. Now what happens is when 31.9 or 32.0, display fluctuates between 31 & 32 very rapidly.

2. I tried used round off from maths library, but again display fluctuates at 34.5 and 34.4. display keep fluctuates at 34 & 35.

3. how to add some hysteresis to this float value so that:
a) temperature keep on showing 31 if temperature goes from 31 to 31.9
b) at 32.0, it shows 32 only
c) but when now temperature falls to 31.9, it don't fall back to 31 on display, but keep it showing 32 until temperature falls below 31.5 ?
d) is there any math function for it in library?
Use fixed point
 
Top