[HDLBits] 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.

复制代码
module top_module (
    input clk,
    input reset,
    input [31:0] in,
    output [31:0] out
);
    reg [31:0] old;
    always@(posedge clk) old<=in;
    always@(posedge clk) begin
        if(reset)
            out<=32'b0;
        else
            out<=old&(~in)|out;
        //这里需要或上一个out才能保持
    end
endmodule
相关推荐
daxi15019 小时前
Verilog入门实战——第5讲:Testbench 仿真编写 + 波形查看与分析
fpga开发
FPGA的花路1 天前
UDP协议
fpga开发·以太网·udp协议
简简单单做算法1 天前
【第2章>第2节】基于FPGA的图像双线性插值实现——理论分析与MATLAB仿真
matlab·fpga·图像双线性插值
LCMICRO-133108477461 天前
长芯微LPS123完全P2P替代ADP123,高性能、低压差的线性稳压器
单片机·嵌入式硬件·fpga开发·硬件工程·dsp开发·线性稳压器
fei_sun1 天前
面经、笔试(持续更新中)
fpga开发·面试
xixixi777771 天前
通信领域的“中国速度”:从5G-A到6G,从地面到星空
人工智能·5g·安全·ai·fpga开发·多模态
Nobody332 天前
Verilog always语句详解:从组合逻辑到时序逻辑
fpga开发
李嘉图Ricado2 天前
FPGA 时序约束与分析
fpga开发
白又白、2 天前
时序优化和上板调试小结
fpga开发
Z22ZHaoGGGG2 天前
verilog实现采样电流有效值的计算
fpga开发