Actually, a full scale A/D reading in left justified 10.6 format is=20 1111111111.000000, in binary, 0000001111111111, or decimal 1023. For a half scale reading (i.e. 2.5V on a 5V reference) would be either=20 1000000000.000000 or 0111111111.000000, in binary 0000001000000000 or=20 0000000111111111, or decimal 511 or 512. When you read the A/D result=20 registers in a PIC, you can choose which format you get. In 10.6 math, there is an imaginary decimal point between bits 5 and 6. =20 Bit 6 has a value of 1, bit 7 is 2, bit 8 is 4, etc. Bit 5 would have a value of 1/2, bit 4 is 1/4, bit 3 is 1/8, bit 2 is=20 1/16, bit 1 is 1/32 and bit 0 is 1/64. Now let's say we are implementing Olin's filter, and want to multiply=20 our A/D reading by 1/16. 1/16 has bit 4 set, and all others cleared, so it is 0000000000.000100,=20 which is a binary 4. when we multiply 0111111111.000000 by 0000000000.000100 we get 0000 0000 0000 0001 1111.1111 0000 0000, which is too large to fit into=20 16 bits, and so becomes a 32 bit bit number, in 20.12 format. But the=20 last 6 bits will always be 0, so we don't really need them. Without=20 them, the number would fit into 16 bits, and in fact would fit into the=20 10.6 format. We could do that by right shifting 6 times and taking the=20 lowest 16 bits. We would end up with 0000 0111 11.11 1100. The end=20 result off all of this is that we took a number, multiplied it by 4 then=20 divided it by 64. Reading the A/D in right justified mode results in a number that is=20 already right shifted by 6 bits (i.e. divided by 64), so taking our=20 reading as 0000000111111111 and multiplying by 0000000000000100 would=20 give us 0000 0111 11.11 1100, which will fit into a 16 bit number without=20 overflow, and is in fact in 10.6 format, with the fractional bits right=20 where they oughta be, without ever needing a 32 bit variable. Kerry alan.b.pearce@stfc.ac.uk wrote: >>> On the other hand, a 1/2 scale right justified A/D reading would be >>> 0000 0010 00.00 0000 >>> =20 >> That doesn't make sense. If you are using right justified A/D >> =20 > readings, > =20 >> then they would be integers. I don't see where the fraction bits are >> supposed to come from in this case. >> =20 > > Part of the problem that I see (and it doesn't matter if he uses a C > compiler or anything else) is that Olin didn't explain himself properly > in the first place. His 10.6 is 10 bits of binary mantissa and 6 bits of > binary fraction, but his arithmetic is only ever done as adds, subtracts > and shifts. But Kerry appears to be thinking of this 10.6 as being like > an IEEE 754 or similar floating point representation, and doing math on > it as though it is an ordinary decimal number, so doing a divide is not > being properly done.=20 > > In your example Kerry, if the full scale is 1000 0000 00.00 0000, then a > 1/2 scale reading is 0100 0000 00.00 0000 > i.e. divide by 2, or a 1 bit right shift. > =20 --=20 Internal Virus Database is out-of-date. Checked by AVG Anti-Virus. Version: 7.0.289 / Virus Database: 267.11.13 - Release Date: 10/6/05 --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .