www.piclist.com/techref/microchip/devices.htm?key=pic

Kübek Tony wrote:

> 3: My current 'idea', try to 'extract' the ones and tens from the

> input ( 24 bit ) and somehow use it to round with. Sofar

> i've managed to extract it but don't know really if this is the way

> to go. I'm using about 200-300 cycles for the extraction

> and have the tens in one byte and the ones in another byte.

Tony, i've been thinking about this rounding off

thing and I hope i'm not annoying you with suggestions

but the topic is intriguing to me. :o)

I think the 10s and 1s solution would work, how about:

(example, round 24bit binary number to nearest decimal 50)

1. add 25 to the 24bit number.

2. extract the 10s and 1s digits.

3. if 10s is greater than 5 subtract 5 from it.

4. multiply 10s by 10 (simple lookup table, 5 bytes)

5. add 1s to 10s (this is now the 50 modulus)

6. subtract the modulus from the 24bit number

All of those are very quick to perform, apart

from step 2; the extracting of the 10s and 1s.

You said you have done this but 300 cycles on

an 18 series PIC seems a lot.

Have you looked for an algorithm that extracts

BCD digits from a binary number? If you could find

a good refined system for this and just use the

section that extracts the last two digits??

:o)

-Roman

--

http://www.piclist.com#nomail Going offline? Don't AutoReply us!

email .....listservSTOPspamEraseMEmitvma.mit.edu with SET PICList DIGEST in the body

See also: www.piclist.com/techref/microchip/devices.htm?key=pic