On Sep 11, 2005, at 8:49 AM, Leon Heller wrote:
>> I have a circuit with an Accelerometer connected to an ATmega32. The
>> Accel measures 2.5V at rest and goes to .5v or up to 4.5v when
>> tilted.
>> The motors I am using on this bot cause vibrations when running and I
>> can't get a clean signal fromt he Accel.
>> Is there a way to filter the noise from the motors out of the Accel
>> signal through CodevisionAVR?
>>
>
> DSP might be applicable, if you have enough spare processing
> capability.
Yes. Unless I read michaelsteinbach's question incorrectly he was
asking how to do DSP functions using CodevisionAVR.
Maybe after he has tried it he will find the AVR is sufficient. Maybe
not.
I would suggest a simple averaging of the inputs from the
accelerometer. If its being shaken then I'd guess half the time its
going one direction and half the time its going the other direction
due to vibration. And that the DC offset is the value he is really
looking for.
Keep a running average. Store a circular buffer of each and every
sample. Sum the samples as they go in, subtract the old samples as
they fall off. The average is this value divided by the number of
samples.
uint16_t samples[COUNT];
uint8_t pos, cnt;
uint32_t sum;
void init_samples(void)
{
sum = 0;
pos = cnt = 0;
}
void newsample( uint16_t new )
{
sum += new; // add to running total
if( cnt < COUNT ) {
samples[cnt++] = new; // only until samples is full
} else {
sum -= samples[pos]; // remove oldest from running total
samples[pos++] = new; // save the new in oldest space
if( pos >= COUNT )
pos = 0;
}
}
And any time you want to know the average its sum/cnt. If you don't
mind goofy values the first COUNT samples then remove if( cnt <
COUNT ) and use sum/COUNT.
void newsample( uint16_t new )
{
sum += new;
sum -= samples[pos];
samples[pos++] = new;
if( pos >= COUNT )
pos = 0;
}
--
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.Message
Re: [AVR-Chat] Sensor filtering
2005-09-11 by David Kelly
Attachments
- No local attachments were found for this message.