Implementation of GPS Precision Clock Based on PIC18F8520 (Figure)

Publisher:捡漏来了Latest update time:2011-03-12 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

GPS (Global Positioning System) is the most complete satellite navigation system in the world. It not only has real-time, continuous and high-precision three-dimensional positioning capabilities covering the entire world, but also has precise timing functions. Using highly stable and accurate satellite-borne atomic clocks as signal sources for time transmission and comparison has become an important means of obtaining time in many fields. Based on this, this paper uses the precise timing function provided by GPS and adopts single-chip microcomputer technology to realize a GPS clock, and displays the time information through LCD.

System composition and hardware implementation
1 System composition
The GPS clock system is mainly composed of three parts: GPS receiver, single chip microcomputer and LCD display, as shown in Figure 1.

Figure 1 GPS clock system block diagram


GPS receiver
In this system, the GPS receiver uses Garmin's GPS15XL, which is a 12-channel GPS receiver with small size, light weight, low power consumption, short first positioning and recapture time, strong anti-blocking and anti-interference capabilities, extremely stable and reliable performance, simple operation and easy development. It can work in the voltage range of 3.3~5.4V, and this system uses +3.3V power supply; the precision of the precision timing type can reach ±50ns (typical value); it has a serial port, the output is RS232, the input can be RS232 or TTL level with RS232 polarity, the baud rate is optional from 300 to 38 400, the default is 4800, no parity check, 8 data bits, 1 start bit, and 1 stop bit. The data output by GPS15XL is based on the NMEA0183 ASCII code interface protocol of the National Marine Electronics Association of the United States, and can output multiple sentences, including longitude, latitude, speed, azimuth, altitude, world time, ephemeris and other information. It can also output Garmin binary format information. It is very suitable for vehicle navigation, maritime navigation, power system time calibration, etc.


The configuration of GPS15XL can be implemented in the program using the microcontroller through NMEA 0183 statements, or it can be done using the SNSRCFG software. The configuration parameters will be saved in the permanent memory and will automatically take effect the next time the power is turned on. To simplify the design, this article adopts the second method, that is, to initialize the configuration of GPS15XL through the SNSRCFG software.


GPS15XL can output two time signals: one is the absolute time (year, month, day, hour, minute, second) of UTC (Coordinated Universal Time) contained in the serial port output information; the other is the synchronization pulse signal 1PPS with an interval of 1s, and the synchronization error between the pulse leading edge and UTC does not exceed 1μs. This system mainly uses the NMEA 0183 sentence output by the serial port to obtain UTC time information.


NMEA 0183 sentences start with "$" and end with , which are the ASCII characters "Carriage Return" (hexadecimal 0D) and "Line Feed" (hexadecimal 0A). The following uses the GPRMC sentence used in this article as an example to illustrate its format:


$GPRMC, <1>, <2>, <3>, <4>, <5>, <6>, <7>, <8>, <9>, <10>, <11>, <12>*hh $GPRMC
: Sentence start mark (Recommended Minimum Specific GPS/TRANSIT Data recommended positioning information)
<1> UTC time, hhmmss (hour, minute, second) format
<2> Positioning status, A = valid positioning, V = invalid positioning
<9> UTC date, ddmmyy (day, month, year) format
The final check code *hh is used for parity check, which is usually not required, but it is recommended to use the check code when there is strong electromagnetic interference in the surrounding environment. hh represents the bitwise XOR value of all characters between "$" and "*" (excluding these two characters).
Microcontroller PIC18F8520


The system uses the high-performance RISC CPU PIC18F8520 produced by Microchip as the controller. It has 32KB of FLASH program memory, 2KB of SRAM data memory, and 1KB of EEPROM data memory. The operating speed can reach 10MIPS. It can work within the clock frequency range of DC to 40MHz. It has a USART interface, supports RS-485 and RS-232, and can be connected to a GPS module to obtain time information. It supports ICSP online serial programming to facilitate software upgrades and maintenance. It supports ICD, which allows online debugging and shortens the development cycle.


LCD display
The system uses LCD1602 as the display device. LCD1602 liquid crystal display module has the advantages of small size, low power consumption, rich display content, ultra-thin and light, and is widely used in pocket instruments and low-power application systems. It can display two lines, 16 characters per line, powered by a single +5V power supply, simple peripheral circuit configuration, low price, and high cost performance.


2 Hardware Circuit
The hardware circuit of the system is shown in Figure 2 and Figure 3.

Figure 2 MCU peripheral circuit connection

Figure 3 Connection between MCU and GPS module


There are two voltages on the circuit board: 3.3V and 5V. The LCD is powered by 5V, while the microcontroller and MAX3232 work at 3.3V. The external power supply is 5V, which is converted to 3.3V by AS2830 to power the microcontroller and MAX3232. As can be seen from Figure 2, the power pin of the microcontroller is not directly connected to 3.3V, but can be connected to 3.3V or VDD through the J2 and J3 jumpers. This is because the microcontroller is powered by MCD2 when the PIC16-MCD2 programmer is used for online programming through the ICSP interface. At this time, the power pin of the microcontroller needs to be connected to VDD (the output voltage VDD of MCD2 is 5V); while during normal operation, the microcontroller is powered by the circuit board, and the J2 and J3 jumpers are connected to 3.3V. The microcontroller works at 3.3V, which can reduce power consumption.


PIC18F8520 has both analog power and analog ground pins as well as digital power and digital ground pins. In circuit design, the analog power and digital power are separated, and the analog ground and digital ground are separated. The analog power and digital power are connected through magnetic beads, and the analog ground and digital ground are connected at a single point through a 0Ω resistor to avoid interference between analog signals and digital signals and improve system reliability.

Software Implementation
The software consists of a main program and an interrupt subroutine, and is implemented in C language using the MPLAB C18 compiler in the MPLAB IDE v8.53 environment.


The system is initialized, data is processed, and LCD is displayed in the main program. The reception of GPS data is realized through serial port interruption. Every time a complete NMEA sentence is received, a flag is set. The main program extracts the UTC time and converts it into Beijing time by querying the flag, and then displays it on the LCD. Since the complex data processing is placed in the main program, the interrupt program can be kept as short as possible. When other interrupts occur, the microcontroller can respond in time, improving the real-time performance of the system. The flow chart is shown in Figure 4.

Figure 4 Flowchart


Since the time output by the GPS module is UTC time, it needs to be converted into local time (Beijing time) according to custom. This work is completed in the main program. According to local time = UTC time + time zone value, Beijing is located in the 8th time zone, and the time zone value is +8, so Beijing time = UTC time +8. In the conversion process, the UTC time of 16:00:00-23:59:59 must be processed accordingly. After +8, it is determined whether the hour is greater than 24. If it is greater, 24 is subtracted, and the date is +1. In addition, it also involves the processing of leap years, long months, and short months.


In the interrupt service program flow chart, when the serial port receives data, it judges the prefix and only judges the character "$". This is because the GPS15XL has been set to only output one NMEA sentence, GPRMC, through the SNSRCFG software.

Debug and run
First, initialize GPS15XL. Connect GPS15XL to PC through serial port, power on GPS15XL, set initialization information with software SNSRCFG, set baud rate to 9600, output only one GPRMC statement (one GPRMC statement is enough to get UTC date and time), write this information into permanent memory in OEM board, it will automatically take effect the next time power is on.


Then, use the PIC16-MCD2 programmer to write the compiled program into the microcontroller through the ICSP interface reserved on the circuit board. When programming, do not power the circuit board. The microcontroller is powered by MCD2. Pay attention to the setting of the jumper on the circuit board.


Finally, connect GPS15XL to the circuit board. Power on the circuit board and GPS15XL, and the timing receiving system enters normal working state. The microcontroller receives the satellite data of GPS15XL through RS-232 serial mode, obtains accurate time information, and converts it into Beijing time, which is displayed on the LCD.
Note: When using, the GPS timing antenna must be placed in an open outdoor area, otherwise it will not receive satellite signals and cannot obtain UTC time information.

Conclusion
This article uses PIC18F8520 to extract GPS high-precision clock and display it on LCD. The clock system implemented is part of the power distribution line fault remote monitoring and positioning system project. After testing, the design runs stably and can provide accurate time information for the entire system, with high reliability, accuracy and practicality. In addition, the core of the GPS clock can also be embedded in other systems, and its time can be used as the system time, such as: financial/securities real-time settlement, civil aviation/railway/traffic dispatching systems, various computer network systems, real-time communication network systems, sports lottery and welfare lottery and other real-time sales systems, etc., which are widely used.

开始插入图片 jsp20110102165208.jpg jsp20110102165255.jpg jsp20110102165426.jpg jsp20110102165523.jpg jsp20110102165534.jpg 结束插入图片
Reference address:Implementation of GPS Precision Clock Based on PIC18F8520 (Figure)

Previous article:Bidirectional electronic car anti-theft system based on LPC930
Next article:MCU power saving mode helps reduce overall power consumption

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号