PDA

View Full Version : Average Values and digital filter ...



jorge
- 11th April 2007, 17:31
I am hoping somebody can give me any hints or directions to my problem…although I ve search the forum i ve not come across to any solution to my problem…

There it goes: I ve done a digital temperature controller, and everything works fine, but I need to implement a new functionality and I really don’t know how…:
I am constantly reading the temperature in one spot and have to estimate the temperature in the product ( for that I use a kind of offset temp value) but the problem itself is that where i read the temperature it fluctuates much more than in the product (because of the thermo mass of the product) so I need to show a temperature that it is something like an average value with least variations possible…
I guess I could use an array of temperature, drop the top and the end values and calculate the medium…but is here any easier way ? I really don’t want to re-write some big parts of the code  ….
I also was working around some digital filter like the concept : temp_med = (20* temp_now + 80*temp_old )/100 , ETC …but I really was hoping something to discover something simple …
Any help from the pros ?

Thanks a lots, I am really feeling lost…

tico
- 11th April 2007, 17:41
http://rentron.com/PicBasic/LM34.htm

FOR sample = 1 TO 20 ' Take 20 samples
ADCIN 0, temp ' Read channel 0 into temp variable
samples = samples + temp ' Accumulate 20 samples
PAUSE 250 ' Wait approximately 1/4 seconds per loop
NEXT sample
temp = samples/20

Darrel Taylor
- 11th April 2007, 19:17
This might work for you.

Averaging 16 bit values without using 32 bit math?
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=7
<br>

Acetronics2
- 12th April 2007, 09:55
Hi, Jorge

Why not place your sensor in a dummy product ??? ( With same thermal mass - and even approaching shape, if convective heat transfer ).

Result would be much more precise ... and doesn't keep you from an averaging !!!

Alain

Bruce
- 12th April 2007, 18:14
Darrels' averaging routine is pretty slick. I would go with that if at all possible.

paul borgmeier
- 14th April 2007, 06:52
For Temperature A2D (0-1023), a favorite of mine if T changes are gradual and code space is a premium...

pseudo-recursive filter (similar to Darrel's except without the smarts)

A2D var word
AVE var word

Main:

' Get new A2D value
A2D = new A2D Value

' Smooth data
Ave = ((((AVE<<1)+AVE)<<1)+AVE+A2D)>>3 'AVE = (7*AVE + A2D) /8

' More stuff here if you want

Goto Main

depending on the smoothing required, you can adjust and change the 7 & 8 in the AVE equation to 15 & 16, 3 & 4, etc., depending on what you need in the way of filtering

jorge
- 18th April 2007, 01:56
...as always you have helped me in finding the path, thanks for your precious time and for your hints !
Darrel´s solution (really good) and the this last one (Paul´s) are on the spot...
Thanks again !
regards, Jorge

Darrel Taylor
- 18th April 2007, 03:11
Hey jorge,

Hope it works out for you.
The only thing it's missing is hysterisis. No matter how much you average, there's always a point where the reading bounces back and forth between two digits.

To illiminate that "wobble", I added some hysterisis to the averaging routine and posted them a couple times ...

http://www.picbasic.co.uk/forum/showthread.php?p=13267

Never did get a response, but I've used them myself since then so at least now I can say that they do work.

HTH,

peu
- 19th April 2007, 03:50
This might work for you.

Averaging 16 bit values without using 32 bit math?
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=7
<br>

Just wanted to say thanks to Darrel, I used this averaging routine in one of my projects that was driving me crazy and it solved the problem I had. http://picbasic.co.uk/forum/images/icons/icon14.gifhttp://picbasic.co.uk/forum/images/icons/icon14.gifhttp://picbasic.co.uk/forum/images/icons/icon14.gif

THANKS!!!

Darrel Taylor
- 19th April 2007, 10:45
Always nice to hear things are working. :)

Thanks for letting me know peu.
<br>

boroko
- 24th April 2010, 10:35
Hi all,
I have the need to slow things down a bit. I'm running a 18F1330 at 32 MHz executing a sense loop for ultrasonics each 32 mS. I have tried to use DT's averaging routine with a 250 reading average, but it still reacts way too fast. I need to dampen it to a 2 or 3 second response so that it doesn't drive the mechanical parts nuts.

It doesn't look like I can just change the AvgCount to a larger variable without messing it up.

Anybody ran into this before?

Thanks for any input while I try and think through this.
Bo

boroko
- 24th April 2010, 12:29
After looking closely at my code, I realized that I had tried to tweak DT's code (http://www.pbpgroup.com/modules/wfsection/article.php?articleid=7).... as always, likely a mistake....

Went back to the original and it is working more like need. Further testing.

Move along, Nothing to see here.
Bo