【发布时间】:2014-05-27 19:08:01
【问题描述】:
当我通过模拟器运行我的模块时,我的输出始终都是 x。
这是我的代码:
module state_machine(
input clk_i,
input reset_n,
input LB,
input RB,
output reg [3:0] outputs
);
reg [3:0] state;
reg [3:0] state_n;
parameter FW = 4'b0101;
parameter BWL = 4'b0000;
parameter BWR = 4'b0000;
parameter SL = 4'b0001;
parameter SR = 4'b0100;
always @ (posedge clk_i, negedge reset_n)
begin
if(!reset_n)
state <= FW;
else
state <= state_n;
end
always @ (*)
begin
case(state)
FW: begin
if(!RB)
state_n = BWR;
else if(!LB)
state_n = BWL;
end
BWL: state_n = SL;
BWR: state_n = SR;
SL: state_n = FW;
SR: state_n = FW;
default: state_n = FW;
endcase
end
always @ (*)
begin
outputs = state;
end
endmodule
clk_i 输入是使用计数器方法制作的慢速时钟,此处为:
module clock_counter(
input clk_i,
input reset_n,
output reg clk_o
);
reg [19:0] count;
always @ (posedge clk_i, negedge reset_n)
begin
count <= count + 1;
if(!reset_n)
begin
clk_o <= 0;
count <= 0;
end
else if(count >= 1039999)
begin
clk_o <= ~clk_o;
count <= 0;
end
end
endmodule
它们都由仅执行此操作的顶级模块实例化。我没有收到任何错误,但我确实收到了一些关于某些我不认识的东西被卡在零的警告。
谁能看出哪里出了问题?
这是我的测试平台代码:
`timescale 1 ns / 1 ns
// Define Module for Test Fixture
module top_module_tf();
// Inputs
reg reset_n;
reg LB;
reg RB;
// Outputs
wire [3:0] outputs;
// Bidirs
// Instantiate the UUT
// Please check and add your parameters manually
top_module UUT (
.reset_n(reset_n),
.LB(LB),
.RB(RB),
.outputs(outputs)
);
// Initialize Inputs
// You can add your stimulus here
initial begin
reset_n = 1; LB = 1; RB = 0;
#500000000 reset_n = 1; LB = 1; RB = 1;
end
endmodule // top_module_tf
【问题讨论】: