SystemVerilog FSM 枚举状态

问题描述 投票:0回答:1

我正在尝试在 SV 中实现以下状态图

有了这些输出逻辑

使用以下代码

`时间刻度1ns / 1ps

 module fsm_example2(input logic clk,
                input logic reset,
                input logic TA,TB,
                output logic [1:0]LA,LB);
         
typedef enum logic [2:0] {S0, S1, S2, S3} statetype;
statetype state, nextstate;     

// state register
always_ff @(posedge clk, posedge reset)
    if (reset) state <= S0;
    else state <= nextstate;            
    
// next state logic
always_comb 
    case (state)
        S0: if(TA) nextstate = S0;
        else nextstate = S1;
        S1: if(TB) nextstate = S0;
        else nextstate = S1;
        default: nextstate = S0;

    endcase

// output logic
assign LA[0] = ~S1 | S0;
assign LA[1] = S1;
assign LB[0] = S1 | S0;
assign LB[1] = ~S1;
endmodule

但是 RTL 原理图似乎没有正确的电路。

我的猜测是关于各州的 typedef 枚举定义。谢谢你的帮助

system-verilog register-transfer-level
1个回答
0
投票

有几个问题。 S0-S3 是常量,因此 LA 和 LB 被分配为常量表达式。

此外,您的输出表达式是 2 位,但您将它们分配给 1 位线路。

assign LA[1] = state ==S1;

你应该能够弄清楚作业。

© www.soinside.com 2019 - 2024. All rights reserved.