# Hysteresis in float value for temperature display

#### Vindhyachal Takniki

Joined Nov 3, 2014
594
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?

#### ericgibbs

Joined Jan 29, 2010
18,630
hi VT,
Which type of MCU and what programming language.??
Post the Code.
E

#### MrChips

Joined Oct 2, 2009
30,448
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.

#### ericgibbs

Joined Jan 29, 2010
18,630
hi MrC,
I think what he is saying is that his display will not show the decimal place value.
E

#### nsaspook

Joined Aug 27, 2009
12,749
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
2,756
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
2,105
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