System verilog 如何用4个触发器制作4位环形计数器?

System verilog 如何用4个触发器制作4位环形计数器?,system-verilog,flip-flop,System Verilog,Flip Flop,我有一个4位的环形计数器,我正试图制作它,我感觉我离它很近,但我不知道如何使一个输入依赖于前一个状态的输出。以下是我所拥有的: `default_nettype none // Empty top module module top ( // I/O ports input logic hz100, reset, input logic [20:0] pb, output logic [7:0] left, right ); // Your code goes her

我有一个4位的环形计数器,我正试图制作它,我感觉我离它很近,但我不知道如何使一个输入依赖于前一个状态的输出。以下是我所拥有的:

`default_nettype none
// Empty top module

module top (
  // I/O ports
  input  logic hz100, reset,
  input  logic [20:0] pb,
  output logic [7:0] left, right
);

  // Your code goes here...
  q[3:0];
  
  assign q[3:0] = right[3:0];
  
  hc74_set setFF(.c(pb[0]), .d(pb[1]), .q(right[0]), .sn(pb[16]));
  hc74_reset resetFF1(.c(pb[0]), .d(pb[1]), .q0(right[1]), .rn(pb[16]));
  hc74_reset resetFF2(.c(pb[0]), .d(pb[1]), .q1(right[2]), .rn(pb[16]));
  hc74_reset resetFF3(.c(pb[0]), .d(pb[1]), .q2(right[3]), .rn(pb[16]));
  
  
endmodule

// Add more modules down here...
// This is a single D flip-flop with an active-low asynchronous set (preset).
// It has no asynchronous reset because the simulator does not allow it.
// Other than the lack of a reset, it is half of a 74HC74 chip.
module hc74_set(input logic d, c, sn,
                  output logic q, qn);
  assign qn = ~q;
  always_ff @(posedge c, negedge sn)
    if (sn == 1'b0)
      q <= 1'b1;
    else
      q <= d;
endmodule

// This is a single D flip-flop with an active-low asynchronous reset (clear).
// It has no asynchronous set because the simulator does not allow it.
// Other than the lack of a set, it is half of a 74HC74 chip.

module hc74_reset(input logic d, c, rn,
                  output logic q, qn);
  assign qn = ~q;
  always_ff @(posedge c, negedge rn)
    if (rn == 1'b0)
      q <= 1'b0;
    else
      q <= d;
endmodule
`default\u nettype none
//空顶模块
模块顶部(
//I/O端口
输入逻辑hz100,复位,
输入逻辑[20:0]pb,
输出逻辑[7:0]左、右
);
//你的密码在这里。。。
q[3:0];
分配q[3:0]=右[3:0];
hc74_集偏移量(.c(pb[0]),.d(pb[1]),.q(右[0]),.sn(pb[16]);
hc74_reset resetFF1(.c(pb[0]),.d(pb[1]),.q0(右[1]),.rn(pb[16]);
hc74_reset resetFF2(.c(pb[0]),.d(pb[1]),.q1(右[2]),.rn(pb[16]);
hc74_reset resetFF3(.c(pb[0]),.d(pb[1]),.q2(右[3]),.rn(pb[16]);
端模
//在这里添加更多模块。。。
//这是一个单D触发器,带有一个有效的低异步设置(预设)。
//它没有异步重置,因为模拟器不允许它。
//除了缺少复位外,它是74HC74芯片的一半。
模块hc74_组(输入逻辑d、c、sn、,
输出逻辑q,qn);
分配qn=~q;
始终\u ff@(正边缘c、负边缘序列号)
如果(sn==1'b0)

q让我们首先确保我们在同一页上

基于维基百科对

这可按以下方式实施:

模块顶部(
//I/O端口
输入逻辑复位,
输入逻辑时钟,
输出逻辑[3:0]环
);
//你的密码在这里。。。
始终@(posedge clk或negedge重置)开始
如果(~reset\n)开始
环=4'b0001;
结束
否则开始

打电话[0]让我们先确认我们在同一页上

基于维基百科对

这可按以下方式实施:

模块顶部(
//I/O端口
输入逻辑复位,
输入逻辑时钟,
输出逻辑[3:0]环
);
//你的密码在这里。。。
始终@(posedge clk或negedge重置)开始
如果(~reset\n)开始
环=4'b0001;
结束
否则开始
环[0]