【HDLBits刷题】Dualedge..

60 篇文章 17 订阅
20 篇文章 4 订阅

You're familiar with flip-flops that are triggered on the positive edge of the clock, or negative edge of the clock. A dual-edge triggered flip-flop is triggered on both edges of the clock. However, FPGAs don't have dual-edge triggered flip-flops, and always @(posedge clk or negedge clk) is not accepted as a legal sensitivity list.

Build a circuit that functionally behaves like a dual-edge triggered flip-flop:

 

(Note: It's not necessarily perfectly equivalent: The output of flip-flops have no glitches, but a larger combinational circuit that emulates this behaviour might. But we'll ignore this detail here.)

我们现在对时钟上升沿与下降沿都已经很熟悉了。但是FPGA没有一个同时检测双边沿的触发器,而且always中的敏感列表也不支持(posedge clk or negedge clk)。

设计一个双边沿检测的触发器,时序如下图所示:

Module Declaration

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

本题有两中解题思路,一种是用MUX,一种是用XOR

MUX代码如下:

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

    reg q1, q2;

    //这里来实现clk的上升沿与下降沿
    assign q = clk?q1:q2;

    always @ (posedge clk)
        begin
            q1 <= d;
        end

    always @ (negedge clk)
        begin
           q2 <= d; 
        end

endmodule

XOR代码如下:

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

    reg p, n;

    // clk的上升沿
    always @(posedge clk)
        p <= d ^ n;

    // clk的下降沿
    always @(negedge clk)
        n <= d ^ p;

    //在上升沿时候,p=d^n, 则q=d^n^n=d;
    //在下降沿时候,n=d^p, 则q=p^d^p=d;
    //加载一个新值时会取消旧值。
    assign q = p ^ n;


    // 这样写是无法综合的
    /*always @(posedge clk, negedge clk) begin
        q <= d;
    end*/


endmodule

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值