怎么在状态机中加计数器?
Case B_state
if cnt=0 then
This_st<=B_state;
cnt<=cnt+1;
elsif cnt=20 then
This_st<=Jump_state;
cnt<=0;
else
This_st<=B_state;
cnt<=cnt+1;
end
这个模式就是用计数器进行跳转的
好的,我试试,多谢了
好像还是不行,我写的程序其中有计算器的一个分支是这样:
s1:begin if (din==1'b1)
begin
Ns=cs;
if(cnt==5'b0)//第50行
cnt<=cnt+1;
else if(cnt==5'b00100)//52行
begin
Ns=s2;
cnt<=0;
end
else
begin
cnt<=cnt+1;
Ns=cs;
end
end
else
Ns=s2;
end
结果报了一大推没见过的错误:
error:HDLCompilers:52 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 50 Illegal operand(s) of binary operator '=='Parsing C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v: 0.03
ERROR:HDLCompilers:71 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 50 Illegal condition expression in if statement
ERROR:HDLCompilers:106 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 51 Illegal left hand side of nonblocking assignment
ERROR:HDLCompilers:52 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 51 Illegal operand(s) of binary operator '+'
ERROR:HDLCompilers:107 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 51 Illegal right hand side of nonblocking assignment
ERROR:HDLCompilers:52 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 52 Illegal operand(s) of binary operator '=='
ERROR:HDLCompilers:71 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 52 Illegal condition expression in if statement
ERROR:HDLCompilers:106 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 55 Illegal left hand side of nonblocking assignment
ERROR:HDLCompilers:106 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 59 Illegal left hand side of nonblocking assignment
ERROR:HDLCompilers:52 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 59 Illegal operand(s) of binary operator '+'
ERROR:HDLCompilers:107 - "C:/Xilinx92i/MYEXERCISE/DDR/statemachine.v" line 59 Illegal right hand side of nonblocking assignment
你把阻塞和非阻塞赋值放一起了
赋值问题
不是这个问题,我试过了
先改了,再把error 贴出来
改过以后问题,还是一样哦
会不会是不能在同一个进程中对同一个值(cnt)进行重复赋值呢?
lz这段状态机逻辑是时序的还是组合逻辑,在组合逻辑下,cnt肯定不能放在里面写了
s1:begin if (din==1'b1)
begin
Ns=cs;
cnt<=cnt+1;
if(cnt==5'b00100)
begin
Ns=s2;
cnt<=0;
end
else
begin
cnt<=cnt+1;
Ns=cs;
end
end
else
Ns=s2;
end
你把代码改成这样子再试一下,感觉你之前的代码逻辑上有点问题
代码写得很乱
哦,谢谢!
还有问题吗?感觉是你Ns赋值的问题
这个问题和容易啊
