View previous topic :: View next topic |
Author |
Message |
Freddie
Joined: 06 Sep 2003 Posts: 49
|
Why is this code not taking the numerical averge correctly? |
Posted: Sun Jan 25, 2004 1:27 pm |
|
|
The code below, running on a 16f876a, CCSv1.184, produces the following output. Can anyone figure out why the numerical average is coming out to be 0385? It should be around 0333.
atodValue = 0333
atodValue = 0333
atodValue = 0333
atodValue = 0334
atodValue = 0333
atodValue = 0334
atodValue = 0333
atodValue = 0332
atodValue = 0333
atodValue = 0334
atodValue = 0333
atodValue AVG= 0385
Code: |
int16 atodValue, int16Temp;
int16Temp = 0;
for(i=0;i<=10;i++)
{
atodValue = Read_ADC();
int16Temp = int16Temp + atodValue;
fprintf(serialPC, "atodValue = %LX\r\n", atodValue);
delay_ms(50);
}
atodValue = 0;
atodValue = int16Temp / (long)10;
fprintf(serialPC, "atodValue AVG= %LX\r\n", atodValue);
|
Last edited by Freddie on Sun Jan 25, 2004 1:55 pm; edited 1 time in total |
|
|
Gerrit
Joined: 15 Sep 2003 Posts: 58
|
|
Posted: Sun Jan 25, 2004 1:45 pm |
|
|
Hi Freddie,
Looks to me that you take 11 samples <= 10
and you devide by 10 that shot be +- 10 % more for output value.
Gerrit |
|
|
Freddie
Joined: 06 Sep 2003 Posts: 49
|
|
Posted: Sun Jan 25, 2004 1:52 pm |
|
|
Yes, that was it! Sometimes you just can't see it for yourself. Thanks. |
|
|
|