Code:
+On page http://techref.massmind.org/techref/piclist/questions.htm you ask how to calculate the great-circle distance with a PIC18F452. (Microchip says the PIC18F452 is "Not Recommended for new design ... Please consider using device PIC18F4520"). The article http://en.wikipedia.org/wiki/Great-circle_distance recommends using this formula for small distances: A = LAT1, B = LONG1 C = LAT2, D = LONG2 // (all in radians; multiply angles in degrees by pi/180 to get angles in radians) // find angular distance S in radians T = ( sin( (C-A)/2 ) )^2 + cos(A)*cos(C)*( sin( (D-B)/2 ) )^2; S = 2*arcsin( sqrt( T ) ); // convert angular distance to distance in meters // (By definition, Earth has a circumference of 40 Megameters) distance = S * (40_000_000 / (2*pi)); So ... What exactly seems to be the problem? If you are writing the program from scratch in assembly language, or C or BASIC compiler doesn't already include a floating-point or fixed-point trig library, you'll need an implementation of "sqrt()", "sin()", "cos()", and "arcsin()" of "enough" accuracy. Oh, and also "*" and "+". (This program, like all PIC programs I've written so far, doesn't need a "/" routine -- "/" is in the source code, but it is pre-computed by my desktop machine at compile time). I suspect all the routines you might need are in the app notes mentioned at http://techref.massmind.org/techref/method/math/fixed.htm . Possibly faster and/or smaller code, written after (?) those app notes were published, are listed at square root in assembly language: /techref/microchip/math/sqrt/ trig functions in assembly language: /techref/microchip/math/index.htm Do you need more accuracy than those implementations give? Is there something we need to fix about the way those functions "fit together" ? What is the size of the resulting program, compared to the 32 KBytes of program space in the PIC18F4520 ?
| file: /techref/member/EDG-TK-FKI/index.htm, 2KB, , updated: 2007/11/8 13:23, local time: 2009/1/8 09:14,
owner: EDG-TK-FKI,
38.103.63.58:LOG IN
|
| ©2009 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? Please DO link to this page! Digg it! <A HREF="http://www.piclist.com/techref/member/EDG-TK-FKI/index.htm"> Member Homepage for EDG-TK-FKI</A> |
| Did you find what you needed? |
|
o List host: MIT, Site host massmind.org, Top posters @20090108 olin piclist, Jinx, eagletalontim, Vitaliy, solarwind, JonnyMac, apptech, Sean Breheny, cdb, M.L., * Page Editors: James Newton, David Cary, and YOU! * Roman Black of Black Robotics donates from sales of Linistep stepper controller kits. * Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters. * Monthly Subscribers: Shultz Electronics, Timothy Weber, on-going support is MOST appreciated! * Contributors: Richard Seriani, Sr. |
|
.