gaoyukun 发表于 2011-8-29 23:50:24

一个状态机程序老报错

小弟不才,用三段输出锁存式状态机 写一个序列检测程序,检测101序列。我的状态可能有冗余,暂时不要关心这些~我想问的是,为什么报错,程序如下

module sq_scan (
                                input dat,clk,rst_n,
                                outputreg led);
        parameter S0 = 4'b 0001,
                S1 = 4'b 0010,
                S2 = 4'b 0100,
                S3 = 4'b 1000;
        reg state,next;
       
always @(posedge clk or negedge rst_n)
                if (!rst_n) state <= S0 ;
                else                state <= next;

always @(state or dat)begin/Error (10028): Can't resolve multiple constant drivers for net "led" at sq_scan.v(14)
                next = 4'bx;
                led= 1'b0;
                case(state)
               S0: if(dat)          next = S1;
                       else      next = S0;
                     S1: if(dat)          next = S1;
                       else        next = S2;
               S2: if(dat)          next = S3;
                       else      next = S0;
               S3: if(dat)          next = S1;
                                  else   next = S2;
      endcase
end
always @(posedge clk or negedge rst_n)
                if (!rst_n) begin
                   led <= 1'b0;
                end
                else begin
                case (next)
                        S0,S1,S2: led <= 1'b0 ;
                        S3      : led <= 1'b1;
                endcase
                end
endmodule

程序老是报错,错误已经标注在报错行的后面了。可是我觉得那句always就应该把涉及状态转变的变量都作为敏感变量啊?请大侠指点一二

syuanwang 发表于 2011-8-30 06:42:06

两个always里都放了
led <= 1'b0;
这个是不允许的

估计LZ可能应该吧
always @(state or dat)中的句子给删了

PS:编译器已经说的非常明白了,led不能多处同时赋值

gaoyukun 发表于 2011-8-30 09:01:12

回复【1楼】syuanwang昙花公公
-----------------------------------------------------------------------

正解!!!多谢多谢。3 always 块状态机,状态转移的那个逻辑里不能出现输出~~~和2 always块搞混了~
页: [1]
查看完整版本: 一个状态机程序老报错