switch-statement - 案例陈述似乎不起作用
问题描述
的值oV
应该是StateToCountSequence
对应于左侧相应iState
值的右侧的值。但是,oV
似乎只有值 2 或 3,如下面的捕获所示。
有谁知道我应该怎么做?
module CounterSkipReverse(iClk, iRst, iSkip, iRev, oState);
input iClk, iRst, iSkip, iRev;
//declare oState:
output integer oState;
//declare internal wires and reg types here:
always @ (posedge iClk) begin
if (iRst == 1)
oState <= 0;
else
if (iSkip == 0 & iRev == 0) oState <= oState + 4'd1;
else if (iSkip == 1 & iRev == 0) oState <= oState + 4'd5;
else if (iSkip == 0 & iRev == 1) oState <= oState - 4'd1;
else if (iSkip == 1 & iRev == 1) oState <= oState + 4'd9;
if (oState < 0) oState <= oState + 4'd14;
if (oState > 14) oState <= oState - 4'd14;
end
endmodule
module StateToCountSequence(iState, oV);
//declare the input and output
input iState;
output reg [3:0]oV;
//declare any internal wire and reg types here.
always @ (iState) begin
case(iState)
4'd0: oV = 4'd3;
4'd1: oV = 4'd2;
4'd2: oV = 4'd4;
4'd3: oV = 4'd9;
4'd4: oV = 4'd9;
4'd5: oV = 4'd0;
4'd6: oV = 4'd7;
4'd7: oV = 4'd1;
4'd8: oV = 4'd1;
4'd9: oV = 4'd5;
4'd10: oV = 4'd1;
4'd11: oV = 4'd7;
4'd12: oV = 4'd0;
4'd13: oV = 4'd8;
4'd14: oV = 4'd9;
endcase
end
//Have you checked for inferred latches in this module?
endmodule
module CompleteCounter(iClk, iRst, iSkip, iRev, oV, oState);
input iClk, iRst, iSkip, iRev;
output [3:0] oV;
//declare oState next line
output [3:0]oState;
CounterSkipReverse cntr(.iClk(iClk), .iRst(iRst), .iSkip(iSkip), .iRev(iRev), .oState(oState));
StateToCountSequence statemap(.iState(oState), .oV(oV));
endmodule
`timescale 1ns / 1ps
module AssignmentTestBench;
//declare internal signals and instantiate module CompleteCounter.
reg iClk, iRst, iSkip, iRev;
wire [3:0]oState;
wire [3:0]oV;
initial begin
iClk = 1'b1;
iRst = 0;
iSkip = 0;
iRev = 0;
end
CompleteCounter counter(iClk, iRst, iSkip, iRev, oV, oState);
//generate test sequences for all state transitions
always begin
#5 iClk = ~iClk; //period 10 ns for clock
end
always begin // control w input and reset
#1;
// iSkip = 0, iRev = 0
#10 iRst = 1'b1;
#10 iRst = 1'b0;
#300; // 30 clock cycles
// iSkip = 1, iRev = 0
#10 iRst = 1'b1;
#10 iRst = 1'b0;
iSkip = 1'b1;
#80;
// iSkip = 1, iRev = 1
#10 iRst = 1'b1;
#10 iRst = 1'b0;
iRev = 1'b1;
#40;
// iSkip = 0, iRev = 1
#10 iRst = 1'b1;
#10 iRst = 1'b0;
iSkip = 1'b0;
#150;
$display("Finished test");
$finish; // remove for modelsim
$stop;
end
endmodule
解决方案
该信号iState
是 中的 1 位信号StateToCountSequence
,这意味着它只能取已知值 0 和 1。因此,您只能设置oV
为 3 和 2。
改变:
input iState;
到:
input [3:0] iState;
推荐阅读
- .net - WCF 性能下降
- pip - 如何使 cython 成为 pip 安装的要求?
- php - 在 Laravel 中显示我想删除的多对多关系的数据时出现问题
- assembly - 如何多次打印 .bmp 图像?
- javascript - 在reduce方法中用momentjs计算小时的差异
- python - 将股票的符号名称写入数据库
- elasticsearch - Elasticsearch 搜索结果相关性问题
- c++ - 虚拟文件系统是这个应用程序的正确概念吗
- html - 用元素循环头数组
- mysql - MySQL Workbench,如何修复“SELECT is not valid at this position for this server version”错误