Binary clock design based on FPGA
Source: InternetPublisher:sigma Keywords: fpga gps binary Updated: 2024/08/02
This solution is an FPGA-based binary clock that uses GPS as a time reference.
Measuring time accurately throughout history has presented many challenges. Only John Harrison designed a reliable clock that could keep reference time at the Greenwich meridian, enabling accurate navigation and charting of unexplored seas and lands in the 1700s.
Today, we live in an increasingly connected world where an accurate time reference is just as important. Without a common time reference, cell towers cannot easily synchronize codes and switch calls as we pass from one cell tower to another. Similarly, time-stamping business and banking transactions without a common time reference can also be challenging and become an arbitration nightmare for the order of events.
Of course, the most accurate clocks available are atomic clocks, but unfortunately, they are also the most expensive, which limits the ability of institutions to use them.
However, there is one time reference that is accurate to +/-10ns and can be extracted from the air for free, and that is the time reference provided by Global Navigation Satellite Systems. The most famous of these is, of course, the Global Positioning System (GPS), although there are several, such as GLONASS and Galileo.
All of these satellites contain atomic clocks, which allow us to achieve a highly accurate time reference across the system.
In this project, we will use the GPS Receiver Pmod to receive the GPS signal and process it so that we can display the time on a binary clock.
For this we will be using Vivado and the SDK, and this will be our last project using the SDK since Vitis is available.
Vivado Design
To start designing, the first thing we need to do is install the Digilent library that will allow us to configure the PmodGPS/
This library supports the use of Pmods in hardware and software development in Vivado and SDK.
To do this, in our Vivado project select, Project Options and choose IP and navigate to the new IP repository.
We also need something to drive the NeoPixel display, also for the previous project I pushed a neopixelIP module to my github here
We can then create a Vivado project that will utilize these IP blocks to communicate with the PmodGPS.
In a new Vivado project, we need the following IP
ZynqPS - Minimized Configuration
PmodGPS - will communicate with the PmodGPS under software control
AXIBRAM Controller - enables ZynqPS to read and write BRAM in the PL
BRAM - Dual-port BRAM containing Neo pixel values
NeoPixelIP - drives NeoPixel drive signals
Processor reset block - provides a reset for the system
AXI Interconnect - enables multiple AXI slave devices to connect to a single PS master
Need to configure PS to provide
Structure clock at 50MHz
20MHz fabric clock - used to clock the NeoPixel IP
GPMasterAXI Interface
Structural breaks enabled
This should produce a block diagram like the following
Before generating and exporting the bitstream, we also need to set the IO location of the pins.
I will be using Pmod2 on the Minized for the PmodGPS and Pmod1 on the NeoPixel driver We do this in the XDC file as shown below.
This way we can implement the design and export the hardware design to the SDK to generate the required software.
Software Design
In the SDK, we need to create a new application and BSP based on the hardware design we just exported from Vivado.
Once it is created in the BSP, we should see the Pmod driver in the BSPMSS file.
For changes, our software application will be interrupt driven.
The architecture that our software solution will follow is
Configuring and Initializing PmodGPS
Configure and initialize the BRAM controller
Configure the interrupt controller and enable interrupts from the PmodGPSUART.
Waiting for PmodGPS lock signal
Reading position and time data from PmodGPS
Convert time to binary elements for display
Update NeoPixel Display
To use PmodGPS and AXIBRAM controller, we can use the API provided in PmodGPS.h and xbram.h
Although you can use the API provided by xscugic.h to configure the interrupt controller
intSetupInterruptSystem(PmodGPS*InstancePtr, u32interruptDeviceID, u32interruptID) {
intResult;
u16Options;
INTC*IntcInstancePtr=&intc;
XScuGic_Config*IntcConfig;
IntcConfig=XScuGic_LookupConfig(interruptDeviceID);
if (NULL == IntcConfig) {
returnXST_FAILURE;
}
Result=XScuGic_CfgInitialize(IntcInstancePtr,IntcConfig,
IntcConfig-》CpuBaseAddress);
if (Result!=XST_SUCCESS){
returnXST_FAILURE;
}
XScuGic_SetPriorityTriggerType(IntcInstancePtr, interruptID, 0xA0, 0x3);
Result=XScuGic_Connect(IntcInstancePtr, interruptID,
(Xil_ExceptionHandler)XUartNs550_InterruptHandler,
&InstancePtr->GPSUart);
if (Result!=XST_SUCCESS){
returnResult;
}
XScuGic_Enable(IntcInstancePtr, interruptID);
XUartNs550_SetHandler(&InstancePtr-》GPSUart, (void*)GPS_intHandler,
InstancePtr);
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)INTC_HANDLER,IntcInstancePtr);
Xil_ExceptionEnable();
Options=XUN_OPTION_DATA_INTR|XUN_OPTION_FIFOS_ENABLE;
XUartNs550_SetOptions(&InstancePtr-》GPSUart, Options);
returnXST_SUCCESS;
}
The first thing I wanted to do was to make sure the PmodGPS was able to lock onto a signal and provide me with an accurate location.
When this code is executed on the Minized with the Pmod2 connected to the PmodGPS we see the following output on the terminal giving me a location.
To check that this was the correct location, entering it into Google Maps provided the location of my office with reasonable accuracy.
As it was able to lock onto a GPS signal, the code was updated to provide the time. This time is called Coordinated Universal Time or UTC for short, which is referenced to Greenwich Mean Time, which also happens to be the same as the UK time at the moment.
The time is output from the PmodGPS as a floating point number, as shown in the terminal output below.
To be able to create a binary clock we need to break it down into the following
Dozens of hours
Hour unit
Ten points
Minutes
10 seconds
Seconds
This will allow us to draw time using the NeoPixelArray.
The binary clock shows the time as follows
On the NeoPixel I will be using a 6x4 LED array in the middle of the array.
But first we need to convert the UTC time to the required format, we can use the following method to split the time (e.g. 153400) into the correct groupings of hours, minutes and seconds.
We can then split each element into tens and units as needed for binary time display.
Once we have separated the digits we need to convert the values to binary, for this I have created a simple subroutine
This function returns a four-bit vector representing the binary number, and for this example we don't need more than 4 bits.
Since the NeoPixel array is treated as one long 64NeoPixel element, for each count position we only need to change the LED offset position.
Depending on whether the bit is set or not, the color of the LED will change, green for set bits and blue otherwise.
I used the following code to determine the value to set the LED to since the binary conversion function returns a pointer.
When I put all of this together, the binary clock runs as expected once the PmodGPS locks onto a signal.
confirm
For many people, reading a binary clock can be different than a traditional clock. So by looking at the NeoPixel display and the UTC time output through the terminal, we can verify that the display is correct.
The decoded times appear to be correct.
in conclusion
This project demonstrates how we can easily and quickly use GPS for systems other than navigation and create an interesting example that can be used as a display etc.
- Production of two-color music lantern
- UCC587x-Q1 power-on false alarm mechanism and initialization precautions
- XDH-2 electrocardiograph circuit
- Enhanced password lock circuit using AE1169
- Wired centralized control circuit that directly starts the water pump motor
- Box type electronic mousetrap circuit
- Toy police car circuit
- Analog counter circuit circuit diagram
- Poultry warming temperature control circuit
- Automobile fuel tank level measurement circuit
- Design based on FPGA configuration circuit
- GPS RF front-end circuit diagram composed of MX2740
- Simple long delay timer circuit
- Refrigerator door opening alarm circuit
- BCD-Binary number conversion circuit diagram
- Binary number multiplication circuit
- 8-bit two's complement addition and subtraction circuit using full adder
- Binary input decimal display circuit
- Binary digital to analog converter circuit diagram
- Alarm type binary password control lock circuit