CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Sensor stabilization

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

Sensor stabilization
PostPosted: Fri Feb 27, 2009 4:08 am     Reply with quote

Hi, I am working on pressure and temperature control systems, and have spent many hours researching and testing filters, IIR, FIR etc, and am also using a hardware IIR filter (10uF tant and 1k resistor) however none of these get rid of the tendency for the display to jump from, for example 23.4 to 23.5 and back continuosly. In the end I decided to use a 16 position moving average filter, for simplicity, and have come up with this routine to further stabilize. It runs on a 20ms interrupt, and while the difference is between 10 and -10, the bigger the difference between the stable reading(oldpresavg) and the new reading (presavg) the faster it updates, and vice verse, as you can see if the difference is 1 unit, it has to be stable for 500ms before update. If the difference is bigger than 10/-10 it updates every 100ms. It seems to work pretty well, just wondering what others have done in this situation, any comments, suggestions, improvements greatly received! Thanks Ryan.

Code:
   olddifference = difference;
   difference = oldpresavg - presavg;
   if(difference < 10 && difference > -10) {
      count = 0;
      if(difference == olddifference) {
         if(difference < 0)
            stable += 0 - difference;
         else
            stable += difference;
      }
      else
         stable = 0;
   }
   if(stable >= 25 || ++count >= 5) {
      oldpresavg = presavg;
      stable = 0;
      count = 0;
   }
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Feb 27, 2009 8:39 am     Reply with quote

That is why an analog display is still preferred for some applications. A flickering last digit can become completely illegible and the whole digit is effectively lost.
Your method sounds OK as long as it is not too complicated. I would be tempted to add a bit of hysteresis, maybe .75 digit, instead of slowing the updates. In the end if this output is meant for a human observer and the observer can't receive the data faster than several times a second, the quickly changing data is useless anyway.
Also consider decimating the data. Just because your display can output any digit in the last decimal place doesn't mean you have to. You could show only even digits. Consider the digital calipers that are used everywhere; with a resolution of 0.0005". The last digit only ever shows '0' or '5'. Sure they could do some interpolation and put any number in that last digit, but it would be useless as it would only represent the strength of the user's thumb and the springiness of the tool.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Sydney



Joined: 13 Feb 2009
Posts: 71

View user's profile Send private message

PostPosted: Fri Feb 27, 2009 2:16 pm     Reply with quote

Thanks for the reply you make some interesting points. Decimating is not really an option, for either my pressure or temperature controller, since the pressure only reads whole numbers already, and the temperature controller needs to have the 0.1°C resolution, and it also doesn't help because the temperature readout would still flick between 19°C and 20°C for example.

For some reason (I needed to use floating point vars, I Think) one of the IIR filters I tried introduced some hysteresis, which although seemed to work very well, and was stable however introduce innaccuracies since a rising temperature would display different to a falling temperature to the same value, ie if the temp rose to 25°C the display would show 24.7°C, and falling to the same value would show 25.3°C, and I wasn't happy with that either.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group