赞
踩
LVDS学习笔记之 IDELAYE2应用及仿真
LVDS学习笔记之 ISERDESE2应用及仿真
LVDS学习笔记之 RX模块设计及自动训练仿真
LVDS接收模块创建的IP核中有IDELAYE2和ISERDESE2原语,前面几期通过先对原语的学习更能让我们懂得如何通过SelectIO创建LVDS IP,更能明白创建的IP各个端口及属性的意义。对于懂得如何编写LVDS发送模块十分重要,本期也是通过这种方式进行学习。
首先要清楚通过SelectIO IP核创建的LVDS发送模块内部到底有什么原语,因此先创建该模块。
跟上期一样,使用软件版本Vivado 18.3,创建名为LVDS_TX的工程,芯片型号选择xc7z020clg400-2芯片。
在IP Catalog中搜索selectIO,双击并打开配置页面。
在弹出的Customize IP进行以下设置。
由于这是发送模块,因此在Data BUS Setup中Data Bus Direction选项设置成为Outpu,具体设置下图所示:
对Clock Setup进行下图所示的设置:
其余部分保持默认,点击OK创建好IP核。
接下来双击下图所示的选项,打开IP核内部源码。
// file: lvds_tx_selectio_wiz.v
// (c) Copyright 2009 - 2013 Xilinx, Inc. All rights reserved.
//
// This file contains confidential and proprietary information
// of Xilinx, Inc. and is protected under U.S. and
// international copyright and other intellectual property
// laws.
//
// DISCLAIMER
// This disclaimer is not a license and does not grant any
// rights to the materials distributed herewith. Except as
// otherwise provided in a valid license issued to you by
// Xilinx, and to the maximum extent permitted by applicable
// law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND
// WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES
// AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING
// BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-
// INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and
// (2) Xilinx shall not be liable (whether in contract or tort,
// including negligence, or under any other theory of
// liability) for any loss or damage of any kind or nature
// related to, arising under or in connection with these
// materials, including for any direct, or any indirect,
// special, incidental, or consequential loss or damage
// (including loss of data, profits, goodwill, or any type of
// loss or damage suffered as a result of any action brought
// by a third party) even if such damage or loss was
// reasonably foreseeable or Xilinx had been advised of the
// possibility of the same.
//
// CRITICAL APPLICATIONS
// Xilinx products are not designed or intended to be fail-
// safe, or for use in any application requiring fail-safe
// performance, such as life-support or safety devices or
// systems, Class III medical devices, nuclear facilities,
// applications related to the deployment of airbags, or any
// other applications that could lead to death, personal
// injury, or severe property or environmental damage
// (individually and collectively, "Critical
// Applications"). Customer assumes the sole risk and
// liability of any use of Xilinx products in Critical
// Applications, subject only to applicable laws and
// regulations governing limitations on product liability.
//
// THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS
// PART OF THIS FILE AT ALL TIMES.
//----------------------------------------------------------------------------
// User entered comments
//----------------------------------------------------------------------------
// None
//----------------------------------------------------------------------------
`timescale 1ps/1ps
module lvds_tx_selectio_wiz
// width of the data for the system
#(parameter SYS_W = 1,
// width of the data for the device
parameter DEV_W = 8)
(
// From the device out to the system
input [DEV_W-1:0] data_out_from_device,
output [SYS_W-1:0] data_out_to_pins_p,
output [SYS_W-1:0] data_out_to_pins_n,
output clk_to_pins_p,
output clk_to_pins_n,
input clk_in, // Fast clock input from PLL/MMCM
input clk_div_in, // Slow clock input from PLL/MMCM
input clk_reset,
input io_reset);
localparam num_serial_bits = DEV_W/SYS_W;
wire clock_enable = 1'b1;
// Signal declarations
------------------------------
wire clk_fwd_out;
// Before the buffer
wire [SYS_W-1:0] data_out_to_pins_int;
// Between the delay and serdes
wire [SYS_W-1:0] data_out_to_pins_predelay;
// Array to use intermediately from the serdes to the internal
// devices. bus "0" is the leftmost bus
wire [SYS_W-1:0] oserdes_d[0:13]; // fills in starting with 13
// Create the clock logic
// We have multiple bits- step over every bit, instantiating the required elements
genvar pin_count;
genvar slice_count;
generate for (pin_count = 0; pin_count < SYS_W; pin_count = pin_count + 1) begin: pins
// Instantiate the buffers
------------------------------
// Instantiate a buffer for every bit of the data bus
OBUFDS
#(.IOSTANDARD ("LVDS_25"))
obufds_inst
(.O (data_out_to_pins_p [pin_count]),
.OB (data_out_to_pins_n [pin_count]),
.I (data_out_to_pins_int[pin_count]));
// Pass through the delay
-------------------------------
assign data_out_to_pins_int[pin_count] = data_out_to_pins_predelay[pin_count];
// Instantiate the serdes primitive
------------------------------
// declare the oserdes
OSERDESE2
# (
.DATA_RATE_OQ ("SDR"),
.DATA_RATE_TQ ("SDR"),
.DATA_WIDTH (8),
.TRISTATE_WIDTH (1),
.SERDES_MODE ("MASTER"))
oserdese2_master (
.D1 (oserdes_d[13][pin_count]),
.D2 (oserdes_d[12][pin_count]),
.D3 (oserdes_d[11][pin_count]),
.D4 (oserdes_d[10][pin_count]),
.D5 (oserdes_d[9][pin_count]),
.D6 (oserdes_d[8][pin_count]),
.D7 (oserdes_d[7][pin_count]),
.D8 (oserdes_d[6][pin_count]),
.T1 (1'b0),
.T2 (1'b0),
.T3 (1'b0),
.T4 (1'b0),
.SHIFTIN1 (1'b0),
.SHIFTIN2 (1'b0),
.SHIFTOUT1 (),
.SHIFTOUT2 (),
.OCE (clock_enable),
.CLK (clk_in),
.CLKDIV (clk_div_in),
.OQ (data_out_to_pins_predelay[pin_count]),
.TQ (),
.OFB (),
.TFB (),
.TBYTEIN (1'b0),
.TBYTEOUT (),
.TCE (1'b0),
.RST (io_reset));
// Concatenate the serdes outputs together. Keep the timesliced
// bits together, and placing the earliest bits on the right
// ie, if data comes in 0, 1, 2, 3, 4, 5, 6, 7, ...
// the output will be 3210, 7654, ...
---------------------------------------------------------
for (slice_count = 0; slice_count < num_serial_bits; slice_count = slice_count + 1) begin: out_slices
// This places the first data in time on the right
assign oserdes_d[14-slice_count-1] =
data_out_from_device[slice_count];
// To place the first data in time on the left, use the
// following code, instead
// assign oserdes_d[slice_count] =
// data_out_from_device[slice_count];
end
end
endgenerate
// declare the oserdes
OSERDESE2
# (
.DATA_RATE_OQ ("DDR"),
.DATA_RATE_TQ ("SDR"),
.DATA_WIDTH (4),
.TRISTATE_WIDTH (1),
.SERDES_MODE ("MASTER"))
clk_fwd (
.D1 (1'b1),
.D2 (1'b0),
.D3 (1'b1),
.D4 (1'b0),
.D5 (1'b1),
.D6 (1'b0),
.D7 (1'b1),
.D8 (1'b0),
.T1 (1'b0),
.T2 (1'b0),
.T3 (1'b0),
.T4 (1'b0),
.SHIFTIN1 (1'b0),
.SHIFTIN2 (1'b0),
.SHIFTOUT1 (),
.SHIFTOUT2 (),
.OCE (clock_enable),
.CLK (clk_in),
.CLKDIV (clk_div_in),
.OQ (clk_fwd_out),
.TQ (),
.OFB (),
.TFB (),
.TBYTEIN (1'b0),
.TBYTEOUT (),
.TCE (1'b0),
.RST (io_reset));
// Clock Output Buffer
OBUFDS
#(.IOSTANDARD ("LVDS_25"))
obufds_inst
(.O (clk_to_pins_p),
.OB (clk_to_pins_n),
.I (clk_fwd_out));
endmodule
我们可以发现创建好后的IP内部只有两个原语,一个是OSERDESE2,另一个是OBUFDS。OBUFDS的功能是将单端信号转化成差分信号,剩下的就是OSERDESE2的功能了。
OSERDESE2原语跟ISERDESE2类似,ISERDESE2是为了将串行数据转化成并行数据,OSERDESE2刚好相反,是将并行书转化成串行数据。OSERDESE2原语框图如下所示。
OSERDESE2模块如下图所示:
OSERDESE2的功能有以下两种:
1.数据并串转换器:在D1到D8上的数据分别在CLK的时钟下依次从OQ端口输出。这种模式使用的最为广泛,LVDS TX也是通过该端口实现并串转换的。值得注意的是,该原语使用时必须要复位,否则会产生意外输出,通过级联可扩展并串转换的位宽。
2.三态并串转换器:在T1到T4上的三态数据通过TFB或者TQ输出,与数据并串转换不同的是,三态最多只能串行化四位并联三态信号,而且三态转换器不能级联。
下们对几个比较重要的端口进行阐述:
下们对几个比较重要的属性进行阐述:
两个OSERDESE2原语可通过上图所示的方式进行级联,同时注意第一个OSERDESE2要设置成Master,第二个要设置成Slave,在SDR/DDR模式下数据位宽如下图所示:
在DDR模式下,位宽分别为10核14时,第二个OSERDESE2原语数据输入端口位置如下图所示。在DDR模式下10位宽时,使用D3-D4作为第二个OSERDESE2的扩展位宽;在DDR模式下14位宽时,使用D3-D8作为第二个OSERDESE2的扩展位宽;
OSERDESE2的输入到输出延迟取决于DATA_RATE和DATA_WIDTH属性。延迟被定义为以下两个事件之间的一段时间:(a)当CLKDIV上升到来时,将输入数据D1-D8进入到OSERDESE2;(b)第一个比特出现在OQ时。下图总结了各种OSERDESE2延迟值。
以2:1 SDR模式为例,讲解各个事件所发生的事,时序如下图所示:
事件1:在CLKDIV的上升沿上,单词AB从FPGA逻辑驱动到OSERDESE2的D1和D2输入(经过一些传播延迟)。
事件2:在CLKDIV的上升沿上,单词AB从D1和D2输入中采样到OSERDESE2中。
事件3:AB被采样到OSERDESE2后,数据位A在OQ出现一个CLK周期,与2:1 SDR模式下OSERDESE2的潜伏期图一致。
对应8:1DDR模式下的时序如上图所示。同样是经过4个CLK,D中的数据对应才从OQ输出。
`timescale 1ns / 1ps
module OSERDESE2_TEST(
input CLK ,
input CLKDIV ,
input RST ,
input [7:0] D ,
input OCE,
output OQ
);
OSERDESE2 #(
.DATA_RATE_OQ("SDR"), // DDR, SDR
.DATA_RATE_TQ("SDR"), // DDR, BUF, SDR
.DATA_WIDTH(2), // Parallel data width (2-8,10,14)
.INIT_OQ(1'b0), // Initial value of OQ output (1'b0,1'b1)
.INIT_TQ(1'b0), // Initial value of TQ output (1'b0,1'b1)
.SERDES_MODE("MASTER"), // MASTER, SLAVE
.SRVAL_OQ(1'b0), // OQ output value when SR is used (1'b0,1'b1)
.SRVAL_TQ(1'b0), // TQ output value when SR is used (1'b0,1'b1)
.TBYTE_CTL("FALSE"), // Enable tristate byte operation (FALSE, TRUE)
.TBYTE_SRC("FALSE"), // Tristate byte source (FALSE, TRUE)
.TRISTATE_WIDTH(1) // 3-state converter width (1,4)
)
OSERDESE2_inst (
.OFB(), // 1-bit output: Feedback path for data
.OQ(OQ), // 1-bit output: Data path output
// SHIFTOUT1 / SHIFTOUT2: 1-bit (each) output: Data output expansion (1-bit each)
.SHIFTOUT1(),
.SHIFTOUT2(),
.TBYTEOUT(), // 1-bit output: Byte group tristate
.TFB(), // 1-bit output: 3-state control
.TQ(), // 1-bit output: 3-state control
.CLK(CLK), // 1-bit input: High speed clock
.CLKDIV(CLKDIV), // 1-bit input: Divided clock
// D1 - D8: 1-bit (each) input: Parallel data inputs (1-bit each)
.D1(D[0]),
.D2(D[1]),
.D3(D[2]),
.D4(D[3]),
.D5(D[4]),
.D6(D[5]),
.D7(D[6]),
.D8(D[7]),
.OCE(OCE), // 1-bit input: Output data clock enable
.RST(RST), // 1-bit input: Reset
// SHIFTIN1 / SHIFTIN2: 1-bit (each) input: Data input expansion (1-bit each)
.SHIFTIN1(1'b0),
.SHIFTIN2(1'b0),
// T1 - T4: 1-bit (each) input: Parallel 3-state inputs
.T1(1'b0),
.T2(1'b0),
.T3(1'b0),
.T4(1'b0),
.TBYTEIN(1'b0), // 1-bit input: Byte group tristate
.TCE(1'b0) // 1-bit input: 3-state clock enable
);
endmodule
`timescale 1ns / 1ps
module OSERDESE2_TEST_tb( );
reg CLK ;
reg CLKDIV ;
reg RST ;
reg [7:0] D ;
reg OCE ;
wire OQ ;
OSERDESE2_TEST
OSERDESE2_TEST_inst
(
.CLK (CLK ),
.CLKDIV (CLKDIV ),
.RST (RST ),
.D (D ),
.OCE (OCE ),
.OQ (OQ )
);
initial begin CLK =1; end
initial begin CLKDIV =1; end
always #(5) CLK=~CLK;
always #(10) CLKDIV=~CLKDIV;
initial begin
test;
$stop;
end
task init;
begin
RST =1;
D =8'd0;
OCE = 1'b1;
#200;
RST =0;
#2000;
end
endtask
task test;
begin
init;
D = 8'b1101_1101;
#5000;
end
endtask
endmodule
UG471 170页给我们提供了一些OSERDESE2时序图,先把实例上的时序图对应仿真,更改不同位宽,不同模式时需要对应修改代码中的一些参数。
首先确保工程代码模式为2:1 SDR,再确保CLK时钟与CLKDIV时钟是两倍关系,及参数图如下所示:
这里我们D = 8’b1101_1101,因此首先会将低位传输,其次再传输高位,因此会持续输送101010…
仿真截图如下:
修改模式为4:1 SDR模式,CLK与CLKDIV为4倍关系:
这里我们D = 8’b1101_1101,因此首先会将低位传输,其次再传输高位,因此会时序循环输出101110111011…
仿真截图如下:
修改模式为8:1 DDR模式,CLK与CLKDIV为4倍关系:
输出会在CLK双沿输出,循环输出1011101110111011…
仿真截图如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。