在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 5157|回复: 4

[求助] 状态机的问题

[复制链接]
发表于 2012-11-21 11:58:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
我自己写的一个自动售货机的代码,但是quartus ii提示:
Warning (10199): Verilog HDL Case Statement warning at sellor.v(77): case item expression never matches the case expression,从s20开始的状态都没有出现,请问是怎么回事啊?不知道为什么不会出现s20及其以后的状态,求大神指点!

module sellor (
                clk,coin_valid,din5,din10,din15,din20,din25,rst_n,

coin_accept,coin_enough,candy_out,dout

);
input wire clk;
input wire coin_valid,din5,din10,din15,din20,din25;
input wire rst_n;
output reg coin_accept,candy_out;
output reg [3:0]dout;
output reg coin_enough;
parameter s0 = 0000, s5 = 0001, s10 = 0011, s15 = 0010, s20 = 0110,
          s25 = 0111,s30 = 0101, s35 = 0100, s40 = 1100,s45 = 1101;
reg [3:0]state;
always @(posedge clk or negedge rst_n)
if (!rst_n)
   begin
    state <= s0;

coin_enough <= 0;

coin_accept <= 0;

end

/*decide the state of the finite state machine*/
else if (coin_valid)
  begin
    case (state)

   s0:

   if (din5)//is it the priority decoder?? maybe using case is different;

state <= s5;

else if (din10)

  state <= s10;

else if (din15)

  state <= s15;

else if (din20)

  state <= s20;

else if (din25)

  state <= s25;

else

  state <= s0;

s5:

   if (din5)

  state <= s10;

else if (din10)

  state <= s15;

else if (din15)

  state <= s20;

else if (din20)

  state <= s25;

else if (din25)

  state <= s30;

else

  state <= s5;

s10:

   if (din5)

  state <= s15;

else if (din10)

  state <= s20;

else if (din15)

  state <= s25;

else if (din20)

  state <= s30;

else if (din25)

  state <= s35;

else

  state <= s10;

s15:

   if (din5)

  state <= s20;

else if (din10)

  state <= s25;

else if (din15)

  state <= s30;

else if (din20)

  state <= s35;

else if (din25)

  state <= s40;

else

  state <= s15;

s20:

   if (din5)

  state <= s25;

else if (din10)

  state <= s30;

else if (din15)

  state <= s35;

else if (din20)

  state <= s40;

else if (din25)

  state <= s45;

else

  state <= s20;

default:

   begin

     state <= state;// can i express like this ??

  coin_enough <= 1;
         end

endcase

coin_accept <= 1;

end
else

   state <= state;//the state of the fsm keep unchanged;


/*deal with the output candy_out of the machine*/

always @(state or rst_n) // is it neccessary to use a if sentence?
  if (!rst_n)
    begin
     candy_out = 0;

  dout = 4'b0000;

end
else

   case (state)
     
s25:

     begin


    candy_out = 1;

dout = 4'b00_00;

state = s0;

  end

s30:

  begin

    candy_out = 1;

    dout = 4'b00_01;

state = s0;

end

   s35:

  begin

    candy_out = 1;

dout = 4'b00_10;

state = s0;

  end

s40:

  begin

    candy_out = 1;

dout = 4'b01_00;

state = s0;

     end

s45:

  begin

    candy_out = 1;

dout = 4'b10_00;

state = s0;

  end

default:

  begin

    candy_out = 0;

dout = 4'b00_00;

state = state;

  end
   endcase
endmodule
发表于 2012-11-21 16:21:33 | 显示全部楼层
学习一下
 楼主| 发表于 2012-11-21 16:40:41 | 显示全部楼层
谢谢各位,我找到问题了,parameter应该是s0=4’b0000;自己太粗心了!!
发表于 2012-11-21 17:59:08 | 显示全部楼层
这代码风格跟谁学的?不出错都难,出错也难debug。。。
 楼主| 发表于 2012-11-21 21:54:05 | 显示全部楼层
回复 4# elec_zxm


    可不可以给点指导啊?自己看的书~~夏宇闻的那本书~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条


小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-22 09:24 , Processed in 0.019804 second(s), 10 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表