Analyzing High-Speed Serial Data Streams in FPGA
FPGA design is a critical branch of IC design, playing a major role in modern hardware architecture. Handling high-speed serial data streams requires a structured pipeline to ensure data integrity and timing accuracy. This article outlines a practical method for processing these streams.
🏗️ Core Principles of Serial Data Processing #
Processing high-speed serial data involves four primary stages:
- Over-sampling: Sampling the serial bitstream at a high-frequency clock, typically 4x the nominal baud rate or higher, depending on the FPGA’s clock capabilities.
- Data Correction: Adjusting the over-sampled data to account for frequency offsets between the transmitter and receiver. This ensures the receiver can correctly parse data at the nominal clock rate.
- Edge Alignment: Processing the signal based on specific encoding schemes, such as NRZI or Manchester encoding. Each encoding requires a specific logic path.
- Serial-to-Parallel Conversion: Converting the serial stream into parallel data frames based on the frame structure.
⏱️ Over-sampling Implementation #
Using Xilinx devices as a reference, the receiver primarily employs IDDR or ISERDERS2 primitives. The system operates in SAME_EDGE_PIPELINED mode with 4x frequency sampling.
The implementation follows these steps:
- Sample the serial data on both the rising and falling edges of the CLK2X clock to achieve 4x sampling.
- Shift the sampled data using the CLK2X clock to produce a continuous sequence of four serial data points.
- Sample the 4x frequency data on a single edge of the CLKX clock to transition the data into the CLKX clock domain, resulting in
CDR_DATA.
For lower-speed serial streams, such as FT3 or standard UART (where the baud rate is very low), this high-speed method may be overkill, and simpler down-sampling techniques can be used.
⚖️ Data Correction and CDR Logic #
In the CLKX clock domain, the Clock and Data Recovery (CDR) block forms an 8-bit CDR data word through shifting.
Bit Position Selection #
The system selects data from the continuous serial stream by defining a selection position (bit_pos) limited to values 0, 1, 2, or 3. For example, if the data stream is represented where the right side is old data and the left side is new data, the system selects from the four bits of D2.
Phase Adjustment Rules #
Because frequency differences between the transmitter and receiver make a fixed selection position impossible to maintain, the system dynamically adjusts the phase. The rules are as follows:
- Data Repetition: If
BIT_POS_DLY = 3andBIT_POS = 0, the data selected last time and the current selection are adjacent, indicating a repeat. - Data Loss: If
BIT_POS_DLY = 0andBIT_POS = 3, the current selection is too far from the last, indicating a lost bit. The system must “fill” the point by repeating the previous point to bridge the gap.
Note: If the data stream is inverted, the order of filling and dropping points is reversed.
Data Buffering #
Due to the frequency mismatch between the transmitter and receiver, a small FIFO is used to buffer data after the drop/fill logic is applied. This buffered data is then passed to the next stage for edge alignment.
The logic for bit position selection can be implemented as follows:
if (P0 ^ P1 == 1) bit_pos <= 2'd0;
else if (P1 ^ P2 == 1) bit_pos <= 2'd3;
else if (P2 ^ P3 == 1) bit_pos <= 2'd2;
else if (P3 ^ Q0 == 1) bit_pos <= 2'd1;🔄 Edge Alignment and Serial-to-Parallel Conversion #
Processing at this stage depends on the signal encoding:
- NRZI: Performs an XOR operation on adjacent data bits.
- Manchester: Performs an XOR operation with the clock signal.
Once the bits are aligned, the system uses frame headers or start delimiters to identify the beginning of a frame. A state machine handles the transition logic to identify the first character. Finally, the serial-to-parallel conversion is completed based on the first character’s definition.
This methodology has been successfully used to implement FT3 encoding and 100M Ethernet NRZI (without a PHY) for commercial applications. For complex real-time data handling, integrating these FPGA blocks with a real-time operating system like VxWorks can streamline the high-level application logic.