HDLBits-Edge capture register

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).对于32位矢量中的每个位,当输入信号在一个时钟周期内从1变为下一个时钟周期的0时,就可以捕获。"捕获 "意味着输出将保持1,直到寄存器被复位(同步复位)。

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.每个输出位的行为就像一个SR触发器:在1到0转换发生后的周期,输出位应该被设置(到1)。当复位为高电平时,输出位应在正的时钟边沿复位(至0)。如果上述两个事件同时发生,复位优先。在下面的示例波形的最后4个周期中,"复位 "事件比 "设置 "事件早发生一个周期,所以这里没有冲突。

In the example waveform below, reset, in[1] and out[1] are shown again separately for clarity.在下面的示例波形中,复位、in[1]和out[1]又分别显示,以示清晰。

输入为32位的数据,捕获每一位的下降沿,如果检测到下降沿,输出中对应的位置高且保持直到检测到reset为高;如果某一个时钟上升沿同时检测到输入数据位的下降沿和reset为高,则reset优先,即输出为低。

module top_module (
    input clk,
    input reset,
    input [31:0] in,
    output [31:0] out
);
    reg [31:0] r_in;
    always @ (posedge clk)
        begin 
            r_in <= in;
            if(reset)
                out <= 0;
            else
                for(int i = 0; i <=31; i ++)
                    begin 
                        if(~in[i] & r_in[i])
                            out[i] <= 1;
                        else
                            out[i] <= out[i];
                    end
        end            
            
endmodule

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

无牙大白鲨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值