在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1565|回复: 2

[求助] Verilog FSM testbench

[复制链接]
发表于 2020-6-16 14:47:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
我在網上找了一個FSM的testbench跟code但是我怎麼樣complie testbench都
沒能顯示出FSM裡的每個state之類的
有人知道怎麼做嗎?

============================================
以下是testbench
=============================================================
`timescale 1ns / 1ps
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects
// Verilog project: Verilog code for Sequence Detector using Moore FSM
// Verilog Testbench for Sequence Detector using Moore FSM
module tb_Sequence_Detector_Moore_FSM_Verilog;
// Inputs
reg sequence_in;
reg clock;
reg reset;
// Outputs
wire detector_out;
// Instantiate the Sequence Detector using Moore FSM
Sequence_Detector_MOORE_Verilog uut (
  .sequence_in(sequence_in),
  .clock(clock),
  .reset(reset),
  .detector_out(detector_out)
);
initial begin
clock = 0;
forever #5 clock=~clock;
end


initial begin
  // Initialize Inputs
  sequence_in = 0;
  reset = 1;
  // Wait 100 ns for global reset to finish
  #30;
      reset = 0;
  #40;
  sequence_in = 1;
  #10;
  sequence_in = 0;
  #10;
  sequence_in = 1;
  #20;
  sequence_in = 0;
  #20;
  sequence_in = 1;
  #20;
  sequence_in = 0;  
  // Add stimulus here
end
endmodule


========================================================================================
以下是code
=======================================================
// fpga4student.com: FPGA projects, Verilog projects, VHDL projects
// Verilog project: Verilog code for Sequence Detector using Moore FSM
// The sequence being detected is "1011" or One Zero One One
module Sequence_Detector_MOORE_Verilog(sequence_in,clock,reset,detector_out);
input clock; // clock signal
input reset; // reset input
input sequence_in; // binary input
output reg detector_out; // output of the sequence detector
parameter  Zero=3'b000, // "Zero" State
    One=3'b001, // "One" State
    OneZero=3'b011, // "OneZero" State
    OneZeroOne=3'b010, // "OnceZeroOne" State
    OneZeroOneOne=3'b110;// "OneZeroOneOne" State
reg [2:0] current_state, next_state; // current state and next state
// sequential memory of the Moore FSM
always @(posedge clock, posedge reset)
begin
if(reset==1)
current_state <= Zero;// when reset=1, reset the state of the FSM to "Zero" State
else
current_state <= next_state; // otherwise, next state
end
// combinational logic of the Moore FSM
// to determine next state
always @(current_state,sequence_in)
begin
case(current_state)
Zero:begin
  if(sequence_in==1)
   next_state <= One;
  else
   next_state <= Zero;
end
One:begin
  if(sequence_in==0)
   next_state <= OneZero;
  else
   next_state <= One;
end
OneZero:begin
  if(sequence_in==0)
   next_state <= Zero;
  else
   next_state <= OneZeroOne;
end
OneZeroOne:begin
  if(sequence_in==0)
   next_state <= OneZero;
  else
   next_state <= OneZeroOneOne;
end
OneZeroOneOne:begin
  if(sequence_in==0)
   next_state <= OneZero;
  else
   next_state <= One;
end
default:next_state <= Zero;
endcase
end
// combinational logic to determine the output
// of the Moore FSM, output only depends on current state
always @(current_state)
begin
case(current_state)
Zero:   detector_out <= 0;
One:   detector_out <= 0;
OneZero:  detector_out <= 0;
OneZeroOne:  detector_out <= 0;
OneZeroOneOne:  detector_out <= 1;
default:  detector_out <= 0;
endcase
end
endmodule


============================================================================
发表于 2020-6-29 12:18:15 | 显示全部楼层
thanks for sharing
 楼主| 发表于 2020-7-2 04:18:48 | 显示全部楼层
所以有人知道怎麼模擬FSM嘛
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条


小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-12-22 15:19 , Processed in 0.018655 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表