简体   繁体   English

如何从Verilog的可变长度输入信号中得出固定长度输出信号

[英]How to derive a Fixed Length Output signal from a variable length Input signal in verilog

I have an HDL Block in which the output follows the input in such a way that when input signal is binary 0, output remains 0 but when input turns 1, output turns 1 for a preset number of clock cycles (signal_length). 我有一个HDL模块,其中输出跟随输入,这样,当输入信号为二进制0时,输出保持为0,但是当输入变为1时,输出变为1达到预设的时钟周期数(signal_length)。 ie input may remain high for suppose 65 or 66 clock cycles but output should remain high for preset number of clock cycles. 也就是说,输入可能会在假设65个或66个时钟周期内保持高电平,但输出应在预设数量的时钟周期内保持高电平。 I tried to accomplish the task with Verilog. 我试图用Verilog完成任务。 But I am having an error and I don't know how to rectify. 但是我有一个错误,我不知道如何纠正。 Hope someone can help. 希望有人能帮忙。

module last_ind
#(
parameter MAX_LENGTH = 262144,
parameter signal_length
)
(
   input           clk,      
   input [17:0] pkt_length,
   input           tdata,
   output          tlast
);
reg [17:0] cnt = 0;

always @ (posedge clk)
begin
if ((tdata==1) && (cnt<signal_length)) 
        tlast <= 1;
 else
        cnt <= 0;
 end
 assign   cnt <= cnt + 1'b1;
 endmodule

maybe something like this will do. 也许这样的事情会做。 It should keep the signal up for the signal_length cycles and will reset when tdata gets '0'. 它应在signal_length周期内保持信号上升,并在tdata为0时复位。 You decide on the correct protocol though. 不过,您可以决定正确的协议。

 reg [17:0]      cnt = signal_length;

 always @ (posedge clk) begin
    if (cnt < signal_lenth)
      cnt <= cnt + 1;
    else if (cnt == signal_length + 1 && tdata == 1 && tlast == 0) begin
      cnt <= 0;
      tlast <= 1;
    end
    else if (tdata == 0) begin 
       cnt <= sighal_length + 1;
       tlast <= 0;
    end
    else
       tlast <= 0;
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM