- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
#define max 0x08 //Max number of samples to average/filter
#define byte unsigned char
#define word unsigned int
#define dword unsigned long
#define FILTER 0
#define AVG 1
typedef struct {
word reading[max];
word result[max];
} ResultStct;
static ResultStct x;
static char samp = 0;//filter;
const byte filter_mode = FILTER;
extern int avg_result;
void MYfilter(word input_sample)
{
byte j;
dword X;
x.reading[samp] = input_sample;
if(samp>0){
X=0;
for (j=0;j<=samp;j++){
X += x.reading[j];
}
avg_result = (X >> 3) - 0x0200;
}
// Shift array of results if we hit max
if (samp >= max-1) {
for (j=0;j<max-1;j++){
x.result[j] = x.result[j+1];
x.reading[j] = x.reading[j+1];
}
samp = max-1;
}
else
{
samp++;
} //end if (i => max)