Averaging & 16 maths


Closed Thread
Results 1 to 3 of 3
  1. #1
    paul.mcallister's Avatar
    paul.mcallister Guest

    Question Averaging & 16 maths

    Hi all,

    I was wondering if someone could help me with an approach to this problem. I have a pressure transducer connected to a 12 bit ADC being read by a 16f876. The problem I have is that when I read the data is varies about 20 counts around the mean.

    I have captured the data via debug commands in to a text file and analyzed in a spread sheet and I know if I take 128 samples and divide it by 128 that it averages out the variation but..... 128 samples summed of 12 bits exceeds the 16 word size.

    Could someone suggest an approach for me.

    Thanks, Paul

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    http://www.picbasic.co.uk/forum/showthread.php?t=1746

    You can always "Sum on the run"... for example...

    Sample=0
    For CounterA=1 to 128
    Gosub GetNewSample
    Sample=Sample+NewSample
    Sample=Sample/2
    Next CounterA

    Not the best solution but it won't spill out of any variables.

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


    Did you find this post helpful? Yes | No

    Default

    Hi Paul,

    I have a little routine that keeps a "Running Average" of 16-bit values, without using 32-bit math.
    I use it for Pressure transducers, Flow sensors, Voltage readings, etc. It works really well for all of them.

    Averaging 16 bit values without using 32 bit math?

    HTH,
       Darrel

Similar Threads

  1. 16 bit PWM using CCP1
    By Normnet in forum mel PIC BASIC Pro
    Replies: 60
    Last Post: - 27th August 2014, 08:13
  2. Darrel's latest 16 bit averaging routine?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 17th October 2009, 01:57
  3. Funny PULSIN values: what is going on???
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 30th April 2008, 08:02
  4. Averaging 16 bit values without using 32 bit math
    By sirvo in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th October 2007, 22:18
  5. How to tell which PICs can handle 16 bit variables?
    By MikeTamu in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st August 2005, 08:44

Members who have read this thread : 1

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