微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > FPGA,CPLD和ASIC > 大家帮我看看这个Verilog程序有问题没?是个控制器的

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

时间:10-02 整理:3721RD 点击:
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

强贴留名

不清楚你在问什么,似乎你什么都没问

你最好先把问题说清楚

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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top