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 14:23, local time: 2024/8/14 20:40,
owner: EDG-TK-FKI,
18.191.240.50:LOG IN
|
©2024 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? <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? From: "http://piclist.com/member/EDG-TK-FKI/index.htm" |