Reading NMEA 0183 and converting it to sine/cosine

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
rayann
Posts: 14
Joined: 20 Jan 2010 20:25
Location: Faroe Islands

Reading NMEA 0183 and converting it to sine/cosine

#1 Post by rayann » 20 Sep 2016 10:24

I have an Autopilot that requires sine cosine input from the compass. My old compass is gone, and they do not make it anymore. I have a compass that gives NMEA 0183 out. Now I want to build a construction that gives sine/cosine out.
the idea is that there is a reference point of 2.5 volts. Then there is an output voltage for East-West where East = 0 volts, and West = 5 volts. And there is a second output for North South. where South is 0 Volts and North is 5 volts.

What I need is to read the NMEA 0183 protocol for to get the heading, and then program 2 analog outputs with the voltage of the sine/cosine function.

Has somebody tried to build/program something like this?

Thanks for any clues you may have

Ray

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Reading NMEA 0183 and converting it to sine/cosine

#2 Post by janni » 20 Sep 2016 12:59

You could try the NMEA library from Libstock. Not sure if it works with enhanced PIC family, but there are processors with multiple 16-bit PWM (like 16F1574/8) that could give you an easy way to make analog outputs (with single op-amp analog filters).

rayann
Posts: 14
Joined: 20 Jan 2010 20:25
Location: Faroe Islands

Re: Reading NMEA 0183 and converting it to sine/cosine

#3 Post by rayann » 06 Jun 2017 00:47

Hey again
thanks for the clues. I have used an PIC16F887 with 2 PWM's one for sine and one for cosine, it works fine with a test input.
But I cant get the NMEA library to work.
I have tried to set up the UART to read the input. I can read the bytes, but what I get makes no sense, and does not come anywhere near the NMEA protocol.
I think Uart should be able to read 4800 baud serial communication, but it seems not to work the way I want it.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Reading NMEA 0183 and converting it to sine/cosine

#4 Post by janni » 06 Jun 2017 01:58

It will be hard to help you without seeing some code. PIC16F887's USART is certainly able to read at 4800 baud.

rayann
Posts: 14
Joined: 20 Jan 2010 20:25
Location: Faroe Islands

Re: Reading NMEA 0183 and converting it to sine/cosine

#5 Post by rayann » 15 Jun 2017 23:41

I have tried different things, but none of it seems to work.
Could there be something with that some bits should be subtracted? I have not been able to see any pattern by comparing what my PC reads, and what the lcd display shows.

I would be thankful for any clues to try out.


Here is the code I have come down to:
-----------------
program Auto_1;

{ Declarations section }
var LCD_RS : sbit at RB4_bit;
var LCD_EN : sbit at RB5_bit;
var LCD_D4 : sbit at RB0_bit;
var LCD_D5 : sbit at RB1_bit;
var LCD_D6 : sbit at RB2_bit;
var LCD_D7 : sbit at RB3_bit;
var LCD_RS_Direction : sbit at TRISB4_bit;
var LCD_EN_Direction : sbit at TRISB5_bit;
var LCD_D4_Direction : sbit at TRISB0_bit;
var LCD_D5_Direction : sbit at TRISB1_bit;
var LCD_D6_Direction : sbit at TRISB2_bit;
var LCD_D7_Direction : sbit at TRISB3_bit;
// End LCD modul setup

var count:byte;
var receive: byte;
var rc :array[50] of byte;

begin
ANSEL := 0; // Configure AN pins as digital I/O
ANSELH := 0;
count :=0;
TRISB := 0x00; // Set PORTB as output
PORTB := 0;
trisC := 0xFF;
portC :=0;

Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);

UART1_Init(4800);
Delay_ms(100);
Count := 0;
while TRUE do
begin
LCD_cmd(_lcd_clear);
count := 0;
while count<49 do
begin
if (UART1_Data_Ready() = 1) then // if data is received
begin
count := count +1;
receive := UART1_Read();
rc[count] := receive;
end;
end;
for count :=0 to 15 do //writing display
begin
LCD_chr(1,count,rc[count]);
end;

for count := 15 to 30 do //writing display
begin
lcd_chr(2,count-14,rc[count]);
end;
for count := 30 to 45 do //writing display
begin
lcd_chr(3,count-29,rc[count]);
end;
delay_ms(3000); // for reading display
end;
end.


I add a picture of how my LCD display looks and a picture of how my PC is reading the message from the fluxgate.
Attachments
DSC_0171.JPG
DSC_0171.JPG (4.04 MiB) Viewed 2717 times
DSC_0172.JPG
DSC_0172.JPG (4.26 MiB) Viewed 2717 times

Post Reply

Return to “mikroPascal PRO for PIC General”