【问题标题】:Problem with adding different numbers to a register in Verilog (Vivado)在 Verilog (Vivado) 中向寄存器添加不同数字的问题
【发布时间】:2021-12-24 11:39:03
【问题描述】:

我目前正在大学课堂上学习如何使用 Vivado 在 Verilog 中进行数字系统设计。我的最后一个项目是美式足球记分牌。我正在努力实现得分功能(适用于两个团队),但在将 6、3、2 和 1 分添加到总分寄存器时遇到了问题。

每个点输入都链接到一个开关。如果我移动一个开关,我想要它到哪里,它会为输出增加 6 个点(用于触地得分)。另一个开关使总分增加 3 分。以此类推2分1分。这是我目前得到的代码。现在,它只成功地将 6 个点添加到寄存器中(每次打开只添加一次)。其他的让我的七段显示器跳来跳去,看起来只要 3、2 和 1 点开关打开,它的添加速度就非常快。

得分最高为 99,因为我每个团队使用两个 7 段显示器。我有一个二进制到十进制模块和一个七段转换器模块,它们都在工作。还有一个 masterReset 输入,它将分数重置为零。重置输入有效。

module teamAPoints(
input masterReset,
input teamATouchdown,
input teamAFieldGoal,
input teamA2PtConv,
input teamAExtraPoint,
output reg [6:0] teamAScore
);


always @ (posedge masterReset or posedge teamATouchdown or posedge teamAFieldGoal or posedge teamA2PtConv or posedge teamAExtraPoint) begin
    if (masterReset) begin
        teamAScore <= 0;
    end
    else if (teamAExtraPoint) begin
        teamAScore <= teamAScore + 1;
    end
    else if (teamA2PtConv) begin
        teamAScore <= teamAScore + 2;
    end
    else if (teamAFieldGoal) begin
        teamAScore <= teamAScore + 3;
    end
    else if (teamATouchdown) begin
        teamAScore <= teamAScore + 6;
    end
end
endmodule

我希望我解释得足够好。我也试过把它变成一个有限状态机,但没有运气。我知道我正在描述 FPGA 上的硬件,而且我非常习惯于 Java 和 C 等标准编程语言。我敢打赌,这就是我的错误的根源。感谢您提供任何和所有帮助/解释。

【问题讨论】:

  • 我也使用 2 点转换输入作为安全输入,因为它们都是 2 点。我的板上只有这么多开关。我应该重命名它

标签: verilog fpga xilinx vivado


【解决方案1】:

您需要有一个寄存器才能存储任何内容。目前您正在使用电线,因此分数没有得到正确更新。您将需要设计时序电路所需的额外时钟信号。试试下面的代码。

   module teamAPoints(
     input masterReset,
     input teamATouchdown,
     input teamAFieldGoal,
     input teamA2PtConv,
     input teamAExtraPoint,
     input clk,     //Added a clock signal
     output reg [6:0] teamAScore
     );


   always @ (posedge clk or posedge masterReset) begin
      if (masterReset) begin
         teamAScore <= 0;
       end
      else if (teamAExtraPoint) begin
         teamAScore <= teamAScore + 1;
       end
     else if (teamA2PtConv) begin
        teamAScore <= teamAScore + 2;
     end
     else if (teamAFieldGoal) begin
        teamAScore <= teamAScore + 3;
     end
     else if (teamATouchdown) begin
        teamAScore <= teamAScore + 6;
     end
  end
 endmodule

在你的测试台下面添加sn-ps

`timescale 1ns/1ps  //change the timescale as per your need.
module tb();

reg clk;  //Declaration

localparam CLK_PERIOD = 10; //Add your clock period here to adjust the frequency

initial
begin
 clk = 1'd0;
end

always
 #CLK_PERIOD/2 : clk = ~clk;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    • 1970-01-01
    相关资源
    最近更新 更多