【FPGA开发技巧】Modelsim仿真中,显示状态机的名称,而非编码数字

示例

被仿真的文件名为:cmd_handle.v,其中有r_st_current和r_st_next两个状态机变量。

该模块在tb文件中,被例化的名称为cmd_handle_u0

按照如下格式写:cmd_handle_u0.r_st_current

示例tb文件:

c 复制代码
`timescale 1ns / 1ps
//
// Company: 
// Engineer: 
// 
// Create Date: 2025/04/10 21:54:40
// Design Name: 
// Module Name: tb_cmd_handle
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//


module tb_cmd_handle();
cmd_handle #(
    .P_SYSTEM_CLK (50_000_000   ),   //输入时钟频率
    .P_BAUD_RATA  (115200       ),   //波特率    
    .P_DATA_WIDTH (8            ),   //Uart数据位宽
    .P_STOP_WIDTH (1            ),   //停止位位宽 1 or 2
    .P_CHECK      (2            )    //0为奇校验,1为偶校验    
)cmd_handle_u0
(
    .i_clk           (clk   ),
    .i_rst           (rst   ),
    
    .i_uart_rx       (w_uart_tx),
    .o_uart_tx       (w_uart_rx),
    
    .o_start_gain    (),
    .o_gain_speed    ()
);

//--------------------------------------------------------------------------
//--    状态机名称查看器
//--------------------------------------------------------------------------
//1个ASSIC码字符宽度是8位,例如"IDLE"有4个字符则需要32位宽
//80宽度可以容纳10个字符
	reg [79:0]              r_st_next          ;
    reg [79:0]              r_st_current          ;
	
//这段参数声明是一定要有的,否则在仿真时会报未声明变量的错误,如下图
localparam  P_ST_IDLE  = 0 ,
            P_ST_READ  = 1 ,
            P_ST_HEAD  = 2 ,
            P_ST_READ2 = 3 ,
            P_ST_A     = 4 ,
            P_ST_DATA  = 5 ,
            P_ST_ANYS  = 6 ;
			
	always @(*) begin
		case(cmd_handle_u0.r_st_current)
			P_ST_IDLE :     r_st_current = "P_ST_IDLE " ;
			P_ST_READ :     r_st_current = "P_ST_READ ";
			P_ST_HEAD :     r_st_current = "P_ST_HEAD ";
			P_ST_READ2:     r_st_current = "P_ST_READ2";
			P_ST_A    :	    r_st_current = "P_ST_A    ";
			P_ST_DATA :     r_st_current = "P_ST_DATA ";
			P_ST_ANYS :     r_st_current = "P_ST_ANYS ";
			default:r_st_current = "P_ST_IDLE ";
		endcase
	end

	always @(*) begin
		case(cmd_handle_u0.r_st_next)
			P_ST_IDLE :     r_st_next = "P_ST_IDLE " ;
			P_ST_READ :     r_st_next = "P_ST_READ ";
			P_ST_HEAD :     r_st_next = "P_ST_HEAD ";
			P_ST_READ2:     r_st_next = "P_ST_READ2";
			P_ST_A    :	    r_st_next = "P_ST_A    ";
			P_ST_DATA :     r_st_next = "P_ST_DATA ";
			P_ST_ANYS :     r_st_next = "P_ST_ANYS ";
			default:        r_st_next = "P_ST_IDLE ";
		endcase
	end

endmodule

直接运行仿真,就可以:

相关推荐
且听风吟5672 小时前
深度为16,位宽8bit的单端口SRAM——学习记录
学习·fpga开发
鸡精拌饭2 小时前
FPAG IP核调用小练习
fpga开发
爱喝西北风的东北风2 小时前
DDS波形发生器仿真及技术原理
单片机·嵌入式硬件·fpga开发
hahaha60166 小时前
Vccaux_IO在DDR3接口中的作用
fpga开发
北京青翼科技21 小时前
【PCIE736-0】基于 PCIE X16 总线架构的 4 路 QSFP28 100G 光纤通道处理平台
图像处理·人工智能·fpga开发·信号处理
奋斗的牛马1 天前
FPGA_UART
fpga开发
ThreeYear_s2 天前
基于FPGA的智能垃圾桶设计-超声波测距模块-人体感应模块-舵机模块 仿真通过
fpga开发
soulermax2 天前
华为数字芯片机考2025合集4已校正
华为·fpga开发·架构·github·硬件架构
apple_ttt2 天前
FPGA时序分析与约束(11)——时钟组
fpga开发