4.Circuits---Sequential Logic---Latches and Flip-Flops----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).
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.
对于 32 位向量中的每一位,当输入信号在一个时钟周期内从 1 变为下一个时钟周期内的 0 时进行捕获。 “捕获”表示输出将保持为 1,直到寄存器被复位(同步复位)。
每个输出位的行为类似于 SR 触发器:输出位应在 1 到 0 转换发生后的周期设置(为 1)。 当复位为高电平时,输出位应在正时钟沿复位(至 0)。 如果以上两个事件同时发生,则重置优先。 在下面示例波形的最后 4 个周期中,“重置”事件比“设置”事件早一个周期发生,因此此处不存在冲突。
在下面的示例波形中,为清楚起见,再次单独显示了复位、in[1] 和 out[1]。
问题分析:
分析方法同习题记录3,不过此题多了一个捕获保持功能,若无重置的情况下,输出取决于是否有下降沿,有下降沿则输出1,无下降沿则输出保持上一个状态(out)。观察逻辑关系易得:
因此out<=(~new_in&pre_in) | out;
这很容易理解:如:
代码解析:
module top_module ( input clk, input reset, input [31:0] in, output [31:0] out ); reg [31:0]temp; always@(posedge clk) temp<=in; always@(posedge clk) begin if(reset==1) out=32'd0; else out<=(~in&temp) |out; end endmodule
标签:reset,输出,--,Verilog,input,output,习题,bit,out From: https://www.cnblogs.com/yphasaki/p/17015418.html