求助关于状态机的一个问题。
时间:10-02
整理:3721RD
点击:
小弟最近在写AES的加密模块,写了一个这样的状态机:always @(posedge iClk or negedge iReset)
begin
if(!iReset)
CS<=IDLE;
else
CS<=NS;
end
always @(posedge iClk)
begin
NS = 3'bx;
case(CS)
IDLE:
begin
iKey <= iInitialkey;
NS <= Round1;
keyValid <= 0;
end
Round1:
begin
totalkey[1279:1152] <= result;
NS <= Round2;
end
Round2:
begin
iKey <= totalkey[1279:1152];
totalkey[1151:1024] <= result;
NS <= Round3;
end
Round3:
begin
iKey <= totalkey[1151:1024];
totalkey[1023:896] <= result;
NS <= Round4;
end
Round4:
begin
iKey <= totalkey[1023:896];
totalkey[895:768] <= result;
NS <= Round5;
end
Round5:
begin
iKey <= totalkey[895:768];
totalkey[767:640] <= result;
NS <= Round6;
end
Round6:
begin
iKey <= totalkey[767:640];
totalkey[639:512] <= result;
NS <= Round7;
end
Round7:
begin
iKey <= totalkey[639:512];
totalkey[511:384] <= result;
NS <= Round8;
end
Round8:
begin
iKey <= totalkey[511:384];
totalkey[383:256] <= result;
NS <= Round9;
end
Round9:
begin
iKey <= totalkey[383:256];
totalkey[255:128] <= result;
NS <= Round10;
end
Round10:
begin iKey <= totalkey[255:128];
totalkey[127:0] <= result;
NS <= Output;
end
Output:
NS<=IDLE;
keyValid <= 1;
end
endcase
end
在quartus中综合用状态机工具查看,各个状态之间都是孤立的没有连线,请问这样的写法有什么问题吗?谢谢
begin
if(!iReset)
CS<=IDLE;
else
CS<=NS;
end
always @(posedge iClk)
begin
NS = 3'bx;
case(CS)
IDLE:
begin
iKey <= iInitialkey;
NS <= Round1;
keyValid <= 0;
end
Round1:
begin
totalkey[1279:1152] <= result;
NS <= Round2;
end
Round2:
begin
iKey <= totalkey[1279:1152];
totalkey[1151:1024] <= result;
NS <= Round3;
end
Round3:
begin
iKey <= totalkey[1151:1024];
totalkey[1023:896] <= result;
NS <= Round4;
end
Round4:
begin
iKey <= totalkey[1023:896];
totalkey[895:768] <= result;
NS <= Round5;
end
Round5:
begin
iKey <= totalkey[895:768];
totalkey[767:640] <= result;
NS <= Round6;
end
Round6:
begin
iKey <= totalkey[767:640];
totalkey[639:512] <= result;
NS <= Round7;
end
Round7:
begin
iKey <= totalkey[639:512];
totalkey[511:384] <= result;
NS <= Round8;
end
Round8:
begin
iKey <= totalkey[511:384];
totalkey[383:256] <= result;
NS <= Round9;
end
Round9:
begin
iKey <= totalkey[383:256];
totalkey[255:128] <= result;
NS <= Round10;
end
Round10:
begin iKey <= totalkey[255:128];
totalkey[127:0] <= result;
NS <= Output;
end
Output:
NS<=IDLE;
keyValid <= 1;
end
endcase
end
在quartus中综合用状态机工具查看,各个状态之间都是孤立的没有连线,请问这样的写法有什么问题吗?谢谢
自己顶一个,实在是看不出来哪里不对。
NS = 3'bx;
个人感觉是这一句有问题,在always @(posedge iClk)这里面也加个复位信号,给NS一个初始状态,然后把NS = 3'bx;删掉
试试,不保证成功
你每一个状态都没有改变自己的复制比如在round6中加一句cs<=round7
把case里的判断cs改为NS
你这个不是标准的两段式状态机写法。你的状态转化那一段是时序逻辑,所以CS会比状态转化晚两个时钟周期。看起来是这样的。所以状态转化不标准,状态机写法也不确认。
小编,如果状态转化是时序的,是不是写一段就可以?
我的想法是这样的,一共要计算10组密钥,因为计算的那个模块很长。所以就打算分十个时钟周期计算,不知道这样用状态机是否正确
你要好好理解状态机的verilog写法。两段法和三段法是比较推荐的写法。任何状态机都肯定是有时序逻辑的。而两段写法只是verilog描述状态机的一种方法。这两者是完全不同的概念,所以不能混淆来说的。
恩,谢谢小编,改了之后显示的状态图是正确的了,现在正在仿真。
