piclist 2008\07\13\084443a >
Thread: Need help with 24F/30F/33F PICs extended precisionMUL/DIVplease
face picon face BY : email (remove spam text)(Olin Lathrop)

Electron wrote:
> In short I have 24bits coming from an ADC, and I have to make them
> 16bits, but inside a certain range of these 24bits.
> ...
> if (adc<=min) {
>    out=0;
> } else if (adc>=max) {
>    out=65535;
> } else {
>    out=(adc-min)*65536/(max-min); /* needs 64bit intermediary
> precision */ }

Take your input value and subtract off MIN.  Now the rest is a scale factor
problem.  If this remaining value is still wider than 16 bits, then left
justify it in a 32 bit number and divide to get the 16 bit result.  If
ADC-MIN always fits in 16 bits, then multiply it by a scale factor such that
the result you want ends up in 16 bits near the high end of the 32 bit

Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products
(978) 742-9014.  Gold level PIC consultants since 2000.
<014901c8e4e6$8a6895a0$0300a8c0@main> 7bit

See also: www.piclist.com/techref/microchip/devices.htm?key=pic
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) Need help with 24F/30F/33F PICs extended precisionMUL/DIVplease

month overview.

new search...