目录
一、Verilog编程入门学习
1、门电路
(1)与门
代码
module top_module(
input a,
input b,
output out );
assign out = a&b;
endmodule
(2)或非门
代码
module top_module(
input a,
input b,
output out );
assign out = ~(a|b);
endmodule
(3)同或门
代码
module top_module(
input a,
input b,
output out );
assign out = ~(a^b);
endmodule
2、组合电路
(1)Declaring wires
代码
module top_module(
input a,
input b,
input c,
input d,
output out,
output out_n );
wire and_ab;
wire and_cd;
assign and_ab = a&b;
assign and_cd = c&d;
assign out = and_ab|and_cd;
assign out_n = ~out;
endmodule
(2)7458
代码
module top_module (
input p1a, p1b, p1c, p1d, p1e, p1f,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y );
wire p11, p12, p21, p22;
assign p11 = (p1a&p1b&p1c);
assign p12 = (p1d&p1e&p1f);
assign p21 = (p2a&p2b);
assign p22 = (p2c&p2d);
assign p1y = p11 | p12;
assign p2y = p21 | p22;
endmodule
(3)7420
代码
module top_module (
input p1a, p1b, p1c, p1d,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y );
assign p1y = ~(p1a&p1b&p1c&p1d);
assign p2y = ~(p2a&p2b&p2c&p2d);
endmodule
3、时序电路
(1)D触发器
D触发器是一种在时钟信号的(通常)正边沿存储位并定期更新的电路。
D 触发器由逻辑合成器在使用时钟 always 模块时创建(请参阅始终阻止 2).D 触发器是“组合逻辑的斑点,然后是触发器”的最简单形式,其中组合逻辑部分只是一根电线。
代码
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
(2)Dff8
代码
module top_module (
input clk,
input [7:0] d,
output [7:0] q
);
always@(posedge clk) begin
q <= d;
end
endmodule
(3)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仿真
1、一位全加器
逻辑表达式如下:
sum = a ⊕ b ⊕ cin;
cout = ab +(a⊕b)cin ;
电路图
2、四位全加器
三、Quartus实验仿真
1、一位全加器
(1)原理图方式
电路图
RTL
(2)Verilog语言方式
module FullAdder_gate(
input a, b, cin,
output sum, cout
);
assign sum = a ^ b ^ cin;
assign cout = (a & b) | ((a^b)&cin);
endmodule
RTL:
2、四位全加器
(1)原理图
RTL:
(2)Verilog
module FullAdder_four_gate (
input [3:0] a, b,
output [3:0] sum,
input cin,
output cout
);
wire c1, c2, c3;
FullAdder_one_gate f1(a[0], b[0], cin, sum[0], c1);
FullAdder_one_gate f2(a[1], b[1], c1, sum[1], c2);
FullAdder_one_gate f3(a[2], b[2], c2, sum[2], c3);
FullAdder_one_gate f4(a[3], b[3], c3, sum[3], cout);
endmodule
module FullAdder_one_gate (
input a, b, cin,
output sum, cout
);
assign sum = a^b^cin;
assign cout = (a&b)|((a^b)&cin);
endmodule
RTL
(3)仿真
借用同学的视频展示效果
参考链接
第15周实验--FPGA编程入门-优快云博客Quartus-II13.1三种方式实现D触发器及时序仿真_quartusd触发器的怎么输出q非-优快云博客 FPGA——1位全加器的实现_fpga全加器代码-优快云博客https://zhuanlan.zhihu.com/c_1131528588117385216