HDLBits Edgecapture

HDLBits Edgecapture

网址:https://hdlbits.01xz.net/wiki/Edgecapture

For each bit in a 32-bit vector, capture when the input signal changes from 1 in one clock cycle to 0 the next. “Capture” means that the output will remain 1 until the register is reset (synchronous reset).

Each output bit behaves like a SR flip-flop: The output bit should be set (to 1) the cycle after a 1 to 0 transition occurs. The output bit should be reset (to 0) at the positive clock edge when reset is high. If both of the above events occur at the same time, reset has precedence. In the last 4 cycles of the example waveform below, the ‘reset’ event occurs one cycle earlier than the ‘set’ event, so there is no conflict here.

In the example waveform below, reset, in[1] and out[1] are shown again separately for clarity.

题目意思就是捕捉in的下降沿,只有在in从1->0变化时out会输出1,其他情况out不会改变。

in_p为in的前一个时钟周期状态,可用D触发器实现。

对应的状态关系为:

in_pinout
00out
01out
101
11out

由上表可得out与in_p和in的表达式:out[i]<=(in_p[i]&in[i])?1:out[i];

module top_module(
	input clk,
    input reset,
    input [31:0] in,
    output [31:0] out
);
    wire [31:0] in_p;
    int i;
    always @(posedge clk) begin
    	in_p<=in;
    end
    always @(posedge clk) begin
        if(reset) out<=32'b0;
        else 
            for(i=0;i<32;i=i+1) 
                out[i]<=(in_p[i]&~in[i])?1:out[i];
        
    end
endmodule
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值