|
|
View previous topic :: View next topic |
Author |
Message |
rwskinner
Joined: 08 Dec 2006 Posts: 125 Location: Texas
|
Please check my Math |
Posted: Tue Oct 19, 2010 9:56 am |
|
|
I'm not much of a C programmer so I may be doing something incorrectly. I'm taking an char buffer (Altitude) and converting it to a Int16.
TmpBuffer is the Ascii Altitiude = "50.4" ending with a null.
fAlt is a float
GPS_Rec.Alt is int16
Code: |
fALT = atof(TmpBuffer); //Read buffer
if (Meters == 1)
fALT *= 3.28f;
GPS_Rec.ALT = (int16)fALT;
|
It appears to work but I have users reporting issues when I get over 1000 meters, the altitude only reports a few hundred feet.
Honestly, I haven't checked to see if it's a GPS issue, parsing issue, or math issue. I just wanted to check and make sure I was doing the calculations right to begin with.
Richard |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 19, 2010 11:39 am |
|
|
Make a test program and put in some number in the range that you want
to test. Run it in MPLAB simulator with printf going to the Output Window,
by selecting UART1 in the Debugger setup menu. The program below
gives this output with vs. 4.112:
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <stdlib.h>
//==========================================
void main()
{
float fALT;
char TmpBuffer[10] = {"1005.4"};
char Meters = 1;
struct {
int16 ALT;
}GPS_Rec;
fALT = atof(TmpBuffer);
if(Meters == 1)
fALT *= 3.28f;
GPS_Rec.ALT = (int16)fALT;
printf("%ld \r", GPS_Rec.ALT);
while(1);
} |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|