Professional Documents
Culture Documents
Página 1 de 13
Sign in
Discussion Groups | 68HC12 | Software Filtering of an ADC input
username:
password:
Join our technical discussions about Freescale
Microcontrollers: M68HC12. (Freescale Semiconductor is a
Ti Stellaris Mcu Subsidiary of Motorola).
Up to 80 MHz, 256 KB Flash, 96 KB
SRAM & USB, CAN, Ethernet &
Not a member? C/C++.
www.ti.com/stellaris
Search 68hc12
Subscribe to 68hc12
Advertise Here
Your Email
68HC1 | 812A4 | 9S12DP256 | I want to be able to 'filter' the value returned from an on-board ADC.
Bootloader | CodeWarrior |
D60A | Debugger | DP256 | ECT When I say 'filter' I think that perhaps 'average' would be a better
| EEPROM | EVB | Flash | HC1 | description.
HCS12 | I2C | IAR | ICC1 |
Interrupts | LCD |
M68KIT912DP256 | I want to be able to set an amount of filtering (say 20%) and none of
MC9S12DP256 | the descriptions of digital filters I've found seem to allow this.
MC9S12DP256B | Metrowerks | They all seem to be designed to filter a specific frequency range that
Motor | MSCAN | Multilink | PLL |
must be stated in the calculations used to design the filter.
Quadrature | SDI | SPI |
Transceiver | XFC
I thought about having a ring buffer to which you place the ADC
results at a constant time interval, then summing the buffer, and
Sponsor
dividing by the number of samples taken. But then how do you allow for
Get EASY design support the amount of filtering you want to apply ??
with
I'm going round in circles with this !!
TI's C2000™
controlSUITE™ software Any thoughts or ideas would be very much appreciated.
suite!
I also need the routine to be fairly quick and not take up too much
RAM as I'm getting a bit short on it.
Sponsor Andy
______________________________
Complete portfolio of 32-bit MCUs plus RFID, low-power RF and ZigBee® solutions. Order a Stellaris
Kit today!
Ti Stellaris Up to 80 MHz, 256 KB Flash, 96 KB SRAM & USB, CAN, Ethernet & C/C++. www.ti.com/stellaris
Discover the benefits of
using the Cosmic HC08 / HCS08 Tools C Compiler, Asm, Sim, Mon08, BDM Debugger and Flash Programmer www.cosmic-software.com
world's lowest power
microcontroller! Spa, Massagem e Bem Estar Saia da correria. Relaxe com nossos descontos de até 70%. Confira! ClubeUrbano.GROUPON.com.br/Spa
Re: Software Filtering of an ADC input - Author Unknown - Mar 7 9:18:00 2004
Discussion Groups This works ok, but if you change NUMSAMP much bigger, you need to make tot
a long.
This keeps the rolling average of NUMSAMP samples but subtracting off the
Comp.Arch.Embedded old sample from the total, adding in the new sample in the total, and
recomputing the avg with one of those clever divide by shifting tricks. By keeping the
68HC12 total, you dont need to add em all up every time.
//---used in rolling avg--------
AT91SAM ARM #define NUMSAMP 8
typedef struct{
AVRclub unsigned char ndx;
int tot;
BasicX
int avg;
int dat[NUMSAMP]; //avg over NUMSAMP readings
FPGA-CPU
}Trollavg;
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedded... Página 2 de 13
______________________________
Have a look at the new TI MCU Center on EmbeddedRelated.com!
Re: Software Filtering of an ADC input - Andrew Leech - Mar 7 9:42:00 2004
I thought about doing it like this, but it would need to have a large
array to average the samples, and I can't afford the RAM space that
would use.
I'm sure there must be some clever way of doing this without using an
array - just can't see it yet.
Andy
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedded... Página 3 de 13
Re: Re: Software Filtering of an ADC input - Robert Imhoff - Mar 7 10:03:00 2004
______________________________
Complete portfolio of 32-bit MCUs plus RFID, low-power RF and ZigBee® solutions. Order a Stellaris
Kit today!
Re: Re: Software Filtering of an ADC input - Author Unknown - Mar 7 10:59:00 2004
I thought about doing it like this, but it would need to have a large
array to average the samples, and I can't afford the RAM space that
would use.
I'm sure there must be some clever way of doing this without using an
array - just can't see it yet.
============================================
OK, there's another trick. When I use floating point, I get a good averaging
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedded... Página 4 de 13
when I 'add 1/64th of the difference' between the raw value and the smoothed
value... but this doesnt work for integers and real long averages because
you compute the difference then try and take 1/64th or 1/128th of it or
1/256th, it right shifts down to nothing. So the trick, which the folks in the
comp.dsp newsgroup told me, it to keep the avgeraged value scaled up by 256
sitting around, then when you compute the difference between the raw and avg
values, you dont need to take 1/256th of it, you just add it into the avg*256
total.thats already there. [Non-text portions of this message have been removed]
Re: Re: Software Filtering of an ADC input - Author Unknown - Mar 7 11:04:00 2004
Re: Software Filtering of an ADC input - Andrew Leech - Mar 7 11:12:00 2004
I'll just keep working on it. I'll figure out a good solution to it
i'm sure. I just thought that someone else might have had a better
idea than me ! --- In , BobGardner@a... wrote:
> In a message dated 3/7/04 10:04:57 AM Eastern Standard Time,
swar@compuserve.
> com writes:
>
> I suppose a sort of "sledgehammer" method would be to put an
> appropriately chosen capacitor across the analog input (and a series
> resistance towards the source of the signal) and let the hardware do
> the filtering ... > ================================
> I think the big picture is that there is a hw and a sw solution to
just
> about every problem, and tayloring the mix in the solution to fit
the context of
> the problem is part of the engineering process.
> Also I've noticed that the hw guys tend to push the hard stuff they
dont
> know how to do over to the sw guys, and they sw guys sort of do the
same thing.
> Every once in a while you'll see some rare bird that knows both hw
and sw, but
> they are few and far between..... > [Non-text portions of this message have been removed]
______________________________
Have a look at the new TI MCU Center on EmbeddedRelated.com!
Re: Software Filtering of an ADC input - Jim Galloway - Mar 7 11:21:00 2004
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedded... Página 5 de 13
Re: Re: Software Filtering of an ADC input - Robert Imhoff - Mar 7 11:24:00 2004
You could use a sort of PID or PI method: take the average of, say, the
last 16 samples as the "i" value, the current value as "p", evtl. the
difference between the last and the present sample as the "D" amount
and combine the three with adjustable weighting to obtain your filtered
value. On Mar 7, 2004, at 5:12 PM, Andrew Leech wrote: > An RC filter approach would work, but
it would make it fairly tricky
> to adjust from software. I could use a digital pot to alter the R
> component, but the whole job becomes rather messy.
>
> I'll just keep working on it. I'll figure out a good solution to it
> i'm sure. I just thought that someone else might have had a better
> idea than me !
Re: Software Filtering of an ADC input - Robert Smith - Mar 7 11:54:00 2004
Andrew --
I have used the following method with good results on several projects:
Subtract 1/8 Prior Accum from 'Prior Accum' to obtain 7/8 'Prior Accum'
Now compute 1/8 of 'New Sample' by shifting right 3 and add this to '7/8
Prior Accum' to
obtain the Updated accumulator and smoothed value.
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedded... Página 6 de 13
Note: If you do this all in fixed point, you can expect to see binary
truncation effects in the result. In effect the output will develop a dead
zone such that new samples very near the running average will not affect the
filter output. The output will jump from one smoothed value to another as
the new samples change by a few counts. This creates a sort of dead zone
effect. This is an inevitble consequence of binary truncation and will show
up in any filtering technique that you devise.
You can examine the results of this filtering process by clever use of
Excel.
Good Luck, Bob Smith --- Avoid computer viruses, Practice safe hex ---
______________________________
Complete portfolio of 32-bit MCUs plus RFID, low-power RF and ZigBee® solutions. Order a Stellaris
Kit today!
> I want to be able to 'filter' the value returned from an on-board ADC.
> When I say 'filter' I think that perhaps 'average' would be a better
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedded... Página 7 de 13
> description.
> I want to be able to set an amount of filtering (say 20%) and none of
> the descriptions of digital filters I've found seem to allow this.
> They all seem to be designed to filter a specific frequency range that
> must be stated in the calculations used to design the filter.
Hi Andrew,
I am not sure if I read you right but it seems you are trying to compensate=
for some sort of noise in the incoming signal.
I.e. the origin of the signals is important because it determines the frequ=
ency range of interest.
Say a small motor with a varying load needs a faster response time then a w=
eigh-cell where accuracy is of more importance and the final measurement may=
take a second or so.
Say for the small motor it could mean a flywheel or other means of mass inc=
rease, for a weigher it could mean a dashpot.
The next step is to minimise the frequency response from amplifiers and oth=
er electronics to what the measurement requires, and of course to what the c=
omputer can handle.
Since this is a relatively cheap step, don't spare the caps, it will preven=
t all sorts of aliassing problems in your digital filters if the signal vari=
ations (or mains noise) don't get that far or are minimised before they get =
to the converters.
I can't over stress that, you will find it takes an amazingly long time and=
an even more amazing sample rate to get some form of accuracy in a signal e=
mbedded in a sine-wave, to say nothing about reduced headroom in the signal =
paths etc.
Keep it out of a device that has to work in a sample/hold fashion and only =
has a limited A/D accuracy as far as possible.
The last step is the one you are interested in, the measurement and/or cont=
rol loop in the computer.
You will find there are as many schemes as there are Engineers, but in the =
end they all try to do the same thing, provide a digital low pass filter in =
some form or another, the cut of frequencies, poles etc determined by how ke=
en the designer is and how fast the computer.
There are some rather involved tomes that will give you all the good stuff,=
but it is very rare to have to go that far, simple solutions usually suffic=
e in most situations.
I.e. a few stages of RC low pass filtering limiting the signals presented t=
o the lowest frequency needed, followed by something similar in the computer=
is usually enough to serve the purpose.
The trade of in computer filters is of course easily seen, the more involve=
d the filter, the slower your sample rate (or the faster the computer has to=
be), often negating the gains by introducing aliassing problems.
I.e. sampling at a rate that coincides with some harmonic or other of the i=
ncoming signal will cause all sorts of grief.
If you have made sure to keep higher frequencies out of the signal path in =
the first place, a simple exponential scheme along the lines of adding the n=
ew value to a multiple of the previous value and weighing it back usually su=
ffices.
If you find you have to lower the cut of frequency beyond the time availabl=
e, re-evaluate the input filtering rather then trying to compensate in the C=
PU with all sorts of interesting algorithms.
Theo
______________________________
Have a look at the new TI MCU Center on EmbeddedRelated.com!
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedded... Página 8 de 13
Re: Re: Software Filtering of an ADC input - linktek - Mar 7 16:58:00 2004
Hi,
You can always use IIR or a more computative FIR software filter with
taylored coefficients.
However, on the KISS solution. Lets say the problem is lack of data
memory. You would like a
adjustable software filter - field tunable. So how about a cascaded running
average filter. In stead of one long array, you first average
the first 8 samples into a running average, and stuff the result of the
first average into a second array doing a running average of the results of
the first running average output in another 8 sample array and so on and so
on .... till you run out of memory. Its obvious to see that this is a easely
tunable filter algorithm.
> I want to be able to 'filter' the value returned from an on-board ADC.
> When I say 'filter' I think that perhaps 'average' would be a better
> description.
> I want to be able to set an amount of filtering (say 20%) and none of
> the descriptions of digital filters I've found seem to allow this.
> They all seem to be designed to filter a specific frequency range that
> must be stated in the calculations used to design the filter.
Hi Andrew,
I am not sure if I read you right but it seems you are trying to compensate=
for some sort of noise in the incoming signal.
I.e. the origin of the signals is important because it determines the frequ=
ency range of interest.
Say a small motor with a varying load needs a faster response time then a w=
eigh-cell where accuracy is of more importance and the final measurement
may=
take a second or so.
Say for the small motor it could mean a flywheel or other means of mass inc=
rease, for a weigher it could mean a dashpot.
The next step is to minimise the frequency response from amplifiers and oth=
er electronics to what the measurement requires, and of course to what the
c=
omputer can handle.
Since this is a relatively cheap step, don't spare the caps, it will preven=
t all sorts of aliassing problems in your digital filters if the signal
vari=
ations (or mains noise) don't get that far or are minimised before they get
=
to the converters.
I can't over stress that, you will find it takes an amazingly long time and=
an even more amazing sample rate to get some form of accuracy in a signal
e=
mbedded in a sine-wave, to say nothing about reduced headroom in the signal
=
paths etc.
Keep it out of a device that has to work in a sample/hold fashion and only =
has a limited A/D accuracy as far as possible.
The last step is the one you are interested in, the measurement and/or cont=
rol loop in the computer.
You will find there are as many schemes as there are Engineers, but in the =
end they all try to do the same thing, provide a digital low pass filter in
=
some form or another, the cut of frequencies, poles etc determined by how
ke=
en the designer is and how fast the computer.
There are some rather involved tomes that will give you all the good stuff,=
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedded... Página 9 de 13
I.e. a few stages of RC low pass filtering limiting the signals presented t=
o the lowest frequency needed, followed by something similar in the
computer=
is usually enough to serve the purpose.
The trade of in computer filters is of course easily seen, the more involve=
d the filter, the slower your sample rate (or the faster the computer has
to=
be), often negating the gains by introducing aliassing problems.
I.e. sampling at a rate that coincides with some harmonic or other of the i=
ncoming signal will cause all sorts of grief.
If you have made sure to keep higher frequencies out of the signal path in =
the first place, a simple exponential scheme along the lines of adding the
n=
ew value to a multiple of the previous value and weighing it back usually
su=
ffices.
If you find you have to lower the cut of frequency beyond the time availabl=
e, re-evaluate the input filtering rather then trying to compensate in the
C=
PU with all sorts of interesting algorithms.
Theo
--------------------------------------------------------To learn more about
Motorola Microcontrollers, please visit
http://www.motorola.com/mcu
o learn more about Motorola Microcontrollers, please visit
http://www.motorola.com/mcu
Re: Software Filtering of an ADC input - Steve Russell - Mar 7 18:21:00 2004
Andy,
The ideal is to have a "brick wall" filter that has zero attenuation at
half the sampling frequency, and very large attenuation at the sampling
frequency and beyond.
A simple RC filter is fairly far from this ideal, but setting its cutoff
frequency as low as you can afford will help.
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedd... Página 10 de 13
The software filter is much cheaper that an analog filter for low frequencies.
Re: Software Filtering of an ADC input - Donald E Haselwood - Mar 7 20:55:00 2004
Andy,
The book, Digital Filters, R.W. Hamming, 1977, Prentice-Hall, has a section
on the frequency response of averages. The book (quite readable) is out of
print, but probably can be located through a university library system. In
case your interested, the passband equ:
Here is a chapter of a (very readable) DSP book you can download (free)
that also talks about averages. He points out that the average is a filter
that responds the quickest to a step input, so for some situations it is
optimal.
http://www.dspguide.com/ch15.htm
You mention "20%" for the filtering. That sounds like you are thinking in
terms an IIR (infinite impluse response) filter, such as the simple digital
implementation of a RC filter, also in the previous posts. If you
implement that form for filter make sure the storage for the accumulated
value will accommodate the largest value. As that "%" gets smaller, which
has the effect of making the cut-off freq lower, the accumulated value gets
very large (but, unlike the circular buffer/average filter, only one value
has to be stored, so it doesn't take a lot of memory).
The characteristics of the signal you are measuring determines the which
type of filter is best (assuming it fits in memory!). The IIR/RC type of
filter "remembers" a big glitch, or noise spike, "forever," i.e. a noise
spike takes a long time to "fade away," whereas the averaging filtering
drops a big number after one cycle around the buffer.
Regards,
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedd... Página 11 de 13
______________________________
Complete portfolio of 32-bit MCUs plus RFID, low-power RF and ZigBee® solutions. Order a Stellaris
Kit today!
RE: Re: Software Filtering of an ADC input - Redd, Emmett R - Mar 8 8:40:00 2004
See below.
As a model, Excel works because each column (or row) can represent the
calculation performed at each successive, uniformly spaced, time step. >
> Cheers,
>
> Theo
Re: Re: Software Filtering of an ADC input - Author Unknown - Mar 8 10:51:00 2004
You can get an excellent tool for characterizing various filters from
Nuhertz Technologies (www.nuhertz.com). I used their Filter Free tool
years ago while researching digital filters for an embedded project. The
tool I used then (version 2.0) generated frequency response graphs,
electrical schematic equivalents, and transfer functions, which made code
generation much easier.
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedd... Página 12 de 13
Karl
linktek
<linktek@shaw. To:
ca> cc:
Subject: Re: [68HC12] Re: Software Filtering of an ADC input
03/07/2004
01:58 PM
Please respond
to 68HC12
Hi,
You can always use IIR or a more computative FIR software filter with
taylored coefficients.
However, on the KISS solution. Lets say the problem is lack of data
memory. You would like a
adjustable software filter - field tunable. So how about a cascaded
running
average filter. In stead of one long array, you first average
the first 8 samples into a running average, and stuff the result of the
first average into a second array doing a running average of the results of
the first running average output in another 8 sample array and so on and so
on .... till you run out of memory. Its obvious to see that this is a
easely
tunable filter algorithm.
______________________________
Complete portfolio of 32-bit MCUs plus RFID, low-power RF and ZigBee® solutions. Order a Stellaris
Kit today!
Re: Re: Software Filtering of an ADC input - Darrell N. - Mar 8 11:32:00 2004
OldSample + NewSample
-----------------------------------
2
I also use a 16 value ring filter, where the new value is added
to a sum, and the oldest value is subtracted out. For 16 bit
values, this requires 32 bytes of buffer, a 2 byte sum, and a 2
byte pointer, as well as your original and filtered values.
This is a total of 40 bytes, which is a pretty good chunk of
RAM.
> I thought about doing it like this, but it would need to have a
> large array to average the samples, and I can't afford the RAM
> space that would use.
>
> I'm sure there must be some clever way of doing this without
> using an array - just can't see it yet.
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010
Software Filtering of an ADC input | 68HC12 | Embedd... Página 13 de 13
Regards,
Darrell Norquay
http://www.embeddedrelated.com/groups/68hc12/show/6089... 21/11/2010