状态机问题,大家帮帮忙!

下面是我的代码,后面是我的仿真时序图,我想问的是为什么在时序图里currentstate有正确的状态8,而nextstate里没有呢?求大家帮帮我!

//Single Write DMA Read(9054)
module    localctrl(
                            //local bus signals
                             LCLK_50MHZ,           //clock to PCI9054,FPGA  
                             SYSRST_,                        
        ADS_,                 //address strobe from 9054
        BLAST_,               //burst last from 9054
        BTERM_,               //burst stop signal         
        LWR_,                 //local bus read/write
        LA,                   //local bus address
        LD,                   //local bus data
        CCS_,                 //chip select signal to 9054 internal register
        LINT_,                //interrupt signal to 9054
        LRESETo_,             //reset signal from 9054
        BIGEND_,               //big end code
        BREQi,
        BREQo,
                             READY_,               //ready signal to PCI9054
                             //bus arbitration
                             LHOLD,                //bus hold request from PLX PCI9054
                             LHOLDA,                //bus hold acknowledge
      
        //RS232 datasheet
        uart_XMIT,
        uart_REC ,
        nextstate ,
       currentstate                          
                            );

input                   LCLK_50MHZ;
input                   ADS_;
input                   BLAST_;
input                   LWR_;
input    [31:1]         LA;  
input      LRESETo_;
input                   BREQo;
input                   LHOLD;
input     uart_REC;
output                  BTERM_;
output                  CCS_;
output                  LINT_;
output                  BREQi;
output                  READY_;
output                  LHOLDA;
output                  BIGEND_;
output     SYSRST_;
output     uart_XMIT;
output [3:0]   nextstate;
output [3:0]   currentstate;
inout   [15:0]          LD;
reg      BTERM_;
reg                     CCS_;
reg      LINT_;
reg                     BREQi;
reg                     READY_;
reg                     LHOLDA;
reg      SYSRST_;
wire                    BIGEND_;
//reg      uart_REC;
wire     uart_XMIT;

rs232    com1(
      .clk(LCLK_50MHZ),      
      .rstn(SYSRST_),
      .datain(data),
      .write_en(write_enable),
      .uart_rec(uart_REC),      
      
      //output
      .uart_xmit(uart_XMIT),
      .dataout(),
      .read_en()            
      );
//interal signal
reg  [3:0]   currentstate;
reg  [3:0]   nextstate;
reg  [15:0]   data;
reg      write_enable;
parameter  idle   = 4'b0000,  //s0
    bushold  = 4'b0001,  //s1:bus hold state
    singlewrite = 4'b0010,  //s2:single cycle write
    DMAread  = 4'b0100,  //s3MA read
    transition  = 4'b1000;  //s4:transition state
assign    BIGEND_ = 1;                //Little end mode,must set the BIGEDND register to 0;
           //otherwise it's big end mode
//produce system reset signal
always   @(posedge  LCLK_50MHZ)
begin
  SYSRST_  <= LRESETo_;  
end
//local bus arbitration
always   @(posedge  LCLK_50MHZ  or negedge SYSRST_)
begin
           if(~SYSRST_)
           begin
     LHOLDA <= 0;
           end
           else
           begin
     if(LHOLD)//The LHOLDA signal will delay 1 clock cycle the LHOLD signal
     begin
        LHOLDA <= LHOLD;
     end
     else     
     begin
       LHOLDA <= 0;
     end
           end
end
always   @(posedge  LCLK_50MHZ  or negedge SYSRST_)
begin
  if(~SYSRST_)
  begin
    currentstate <= idle;
  end
  else
  begin
    currentstate <= nextstate;
  end
end
always  @(currentstate or LWR_ or ADS_ or BLAST_)
begin
        //default  
  nextstate   = currentstate;   //
  casex(currentstate)
  idle:
  begin
    if(LHOLD)
    begin
      nextstate = bushold;
    end
    else
    begin
      nextstate = idle;
    end
  end
  bushold:
  begin   
    if(LHOLD)
    begin
      if(~ADS_)
      begin
        if(LWR_)
        begin
          nextstate = singlewrite;
        end
        else
        begin
          nextstate = DMAread;
        end
      end
      else
      begin
        nextstate = bushold;
      end
    end   
    else
    begin
      nextstate = idle;
    end
   
  end
  singlewrite:
  begin
          if(~BLAST_)
    begin
      nextstate = transition;
    end
    else
    begin
      nextstate = singlewrite;
    end
  end
  DMAread:
  begin
    if(~BLAST_)                             //may be single read
    begin
      nextstate = transition;
    end
    else
    begin
      nextstate = DMAread;         //connect with the fifo FSM
    end
  end
  transition:
  begin
    if(LHOLD)
    begin
      nextstate = bushold;
    end
    else
    begin
      nextstate = idle;
    end
  end
  default:
  begin
    nextstate = idle;
  end
  endcase
end
always   @(posedge  LCLK_50MHZ  or negedge SYSRST_)
begin
  if(~SYSRST_)
  begin   
    READY_   <= 1;
    LINT_   <= 1;
  end
  casex(nextstate)
  idle:
  begin   
    READY_   <= 1;
    LINT_   <= 1;
  end
  bushold:
  begin   
   
  end
  singlewrite:
  begin
          READY_   <= 0;
    //address   <= LA;
    //dataread  <= LD;
  end
  DMAread:
  begin
    READY_   <= 0;
  end
  transition:
  begin
   
  end
  default:
  begin   
    READY_   <= 1;
    LINT_   <= 1;
  end
  endcase
end
endmodule


1.jpg


我也来说两句 查看全部回复

最新回复

  • anchoret (2008-8-07 11:29:44)

    怎么没人帮忙啊,哪位给看看吧,不胜感激!!
  • windzjy (2008-8-07 14:04:32)

    即使没有你说的那个问题,好像也不对吧,currentstate比nextstate应该延迟一个时钟周期呢,为什么你的是对齐的?好像不是你的代码的问题
  • anchoret (2008-8-08 13:44:41)

    是啊,怎么回事呢?我用QuartusII仿真的!
  • hagelee (2008-8-08 13:49:51)

    路过,学习下!
  • wangling300 (2008-8-08 15:48:38)

    always  @(*)//改用*比较保险
    begin
            //default  
      nextstate   = currentstate;   //
      case(currentstate)//用case试试看,casex容易出现意想不到的问题
      idle:
      begin
        if(LHOLD)
        begin
          nextstate = bushold;
        end
        else
        begin
          nextstate = idle;
        end
      end
      bushold:
      begin   
        if(LHOLD)
        begin
          if(~ADS_)
          begin
            if(LWR_)
            begin
              nextstate = singlewrite;
            end
            else
            begin
              nextstate = DMAread;
            end
          end
          else
          begin
            nextstate = bushold;
          end
        end   
        else
        begin
          nextstate = idle;
        end
       
      end
      singlewrite:
      begin
              if(~BLAST_)
        begin
          nextstate = transition;
        end
        else
        begin
          nextstate = singlewrite;
        end
      end
      DMAread:
      begin
        if(~BLAST_)                             //may be single read
        begin
          nextstate = transition;
        end
        else
        begin
          nextstate = DMAread;         //connect with the fifo FSM
        end
      end
      transition:
      begin
        if(LHOLD)
        begin
          nextstate = bushold;
        end
        else
        begin
          nextstate = idle;
        end
      end
      default:
      begin
        nextstate = idle;
      end
      endcase
    end
  • anchoret (2008-8-08 16:09:21)

    好的,我试试
  • anchoret (2008-8-08 16:36:56)

    效果还是一样!