如何创建可合成的延迟?

时间:2016-03-05 06:58:55

标签: verilog quartus

我得到了如下代码,clk =#10~clk

    always@ (posedge clk)begin
    for (g=0;g<8;g=g+1) begin
    ws = 1;
    #20
    ws = 0;
    #20;
    end

有没有其他方法可以使延迟20在上面的编码中合成?

2 个答案:

答案 0 :(得分:0)

触发器是合成延迟的唯一方法:

always @(posedge clk)
  q <= d;

使用clk = #10 ~clk;q将比#10d

答案 1 :(得分:0)

问题似乎不是如何合成#20,而是如何控制信号进入RAM的时序。数字设计基于时钟边缘,每个正边沿或负边沿设定距离为一部分,这是时钟周期或1 /频率。

要按照您的描述对事件进行排序,您需要一个FSM(有限状态机)来控制或排序它。我在下面列出了一个小例子:

EDA Playground

上提供
module tb;

  //Tb component
  reg clk;
  reg rst_n;
  initial begin :clk_and_reset
    clk = 0;
    rst_n = 0;
    #40 rst_n = 1;
    #40;
    forever begin
      #20 clk = ~clk;
    end
  end

  //Design
  reg [1:0] state;
  reg [1:0] next_state;
  reg [31:0] counter;
  reg ws;

  localparam S_IDLE = 'd0;
  localparam S_WAIT = 'd1;
  localparam S_OFF  = 'd2;

  always @(posedge clk, negedge rst_n) begin
    if (~rst_n) begin
      state <= S_IDLE;
    end
    else begin
      case(state)
        S_IDLE : begin
          state   <= S_WAIT;
          counter <= 'b0;
        S_WAIT : 
          if (counter < 32'd10) begin
            state   <= S_WAIT;  //Wait for 10 clock cycles
            counter <= counter + 1;
          end
          else begin
            state   <= S_OFF;
            counter <= 'b0;
          end
        S_OFF :  state <= S_IDLE;
     default  :  state <= S_IDLE; //IDLE 
    end
  end


  //Output decode based on state
  always @* begin
    //ws goes high when in Wait state
    ws = (state == S_WAIT);
  end


  //Test program
  initial begin
    repeat (10) begin
      @(posedge clk);
      $display("%4t : State %b: ws :%b", $realtime, state, ws);
    end
    $finish();
  end


endmodule

这可以通过保持空闲直到触发然后通过使用计数器并等待x个时钟,x个时钟关闭然后再回到空闲并等待再次触发来扩展。

更新

我已更新代码示例以保持 WAIT 状态10个时钟周期,以演示如何控制转换之间的延迟。