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

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

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1904|回复: 5

大家帮我看看这个Verilog程序有问题没?是个控制器的

[复制链接]
发表于 2008-6-21 16:41:46 | 显示全部楼层 |阅读模式

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

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

x
module controller (start,clk, Z, clear, plsr_load, add_sub_S1, add_sub_S2, latch_result);
    input start;
    input clk;
    input Z;
    output clear;
    reg clear;
    output plsr_load;
    reg plsr_load;
    output add_sub_S1;
    reg add_sub_S1;
    output add_sub_S2;
    reg add_sub_S2;
    output latch_result;
    reg latch_result;
    parameter[1:0] S0=0 ;
    parameter[1:0] S1=1 ;
    parameter[1:0] S2=2 ;
    parameter[1:0] S3=3 ;
    reg[1:0] present_state;
    reg[1:0] next_state;
    always @(present_state or start or Z)
    begin : nextstate_logic
       case (present_state)
          S0 :
                   begin
                      clear <= 1'b0 ;
                      plsr_load <= 1'b1 ;
                      add_sub_S1 <= 1'b0 ;
                      latch_result <= 1'b0 ;
                      add_sub_S2 <= 1'b0 ;
                      if (start == 1'b1)
                      begin
                         next_state <= S1 ;
                      end
                      else
                      begin
                         next_state <= S0 ;
                      end
                   end
          S1 :
                   begin
                      clear <= 1'b0 ;
                      plsr_load <= 1'b0 ;
                      add_sub_S1 <= 1'b0 ;
                      latch_result <= 1'b0 ;
                      add_sub_S2 <= 1'b1 ;
                      next_state <= S2 ;
                   end
          S2 :
                   begin
                      clear <= 1'b1 ;
                      plsr_load <= 1'b1 ;
                      add_sub_S1 <= 1'b0 ;
                      latch_result <= 1'b0 ;
                      add_sub_S2 <= 1'b0 ;
                      if (Z == 1'b1)
                      begin
                         next_state <= S3 ;
                      end
                      else
                      begin
                         next_state <= S2 ;
                      end
                   end
          S3 :
                   begin
                      clear <= 1'b1 ;
                      plsr_load <= 1'b1 ;
                      add_sub_S1 <= 1'b1 ;
                      latch_result <= 1'b1 ;
                      add_sub_S2 <= 1'b0 ;
                      next_state <= S1 ;
                   end
       endcase
    end
     always @(clk)
    begin : state_register
       if (clk == 1'b1)
       begin
          present_state <= next_state ;
       end
    end
   endmodule
头像被屏蔽
发表于 2008-6-21 18:02:24 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
发表于 2008-6-23 09:12:40 | 显示全部楼层
你得先说说你要实现什么功能
发表于 2008-6-23 09:27:53 | 显示全部楼层
不清楚你在问什么,似乎你什么都没问
发表于 2008-6-23 20:15:22 | 显示全部楼层
你最好先把问题说清楚
发表于 2008-6-23 23:27:47 | 显示全部楼层
a quick look on the code. You forgot the initializaiton of signal "present_state". you can fix it in either of following ways,
1. force present_state to '0' when declaration, like
    " reg[1:0] present_state= 0 "
2. introduce a reset signal and code the circuit (recommand)
   "input reset:
   always @(present_state or start or Z or reset)
    begin : nextstate_logic
      if(reset == 1) begin
          present_state = S0; // asynchronized reset
          next_state = S0; //synchronized reset
       end
       case (present_state)
          S0 :
      .....  "

And one more suggestion of verilog style, when you use
" always @(clk)
       if (clk == 1'b1) "
to try to make to flip-flop, please use
"always@(posedge clk)"
instead.

The one you are using in the code is laughable bad style, unless you are trying to make a latch with some more circuitry
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

×

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

GMT+8, 2024-5-20 14:57 , Processed in 0.034312 second(s), 12 queries , Gzip On, Redis On.

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