Kerry Wentworth wrote: > Actually, a full scale A/D reading in left justified 10.6 format is > 1111111111.000000, in binary, 0000001111111111, or decimal 1023. > For a half scale reading (i.e. 2.5V on a 5V reference) would be either > 1000000000.000000 or 0111111111.000000, in binary 0000001000000000 or > 0000000111111111, or decimal 511 or 512. When you read the A/D result > 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. 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 > 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 > our A/D reading by 1/16. > 1/16 has bit 4 set, and all others cleared, so it is > 0000000000.000100, 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 16 bits, and so becomes a 32 bit bit number, in 20.12 format. > But the last 6 bits will always be 0, so we don't really need them. > Without them, the number would fit into 16 bits, and in fact would > fit into the > 10.6 format. We could do that by right shifting 6 times and taking > the lowest 16 bits. We would end up with 0000 0111 11.11 1100. The > end result off all of this is that we took a number, multiplied it by > 4 then divided it by 64. > > Reading the A/D in right justified mode results in a number that is > already right shifted by 6 bits (i.e. divided by 64), so taking our > reading as 0000000111111111 and multiplying by 0000000000000100 would > give us > 0000 0111 11.11 1100, which will fit into a 16 bit number without > overflow, and is in fact in 10.6 format, with the fractional bits > right where they oughta be, without ever needing a 32 bit variable. Did I miss a point you were trying to make somewhere in there, a question, or are you just saying out loud what you think you understand to try to mak= e more sense of it? ******************************************************************** Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products (978) 742-9014. Gold level PIC consultants since 2000. --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .