|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
时钟上升沿到来时,data左移,同时data最高位赋给x,同样在该上升沿到来时,进入状态判断,第一个x=1时应该进入状态A(001),为什么modelsim仿真波形图显示x=1下一周期才变为状态A,感觉状态(state)的输出滞后一个周期,希望大神帮忙看看哪里出了问题,或者解释一下是什么原因?谢谢(附代码和仿真结果图)
- //模块代码a
- module seqdet(clk,rst,x,state,z);
- input clk,rst,x;
- output [2:0] state;
- output z;
- reg [2:0] state;
- wire z;
-
- parameter IDLE='d0,A='d1,B='d2,C='d3,D='d4,E='d5,F='d6,G='d7;
-
- assign z=(state==E&&x==0)?1:0;
-
- always @(posedge clk)
- if(!rst)
- begin
- state<=IDLE;
- end
- else
- casex(state)
- IDLE:if(x==1)
- begin
- state<=A;
- end
- A: if(x==0)
- begin
- state<=B;
- end
- B: if(x==0)
- begin
- state<=C;
- end
- else
- begin
- state<=F;
- end
- C: if(x==1)
- begin
- state<=D;
- end
- else
- begin
- state<=G;
- end
- D: if(x==0)
- begin
- state<=E;
- end
- else
- begin
- state<=A;
- end
- E: if(x==0)
- begin
- state<=C;
- end
- else
- begin
- state<=A;
- end
- F: if(x==1)
- begin
- state<=A;
- end
- else
- begin
- state<=B;
- end
- G: if(x==1)
- begin
- state<=F;
- end
- default: state<=IDLE;
- endcase
-
-
- endmodule
- module seqdet_test;
- // Inputs
- reg clk;
- reg rst;
- reg [23:0] data;
- // Outputs
- wire [2:0] state;
- wire z,x;
-
- always #10 clk=~clk;
-
- always @(posedge clk)
- data={data[22:0],data[23]};
-
- assign x=data[23];
- // Instantiate the Unit Under Test (UUT)
- seqdet uut (
- .clk(clk),
- .rst(rst),
- .x(x),
- .state(state),
- .z(z)
- );
- initial begin
-
- clk = 0;
- rst = 1;
- #2 rst=0;
- #30 rst=1;
- data='b11001001000010010100;
- #500 $stop;
- end
-
- endmodule
复制代码 |
|