GPS NMEA antenna aiming tracker.

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi jjw,
I have just tried your arctan function as part of a Oshonsoft Basic program I have written for Camerart, it looks good, returns degree values within +/-0.5 degrees.

Thanks for that Function.;)

Eric
The PICs arrived, BUT! they are the tiny surface mount ones:mad: I'll order some more with legs I can see:)

Camerart.
 

THE_RB

Joined Feb 11, 2008
5,438
The_RB,

The NMEA sentences that look most likely, are GGA The form they arrive at the PIC is: $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47

There would be one of these sentences for the tracker, which (at the moment) is fixed and typed in via a 4X4 keyboard. The second one will be received using a receiver.
...
OK, that's all standard.

You need to get a crude grid Xdist,Ydist between the two coord sets. This is the basic process in simple terms;

1. Calc distance as degrees lat by lat2-lat1
2. Calc distance as degrees long by long2-long1
3. convert lat dist to a proper distance; from degrees to metres
4. convert long dist to a proper distance; from degrees to metres

In step 4, the amount of metres per degree will change depending how far north or south you are. So for step 3 you can use a fixed scaling factor based on the planet circumference, but in step 4 you need a specific scaling factor to suit your base station location. I hope that makes sense.
 

THE_RB

Joined Feb 11, 2008
5,438
Rich (BB code):
Function arctan(arg As Single) As Single
  If arg <= 1 Then
    arctan = arg / (0.281125 * arg * arg + 1) * 57.296
  Else
    arctan = (1.5708 - arg / (arg * arg + 0.28125)) * 57.296
  Endif
End Function
This takes about 0.5ms with 16F877 and 20MHz oscillator.
I believe that handling all quadrants will be clearly less than 1ms.
The error is less than 0.26 degrees.
I would point out that the other suggestion of using a lookup table (say 128 entries over 45 degrees) would be many times faster, accuracy within about +/-0.2 degree, and can be done with unsigned int or unsigned long so as not require the floating point library which uses a ton of ROM.

And with some simple interpolation between two table entries by averaging, could be maybe ten times more accurate, and still not require floating point.
:)
 

jjw

Joined Dec 24, 2013
823
Yes, if the speed and accuracy is needed..
I have estimated that all this lat/long stuff will take less than 20ms.
with floating point.
With LCD-library and arctan the ROM is now about 1.7K.
He has 16K ROM and can double it and also the CPU speed can be doubled.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,730
OK, that's all standard.

You need to get a crude grid Xdist,Ydist between the two coord sets. This is the basic process in simple terms;

1. Calc distance as degrees lat by lat2-lat1
2. Calc distance as degrees long by long2-long1
3. convert lat dist to a proper distance; from degrees to metres
4. convert long dist to a proper distance; from degrees to metres

In step 4, the amount of metres per degree will change depending how far north or south you are. So for step 3 you can use a fixed scaling factor based on the planet circumference, but in step 4 you need a specific scaling factor to suit your base station location. I hope that makes sense.
The_RB,
I almost see it! It will be come clearer as time and use go on, thanks.
Camerart.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
I would point out that the other suggestion of using a lookup table (say 128 entries over 45 degrees) would be many times faster, accuracy within about +/-0.2 degree, and can be done with unsigned int or unsigned long so as not require the floating point library which uses a ton of ROM.

And with some simple interpolation between two table entries by averaging, could be maybe ten times more accurate, and still not require floating point.
:)
Th_RB,

I think the PIC was chosen because it can 'do' floating point especially for this, but as before, it's a bit beyond me!

Camerart.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Yes, if the speed and accuracy is needed..
I have estimated that all this lat/long stuff will take less than 20ms.
with floating point.
With LCD-library and arctan the ROM is now about 1.7K.
He has 16K ROM and can double it and also the CPU speed can be doubled.
JJW,

From memory, and as I can only work with basic (Oshonsoft) I don't think that arctan is included.

Camerart.
 

ericgibbs

Joined Jan 29, 2010
18,865
JJW,

From memory, and as I can only work with basic (Oshonsoft) I don't think that arctan is included.

Camerart.
hi C,
I have thoroughly tested 'jjw's ArcTan Function in a Demo GPS Oshonsoft program, its much better than +/-0.5 degree, its in the order of +/-0.25 degree, from 0 thru 90 degrees.

I will use that Arctan Function in future Apps.:)

Eric
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
I have thoroughly tested 'jjw's ArcTan Function in a Demo GPS Oshonsoft program, its much better than +/-0.5 degree, its in the order of +/-0.25 degree, from 0 thru 90 degrees.

I will use that Arctan Function in future Apps.:)

Eric
JJW and Eric,

Well done, it seems good.

Just received the PICs, and making up a circuit, with LCD and Keyboard.

Camerart.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
You don't need to toggle it twice..

[CODEoop:

Toggle RA4
WaitMs 1000
Toggle RA4
WaitMs 1000
Goto loop][/CODE]
Hi E,
The LCD and Keypad are connected, but not set-up.

I read that to start the XTL, I need to change from the 18pF ones to 15pF(The XTLs are 18pF) , and configure it to HS. With 18pF and set to XT, it will fire sometimes at the correct rate. Sometimes, the timing is incorrect, and I read that there is an internal timer that switches in if the XTL doesn't start. this sound a bit dangerous, and I would prefer it not to do that, so I can tell the XTL is working or not.

Even though I'm sure many previous programs are incompatible with the 18 PIC, I can only copy and paste, then try to solve each compile problem. Here is the latest effort!

Cheers, Camerart.
 

Attachments

Last edited:

ericgibbs

Joined Jan 29, 2010
18,865
hi,
I have used 15pF, 18pF and 22pF caps with a 20MHZ xtal I have never had a start up problem.
Config for HS and you will not have a problem.
E
 

ericgibbs

Joined Jan 29, 2010
18,865
Even though I'm sure many previous programs are incompatible with the 18 PIC, I can only copy and paste, then try to solve each compile problem. Here is the latest effort!
hi C,
Make these changes to enable the compile.
E

Rich (BB code):
'GIEH INTCON = 1
'INTCON.GIE = 7
INTCON.PEIE = 1
PIE1.RCIE = 1
PIR1.RCIF = 0
Hseropen 9600

Lcdinit
loop:
Toggle RA4
WaitMs 1000 ' 1 sec delay

Goto loop

End                                               

On High Interrupt  '>>>>>>>>.error 'add High to clear the error
'''The 18F Pics have different priority levels.

Save System
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
Make these changes to enable the compile.
E

Rich (BB code):
'GIEH INTCON = 1
'INTCON.GIE = 7
INTCON.PEIE = 1
PIE1.RCIE = 1
PIR1.RCIF = 0
Hseropen 9600

Lcdinit
loop:
Toggle RA4
WaitMs 1000 ' 1 sec delay

Goto loop

End                                               

On High Interrupt  '>>>>>>>>.error 'add High to clear the error
'''The 18F Pics have different priority levels.

Save System
Hi E,

Thanks, will do.

C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
The program is now compiling.

1/ Can't get the XTL to 'sing' I've tried changing the XTL to 4MHz, and setting up a test bed with only XTL and led connected. I've tried different crystals, different config settings, changed the PIC and the capacitors??? A friend has given me a 20MHz XTL, that he tested first, didn't work. I'm out of ideas. I have lots of other circuits with XTLs working ok!

Can someone remind me how I entered the NMEA sentence, please. Is it into the UART or serial module? The serial module always shuts down the simulator, the UART reports 'UART receiver is not enabled'.

Cheers, Camerart.
 
Last edited:

jjw

Joined Dec 24, 2013
823
The program is now compiling.

1/ Can't get the XTL to 'sing' I've tried changing the XTL to 4MHz, and setting up a test bed with only XTL and led connected. I've tried different crystals, different config settings, changed the PIC and the capacitors??? A friend has given me a 20MHz XTL, that he tested first, didn't work. I'm out of ideas. I have lots of other circuits with XTLs working ok!

...

Cheers, Camerart.
How is the oscillator configured?
Show us the osccon register.
It should be HS-crystal and PLL not enabled.
You might need a series resistor between crystal and osc2-pin, see the docs.
 
Top