目录
一、Verilog编程入门
1.1门电路
①非门
②与门
③或非门
1.2组合电路
①Declaring wires
②7458
③Vector0
1.3时序电路
①Dff
②Dff8
③Dff8r
二、使用Logisim进行仿真设计
2.1完成一个1位全加器的设计并测试
2.1.1设计一个1位半加器电路
2.1.2在半加器电路基础上,实现1位全加器电路
三、基于Quartus进行实验并仿真
3.1输入原理图实现1位加法器
3.1.1半加器原理图输入
①绘制实现
②仿真实现
③仿真结果
3.1.2全加器原理图输入
①将设计项目设置为可调用的元件
②绘制过程实现
③仿真实现
④仿真测试结果
四、Verilog编程实现1位加法器
4.1代码实现
4.2仿真实现
五、四位全加器
5.1四位全加器的原理图设计
①原理图
②RTL电路图如下
③仿真测试
④仿真结果
5.2四位全加器的Verilog编程实现
①创建文件
②代码实现
③RTL电路图
一、Verilog编程入门
1.1门电路
①非门
代码
下面展示一些 内联代码片。
module top_module( input in, output out );
assign out = ~ in;
endmodule
结果
②与门
代码
module top_module(
input a,
input b,
output out );
assign out = a & b;
endmodule
结果
③或非门
代码
module top_module(
input a,
input b,
output out );
assign out =~ (a | b);
endmodule
结果
1.2组合电路
①Declaring wires
代码
`default_nettype none
module top_module(
input a,
input b,
input c,
input d,
output out,
output out_n );
wire and_1 = a & b;
wire and_2 = c & d;
wire or_1 = and_1 | and_2;
assign out = or_1;
assign out_n = ~or_1;
endmodule
结果
②7458
代码
module top_module (
input p1a, p1b, p1c, p1d, p1e, p1f,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y );
assign p1y = (p1a & p1b & p1c) | (p1d & p1e & p1f);
assign p2y = (p2a & p2b) | (p2d & p2c);
endmodule结果
③Vector0
代码
module top_module (
input wire [2:0] vec,
output wire [2:0] outv,
output wire o2,
output wire o1,
output wire o0 ); // Module body starts after module declaration
assign outv = vec;
assign o0 = vec[0];
assign o1 = vec[1];
assign o2 = vec[2];
endmodule
结果
1.3时序电路
①Dff
代码
module top_module (
input clk, // Clocks are used in sequential circuits
input d,
output reg q );//
// Use a clocked always block
// copy d to q at every positive edge of clk
// Clocked always blocks should use non-blocking assignments
always@(posedge clk) begin
q <= d;
end
endmodule
结果
②Dff8
代码
module top_module (
input clk,
input [7:0] d,
output [7:0] q
);
always@(posedge clk) begin
q <= d;
end
endmodule
结果
③Dff8r
代码
module top_module (
input clk,
input reset, // Synchronous reset
input [7:0] d,
output [7:0] q
);
always@(posedge clk) begin
q <= (~{8{reset}} & d);
end
endmodule
结果
二、使用Logisim进行仿真设计
2.1完成一个1位全加器的设计并测试
2.1.1设计一个1位半加器电路
2.1.2在半加器电路基础上,实现1位全加器电路
三、基于Quartus进行实验并仿真
3.1输入原理图实现1位加法器
3.1.1半加器原理图输入
①绘制实现
保存文件并编译,通过tool->Netlist Viewers->RTL Viewer查看电路图:
②仿真实现
编辑信号
③仿真结果
功能仿真结果
时序仿真结果
通过仿真结果,可以发现得到的结果与真值表中是相吻合的。
3.1.2全加器原理图输入
①将设计项目设置为可调用的元件
②绘制过程实现
首先选择File->New,进入后选择Block Diagram/Schematic File
选择元件
添加输入输出,完成效果
保存文件并编译,通过tool->Netlist Viewers->RTL Viewer查看电路图:
③仿真实现
跟半加器同理添加信号,然后编辑信号
④仿真测试结果
功能仿真结果:
时序仿真结果:
四、Verilog编程实现1位加法器
4.1代码实现
module full_adder(
//输入信号,ain表示被加数,bin表示加数,cin表示低位向高位的进位
input ain,bin,cin,
//输出信号,cout表示向高位的进位,sum表示本位的相加和
output reg cout,sum
);
reg s1,s2,s3;
always @(ain or bin or cin) begin
sum=(ain^bin)^cin;//本位和输出表达式
s1=ain&cin;
s2=bin&cin;
s3=ain&bin;
cout=(s1|s2)|s3;//高位进位输出表达式
end
endmodule
保存文件并编译,通过tool->Netlist Viewers->RTL Viewer查看电路图:
4.2仿真实现
同理添加信号并编辑信号
功能仿真结果:
时序仿真结果:
通过仿真结果,可以发现得到的结果与真值表中是相吻合的。
五、四位全加器
5.1四位全加器的原理图设计
①原理图
将一位全加器设置为可调用的元件并设计出原理图:
②RTL电路图如下
③仿真测试
编辑信号:
④仿真结果
功能仿真结果:
时序仿真结果:
5.2四位全加器的Verilog编程实现
①创建文件
②代码实现
//数据流描述4位全加器
module four_adder1(
input[3:0] a,b,
output[3:0] s,
output cout,
input cin
);
assign{cout,s} = a+b+cin;
endmodule
③RTL电路图