|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
新接触verilog,自己写了一段代码,用到了case的嵌套,但是一直执行内部的case,跳不出来,请高手指点迷津!
case(state)
idle: begin
case({A,B}) //four initial states of A and B
2'b00: begin
AO<=0;
BO<=0;
if(a2==0&a1==1&b1==b2==0) //a==b==0,but posedge of A comes first,A lead
begin
dependa<=1;
AO<=~AO;
state<=edgecount; //goto count the edge of A,AO and BO change according their counters
end
else
begin
if(b2==0&b1==1&a1==a2==0) //a==b==0,but posedge of B comes first,B lead
begin
dependb<=1;
BO<=~BO;
state<=edgecount; //goto count the edge of A,AO and BO change according their counters
end
else state<=idle;
end
end
2'b01: begin
AO<=0;
BO<=1;
if(a1==a2==0&b2==1&b1==0) //A==0,B==1,but negedge of B comes first, A lead
begin
dependb<=1;
BO<=~BO;
state<=edgecount;
end
else
begin
if (b1==b2==1&a2==0&a1==1) //A==0,B==1,but posedge of A comes first,B lead
begin
dependa<=1;
AO<=~AO;
state<=edgecount;
end
else state<=idle;
end
end
2'b10: begin
AO<=1;
BO<=0;
if(a1==a2==1&b2==0&b1==1)//A==1,B==0,but posedge of B comes first, A lead
begin
dependb<=1;
BO<=~BO;
state<=edgecount;
end
else begin
if(b1==b2==0&a2==1&a1==0)//A==1,B==0,but negedge of A comes first ,B lead
begin
dependa<=1;
AO<=~AO;
state<=edgecount;
end
else state<=idle;
end
end
2'b11: begin
AO<=1;
BO<=1;
if(b1==b2==1&a2==1&a1==0) //A==B==1,but negedge of A comes first,A lead
begin
dependa<=1;
AO<=~AO;
state<=edgecount;
end
else
begin
if(a1==a2==1&b2==1&b1==0) //A==B==1,but negedge of B comes first,B lead
begin
dependb<=1;
BO<=~BO;
state<=edgecount;
end
else state<=idle;
end
end
endcase
end
edgecount: begin
if(ena)
state<=achange; //state changes form edgecount to achange
else begin
if(enb)
state<=bchange; //state changes form edgecount to bchange
else state<=edgecount;
end
end
achange: begin
state<=edgecount; //state changes from change to edgecount
AO<=~AO; //AO changes
end
bchange: begin
state<=edgecount; //state changes from change to pulsecount
BO<=~BO; //BO changes
end
endcase
代码实现的任务是:检测原信号AB,先判断它们的初值,直接赋给AO、BO,然后哪个边沿先到,对应的输出信号跳变,然后跳出内部case,执行外部case的edgecount分支。但是实际上程序好像是一直在内部case中执行。
请路过的高手帮帮忙哦,不胜感激! |
|