It is currently 15 Oct 2018 20:04

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 20 Sep 2016 10:24 
Offline

Joined: 20 Jan 2010 20:25
Posts: 14
Location: Faroe Islands
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


Top
 Profile  
 
PostPosted: 20 Sep 2016 12:59 
Offline

Joined: 18 Feb 2006 13:17
Posts: 4978
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).

_________________
Replacement libraries for mP PRO and PIC18 processors, mP PRO tips & trics


Top
 Profile  
 
PostPosted: 06 Jun 2017 00:47 
Offline

Joined: 20 Jan 2010 20:25
Posts: 14
Location: Faroe Islands
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.


Top
 Profile  
 
PostPosted: 06 Jun 2017 01:58 
Offline

Joined: 18 Feb 2006 13:17
Posts: 4978
It will be hard to help you without seeing some code. PIC16F887's USART is certainly able to read at 4800 baud.

_________________
Replacement libraries for mP PRO and PIC18 processors, mP PRO tips & trics


Top
 Profile  
 
PostPosted: 15 Jun 2017 23:41 
Offline

Joined: 20 Jan 2010 20:25
Posts: 14
Location: Faroe Islands
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 839 times ]
DSC_0172.JPG
DSC_0172.JPG [ 4.26 MiB | Viewed 839 times ]
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


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 post attachments in this forum

Search for:
Jump to: