Can you explain me on which part of the code are you adding the 8 values to avg_weight ?[/quote]
This does the averaging
// AVERAGING IS DONE HERE
avg_weight += new_weight;
avg_weight /= AVG_FILTER_WINDOW_SIZE;
After eight operations...I should get the first average result.
After 8 operations, but you are dividing by 8 all the time, check it out, you need to divide by 8 only after you have added 8 operations, otherwise your calculation is not correct.
And as Kender mentioned you should be using a type of array or table to have the 8 measurements and then calculate the average.
Added after 5 minutes:
daviddlc said:
Can you explain me on which part of the code are you adding the 8 values to avg_weight ?
This does the averaging
// AVERAGING IS DONE HERE
avg_weight += new_weight;
avg_weight /= AVG_FILTER_WINDOW_SIZE;
After eight operations...I should get the first average result.
After 8 operations, but you are dividing by 8 all the time, check it out, you need to divide by 8 only after you have added 8 operations, otherwise your calculation is not correct.
And as Kender mentioned you should be using a type of array or table to have the 8 measurements and then calculate the average.[/quote]
Corrections:
You are dividing by 8 all the time, check it out, you need to divide by 8 only after you have added 8 operations, otherwise your calculation is not correct.
And as
Odiseo mentioned you should be using a type of array or table to have the 8 measurements and then calculate the average