ChipCenter Questlink
SEARCH CHIPCENTER
Search Type:
Search for:




Knowledge Centers
Product Reviews
Data Sheets
Guides & Experts
News
International
Ask Us
Circuit Cellar Online
App Notes
NetSeminars
Careers
Resources
FAQ
EE Times Network
Electronics Group Sites

Question

 

THE ENGINEERS TECH-HELP RESOURCE

Let us help keep your project on track or simplify your design decision. Put your tough technical questions in front of the ASK US team.

QUESTION
 

Can anyone give me some pointers on how to apply a digital filter on a fuel-level signal for use in a vehicle. I'm using a pivot-float type sensor (i.e., something like that used in the toilet cistern). I've looked through my Circuit Cellar back issues and come across the article "A Digital Filtering Primer" in issue 52. This gives a good explanation of how to implement an averaging filter in C. The equation is simply:

Xnew = Xraw + K × (Xold –Xraw)

My problem is: How do I determine the parameters, like (1) sampling rate, (2) filter constant K, and so on? I can sample the signal at a maximum of 7 Hz, but I don't think that's an issue for this type of sensor. I'm thinking more along the lines of slowing it down to say 1 Hz or less. I also need to adjust the parameters according to whether the vehicle is moving or stationery, due to the extra splashing inside the tank with a moving vehicle.

People around the office have been quoting stuff like "Use a 2-minute averaging filter when moving, and a 15-second filter when not moving." Another consideration that may affect all this is that I need to know when the rate of change of fuel level is above some arbitrary threshold (i.e., I'm trying to indicate when there's a major fuel leak [or someone is stealing the fuel]). This is likely to be only applied when the vehicle is stationary, avoiding the confusion between fuel splashing and fuel disappearing.

Brad Forth

ANSWER

Oh boy, a classic control problem. You don't see many presented so clearly. Let's assume the problem is exactly as you presented it. I mean there is no sticking in the mechanism, no electrical noise, the little float is not sinking. If all that is true, we can think of the problem and solution as a classic PID control.

The classic PID control is a closed-loop system and has a set point as an input along with an error signal derived from previous readings. At the end of this you will find references to web articles that talk about this classic PID control.

Your fuel gauge readout is an open-loop version of those systems. Let's think of your input signal as a combination of information (signal) and noise. The information is the DC level of fuel in the tank. Ignoring the noise for the momen,; how does the signal behave? Well, the fastest it rises is when you fill the tank and the fastest it falls is when there is a leak. The normal fall time for a car is full to empty in 400 miles or 8 h. Very, very slow. The fill time is about 2 to 3 min,. Still, very, very slow. A detectable leak (or pilferage) is about the same as filling.

Next let's try to gather some real-world data. When you drive in to fill up your car and shut the engine off, the old reading is saved on the gauge. After fill up when power is applied, that fuel gauge rises ever so slowly. Let's say it goes from empty to full (0% to 100%) in one minute. Make your own tests and change any of my assumptions.

I believe that a simple low-pass filter will do the job, just an 'R' and a 'C'. What is the digital equivalent? Well, it's the average of all the input readings. That's impossible to achieve since the total would become a large number, as would the number of readings. So another similar approach is:

Next Reading = Factor ×Last Reading + (1-Factor) ×New Input

Factor 0.1 is for real slow response. I've attached a spreadsheet where I've got a signal and I've added some noise and then I applied this filter.

spead1.xls

I plotted the results. You can change the factor and change the noise type and see your results. With a factor of .1, I get to a good reading in 16 samples.

The last issue is sample rate. How fast is necessary? Well, you only need to sample fast enough to capture your information (basically DC in this case) and no need to go fast enough to capture the frequency of the noise. The tradeoff is faster response on the gauge verses more noise getting through. Faster sampling will mean a lower factor on the filter for the same results.

Well, I didn't give you the "'answer" but perhaps you can use these tools to get there on your own. I think it would be interesting to see what your testing exposed and what numbers you finally decided upon.

The PID control is well known and here are a number of links I found that will explain the math in more detail than I can in this forum. A comparison between various available controls

http://www.expertune.com/

A page posted by John Shaw that looks informative.

http://ww.jashaw.com/

Especially this one

http://www.jashaw.com/pid/description.htm

Tutorial on PID loops

lansce.lanl.gov/lansce8/Epics/dbase/recref/Recordref-28.html

In PID loops, each of the terms have a gain associated with them:

K(P) is the gain for the Proportional loop.

K(I) is the gain for the Integral loop.

K(D) is the gain for the Derivative loop.

By adjusting the magnitude of these gains you can extract the response you desire.


George Martin

BROUGHT TO YOU BY:
 

 

 

COPYRIGHT
 

 

 

Entire contents copyright ý 1999 by Circuit Cellar Incorporated and ChipCenter, LLC. All rights reserved. Circuit Cellar and Circuit Cellar INK are the registered trademarks of Circuit Cellar Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar Inc. is prohibited. Disclaimer

 

Click here to get your listing up.

Copyright © 2003 ChipCenter-QuestLink
About ChipCenter-Questlink  Contact Us  Privacy Statement   Advertising Information  FAQ