Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

distance and bearing with PIC

Status
Not open for further replies.

zahidkhan

Member level 2
Joined
Aug 5, 2004
Messages
52
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
428
what is the efficient method of computing distance and bearing between two latitudes and longitudes using PIC 16F877 or 18F452.Using trig function consumes all rom.
any suggestions ?
 

How do a few trig functions consume all of ROM?
How much ROM do you have?
Post your calculations, because it shouldn't be that math intensive.
 

newelltech said:
How do a few trig functions consume all of ROM?
How much ROM do you have?
Post your calculations, because it shouldn't be that math intensive.[/quot]
with 16f877A ROM usage for gps parsing is about 35% but including the following code ,ROM usage jumps to more than 80%. and yet goal is not achieved as calculations are not accurate.

Code:
#include<math.h>
#include<stdio.h>
#define PI 3.141592654
#define EARTH 6371
void dist();
void dist()
{


   float lat1,lat2,dlat,long1,long2,dlong,tmp1,tmp2,tmp3,tmp4,d,bearing;
   lat1=31.000000*PI/180;
   lat2=31.600000*PI/180;
   long1=74.002000*PI/180;
   long2=74.000000*PI/180;
   dlat=lat1-lat2;
   dlong=long1-long2;
   //tmp1=(sin(dlat/2)*sin(dlat/2))+cos(lat1)*cos(lat2)*(sin(dlong/2)*sin(dlong/2));
   //tmp2=2*atan2(sqrt(tmp1),sqrt(1-tmp1));
   //d=EARTH*tmp2;

   //d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(long2-long1))*EARTH;
   //bearing=atan2(sin(dlong).cos(lat2),cos(lat1).sin(lat2)-sin(lat1).cos(lat2).cos(dlong) )
   tmp1=sin(dlong)*cos(lat2);
   tmp2=cos(lat1)*sin(lat2);
   tmp3=sin(lat1)*cos(lat2);
   tmp4=cos(dlong);
   d=atan2(tmp1,tmp2-(tmp3*tmp4));
   tmp1=sin(lat2)-(sin(lat1)*cos(d));
   tmp2=cos(lat1)*sin(d);
   bearing=tmp1/tmp2;
      printf(lcd_putc,"\%4.4f",d);
            printf(lcd_putc,"\n\%4.4f",bearing);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top