简体   繁体   English

结构性Verilog计数器初始化

[英]Structural Verilog Counter Initialization

So I'm a newcomer to verilog and am trying to make a counter using structural verilog. 因此,我是verilog的新手,并正在尝试使用结构性verilog进行反制。 The counter is made of 4 D-type flip flops. 该计数器由4个D型触发器组成。
The functionality of the flip flops has been verified so that's not the problem. 触发器的功能已经过验证,因此不是问题。

The problem I'm finding is that when beginning the simulation, the wire l1 (linking d to q_bar) is undefined. 我发现的问题是,开始仿真时,导线l1(将d链接到q_bar)未定义。
This can be solved by resetting the flip flop and giving q_bar a defined value. 这可以通过重置触发器并为q_bar定义一个值来解决。
However, when it comes to FF1, the reset does not work since it is a synchronous reset and there is no rising clock edge when the reset is high. 但是,当涉及到FF1时,由于它是同步复位,并且复位为高电平时,没有上升时钟沿,因此该复位不起作用。

So my question is, 所以我的问题是

How can I reset the flip-flops, or even better is there any way of initializing the output of the flip flop? 如何重置触发器,或者更好的方法是初始化触发器的输出?

This is my code: 这是我的代码:

module sr_latch(q, q_bar, r, s);
   output q;
   output q_bar;
   input  s;
   input  r;

   nor #1(q_bar, s, q);
   nor #1(q, r, q_bar);
endmodule 


module d_latch(clk,q,q_bar,d);
  output q, q_bar;
  input clk,d;
  wire d_bar,r,s;

  sr_latch A(q, q_bar, r, s);

  not (d_bar, d);
  and (s, d, clk);
  and (r, d_bar, clk);

endmodule


module d_type_ff (clk, d, q, q_bar);
  output q, q_bar;
  input clk, d;
  wire d1, d2, clk_bar;

  d_latch Master(clk_bar, d1, d2, d);
  d_latch Slave(clk, q, q_bar, d1);

  not(clk_bar, clk);

endmodule

module d_type_ff_rst (clk, d, q, q_bar, reset);
    output q;
    output q_bar;
    input clk, d, reset;
    wire d_in, rst_bar;

    d_type_ff A(clk, d_in, q, q_bar);

    not(rst_bar, reset);
    and(d_in, rst_bar, d);

endmodule

module counter_S (clk, reset, enable, count);
  input clk, reset, enable;
  output  [3:0] count;       //MSB count[3]
                            //LSB count[0]
  wire l1, l2, l3, l4;

  d_type_ff_rst FF0 (clk, l1, count[0], l1, reset);
  d_type_ff_rst FF1 (l1, l2, count[1], l2, reset);
  d_type_ff_rst FF2 (l2, l3, count[2], l3, reset);
  d_type_ff_rst FF3 (l3, l4, count[3], l4, reset);


endmodule

And the testbench 和测试台

module counter_tm();
wire [3:0] count;
reg clk, reset, enable;


counter_S DUT(clk, reset, enable, count);

 always #10 clk <= ~clk;


initial
begin

  clk <= 1'b0;
  reset = 1'b1;
  enable = 1'b1;

  #10
  reset = 1'b0;


end
endmodule

You change reset coincident with the edge of the clock. 您更改与时钟边缘一致的重置。 You need to hold reset active a little longer. 您需要将重置活动保持一段时间。

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

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