| ??? 10/12/03 17:37 Read: times |
#56560 - RE: Avaraging Responding to: ???'s previous message |
For this type of thing, I use a moving average -- something like the following, which I did not check for errors or compile, but it should give you the general idea. By the way, I use 16 sample points for the obvious reasons.
#define ADC_CH_5VOLTS 0
#define ADC_CH_TEMP 1
extern unsigned AdcRead(unsigned char channel);
struct MOVING_AVG
{
unsigned char sampleIdx;
unsigned sample[16];
unsigned sampleTotal;
};
struct MOVING_AVG Ma5Volts;
struct MOVING_AVG MaTemp;
unsigned Adc5Volts;
unsigned AdcTemp;
static unsigned maUpdate(struct MOVING_AVG *maP, unsigned sample)
{
maP->sampleTotal -= maP->sample[sampleIdx];
maP->sampleTotal += sample;
maP->sample[sampleIdx] = sample;
return (maP->sampleTotal >> 4);
}
void main(void)
{
for (;;)
{
Adc5Volts = maUpdate(&Ma5Volts, AdcRead(ADC_CH_5VOLTS));
AdcTemp = maUpdate(&MaTemp, AdcRead(ADC_CH_TEMP));
}
}
|
| Topic | Author | Date |
| Avaraging | 01/01/70 00:00 | |
| RE: Avaraging | 01/01/70 00:00 | |
| RE: Avaraging | 01/01/70 00:00 | |
| RE: Avaraging | 01/01/70 00:00 | |
| RE: Avaraging | 01/01/70 00:00 | |
| RE: Avaraging | 01/01/70 00:00 | |
| RE: Avaraging | 01/01/70 00:00 | |
RE: Avaraging | 01/01/70 00:00 |



