实验一 基本门电路

实验目的

熟悉 Vivado 开发环境,掌握设计流程,包括如何用 Verilog 语言设计电
路、仿真、综合、实现与下载。

实验内容

门电路设计:
使用 Verilog HDL 语言的数据流描述方法设计一个数据宽度可在 1~32
之间变化的 2 输入与门 andgate(或门、非门、与非门等基本门电路),利
用仿真来验证设计。并将该与门封装成可变数据宽度参数的 IP 核。

代码如下
and_notgate.xpr
`timescale 1ns / 1ps

module and_notgate #(parameter WIDTH=8)(
    input [(WIDTH-1):0]a,
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=~(a&b);
endmodule

仿真文件:
and_notgate_sim2

`timescale 1ns / 1ps

module and_notgate_sim2( );
//input
    reg a=0;
    reg b=0;
    
//output
    wire c;
    and_notgate #(1) u(a,b,c);
     
    initial begin
    #100 a=1;
    #100 begin a=0; b=1;end
    #100 a=1;
    end

endmodule

仿真波形图:
在这里插入图片描述

andgate.xpr
`timescale 1ns / 1ps

module andgate #(parameter WIDTH=8)    //指定数据宽度参数,缺省值是8
(
    input [(WIDTH-1):0]a,              //出具位数由参数WIDTH决定
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=a&b;                     //2输入与门
endmodule

仿真文件:
andgate_sim2

`timescale 1ns / 1ps

module andgate_sim2( );
//input
    reg a=0;
    reg b=0;

 //output
    wire c;
    andgate #(1) u(a,b,c);   //实例化与门的时候,设定宽度为1
    
    initial begin
    #100 a=1;
    #100 begin a=0;b=1;end
    #100 a=1;
    end
endmodule

仿真波形图:
在这里插入图片描述

notgate.xpr
`timescale 1ns / 1ps

module notgate #(parameter WIDTH=8)(
    input [(WIDTH-1):0]a,
    output [(WIDTH-1):0]b
    );
    
    assign b=~a;
endmodule

仿真文件:
notgate_sim2

`timescale 1ns / 1ps

module notgate_sim2( );
//input
    reg a=0;

 //output
    wire b;
    notgate #(1) u(a,b);   //实例化非门的时候,设定宽度为1
    
    initial begin
    #100 a=1;
    #100 begin a=0;end
    #100 a=1;
    end
endmodule

仿真波形图:
在这里插入图片描述

nxorgate.xpr
`timescale 1ns / 1ps

module nxorgate #(parameter WIDTH=8)(
    input [(WIDTH-1):0]a,
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=~(a^b);
endmodule

仿真文件:
nxorgate_sim2

`timescale 1ns / 1ps

module nxorgate_sim2( );
//input
    reg a=0;
    reg b=0;
    
//output
    wire c;
    nxorgate #(1) u(a,b,c);        //传入参数为1,设置宽度WIDTH=1
     
    initial begin
    #100 a=1;
    #100 begin a=0; b=1;end
    #100 a=1;
    end

endmodule

仿真波形图:
在这里插入图片描述

or_notgate.xpr
`timescale 1ns / 1ps

module or_notgate #(parameter WIDTH=8)(
    input [(WIDTH-1):0]a,
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=~(a|b);
endmodule

仿真文件:
or_notgate_sim2

`timescale 1ns / 1ps

module or_notgate_sim2( );
//input
    reg a=0;
    reg b=0;
    
//output
    wire c;
    or_notgate #(1) u(a,b,c);
     
    initial begin
    #100 a=1;
    #100 begin a=0; b=1;end
    #100 a=1;
    end

endmodule

仿真波形图:
在这里插入图片描述

orgate.xpr
`timescale 1ns / 1ps

module orgate #(parameter WIDTH=8)    //指定数据宽度参数,缺省值是8
(
    input [(WIDTH-1):0]a,              //出具位数由参数WIDTH决定
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=a|b;                     //2输入或门
endmodule

仿真文件:
orgate_sim

`timescale 1ns / 1ps

module orgate_sim( );
    reg [31:0]a=32'h00000000;
    reg [31:0]b=32'h00000000;
    
    wire [31:0]c;
    orgate #(32) u(a,b,c);
    
    initial begin
    #100 a=32'hffffffff;
    #100 begin a=32'h00000000;b=32'hffffffff;end
    #100 a=32'h007fa509;
    #100 a=32'hffffffff;
    end
endmodule

仿真波形图:
在这里插入图片描述

xorgate.xpr
`timescale 1ns / 1ps

module xorgate #(parameter WIDTH=8)(
    input [(WIDTH-1):0]a,
    input [(WIDTH-1):0]b,
    output [(WIDTH-1):0]c
    );
    
    assign c=a^b;
endmodule

仿真文件:
xorgate_sim2

`timescale 1ns / 1ps

module xorgate_sim2( );
//input
    reg a=0;
    reg b=0;
    
//output
    wire c;
    xorgate #(1) u(a,b,c);        //传入参数为1,设置宽度WIDTH=1
     
    initial begin
    #100 a=1;
    #100 begin a=0; b=1;end
    #100 a=1;
    end

endmodule

仿真波形图:
在这里插入图片描述

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
VerilogHDL是一种硬件描述语言,用于设计数字电路。门电路是数字电路中最基本的电路,它可以实现与、或、非等逻辑运算。下面介绍VerilogHDL基础门电路设计实验原理。 实验目的:掌握VerilogHDL语言编写基本门电路的方法。 实验原理: 1. VerilogHDL语言的基本结构 VerilogHDL语言的结构包括模块、端口、信号、赋值语句等。其中,模块是VerilogHDL的基本组成单元,端口用于连接不同模块的信号,信号用于传递数据和控制信息,赋值语句用于对信号进行赋值操作。 2. 门电路基本原理 门电路是数字电路的基本单元,它实现逻辑运算,包括与、或、非等。与门、或门和非门的真值表分别如下: 与门: A | B | Y --|---|-- 0 | 0 | 0 0 | 1 | 0 1 | 0 | 0 1 | 1 | 1 或门: A | B | Y --|---|-- 0 | 0 | 0 0 | 1 | 1 1 | 0 | 1 1 | 1 | 1 非门: A | Y --|-- 0 | 1 1 | 0 3. 基本门电路的VerilogHDL实现 以与门为例,其VerilogHDL代码如下: ``` module and_gate(input A, input B, output Y); assign Y = A & B; endmodule ``` 其中,module定义了一个模块,input定义了输入端口,output定义了输出端口,assign用于对信号进行赋值操作。 以或门为例,其VerilogHDL代码如下: ``` module or_gate(input A, input B, output Y); assign Y = A | B; endmodule ``` 以非门为例,其VerilogHDL代码如下: ``` module not_gate(input A, output Y); assign Y = ~A; endmodule ``` 4. 门电路的组合 多个门电路可以组合在一起实现更复杂的逻辑运算,如与非、或非、异或等。以与非门为例,其VerilogHDL代码如下: ``` module nand_gate(input A, input B, output Y); wire w1; and_gate and(A, B, w1); not_gate not(w1, Y); endmodule ``` 其中,wire定义了一个中间信号,and_gate和not_gate分别实现了与和非的逻辑运算。 实验步骤: 1. 打开VerilogHDL开发环境,新建一个工程,命名为gate_design。 2. 在工程中新建一个VerilogHDL文件,命名为and_gate.v,输入与门的VerilogHDL代码。 3. 在工程中新建一个VerilogHDL文件,命名为or_gate.v,输入或门的VerilogHDL代码。 4. 在工程中新建一个VerilogHDL文件,命名为not_gate.v,输入非门的VerilogHDL代码。 5. 在工程中新建一个VerilogHDL文件,命名为nand_gate.v,输入与非门的VerilogHDL代码。 6. 编译并综合所有的VerilogHDL文件,生成门电路的网表文件。 7. 下载网表文件到FPGA开发板中,验证门电路的功能。 总结: VerilogHDL是设计数字电路的重要工具,可以用于实现基本门电路和复杂逻辑运算。掌握VerilogHDL语言的基本结构和门电路基本原理,可以编写出实用的数字电路。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

罗娜mei

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值