Dealing with large numbers that exceed the 16-bit limit
Andy McLeod
Posts: 40
I am sampling from a 12-bit ADC at 10Hz for 30 seconds per sample cycle. All I need is the mean value, the raw values are discarded. While summing these 300 12-bit numbers, I exceed the 16 bit limit of 65536 for the Stamp rather quickly. Does anyone have a routine that will allow me to do this?
Comments
Define Sample as a WORD····· <- This is your input variable
Define Average as a WORD···· <- This is your output variable
Define DataBase as a WORD
Define SampleNum as a CONstant (with 12-bits, the MAXIMUM this can be is 16 ; 65536 / 2^12 = 16 )
Main Program Loop:
{ Update Sample here }
DataBase = DataBase - Average + Sample
Average = DataBase / SampleNum
{ Read Average Here }
return to 'Main Program Loop'
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
·
·· Also check the following link from Dr. Tracy Allen’s website.· He has some interesting math routines on there as well as a wealth of other useful information.· Take care.
http://www.emesys.com/BS2math6.htm
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
If you voltage doesn't change too much, you could take an initial reading, then sum the DIFFERENCES between each sample and the initial reading. After all the samples are taken, divide the sum of difference by the number of samples and add to the initial reading.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
"People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
·