Hi TOM,
I think it's overflowing in this statement
Dec_speed = (Dec_speed*115)/100
This shoud work better
Dec_speed = Dec_speed*115
Dec_speed = DIV32 100
HTH,
Darrel
Hi TOM,
I think it's overflowing in this statement
Dec_speed = (Dec_speed*115)/100
This shoud work better
Dec_speed = Dec_speed*115
Dec_speed = DIV32 100
HTH,
Darrel
If you want to speed it up and add some accuracy you could use....
Dec_speed = Dec_speed + (Dec_speed ** 9882)
..... this will give you 1kn = 1.1507873mph which is darn close to the 1.15078030303 it should be.
/Ingvar
That's good Ingvar, got me thinking.
But, since we're going for accuracy too.
1 Nautical Mile = 6076.11549 Feet
1 Mile = 5280 Feet
So the conversion is 1.150779449 (6076.11549/5280), and the number we need is [0.150779449 * 65536] or 9881.482. It's closer to 9881 than 9882
But the biggest problem is with the integer nature of the calculation. Most of the added accuracy is lost in the Low Word of the ** multiplication..
For instance, at 45.0 knots, the MPH is 51.78 MPH (45 * 1.150779449) which is closest to 51.8 MPH.
However, either of our previous formula's will only show 51.7 MPH.
Here's another way that does the same thing as the **, but also allows you to round the result according to the low Word of the multiplication.This will hold the result to +/- 1/2 Least Significant Digit.Code:Dummy = Dec_speed * 9881 Dummy = R0 ; Get High Word of Multiply result IF R2 > 32768 then Dummy = Dummy + 1 ; Round to nearest .1 MPH Dec_speed = Dec_speed + Dummy
Best regards,
Darrel
Last edited by Darrel Taylor; - 28th June 2005 at 18:23.
Hi Darrel,
Isn't it wonderful when we try to improve the accuracy with about half a ppm .... and the world has hardly descided how long a nautical mile really is. I got "1 knot = 1.15078030303 mph" from http://www.geocities.com/TheTropics/...311/ktmph.html , but after doing a little more digging around, i now agree with you. It shows that you can't really trust anything you find on the net.
BTW, i really like the way you do the rounding, i can imagine that beeing speedy in assembler ....... i just might steal it sometime ;-)
Just to be a pain, i'll show how i'd do this calculation with rounding(and adding that extra little accuracy). Perhaps someone will find it useful.
Dec_speed = ((Dec_speed */ 2946) + 5) / 10
It's probably a little slower than your method since it involves a division.
/Ingvar
Ingvar,
OK, now we're getting silly, but I just can't resist.
Same thing as before, With Rounding, less code.Saved 30 Words in the process.Code:Dummy = Dec_speed * 9881 Dec_speed = R0 + R2.15 + Dec_speed
OK, I'll quit now,
Darrel
While were on the task of reducing and optimizing Toms code, i feel a strong urge to reduce ............ into .....SSD4= (ssmax[18]>>4)
SSD3= (ssmax[18] & $f)
SSD2= (ssmax[17]>>4)
SSD1= (ssmax[17] & $f)
Then convert to Decimal:
Dec_speed=(ssd4*4096)+(ssd3*256)+(ssd2*16)+ssd1 ' convert to dec
...... thus saving time, codespace and ram ... you name it.Code:Dec_speed.HighByte = ssmax[18] Dec_speed.LowByte = ssmax[17]
How about it Darrel, want a shot at it ;-)
Good eye Ingvar,
I didn't even notice that he was Ripping them apart, just to re-assemble them back exactly like they were. That's a pretty big code savings.
And, here's my "Shot at it"
Zero Code.Code:@Dec_Speed = _ssmax + 17 Dec_Speed VAR WORD EXT
Think we can reduce it even farther??
Darrel
Bookmarks