I used the Cordic to get the heading and distance. To get this to work, you need to calculate the difference between the two waypoints
lathome_hi = the 37 part of the 37.12345 degrees
lathome_low = the 0.1234 (as a whole number 1234) part of 37.1234 degrees
This allows you to have a 3 degree difference in distance, or about 180 miles, although you could add some math division to allow further distances.
The above code was for the cordic made for a Pic16f device. The PIC18 cordic allows positive and negative numbers, so it figures the quadrant for you.Code:GPSMath: latlow_dif = lathome_low - latdest_low 'find difference in present loc and destination lathi_dif = lathome_hi - latdest_hi lathi_dif = lathi_dif * 10000 'multiply integer degree difference by 10000 lat_dif = lathi_dif + latlow_dif 'so we can add decimal degrees to 16 bit number lonlow_dif = lonhome_low - londest_low lonhi_dif = lonhome_hi - londest_hi lonhi_dif = lonhi_dif * 10000 lon_dif = lonhi_dif + lonlow_dif if west = 0 then toggle lon_dif.15 'inverse negative bit for east europe if north = 0 then toggle lat_dif.15 'inverse negative bit for southern hemisphere quadrant = 1 'if lat_dif.15 = 1 and lon_dif.15 = 0 then quadrant =1 if lat_dif.15 = 0 and lon_dif.15 = 0 then quadrant =2 'see which results are negative if lat_dif.15 = 0 and lon_dif.15 = 1 then quadrant =3 if lat_dif.15 = 1 and lon_dif.15 = 1 then quadrant =4 if north = 0 then toggle lat_dif.15 'get rid of falsing for S hem so we can do math gosub do_cordic 'perform cos and atan functions to determine bearing and distance to waypoint 'adds angle of triange to quadrant angle. (Yeah, my quads don't match what you learned in school) if quadrant = 1 then b2dest = 900 - b2dest if quadrant = 2 then b2dest = 900 + b2dest if quadrant = 3 then b2dest = 2700 - b2dest if quadrant = 4 then b2dest = 2700 + b2dest ' my quadrants ' N ' | ' 4 | 1 'W______|________E ' | ' 3 | 2 ' | ' S
See the cordic and the last post here:
http://www.picbasic.co.uk/forum/show...ghlight=cordic
Bookmarks