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
$GPRMC, <1>, <2>, <3>, <4>, <5>, <6>, <7>, <8>, <9>, <10>, <11>, <12>*hh
: 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.
Previous article:Bidirectional electronic car anti-theft system based on LPC930
Next article:MCU power saving mode helps reduce overall power consumption
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- mPower1203 programmable power supply also supports third-party applications to obtain the current of the device under test in real time
- MSP430F149 Learning Road - Capture/Compare Mode
- [Flower carving hands-on] Interesting and fun music visualization series of small projects (29) - 16X16 hard screen light
- The role of reference voltage in AD conversion
- DIY a USB hub shell
- Design experience exchange: Matters needing attention in AD sampling
- Analysis of the Causes of Operational Amplifier Oscillation and Self-excitation
- (Bonus 14) GD32L233 Review - Driving Segment Code LCD
- China's chip self-sufficiency rate was 30% last year, and the goal is to reach 70% by 2025 (attached with representative companies in 70 sub-sectors of domestic chips)
- 【New Year's Taste Competition】New Year's Eve Reunion Dinner and My Wedding