piclist 2002\08\27\122654a >
Thread: Real newbie question on ADC
www.piclist.com/techref/microchip/begin.htm?key=adc
flavicon
face BY : Mike Mansheim email (remove spam text)



>>> FILT <-- FILT + (NEW - FILT) * FF

>> Using your formula and simulating in Excel I always get an offset
>> dependant on FF...<snip>

> The formula was not intended for just integers.  It is usually a good
> idea to have enough fraction bits for the bits of shifting implied by
> FF... <snip>

If you're not familiar with fraction bits (newbie reference in subject),
that just means you carry the working data in the upper bits of a longer
variable.  For example, if you want to use the full 10 bits of the a/d,
you can use a 16 bit variable and use the bottom 6 bits as fraction bits.

An example, in C, that shows how this works:
(the variables are 16 bit unsigned integers)

// read_a2d() is some function that puts 10 bit a/d reading in NEW

// shift new a/d reading to the top of the word
NEW = read_a2d() << 6;

// this is for FF = 1/8
FILT = FILT + (NEW/8) - (FILT/8);  // this particular rendition of
                                   // the formula does the divide
                                   // twice, but lets you completely
                                   // ignore signs

then if you need to use the filtered reading for anything, pick off the
top ten bits of FILT.  Say you have a display function that takes a 16
bit variable as a parameter:

display(FILT >> 6);   // (but don't use FILT = FILT >> 6; to work with
                     //  it; you'll lose the fraction bits

As Olin pointed out, if you use an 8 bit a/d reading and 8 fraction bits,
the bit shifting in this example simply becomes a matter of selecting
high and low bytes.  And if FF = 1/256, then the divide(s) get real
simple too!

Hope this helps.

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


<OF48AAA6C2.70D421AD-ON86256C22.0053EB1A@graco.com>

See also: www.piclist.com/techref/microchip/begin.htm?key=adc
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Real newbie question on ADC

month overview.

new search...