PDA

View Full Version : Averaging & 16 maths



paul.mcallister
- 22nd May 2005, 15:03
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

Melanie
- 22nd May 2005, 15:37
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.

Darrel Taylor
- 22nd May 2005, 18:17
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? (http://www.pbpgroup.com/modules/wfsection/article.php?articleid=7)

HTH,
   Darrel