探究Modelsim仿真--波形状态机名称显示

在通常的modelsim波形仿真中,状态机的显示为16进制,如 3‘h1。如下图所示str_cur为状态跳变信号。
为了更加直观的以文本形式显示状态机的跳变,如自己定义的idle等,我们可以使用
virtual typevirtual function
状态机源文件:
//vending-machine// 2 yuan for a bottle of drink// only 2 coins supported: 5 jiao and 1 yuan// finish the function of selling and changing
module vending_machine ( input clk , input rstn , input [1:0] coin , //01 for 0.5 jiao, 10 for 1 yuan
output [1:0] change , output sell //output the drink );
//machine state decode parameter idle = 3‘d0 ; parameter get05 = 3’d1 ; parameter get10 = 3‘d2 ; parameter get15 = 3’d3 ;
//machine variable reg [2:0] st_cur ;
//(1) using one state-variable do describe reg [1:0] change_r ; reg sell_r ; always @(posedge clk or negedge rstn) begin if (!rstn) begin st_cur 《= ‘b0 ; change_r 《= 2’b0 ; sell_r 《= 1‘b0 ; end else begin case(st_cur)
idle: begin change_r 《= 2’b0 ; sell_r 《= 1‘b0 ; case (coin) 2’b01: st_cur 《= get05 ; 2‘b10: st_cur 《= get10 ; endcase end get05: begin case (coin) 2’b01: st_cur 《= get10 ; 2‘b10: st_cur 《= get15 ; endcase end
get10: case (coin) 2’b01: begin st_cur 《= get15 ; end 2‘b10: begin st_cur 《= idle ; sell_r 《= 1’b1 ; end endcase
get15: case (coin) 2‘b01: begin st_cur 《= idle ; sell_r 《= 1’b1 ; end 2‘b10: begin st_cur 《= idle ; change_r 《= 2’b1 ; sell_r 《= 1‘b1 ; end endcase
default: begin st_cur 《= idle ; end
endcase // case (st_cur) end // else: !if(!rstn) end
assign sell = sell_r ; assign change = change_r ;
endmodule
仿真顶层文件:
`timescale 1ns/1ps
module tb_vending_machine;
reg clk; reg rstn ; reg [1:0] coin ; wire [1:0] change ; wire sell ;
//clock generating parameter cycle_200mhz = 10 ; // always begin clk = 0 ; #(cycle_200mhz/2) ; clk = 1 ; #(cycle_200mhz/2) ; end
//motivation generating reg [9:0] buy_oper ; //store state of the buy operation initial begin buy_oper = ’h0 ; coin = 2‘h0 ; rstn = 1’b0 ; #8 rstn = 1‘b1 ; @(negedge clk) ;
//case(1) 0.5 -》 0.5 -》 0.5 -》 0.5 #16 ; buy_oper = 10’b00_0101_0101 ; repeat(5) begin @(negedge clk) ; coin = buy_oper[1:0] ; buy_oper = buy_oper 》》 2 ; end
//case(2) 1 -》 0.5 -》 1, taking change #16 ; buy_oper = 10‘b00_0010_0110 ; repeat(5) begin @(negedge clk) ; coin = buy_oper[1:0] ; buy_oper = buy_oper 》》 2 ; end
//case(3) 0.5 -》 1 -》 0.5 #16 ; buy_oper = 10’b00_0001_1001 ; repeat(5) begin @(negedge clk) ; coin = buy_oper[1:0] ; buy_oper = buy_oper 》》 2 ; end
//case(4) 0.5 -》 0.5 -》 0.5 -》 1, taking change #16 ; buy_oper = 10‘b00_1001_0101 ; repeat(5) begin @(negedge clk) ; coin = buy_oper[1:0] ; buy_oper = buy_oper 》》 2 ; end end
vending_machine u_mealy ( .clk (clk), .rstn (rstn), .coin (coin), .change (change), .sell (sell));
//simulation finish always begin #100; if ($time 》= 10000) $finish ; end
endmodule // test
仿真脚本sim.do文件:
#build a new libraryvlib work
#switch to the emulation source file directory
vlog +acc “tb_vending_machine.v”vlog +acc “vending_machine.v”
#start simulation
vsim -voptargs=+acc work.tb_vending_machine
#add all the signals on the top layeradd wave *#do wave.do
virtual type { {0x00 idle} {0x01 get05} {0x02 get10} {0x03 get15}} fsm_typevirtual function {(fsm_type)/tb_vending_machine/u_mealy/st_cur} state1add wave u_mealy/st_curadd wave -color pink /tb_vending_machine/u_mealy/state1
view structureview signalsrun -all
仿真结果如下
状态机二进制被文本所替代。


高级程序员需要学习哪些知识
西门子在拉斯维加斯测试道路连网设施
萝卜快跑在合肥市开启商业化试点 满足用户日常出行需求
详述摄像头模组激光焊锡方案的应用
腾讯启动碳中和规划,用AI与大数据助力实现0碳排放
探究Modelsim仿真--波形状态机名称显示
JDI 获救!中国投资公司Harvest Group确定增加投资到4亿美金
力压小米与魅蓝?360手机vizza用实力上位的899元新千元机之王!
TCL 98X9C量子点Pro诠释经典永不过时
为什么发送CANFD加速报文要开启发送延迟补偿(TDC)?
SD-WAN组网能给企业带来哪些便利?
晶体管开关电路设计案例分析
什么是并行比较型ADC
联发科计划收购博通的芯片业务来跟高通等公司竞争
如果未借助红外热成像技术,你看到的只是冰山一角
区块链何时才能真正普及?
区块链应该如何一步步推进
双网口IO模块的优势是什么
6N1胆石混合功放的制作方法
Beyond5G/6G时代备受期待的太赫兹波的通信和传感