本帖最后由 泼墨染笛香 于 2025-1-8 17:42 编辑
问题1:生成的状态机表格中always0和!always0是什么条件? 问题2:为什么下面两组代码生成的结果不一样?
代码见下方(quartus II中编译后查看"Analysis & Synthesis"-"Netlist Viewers"-"State Machine Viewer")
`timescale 1ns/1ns
module complex_fsm
(
input wire sys_clk , //系统时钟50MHz
input wire sys_rst_n , //全局复位
input wire pi_money_one , //投币1元
input wire pi_money_half //投币0.5元
);
//只有五种状态,使用独热码
parameter IDLE = 5'b00001;
parameter HALF = 5'b00010;
parameter ONE = 5'b00100;
parameter ONE_HALF = 5'b01000;
parameter TWO = 5'b10000;
reg [4:0] state;
wire [1:0] pi_money;
assign pi_money = {pi_money_one, pi_money_half};
always@(posedge sys_clk or negedge sys_rst_n)
if(sys_rst_n == 1'b0)
state <= IDLE; //任何情况下只要按复位就回到初始状态
else case(state)
IDLE :if(pi_money == 2'b01)
state <= HALF;
else if(pi_money == 2'b10)
state <= ONE;
else
state <= IDLE;
HALF :if(pi_money == 2'b01)
state <= ONE;
else if(pi_money == 2'b10)
state <= ONE_HALF;
else
state <= HALF;
ONE :if(pi_money == 2'b01)
state <= ONE_HALF;
else if(pi_money == 2'b10)
state <= TWO;
else
state <= ONE;
ONE_HALF:if(pi_money == 2'b01)
state <= TWO;
else if(pi_money == 2'b10)
state <= IDLE;
else
state <= ONE_HALF;
//情况1 合理
// TWO :if((pi_money == 2'b01))
// state <= IDLE; //01
// else
// state <= TWO; //x0 11
//情况2 合理
// TWO :if((pi_money == 2'b10))
// state <= IDLE; //10
// else
// state <= TWO; //x0 11
//情况3.1 不懂
TWO :if((pi_money == 2'b01) || (pi_money == 2'b10))
state <= IDLE; //always0。不该是10 01?
else
state <= TWO; //!always0。不该是00 11?
//情况3.2。3.2和3.1不等价?生成状态机表格与3.1不同。不懂。
// TWO :if((pi_money == 2'b01) || (pi_money == 2'b10))
// state <= IDLE; //01 10
// else if((pi_money == 2'b00) || (pi_money == 2'b11))
// state <= TWO; //00 11
default : state <= IDLE;//跳转到编码的状态之外也回到初始状态
endcase
endmodule
|