嵌入式作业十五(FPAG入门)

本文介绍了Verilog编程的基础,包括门电路(与门、或非门、同或门)、组合电路(如7458和7420逻辑门)以及时序电路(D触发器和DFF电路)。此外,还涉及了Logisim软件中的全加器仿真和Quartus实验中的一位和四位全加器实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、Verilog编程入门学习

1、门电路

2、组合电路

3、时序电路

二、Logisim仿真

1、一位全加器

2、四位全加器

三、Quartus实验仿真

1、一位全加器

2、四位全加器


一、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 触发器是“组合逻辑的斑点,然后是触发器”的最简单形式,其中组合逻辑部分只是一根电线。

Dff.png

代码

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值