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
网上的答案不太看得懂,打一拍将信号存起来很好理解,但是怎么决定存起来的信号和原信号之间的逻辑关系不太看的明白,自己想了个比较易懂的解法:
①随便画一个信号,并且画出打一拍后的信号
②根据需要要求(正边沿/双边沿)写出输出的正负值(以原始信号为准),如下图
③填充1结束后,其余位置全补上0,建立一个真值表,如图:
④根据真值表确定逻辑关系(如图为异或)
最后的代码:
module top_module (
input clk,
input [7:0] in,
output [7:0] anyedge
);
reg [7:0] mid;
always@(posedge clk)begin
mid <= in;
anyedge <= in^mid;
end
endmodule
编译通过~