Average Word
Hi All
I am working on a project that uses the count command and I would like to take the average from 5 samples ( Word Size ) . I am using the BS2P 24. I am almost out of RAM, so if any way to store the 5 values in the EEPROM or the SP would help.
Thanks
TC
I am working on a project that uses the count command and I would like to take the average from 5 samples ( Word Size ) . I am using the BS2P 24. I am almost out of RAM, so if any way to store the 5 values in the EEPROM or the SP would help.
Thanks
TC
Comments
You could use the "PUT" and "GET" commands to temporarily store the
data in the scratchpad. Depending on how you are getting the samples
(I2CIN, SHIFTIN, SERIN, etc.) you can use the SPSTR modifier to take
the data and put it right into the scrathcpad RAM (starting at
location 0). Jon Williams talks about this in another thread (I think
it related to the I2C commands). You won't find it in the manual,
however. Once it's in the SP, you can use the "GET" command to
retrieve the data (you can use the "PUT" command to put it there
manually). You could also use an outboard EEPROM to store the data--
you could then have 1000s of samples if you wanted. You can find some
information on I2C EEPROM at:
http://www.high-techgarage.com/tutorial/i2c.php
Good luck with your project!
--Jeff Wallace
Add a RTC, 256k EEPROM and an I2C bus to your BS2
http://www.high-techgarage.com/products/timekeeper.php
--- In basicstamps@y..., "Anthony Conti" <aconti@n...> wrote:
> Hi All
>
> I am working on a project that uses the count command and I would
like to take the average from 5 samples ( Word Size ) . I am using
the BS2P 24. I am almost out of RAM, so if any way to store the 5
values in the EEPROM or the SP would help.
>
> Thanks
> TC
1000 + 750 + 890 + 600 + 900 = 4140
4140 / 5 = 828
Would the stamp work the same way? I think the max value will be 1500 to 2000.
TC
·
TABLE WAS SUPPOSED TO GO HERE
>and I need the Average of 5 readings. we found out how to do
>averaging in school like this:
> 1000 + 750 + 890 + 600 + 900 = 4140
>4140 / 5 = 828
> Would the stamp work the same way? I think the max value will be
>1500 to 2000.
> TC
No need to store all 5 values, just the running sum:
x var word
y var word
i var nib
top:
y=0
for i=1 to 5
count cpin,ctime,[noparse][[/noparse]x]
y=y+x 'accumulate
next
y=y/5 ' average
debug ?y
goto top
-- Tracy
(just like READ and WRITE) only work with byte variables, so you´ll have to do
two PUTs and two GETs for each value.
If the sum of five values will exceed $FFFF, you can grab a value, divide by
five, then add to an accumulator. When you have done this with five values, the
accumulator will hold the average.
-- Jon Williams
-- Applications Engineer, Parallax