一、实验目的
1.熟悉用Quartus编译Verilog语言的方法。
2.掌握用Verilog HDL语言描述加法器的方法。
3.利用IP核建立编码器,参数化IP核。
4.顶层文件设置。
二、实验原理
将8 bit数据分成3 bit和5 bit两组,分别对应10 bit中的4 bit和6 bit,直流平衡代码的不平衡度就是通过“0”的个数减去“1”的个数来计算得到的。如果4 bit和6 bit的各分组中“0”和“1”的个数相等,称为完美平衡代码,或称为完美的直流平衡代码,无需补偿,但是这种情况是不可能的。因为在4bit的子分组中,16种编码中只有6种是完美平衡的,这对于3 bit的8种编码值是不够的。同时,在6bit的子分组中也只有20种编码是完美平衡的,对于5 bit的32种编码值也是不够的。由于4 bit和6bit的两个子分组都是偶数个位数,而不平衡度不可能是“+1”或“-1”,因此,在8B /10B编码方案中还要使用不平衡度为“ +2 ”和“-2”的值。在编码过程中,用一个极性偏差(running disparity,RD)参数表示不平衡度,在不平衡时用2个10 bit字符表示一个8位字符,其中一个称为RD -,表示“ 1”的个数比“0”的个数多2个,另一个称为RD+,表示“0”的个数比“1”的个数多2个。
8B /10B编码方法是把8 bit代码组合编码成10bit代码,代码组合包含256个数据字符编码和12个控制字符编码,分别记为Dx. y和Kx. y。8B /10B编码方案是把8 bit数据分成2个子分组:3个最高有效位(y)和5个最低有效位(x)。代码字按顺序排列,从最高有效位到最低有效位分别记为H、G、F和E、D、C、B、A。3 bit的子分组编码成4 bit,记为j、h、g、f;5 bit的子分组编码成6 bit,记为i、e、d、c、b、a,其映射关系如图1所示,4 bit和6 bit的子分组再组合成10 bit的编码值。
表1列出了3 bit编码成4 bit和5 bit编码成6bit的代码值,在3 bit到4 bit的编码中,编码1、2、5、6使用了“1”和“0”相邻的完美平衡代码,编码采用一对一的关系;编码3使用了“1”和“0”有间隔的完美平衡代码,编码采用一对二的关系;编码0和4使用了“1”和“0”有间隔的不平衡代码,编码也采用一对二的关系;编码7使用了3个连续“1”或“0”的不平衡代码,为了防止更多连续“1”或“0”出现,提供了4种代码选择。在4 bit到6 bit编码中,有19个编码RD -和RD+代码相同,编码7的RD -是111000,而RD+是000111。其余12个不平衡代码的RD -编码值包含4个“1”,而RD -编码值包含4个“0”。8B /10B编码规则将4 bit和6 bit组合,使其最坏的情况下10 bit代码值的不平衡度为“+2”或“-2”,例如:不平衡度为“+2”的4 bit编码值是不会和不平衡度为“+2”的6 bit编码值组合在一起的,因为那样会产生一个不平衡度为“+4”的10 bit的编码值。
表1 8B /10B子分组的编码表
三、实验步骤
1.打开QuartusⅡ软件,熟悉软件界面及窗口命令。
2. 选择File < New Project Wizard弹出对话框,该对话框显示Wizard所包含的各项内容,在弹出的窗口中输入项目的名称和存储位置。如果选中Don’t show me this introduction again。那么在下一次在新建项目是可以不再显示本对话框。点击Next按钮。
3.选择实验板的具体型号,芯片型号。
选择设置参数完成后显示如图,点击finish按钮完成工程建立。
4.选择tools< MegaWizard plug-In Manager建立8B10B编码器IP核。
选择Communications<8B10B Encoder-Decoder建立8B10B编码器。
5.根据向导,建立8B10B个各项参数和工程文件。
6.建立仿真模型。启动ModelSim,选择菜单“File New Poject”,会打开“Creat Project”对话框。在“Creat Projec”t对话框中填写“Project Name”为“bianma”,然后在“Project Location”栏中选择Project文件的存储目录,保留“Default Library Name”的设置为work。点击OK按键确认,在ModelSim软件主窗口的工作区中即增加了一个空的Project标签,同时弹出一个“Add items to the Project”对话框。
7.在工作区中的Project标签页中可以看到新加入的文件,单击右键,选取“Compile Compile All”命令对加入的文件进行编译。编译完成。
8.两个文件编译完后,用鼠标点击“Library”标签栏。在标签栏中用鼠标点击work库前面的“+”,展开work库,就会看到两个编译了的设计单元。
9.导入设计单元。双击Library标签页中的“bianma”,在工作区中将会出现sim标签,并在右边的对象窗口列出了bianma单元所用到的信号,之后开始进行仿真,选择simulate 10.设置顶层文件,向bianmaqi工程中添加bianma文件并打开。 11.对当前打开的文件创建模块单元操作,选择File 13.添加输入输出管脚,同样在空白处双击,在name对话框中输入input/Output进行模块的添加,将各个模块连接起来,更改各引脚名称,形成顶层原理图。 4、时序分析 在完成电路的代码输入及仿真之后,就要进行FPGA实现和电路级的验证了。FPGA设计中的约束主要可以分为两个方面,一是时序约束,另一个是管脚约束,而一般不考虑面积约束、设计规则约束和工作环境约束。 1 时序约束 时序约束主要分为输入/输出延时约束、时钟约束以及异步时钟约束等内容。本实验由于要实现时钟域的切换,则需要三个时钟域,一是输入数据的8M时钟;二是输出数据的10M时钟;三是系统时钟,该时钟作为整个电路的同步时钟,控制数据的读写。 2 引脚锁定约束 设计中所有的端口都需要与FPGA器件的管脚(pin)映射起来才能实现与PBC上的电路进行信号联系。在电路板上电源(VDD/GND)部分已经固定好了,不需要进行管脚的映射。其余的管脚需要参照PCB板上的布线,将时钟信号、复位信号、开关量输入信号等管脚与设计端口锁定。 选择Assignments // megafunction wizard: %8B10B Encoder-Decoder v11.0% // GENERATION: XML // ============================================================ // Megafunction Name(s): // bianma_dec8b10b // ============================================================ // Generated by 8B10B Encoder-Decoder 11.0 [Altera, IP Toolbench 1.3.0 Build 208] // ************************************************************ // THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE! // ************************************************************ // Copyright (C) 1991-2015 Altera Corporation // Any megafunction design, and related net list (encrypted or decrypted), // support information, device programming or simulation file, and any other // associated documentation or information provided by Altera or a partner // under Altera's Megafunction Partnership Program may be used only to // program PLD devices (but not masked PLD devices) from Altera. Any other // use of such megafunction design, net list, support information, device // programming or simulation file, or any other related documentation or // information is prohibited for any other purpose, including, but not // limited to modification, reverse engineering, de-compiling, or use with // any other silicon devices, unless such use is explicitly licensed under // a separate agreement with Altera or a megafunction partner. Title to // the intellectual property, including patents, copyrights, trademarks, // trade secrets, or maskworks, embodied in any such megafunction design, // net list, support information, device programming or simulation file, or // any other related documentation or information provided by Altera or a // megafunction partner, remains with Altera, the megafunction partner, or // their respective licensors. No other licenses, including any licenses // needed under any third party's intellectual property, are provided herein. module bianmaqi ( clk, reset_n, idle_del, ena, datain, rdforce, rdin, valid, dataout, kout, kerr, rdcascade, rdout, rderr); input clk; input reset_n; input idle_del; input ena; input [9:0] datain; input rdforce; input rdin; output valid; output [7:0] dataout; output kout; output kerr; output rdcascade; output rdout; output rderr; bianma_dec8b10b bianma_dec8b10b_inst( .clk(clk), .reset_n(reset_n), .idle_del(idle_del), .ena(ena), .datain(datain), .rdforce(rdforce), .rdin(rdin), .valid(valid), .dataout(dataout), .kout(kout), .kerr(kerr), .rdcascade(rdcascade), .rdout(rdout), .rderr(rderr)); endmodule // ========================================================= // 8B10B Encoder-Decoder Wizard Data // =============================== // DO NOT EDIT FOLLOWING DATA // @Altera, IP Toolbench@ // Warning: If you modify this section, 8B10B Encoder-Decoder Wizard may not be able to reproduce your chosen configuration. // // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // Retrieval info: // =========================================================下载本文