HDLBits练习汇总-10-时序逻辑设计测试--锁存器和触发器(一)

简介: HDLBits练习汇总-10-时序逻辑设计测试--锁存器和触发器

D触发器


创建单个 D 触发器。

image.png

D触发器是一种存储位并在时钟信号(通常)正沿处定期更新的电路。D 触发器在使用时钟始终块时由逻辑合成器创建。AD触发器是“组合逻辑块后跟触发器”的最简单形式,其中组合逻辑部分只是一条线。

Module Declaration

module top_module (
    input clk,    // Clocks are used in sequential circuits
    input d,
    output reg q );

答案:

module top_module (
    input clk,    // Clocks are used in sequential circuits
    input d,
    output reg q );//
    always @(posedge clk)begin
        q <= d ;
    end
endmodule

8个 D触发器


创建 8 个 D 触发器。所有 DFF 都应由clk 的上升沿触发。

Module Declaration

module top_module (
    input clk,
    input [7:0] d,
    output [7:0] q
);

答案:

module top_module (
    input clk,
    input [7:0] d,
    output [7:0] q
);
  always @(posedge clk)begin
        q <= d ;
    end
endmodule

8个带同步复位的D触发器


创建具有高电平有效同步复位的 8 个 D 触发器。所有 DFF 都应由clk 的上升沿触发。

Module Declaration

module top_module (
    input clk,
    input reset,            // Synchronous reset
    input [7:0] d,
    output [7:0] q
);

答案:

module top_module (
    input clk,
    input reset,            // Synchronous reset
    input [7:0] d,
    output [7:0] q
);
  always @(posedge clk)begin
        if(reset == 1)
            q <= 0 ;
        else
          q <= d ;
    end
endmodule

8个带复位值的D触发器


创建具有高电平有效同步复位的 8 个 D 触发器。触发器必须重置为 0x34 而不是零。所有的DFF应由被触发负的边缘CLK。

Module Declaration

module top_module (
    input clk,
    input reset,            // Synchronous reset
    input [7:0] d,
    output [7:0] q
);

答案:

module top_module (
    input clk,
    input reset,
    input [7:0] d,
    output [7:0] q
);
    always @(negedge clk)begin
        if(reset == 1)
            q <= 8'h34;
        else
          q <= d ;
    end
endmodule

8个带异步复位的D触发器


创建具有高电平有效异步复位的 8 个 D 触发器。所有 DFF 都应由clk 的上升沿触发。

Module Declaration

module top_module (
    input clk,
    input areset,   // active high asynchronous reset
    input [7:0] d,
    output [7:0] q
);

答案:

module top_module (
    input clk,
    input areset,   // active high asynchronous reset
    input [7:0] d,
    output [7:0] q
);
    always @(posedge clk or posedge areset)begin
        if(areset == 1)
            q <= 8'h00;
        else
          q <= d ;
    end
endmodule

16 个 D 触发器


创建 16 个 D 触发器。有时只修改一组触发器的一部分很有用。字节使能输入控制是否应在该周期写入 16 个寄存器的每个字节。byteena[1]控制高字节d[15:8],而byteena[0]控制低字节d[7:0]。

resetn是一个同步的、低电平有效的复位。

所有 DFF 都应由clk 的上升沿触发。

Module Declaration

module top_module (
    input clk,
    input resetn,
    input [1:0] byteena,
    input [15:0] d,
    output [15:0] q
);

答案:

module top_module (
    input clk,
    input resetn,
    input [1:0] byteena,
    input [15:0] d,
    output [15:0] q
);
    always @(posedge clk)begin
        if(resetn == 0)
            q <= 8'h00;
        else if(byteena [1] ==1 && byteena [0] ==1)
            q <= d;
        else if(byteena [1] ==1)
            q[15:8]<= d[15:8];
        else if(byteena [0] ==1)
            q[7:0]<= d[7:0];
        else 
            q <= q;
    end
endmodule

D 锁存器


实现以下电路:

image.png

请注意,这是一个闩锁,因此预计会出现有关推断闩锁的 Quartus 警告。

Module Declaration

module top_module (
    input d, 
    input ena,
    output q);

答案:

module top_module (
    input d, 
    input ena,
    output q);
  always @(ena)begin
        if(ena == 1)
          q = d ;
    end
endmodule

DFF


实现以下电路:

image.png

Module Declaration

module top_module (
    input clk,
    input d, 
    input ar,   // asynchronous reset
    output q);

答案:

module top_module (
    input clk,
    input d, 
    input ar,   // asynchronous reset
    output q);
    always @(posedge clk or posedge ar)begin
        if(ar == 1)begin
           q<=0;    
        end
        else begin
           q<=d; 
        end
    end
endmodule

DFF1


实现以下电路:

image.png

Module Declaration

module top_module (
    input clk,
    input d, 
    input r,   // synchronous reset
    output q);

答案:

module top_module (
    input clk,
    input d, 
    input r,   // synchronous reset
    output q);
  always @(posedge clk)begin
        if(r == 1)begin
           q<=0;    
        end
        else begin
           q<=d; 
        end
    end
endmodule

DFF+gate


Module Declaration

module top_module (
    input clk,
    input in, 
    output out);

答案:

module top_module (
    input clk,
    input in, 
    output out);
  always @(posedge clk)begin
      out<=in^out; 
    end
endmodule

MAX and DFF


考虑下面的时序电路:

image.png

假设您要为该电路实现分层 Verilog 代码,使用其中包含触发器和多路复用器的子模块的三个实例。为此子模块编写一个名为top_module的 Verilog 模块(包含一个触发器和多路复用器)。

Module Declaration

module top_module (
  input clk,
  input L,
  input r_in,
  input q_in,
  output reg Q);

答案:

module top_module (
  input clk,
  input L,
  input r_in,
  input q_in,
  output reg Q);
    always @(posedge clk)begin
        if(L==0)begin
            Q <= q_in;
        end
        else begin
           Q <= r_in; 
        end
    end
endmodule

MAX and DFF1


考虑如下所示的n位移位寄存器电路:

image.png

为该电路的一个阶段编写一个名为 top_module 的 Verilog 模块,包括触发器和多路复用器。

Module Declaration

module top_module (
    input clk,
    input w, R, E, L,
    output Q
);

答案:

module top_module (
    input clk,
    input w, R, E, L,
    output Q
);
    wire E_in = (E==1)?w:Q;
    always @(posedge clk)begin
        if(L==1)begin
            Q <= R;
        end
        else begin
            Q <= E_in;
        end
    end
endmodule

DFF and gates


给定如图所示的有限状态机电路,假设 D 触发器在机器启动之前初始复位为零。

建立这个电路。

image.png

Module Declaration

module top_module (
    input clk,
    input x,
    output z
); 

答案:

module top_module (
    input clk,
    input x,
    output z
); 
    assign z = !(Q0|Q1|Q2);
    reg Q0;
    always @(posedge clk)begin
      Q0 <= x^Q0;
    end
    reg Q1;
    always @(posedge clk)begin
      Q1 <= x&!Q1;
    end
    reg Q2;
    always @(posedge clk)begin
      Q2 <= x|!Q2;
    end
endmodule


目录
相关文章
|
3月前
|
存储 缓存 网络协议
dpdk课程学习之练习笔记二(arp, udp协议api测试)
dpdk课程学习之练习笔记二(arp, udp协议api测试)
132 0
|
11月前
|
SQL 安全 网络安全
交易所开发测试版丨交易所系统开发规则玩法/架构设计/项目步骤/方案逻辑/案例解析/源码部署
The development process of the exchange system involves multiple steps and links. The following is the detailed process and steps for the development of the exchange system:
|
26天前
|
测试技术
详解单元测试问题之@InjectMocks注解的执行逻辑如何解决
详解单元测试问题之@InjectMocks注解的执行逻辑如何解决
15 1
|
1月前
|
测试技术 UED
软件测试的科学与艺术:从数据导向到逻辑严密的实践
本文旨在探讨软件测试领域中数据导向和逻辑严密性的重要性,并分析如何通过科学严谨的方法提升测试效率和质量。文章首先概述了软件测试的基本概念和挑战,随后深入讨论了数据在测试设计和结果分析中的关键作用,以及如何利用逻辑推理来构建有效的测试案例和识别潜在缺陷。最后,本文提出了一系列实践建议,旨在帮助测试人员更好地整合数据驱动和逻辑推理方法,以实现软件测试的最优化。
18 0
|
1月前
|
Java jenkins 持续交付
Jenkins是开源CI/CD工具,用于自动化Java项目构建、测试和部署。通过配置源码管理、构建触发器、执行Maven目标,实现代码提交即触发构建和测试
【7月更文挑战第1天】Jenkins是开源CI/CD工具,用于自动化Java项目构建、测试和部署。通过配置源码管理、构建触发器、执行Maven目标,实现代码提交即触发构建和测试。成功后,Jenkins执行部署任务,发布到服务器或云环境。使用Jenkins能提升效率,保证软件质量,加速上线,并需维护其稳定运行。
83 0
|
2月前
|
SQL 存储 关系型数据库
MySQL的触发器创建与使用——使用Baidu Comate生成与触发测试完整过程
MySQL的触发器创建与使用——使用Baidu Comate生成与触发测试完整过程
22 0
|
2月前
|
存储
数字逻辑与模拟电子技术-部分知识点(4)——数电部分-组合电路的一般分析和设计方法、三人和四人表决器的设计、SR触发器、D触发器、JK触发器
数字逻辑与模拟电子技术-部分知识点(4)——数电部分-组合电路的一般分析和设计方法、三人和四人表决器的设计、SR触发器、D触发器、JK触发器
57 0
|
3月前
|
缓存 监控 网络协议
dpdk课程学习之练习笔记五(kni理解及测试)
dpdk课程学习之练习笔记五(kni理解及测试)
181 0
|
3月前
|
存储
存地址实现组包逻辑的一个测试代码。
存地址实现组包逻辑的一个测试代码。
29 0
|
12月前
|
测试技术 编译器
软件测试用例经典方法 | 逻辑覆盖测试法及案例
逻辑覆盖测试法是常用的一类白盒测试方法,其以程序内部逻辑结构为基础,通过对程序逻辑结构的遍历来实现程序测试的覆盖。逻辑覆盖测试法要求测试人员对程序的逻辑结构有清晰的了解。 逻辑覆盖测试法是一系列测试过程的总称,是使测试过程逐渐进行越来越完整的通路测试。从覆盖源程序语句的详尽程度,可以将其分为语句覆盖、判定覆盖、条件覆盖、判断/条件覆盖、条件组合覆盖和路径覆盖等。接下来将通过下面程序的逻辑覆盖测试用例一一介绍这些覆盖准则,该程序的流程图如图4-1所示,其中,a、b、c、d、e是控制流上的若干程序点。
354 0
软件测试用例经典方法 | 逻辑覆盖测试法及案例

热门文章

最新文章