简体   繁体   English

4位同步双递减计数器jk触发器

[英]4-bit synchronous double down counter jk flip flop

Recently, I am trying to learn digital design and Verilog HDL.最近,我正在尝试学习数字设计和 Verilog HDL。 I am currently working on flip flops.我目前正在研究人字拖。 I was trying to construct a 4-bit synchronous double countdown (down counter) with jk flip flop.我试图用 jk 触发器构建一个 4 位同步双倒计时(递减计数器)。

Ex: 1111 - 1101 - 1011 - 1001 -.. (15 - 13 - 11 -..) etc.例如:1111 - 1101 - 1011 - 1001 -.. (15 - 13 - 11 -..) 等。

While I was researching on the net, I always found synchronous down counter like 1111 - 1110 - 1101 etc.当我在网上研究时,我总是发现像 1111 - 1110 - 1101 等同步递减计数器。

How can I implement 4-bit synchronous double countdown (down counter) with jk flip flop?如何使用 jk 触发器实现 4 位同步双倒数(倒数计数器)?

First thing that comes to my mind is a FSM.我首先想到的是FSM。 What buggers me is the requirement of using JK flipflops.困扰我的是使用 JK 人字拖的要求。 Verilog can allow designs at the PMOS/NMOS level, but I'm not sure this is what you really wwant to do. Verilog 可以允许在 PMOS/NMOS 级别进行设计,但我不确定这是否是您真正想要做的。

A behavioral description of such counter is very straightforward if a FSM is implemented.如果实现了 FSM,则此类计数器的行为描述非常简单。 This one is a 3-bit double countdown.这是一个 3 位双倒计时。 I think you can easily modify it to siut your 4-bit counter.我认为您可以轻松地对其进行修改以适应您的 4 位计数器。

module countdown (
  input wire clk,
  input wire rst,
  output reg [2:0] out
  );

  initial out = 3'd7;

  always @(posedge clk or posedge rst) begin
    if (rst == 1'b1) begin
      out <= 3'd7;
    end
    else begin
      case (out)
        3'd7   : out <= 3'd5;
        3'd5   : out <= 3'd3;
        3'd3   : out <= 3'd1;
        3'd1   : out <= 3'd7;
        default: out <= 3'd7;
      endcase
    end
  end
endmodule

Of course, there is another way: using an adder.当然,还有另一种方法:使用加法器。 For 4 bits, it would be like this:对于 4 位,它将是这样的:

module countdown4b (
  input wire clk,
  input wire rst,
  output reg [3:0] out
  );

  initial out = 4'b1111;

  always @(posedge clk)
    out <= out + 4'b1110;  // -2

endmodule

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

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