【发布时间】:2022-01-18 02:15:13
【问题描述】:
我正在尝试为 RISC 处理器创建程序计数器,但我不确定为什么测试台没有按预期工作。测试台的编写方式可能有问题,但我似乎找不到。在测试台的模拟中,计数器值似乎没有像预期的那样增加一。任何帮助将不胜感激。
module ProgramCounter
// identify inputs and outputs, define if the input/output is signed.
(
input Clock,
input logic Reset,
input logic [15:0] LoadValue,
input logic LoadEnable,
input logic signed [8:0] Offset,
input logic OffsetEnable,
output logic signed [15:0] CounterValue
);
// Clock, Reset, LoadEnable and OffsetEnable triggered at positive edge of clock.
always_ff@(posedge Clock)
begin
if (Reset) CounterValue <= '0; //if reset is TRUE, CounterValue is zero.
else if (LoadEnable) CounterValue <= LoadValue; //if LoadEnable is TRUE, CounterValue is equal to LoadValue.
else if (OffsetEnable) CounterValue <= CounterValue + Offset;//if OffsetEnableEnable is TRUE, CounterValue is CounterValue plus Offset.
else CounterValue <= CounterValue + 1;//otherwise, CounterValue increases with the clock.
end
endmodule
// ProgramCounterTestBench
//
//
// This module implements a testbench for
// the Program Counter
//
module ProgramCounterTestBench();
// These are the signals that connect to
// the program counter
logic Clock = '0;
logic Reset;
logic signed [15:0] LoadValue;
logic LoadEnable;
logic signed [8:0] Offset;
logic OffsetEnable;
logic signed [15:0] CounterValue;
// this is another method to create an instantiation
// of the program counter
ProgramCounter uut
(
.Clock,
.Reset,
.LoadValue,
.LoadEnable,
.Offset,
.OffsetEnable,
.CounterValue
);
default clocking @(posedge Clock);
endclocking
always #10 Clock++;
initial
begin
Reset = 0;
LoadEnable = 0;
OffsetEnable = 0;
LoadValue = 16'b0000000000000000;
Offset = 9'b000000000;
CounterValue = 16'b0000000000000010;
#60
#10 Reset = 0;
LoadEnable = 1;
LoadValue = 16'b0101010101010101;
#10 Reset = 1;
LoadEnable = 0;
OffsetEnable = 0;
LoadValue = 16'b0101010101010101;
Offset = 9'b000000000;
#10 Reset = 0;
LoadEnable = 1;
OffsetEnable = 0;
LoadValue = 16'b0101010101010101;
Offset = 9'b000000000;
#10 Reset = 0;
LoadEnable = 0;
OffsetEnable = 0;
#10 Reset = 0;
LoadEnable = 0;
OffsetEnable = 1;
LoadValue = 16'b0101010101010101;
Offset = 9'b101000000;
end
endmodule
【问题讨论】:
标签: verilog test-bench