Average Values and digital filter ...


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2004
    Posts
    25

    Default Average Values and digital filter ...

    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…

  2. #2
    Join Date
    Dec 2006
    Posts
    38


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    This might work for you.

    Averaging 16 bit values without using 32 bit math?
    http://www.pbpgroup.com/modules/wfse...hp?articleid=7
    <br>
    DT

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Smile

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Darrels' averaging routine is pretty slick. I would go with that if at all possible.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    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)
    Code:
    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
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  7. #7
    Join Date
    Nov 2004
    Posts
    25


    Did you find this post helpful? Yes | No

    Default thanks to all...

    ...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

  8. #8
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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,
    DT

  9. #9
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by Darrel Taylor View Post
    This might work for you.

    Averaging 16 bit values without using 32 bit math?
    http://www.pbpgroup.com/modules/wfse...hp?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.

    THANKS!!!

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Always nice to hear things are working.

    Thanks for letting me know peu.
    <br>
    DT

  11. #11
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Averaging lots of numbers

    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

  12. #12
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    231


    Did you find this post helpful? Yes | No

    Default Progress

    After looking closely at my code, I realized that I had tried to tweak DT's code.... 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

Similar Threads

  1. Funny PULSIN values: what is going on???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th April 2008, 08:02
  2. 16F877A problem: "coupled" digital values
    By Lupo83 in forum General
    Replies: 16
    Last Post: - 4th December 2007, 12:46
  3. 2nd Order Digital Filter for 24-bit
    By sefayil in forum mel PIC BASIC
    Replies: 0
    Last Post: - 2nd December 2005, 21:55
  4. digital filter
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th September 2004, 01:28
  5. implementig digital filter and my problems????????
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd June 2004, 18:06

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts