Wednesday, 14 August 2013

GPS Module interfacing with PIC24, DsPIC33, DsPIC30, Holux M-89. (Code + Simulation)

This post will provide a working example of how to interface GPS receiver with 16Bit PIC Microcontrollers. I am using Taiwan made Holux M-89 chipset module. I just used its three wires Vcc, GND and TXD. Vcc and GND is connected to 5.0V and ground points respectively. While TXD is serially IN using USB-serial module. As I mentioned in my previous post that Proteus have a feature to interface Physical port with Simulation. So I am using this feature named (COMPIM). And hence rest of the circuit is based on Proteus simulation. I practically used this receiver when I was I university.

You may download code and Proteus Simulation from the download section at the bottom of this post. I am using MPLAB X IDE, C30 Compiler and Proteus Simulation on v8.0. This code is written in C Language and will work on PIC24, DsPIC33 and DsPIC30 (16bit microcontroller) by slightly changing the code.

Before proceeding further I supposed that you know following. If not then please go through following pages first.

·         How to use UART module for 16Bit PIC microcontrollers (Click here).
·         How to interface LCD with 16Bit PIC microcontrollers (Click here).

GPS modules transmits the string containing different commands these commands are known as NMEA commands (developed by National Marine Electronics Association). I supposed that you know basics of these commands. Now in this post I only decode one command that gives me basic information such as Universal Time Constant (UTC), GPS Coordinates both Latitude and Longitude, GPS fix or not. And No. of satellites being tracked. This command starts with $GPGGA. Please remember that the signal coming from satellites has power of few attoWatt. So this signal is very weak. You need to experiment this outside LOS is best for tracking more satellites. Location is fixed with more than three satellites when being tracked. I tracked down 11 satellites when making code and simulation of this post.

Experimental Setup:

Holux M-89 module which is powered with 5.0V externally. And a USB-serial Port is used to link serial data with Proteus simulation by using COMPIM (Physical serial port linking feature) in Proteus.

Proteus Simulation:
In the following figure 1. I have circuit for Simulation. As you have seen that LCD is connected to PortB. And a COMPIM is connected to Uart1 of PIC24. Now this COMPIM is responsible for communicating serially over the physical Serial COM port. Means you can send and receive data externally through this Port quite amazing. Now this COMPIM is connected with TXD pin and GND of Holux M-89 module. I am going with default GPS module setting as with 4800bps; string continuously sending after every one second. This module when fix the location the LED on it flashes with 2Hz frequency.

Figure 1. Proteus Schematic.

In the following figure 2. Animation will demonstrate the LCD updates and data string that I am receiving form the GPS receiver. As I mentioned above GPS module sends this string after every 1 second. This string is shown in virtual terminal. And as I Mentioned above that I am only decoding one command ie $GPGGA. So in first line I have UTC time then I have Latitude data and a longitude data and then fix value 0 for invalid and 1 for fixed location and at the end I have no. of satellites being tracked down by GPS receiver.

Figure 2. GPS Data on LCD + NMEA string.

            In the following figure 3. It is shown very clearly that I will decode only this command from so many of them. I am receiving the string in DockLight.

Figure 3. NMEA string after every 1 second.


In the following figure 4. This is the main function in which I first Initialize the LCD and then opened the Uart module as 4800bps baudrate. Then I just displayed some strings on LCD first than a loop calling a function named GPS_GetDataAndDisplayIt().

Figure 4. GPS main function.

In the following figure 5. We have a function named GPS_GetDataAndDisplayIt() which is responsible for getting data and decoding the command and displaying It on LCD. The command has following format.


Where as:

Sentence Identifier
Global Positioning System Fix Data
17:08:34 Z
4124.8963, N
41d 24.8963' N or 41d 24' 54" N
08151.6838, W
81d 51.6838' W or 81d 51' 41" W
Fix Quality:
- 0 = Invalid
- 1 = GPS fix
- 2 = DGPS fix
Data is from a GPS fix
Number of Satellites
5 Satellites are in view
Horizontal Dilution of Precision (HDOP)
Relative accuracy of horizontal position
280.2, M
280.2 meters above mean sea level
Height of geoid above WGS84 ellipsoid
-34.0, M
-34.0 meters
Time since last DGPS update
No last update
DGPS reference station id
No station id
Used by program to check for transmission errors

For more information you may visit the NMEA commands. In this function I called function ReadCharFromUart1() for reading character from uart1 then going through if statements for searching GGA starting sequence of command to be decoded. Then with the ‘,’ I got UTC time first which is displayed in LCD. Then with the comma separation we have Latitude it is also displayed as you may read the comments in code for step by step decoding. After this we have longitude information which is also displayed on LCD. Then we have fix and No. of satellites data. After this I have limitation of space on LCD so rest of them will be ignored. All of these functions that I called in this function are all mentioned with details in their respective posts.

Figure 5. Get data and Displaying GPS function.

For having a clear picture of experimental setup please watch this video.

For another new GPS module or for practical example click here.


You can download Code (MPLAB X and C30 compiler) and Proteus (v8) Simulation. Click here

Reading Suggestions:
·         Over Voltage Protection
·         AC Voltmeter RMS + Peak voltage

For all topics Click here:

That’s all for this post hope you will learn please comment if you have any questions for upcoming posts please subscribe or follow.

All the text and graphics contained on this blog belongs to owner except otherwise mentioned. Other parties' trademarks and service marks that may be referred to herein are the property of their respective owners. Reproducing or distributing text and graphics on your own site is strictly not allowed without proper linking to original content and before publishing that you should ask for permission. 
© Copyright 2013 IbrahimLabs. All rights reserved.

Getting started with Arduino coding. (A beginner’s quick guide)

Welcome to my first Arduino coding guide. This would take you to kickstart with Arduino boards. I would go through following things real...