Hello Darrell,,
Darrell>>Zero Code.
Think we can reduce it even farther?? <<
There goes the bankruptsy of Pkzip....
Dwayne
Hello Darrell,,
Darrell>>Zero Code.
Think we can reduce it even farther?? <<
There goes the bankruptsy of Pkzip....
Dwayne
Ability to Fly:
Hurling yourself towards the ground, and missing.
Engineers that Contribute to flying:
Both optimists and pessimists contribute to the society. The optimist invents the aeroplane, the pessimist the parachute
Pilots that are Flying:
Those who know their limitations, and respect the green side of the grass...
Ouch, i believe your "Shot at it" found it's target ..... sinking .... mayday. It's difficult to beat zero code, really difficult ...... sort of impossible.
However, i want to point out that if you change the value of "Dec_Speed" you infact change the values in the array(ssmax17&18). This makes it impossible to use for other tasks, not a problem in this application(i hope). I bet you know that but some people find it difficult to get their head around this.
Good job!
/Ingvar
All true, I guess it's Bad Form to re-use variables like that.
So here it is. The End all, Be all solution to Tom's Knot to MPH conversion.That way it preserves the original Knots value and calculates Dec_speed from it.Code:@Knots = _ssmax + 17 Knots VAR WORD ext Dec_speed = Knots * 9881 Dec_speed = R0 + R2.15 + Knots
Ok, now I really quit.
Darrel
Darrel, Ingvar,
I hope you do not mind dusting off this OLD thread.
Quote by Ingvar... "I bet you know that but some people find it difficult to get their head around this."
Boy was he right...Very interesting but difficult to follow for a newbie.
I am also trying to convert knots and fractional knots to mph.h
Darrel could you please explain/elaborate on the code from your last post...
@Knots = _ssmax + 17
Knots VAR WORD ext
Dec_speed = Knots * 9881
Dec_speed = R0 + R2.15 + Knots
I thought that "@" usually proceeds "one line of assembly code"
As I read through this thread, I was not able to follow with much clarity.
In my gps program I end up with two variables containing integer knots and decimal knots.
If we assume the variables used are knots (whole knots) and knotsten (fractional knots) how would I apply your final code to provide mph.h?
Thanks much
Dwight
I wish one could edit their own posts for a longer time than just 1 hour after posting.
I would like to clarify my question posted above...
Darrel, Ingvar,
I hope you do not mind dusting off this OLD thread.
Quote by Ingvar... "I bet you know that but some people find it difficult to get their head around this."
Boy was he right... Very interesting but difficult to follow for a newbie.
I am also trying to convert knots and fractional knots to mph.h
Darrel could you please explain/elaborate on the code from your last post...
@Knots = _ssmax + 17
Knots VAR WORD ext
Dec_speed = Knots * 9881
Dec_speed = R0 + R2.15 + Knots
1. I thought that "@" usually proceeds "one line of assembly code"?
2. The last two lines of your code equates "Dec_speed" to one thing and then another thing. Doesn't the second line negate the first? Or, is the code shown out of context?
3. What are the items "R0" and "R2.15"? variables? or math function?
As I read through this thread, I was not able to follow with much clarity, sorry, newbie alert!!.
In my gps program I end up with two variables containing integer knots and decimal knots.
If we assume the variables used are knots (whole knots) and knotsten (fractional knots) how would I apply your final code to provide mph.h? (miles per hour & fractional miles per hour)
Thanks much
Dwight
1. I thought that "@" usually proceeds "one line of assembly code"?
It does, and that's what it is.
But he had the value stored in a specific location in an array, so you should just forget that part and make it ...
Knots VAR WORD
R0 and R2 are two of PBP's system variables.
When you do a multiplication (Knots * 9881), R2 has the low word of the result which also gets copied to Dec_speed.
And R0 has the High Word of the result, the same as if you did a Knots ** 9881, without having to do the multiplication a second time.
So yes, the second Dec_speed does "negate" the first one, but the result is still in R0 and R2 so it doesn't matter.
MPH = Knots * 1.150779
And 9881 / 65536 = 0.150772, which is as close as we can get with integer math. That's the decimal part.
The integer part is 1, so just adding Knots to the final result is the same thing.
R2.15 is the highest bit in the low word, so it indicates if the high word should be rounded up or down.
So all together, the multiplication does (Knots * 0.150772), the result is in R0, Round up if R2.15=1, then add Knots (knots * 1).
Clear as mud.
<br>
Last edited by Darrel Taylor; - 9th March 2010 at 02:17.
DT
Thanks Darrel,
sorry it took so long for me to get back to this thread...
here is my code as I have it now (seems to work ok)
I enter the subroutine having parsed the NMEA $GPRMC recieved from the GPS.
VAR "Knots" contains the integar value, VAR "Knotss" contains the decimal or fractional value of speed data recieved from the GPS.
Code:CalcMPH: arraywrite speed,[dec2 knots,dec2 knotss] 'combine knots and knotss into 4 byte array arrayread speed,[dec4 kk] 'now get the 4 digit dec value of the array mph = kk * 9881 mph = R0 + R2.15 + kk 'mph now contains 4 digit value of mph/tenths/hundredths mphh = mph//100 'isolate tenths and hundredths mphh = mphh/10 'eliminate the hundreths and keep tenths mph = mph/100 'now keep integer mph, first two digits of 4 digit value return
I would like to learn more about the use of system variables (R0, R2...) can you point me to where these are documented? I searched the 12f683 document and did not find them.
Thanks for your help.
Dwight
Bookmarks