www.piclist.com/techref/microchip/math/index.htm?key=math

Hi,

I forgot to reply to your question Philip :)

anyway here goes:

Philip Martin wrote:

<snip>

>get into this figure to convert it into MPH. Thus 122.75 / 12.63

seconds

>would be 9.718 mph.

<snip>

>Route b)

>

>12275 = 2F (msb) & F3 (lsb) / 1263 = 04 (msb) & EF (lsb) = 00 09 (msb)

. 03

>83 (lsb) or 9.908.

>

>Question:

>

>Would I be right in thinking that route b) is the more correct way to

do it

>and the error is due to the maths capability of the math routine?

Well not really, you start with the value 12.275 which has as many digit

as you need

then you divide it, this way you are ( alomost ) bound to 'loose'

digits(accuracy).

If you instead convert it to 8.16 format you will have this:

122 = 0x7A

275 * 65.534 = 18021.85 = 0x4666

all togehter:

0x7A4666

Divide by 12.63 will generate:

0x09AE6B

to convert to 'fixed 4 digit after decimal point''

Multiply by 10000 / 256*256 = 0.152588 ( rounded )

will generate:

0x017A2D which is 96813 in decimal with 4 digits after dp we get

9.6813 mph which is closer than your original formulas.

I'm sorry for the bad example to the maths pro's on the list but I'm in

a hurry :)

/Tony

Tony Kübek, Flintab AB

²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²

E-mail: spamBeGonetony.kubekTakeThisOuTflintab.com

²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²

--

http://www.piclist.com hint: The PICList is archived three different

ways. See http://www.piclist.com/#archives for details.

See also: www.piclist.com/techref/microchip/math/index.htm?key=math