HDLBits刷题Day10,3.2.1.7 D Latch - 3.2.1.13 DFFs and gates

3.2.1.7 D Latch

问题描述

实现以下电路:

请注意,这是一个锁存器,因此预计会出现关于已推断锁存器的 Quartus 警告。锁存器是电平敏感(非边沿敏感)电路,因此在一个始终块中,它们使用电平敏感灵敏度列表。但是,它们仍然是顺序元素,因此应该使用非阻塞赋值,D 锁存器在启用时就像一条线,在禁用时保留当前值。

 代码:

module top_module (
    input d, 
    input ena,
    output q);
    always @(*)
        begin
            if(ena)
                q <= d;
        end
endmodule
3.2.1.8 DFF

 问题描述

代码:

module top_module (
    input clk,
    input d, 
    input ar,  //异步复位
    output q);
    always @(posedge clk or posedge ar)
        begin
            if(ar)
                q <= 1'b0;
            else
                q <= d;
        end
endmodule
3.2.1.9 DFF

 问题描述

 

代码:

module top_module (
    input clk,
    input d, 
    input r,   // 同步复位
    output q);
    always @(posedge clk)
        begin
            if(!r)
                q <= d;
            else
                q <= 1'b0;
        end
endmodule
3.2.1.10 DFF+gate

问题描述

代码:

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

 

3.2.1.11 Mux and DFF

问题描述

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

代码:

module top_module (
	input clk,
	input L,
	input r_in,
	input q_in,
	output reg Q);
	// 要编写的是子模块的module
    always @(posedge clk) begin
        Q<=L?r_in:q_in;
    end
endmodule
3.2.1.12 Mux and DFF

问题描述

考虑如下所示的n位移位寄存器电路,为该电路的一个阶段编写一个名为 top_module 的 Verilog 模块,包括触发器和多路复用器。 

代码:

module top_module (
    input clk,
    input w, R, E, L,
    output Q
);
    always @(posedge clk) begin
        Q<=L? R:(E?w:Q);
    end
endmodule
3.2.1.13 DFFs and gates

问题描述

给定如图所示的有限状态机电路,假设 D 触发器在机器开始之前初始复位为零,建立这个电路。小心复位状态。确保每个 D 触发器的Q非·输出确实是其 Q 输出的倒数,即使在模拟的第一个时钟沿之前也是如此。 

代码:

module top_module (
    input clk,
    input x,
    output z
); 
reg q1,q2,q3;
    always @(posedge clk) begin
            q1 <= x^q1;
            q2 <= x&(~q2);
            q3 <= x|(~q3);
    end
    assign z = ~(q1|q2|q3);
endmodule

 

  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值