FPGA/HDLBits

Edgedetect2

장영현 2023. 6. 27. 16:20
728x90

For each bit in an 8-bit vector, detect when the input signal changes from one clock cycle to the next (detect any edge). The output bit should be set the cycle after a 0 to 1 transition occurs.

Here are some examples. For clarity, in[1] and anyedge[1] are shown separately

module top_module (
    input clk,
    input [7:0] in,
    output [7:0] anyedge
);
    wire [7:0] data;
    always @(posedge clk)begin
    	data <= in;
        anyedge <= in ~^ ~data;
    end
endmodule