4

基础逻辑门_zhang_shiwei的技术博客_51CTO博客

 1 year ago
source link: https://blog.51cto.com/u_15641375/5885110
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Verilog HDL简介

Verilog HDL 设计语言支持3种设计风格: 门级,数据流级和行为级。 门级和数据流级设计风格通常用于设计组合逻辑电路,而行为级设计风格既可以用于设计组合逻辑电路又可以设计时序逻辑电路。本次实验通过使用Vivado 2015.1软件工具,以Basys3和Nexys4 DDR开发板为目标板,设计简单的组合逻辑电路来展示3种设计风格的用法。请参考Vivado手册了解如何使用Vivado工具创建工程并验证数字电路。

Nexys4 DDR简介

Nexys4 DDR 特性如下:

  • 128 MiB DDR 2 SDRAM
  • 16Mbytes SPI (quad 模式) PCM 非易失型存储器
  • 16Mbytes 并行 PCM 非易失型存储器
  • 10/100 以太网PHY
  • USB-UART 和 USB-HID 端口(用于鼠标和键盘)
  • 8-bit VGA 端口
  • 100MHz CMOS 振荡器
  • 72个I/O连接到扩展连接器
  • GPIO 包括 8个LED, 5个按键开关,8个拨码开关和2个4位7段数码管

Nexys4 DDR 开发板如下图所示

基础逻辑门_开发板

Verilog HDL 支持内建的原始的门级设计。门级支持包括多输入、多输出、三态和拉态。 多输入门支持包括: and, nand, or, nor, xor, 和xnor,它们的输入为2个及以上,输出只有1个。多输出门支持包括buf 和 not ,它们的输出为2个及以上,输入只有1个。 Verilog HDL语言还支持三态门: bufif0, bufif1, notif0, 和notif1。这些三态门有一个输入,一个控制信号和一个输出。拉门支持包括pullup和 pulldown,只有一个输出(没有输入)。这些门的零延迟的基本语法如下:

and | nand | or | nor | xor | xnor [instance name] (out, in1, …, inN); // [] is optional and | is
selection
buf | not [instance name] (out1, out2, …, out2, input);
bufif0 | bufif1 | notif0 | notif1 [instance name] (outputA, inputB, controlC);
pullup | pulldown [instance name] (output A); 你也可以在同一语句中,用逗号分隔,创建多个相同类型门的实例,比如:

Verilog HDL语言也允许在实例化门电路时加入延迟。 加入的延迟来自输入或输出。这些延迟可以表达为上升、下降或关断延迟;在一个实例中可以使用1、2或3种延迟。关断延迟可以用于输出能被关掉的门 (如 notif1).比如,

and #5 A1(Out, in1, in2); // the rise and fall delays are 5 units
and #(2,5) A2(out2, in1, in2); // the rise delay is 2 unit and the fall delay is 5
units notif1 #(2, 5, 4) A3(out3, in2, ctrl1); //the rise delay is 2, the fall delay is 5, and the turn- off delay is 4 unit
  • 打开 Vivado并创建空白工程,取名为 lab1.1 (参考 Vivado2015.1 手册 Step 1)。
基础逻辑门_ios_02
基础逻辑门_开发板_03
基础逻辑门_ios_04

创建文件create file

基础逻辑门_建模_05

添加xdc文件

基础逻辑门_开发板_06

选择配置文件

基础逻辑门_建模_07
  • 使用门级建模风格创建Verilog module包含3个输入(in1,in2,select)和1个输出(out) (参考Vivado2015.1手册 Step 1).

提示:单击在New Project窗口,Add Source上的绿色加号按钮。然后单击Create File。修改文件名为lab1_1_1,单击OK。确认目标语言和仿真语言都设置为Verilog。单击两次Next。

  • 将适合开发板的XDC文件添加到工程。

提示:单击在New Project窗口Add Constraints上的绿色加号按钮。单击AddFile.选择Basys3_Master.xdc (Basys3)或Nexys4DDR_Master.xdc (Nexys4 DDR)。点击Next。

  • 在New Project窗口选择xc7a35tcpg236-1(Basys3)或xc7a100tcsg324-1(Nexys4 DDR)。单击Next。单击Finish。
  • 一个定义Module的窗口会出现, 通过单击Port Name并输入变量名,创建3个输入 (in1, in2, select) 和1个输出(out) 。 通过单击下拉列表选择正确的方向修改 Direction。单击OK。
基础逻辑门_ios_08
  • 打开lab1.1.v 文件编辑其中内容。 在分号 (;)后添加上文电路的结构逻辑。选择File > Save File或 CRTL-S保存。
    单击RTL Analysis上的 Elaborated Design选项卡。
    单击 Schematic 查看门级建模的设计。

使用门级建模的方式写,verilog的代码如下:

module

ab1_1( input in1,in2, input select, output out );

wire temp1,temp2,temp3;

not (temp1,select);

and (temp2,temp1,in1);

and (temp3,select,in2);

or (out,temp2,temp3);

endmodule

点击Schematic 查看门级建模的设计

基础逻辑门_ios_09

大致如下的电路:

基础逻辑门_建模_10

由此我们可以知道我们设计的门级建模的确是对的。

编辑XDC文件。去注释并将 SW0 和 SW1赋给in1 和 in2, SW7 给 select, LED0给out。保存XDC文件。 生成比特流文件,将其下载到Basys3或Nexys4 DDR开发板,并验证功能

打开xdc文件

基础逻辑门_ios_11

修改xdc文件对应段落:

set_property -dict { PACKAGE_PIN J15 IOSTANDARD LVCMOS33 } [get_ports { in1 }]; #IO_L24N_T3_RS0_15 Sch=sw[0]
set_property -dict { PACKAGE_PIN L16 IOSTANDARD LVCMOS33 } [get_ports { in2 }]; #IO_L3N_T0_DQS_EMCCLK_14 Sch=sw[1]
#set_property -dict { PACKAGE_PIN M13 IOSTANDARD LVCMOS33 } [get_ports { sw[2] }]; #IO_L6N_T0_D08_VREF_14 Sch=sw[2]
#set_property -dict { PACKAGE_PIN R15 IOSTANDARD LVCMOS33 } [get_ports { sw[3] }]; #IO_L13N_T2_MRCC_14 Sch=sw[3]
#set_property -dict { PACKAGE_PIN R17 IOSTANDARD LVCMOS33 } [get_ports { sw[4] }]; #IO_L12N_T1_MRCC_14 Sch=sw[4]
#set_property -dict { PACKAGE_PIN T18 IOSTANDARD LVCMOS33 } [get_ports { sw[5] }]; #IO_L7N_T1_D10_14 Sch=sw[5]
#set_property -dict { PACKAGE_PIN U18 IOSTANDARD LVCMOS33 } [get_ports { sw[6] }]; #IO_L17N_T2_A13_D29_14 Sch=sw[6]
set_property -dict { PACKAGE_PIN R13 IOSTANDARD LVCMOS33 } [get_ports { select }]; #IO_L5N_T0_D07_14 Sch=sw[7]
#set_property -dict { PACKAGE_PIN T8 IOSTANDARD LVCMOS18 } [get_ports { sw[8] }]; #IO_L24N_T3_34 Sch=sw[8]
#set_property -dict { PACKAGE_PIN U8 IOSTANDARD LVCMOS18 } [get_ports { sw[9] }]; #IO_25_34 Sch=sw[9]
#set_property -dict { PACKAGE_PIN R16 IOSTANDARD LVCMOS33 } [get_ports { sw[10] }]; #IO_L15P_T2_DQS_RDWR_B_14 Sch=sw[10]
#set_property -dict { PACKAGE_PIN T13 IOSTANDARD LVCMOS33 } [get_ports { sw[11] }]; #IO_L23P_T3_A03_D19_14 Sch=sw[11]
#set_property -dict { PACKAGE_PIN H6 IOSTANDARD LVCMOS33 } [get_ports { sw[12] }]; #IO_L24P_T3_35 Sch=sw[12]
#set_property -dict { PACKAGE_PIN U12 IOSTANDARD LVCMOS33 } [get_ports { sw[13] }]; #IO_L20P_T3_A08_D24_14 Sch=sw[13]
#set_property -dict { PACKAGE_PIN U11 IOSTANDARD LVCMOS33 } [get_ports { sw[14] }]; #IO_L19N_T3_A09_D25_VREF_14 Sch=sw[14]
#set_property -dict { PACKAGE_PIN V10 IOSTANDARD LVCMOS33 } [get_ports { sw[15] }]; #IO_L21P_T3_DQS_14 Sch=sw[15]


## LEDs

set_property -dict { PACKAGE_PIN H17 IOSTANDARD LVCMOS33 } [get_ports { out }]; #IO_L18P_T2_A24_15 Sch=led[0]
# set_property -dict { PACKAGE_PIN K15 IOSTANDARD LVCMOS33 } [get_ports { led[1] }]; #IO_L24P_T3_RS1_15 Sch=led[1]
# set_property -dict { PACKAGE_PIN J13 IOSTANDARD LVCMOS33 } [get_ports { led[2] }]; #IO_L17N_T2_A25_15 Sch=led[2]
# set_property -dict { PACKAGE_PIN N14 IOSTANDARD LVCMOS33 } [get_ports { led[3] }]; #IO_L8P_T1_D11_14 Sch=led[3]
# set_property -dict { PACKAGE_PIN R18 IOSTANDARD LVCMOS33 } [get_ports { led[4] }]; #IO_L7P_T1_D09_14 Sch=led[4]
# set_property -dict { PACKAGE_PIN V17 IOSTANDARD LVCMOS33 } [get_ports { led[5] }]; #IO_L18N_T2_A11_D27_14 Sch=led[5]
# set_property -dict { PACKAGE_PIN U17 IOSTANDARD LVCMOS33 } [get_ports { led[6] }]; #IO_L17P_T2_A14_D30_14 Sch=led[6]
# set_property -dict { PACKAGE_PIN U16 IOSTANDARD LVCMOS33 } [get_ports { led[7] }]; #IO_L18P_T2_A12_D28_14 Sch=led[7]
#set_property -dict { PACKAGE_PIN V16 IOSTANDARD LVCMOS33 } [get_ports { led[8] }]; #IO_L16N_T2_A15_D31_14 Sch=led[8]
#set_property -dict { PACKAGE_PIN T15 IOSTANDARD LVCMOS33 } [get_ports { led[9] }]; #IO_L14N_T2_SRCC_14 Sch=led[9]
#set_property -dict { PACKAGE_PIN U14 IOSTANDARD LVCMOS33 } [get_ports { led[10] }]; #IO_L22P_T3_A05_D21_14 Sch=led[10]
#set_property -dict { PACKAGE_PIN T16 IOSTANDARD LVCMOS33 } [get_ports { led[11] }]; #IO_L15N_T2_DQS_DOUT_CSO_B_14 Sch=led[11]
#set_property -dict { PACKAGE_PIN V15 IOSTANDARD LVCMOS33 } [get_ports { led[12] }]; #IO_L16P_T2_CSI_B_14 Sch=led[12]
#set_property -dict { PACKAGE_PIN V14 IOSTANDARD LVCMOS33 } [get_ports { led[13] }]; #IO_L22N_T3_A04_D20_14 Sch=led[13]
#set_property -dict { PACKAGE_PIN V12 IOSTANDARD LVCMOS33 } [get_ports { led[14] }]; #IO_L20N_T3_A07_D23_14 Sch=led[14]
#set_property -dict { PACKAGE_PIN V11 IOSTANDARD LVCMOS33 } [get_ports { led[15] }]; #IO_L21N_T3_DQS_A06_D22_14 Sch=led[15]

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK