Shop OBEX P1 Docs P2 Docs Learn Events
Dealing with large numbers that exceed the 16-bit limit — Parallax Forums

Dealing with large numbers that exceed the 16-bit limit

Andy McLeodAndy McLeod Posts: 40
edited 2006-10-18 16:22 in BASIC Stamp
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

  • Beau SchwabeBeau Schwabe Posts: 6,563
    edited 2006-10-18 15:04
    This works like a Digital LOW-PASS filter.· With a 12-bit input value you would effectively have a 16 sample averaging window.

    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.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-18 15:19
    Andy,
    ·
    ·· 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
  • BeanBean Posts: 8,129
    edited 2006-10-18 16:22
    Andy,

    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
    ·
Sign In or Register to comment.