Hi!

How about just adding the 2000 raw integer ADC readings in an uint32_t
variable and at the end just divide with the numbers of readings. An
uin32_t is much bigger than the 2000*1000, the maximum the samples can sum
up. :-)

--
Razvan ME

On Sun, 27 Sep 2009, Guillermo De Cesco wrote:

> Hi,
>
> cause buffer size(2000) is bigger than any actual number (0-1000). you
> should promote the division opoeration to float
> in order to get something different from cero, that is,
>
> average += (1.0 * x) / buff_size;
>
> the 1.0 * will do the trick. then if you whant just an integer as result you
> should cast the average to int
> that is,
>
> average = (int) average;
>
> good luck
>
> -Bill
>
> On Sat, Sep 26, 2009 at 1:37 AM, Akankshu Dhawan <[email protected]> wrote:
>
>> Hi All
>> I am using IRIS motes and wanted to calculate average values for 2000
>> values so I decided dividing each one of them by the BUF_SIZE (2000) and
>> then transferring it to a variable. This involves handling float values,
>> since max adc value is 1000(approx) , but when I do this division all values
>> I get are zero... can you tell me how I can deal with floating values ?
>>
>>
>> or if there is a predefined function for calculating averages ?
>>
>> I dont need the average value to be floating .. that final value should be
>> integer...
>>
>> so basically, I have 2000 values between 0-1000 and I want their
>> average/mean value.... do you have any suggestions ?
>>
>> Thanks
>> Akankshu
>>
>> --
>> First they ignore you, then they laugh at you, then they fight you, then
>> you win.
>> - Mahatma Gandhi
>>
>> _______________________________________________
>> Tinyos-help mailing list
>> [email protected]
>> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>>
>
>
>
> --
> Ing. Guillermo De Cesco
> Invenio Ingenieria srl.
> tel: (54)2944 442119
> web: www.invenioing.com
> Av. Pioneros 4163 Dpto 6. CP(R8402AMH)
> San Carlos de Bariloche.
> Rio Negro, Argentina.
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to