SystemVerilog 编写FSM


好书:

https://github.com/yllinux/blogPic/blob/master/doc/CummingsSNUG2003SJ_SystemVerilogFSM.pdf

https://github.com/yllinux/blogPic/blob/master/doc/CummingsSNUG2019SV_FSM1.pdf

题目

SystemVerilog实现

module ExampleFSM (
input logic clk ,
input logic reset ,
input logic X ,
output logic Y
); typedef enum logic [2:0] {A, B, C, D, E} state ; // 定义枚举类型 state currentState, nextState ; // 声明自定义类型变量 always_ff @(posedge clk , posedge reset) // 状态转移,同步时序,推荐3行式
if (reset) currentState <= A ;
else currentState <= nextState ; always_comb begin // 状态转移条件判断,组合逻辑
nextState = 3'bxxx ; //@ loopback,需要写上
case (currentState)
A : if (X) nextState = C ;
else nextState = B ;
B : if (X) nextState = D ;
else nextState = B ; //@LB
C : if (X) nextState = C ;
else nextState = E ;
D : if (X) nextState = C ;
else nextState = E ;
E : if (X) nextState = D ;
else nextState = B ;
default : nextState = A ; // 需要写上
endcase
end // assign Y = (currentState == D | currentState == E) ; // 组合输出 // always_ff @(posedge clk , posedge reset)
// if (reset)
// Y <= 1'b0 ;
// else begin
// Y <= (nextState == D | nextState == E) ;
// end always_ff @(posedge clk , posedge reset)
if (reset)
Y <= 1'b0 ;
else begin
Y <= 1'b0 ;
case (nextState)
D : Y <= 1'b1 ;
E : Y <= 1'b1 ;
// don't need default
endcase
end endmodule

仿真

`timescale 1ns/1ns
module ExampleFSM_TB ();
logic clk=1 ;
logic reset ; logic in ;
logic out ;
logic expectOut ;
logic [31:0] i ; ExampleFSM dut (
.clk ( clk ),
.reset ( reset ),
.X ( in ),
.Y ( out )
); logic [2:0] testVector [1000:0] ; initial begin
$readmemb ("TestBenchVector.txt", testVector, 0, 19) ;
i = 0;
reset = 1; in = 0; #200ns; $finish;
end always @(posedge clk) begin
{reset, in, expectOut} <= #2 testVector[i] ;
$display(reset, in, expectOut, $time);
end always @(negedge clk) begin
if (expectOut !== out) begin
$display("wrong output for inputs %b, %b != %b, address %d", {reset, in}, expectOut, out, i, $time);
end
i = i + 1 ;
end always begin
clk <= 1; #5 ;
clk <= 0; #5 ;
end //-----------------------------------------
// for VCS generate fsdb file
//-----------------------------------------
initial begin
$fsdbDumpfile("./digital.fsdb");
$fsdbDumpvars(0,ExampleFSM_TB,"+all");
$fsdbDumpflush();
end endmodule

激励向量文件:TestBenchVector.txt

10_0
10_0
10_0
00_0
01_0
01_1
01_0
00_0
01_0 // 01_1
00_1
10_1
11_0
11_0
11_0
11_0
11_0
11_0
11_0
11_0
11_0

SystemVerilog 编写FSM的更多相关文章

  1. 关于RiscV的一些资料整理

    1. 基于RISC-V架构的开源处理器及SoC研究综述 https://mp.weixin.qq.com/s/qSD-q8y0_MY8R0MBA85ZZg 原文链接: https://blog.csd ...

  2. 《SystemVerilog验证-测试平台编写指南》学习 - 第3章 过程语句和子程序

    <SystemVerilog验证-测试平台编写指南>学习 - 第3章 过程语句和子程序 3.1 过程语句 3.2 任务.函数以及void函数 3.3 任务和函数概述 3.4 子程序参数 3 ...

  3. 《SystemVerilog验证-测试平台编写指南》学习 - 第2章 数据类型

    <SystemVerilog验证-测试平台编写指南>学习 - 第2章 数据类型 2.1 内建数据类型 2.2 定宽数组 2.2.1 声明 2.2.2 常量数组 2.2.3 基本的数组操作 ...

  4. 《SystemVerilog验证-测试平台编写指南》学习 - 第1章 验证导论

    <SystemVerilog验证-测试平台编写指南>学习 - 第1章 验证导论 测试平台(testbench)的功能 方法学基础 1. 受约束的随机激励 2. 功能覆盖率 3. 分层的测试 ...

  5. 使用有限状态机(FSM)编写的敌人AI

    using UnityEngine; using System.Collections; public class AttackState : FSMState { public AttackStat ...

  6. paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之fsm summary

    主要是1.不要用1段式写FSM 2.不要用状态编码写one-hot FSM ,要用索引编码写one-hot FSM.

  7. paper:synthesizable finite state machine design techniques using the new systemverilog 3.0 enhancements 之 FSM Coding Goals

    1.the fsm coding style should be easily modifiable to change state encoding and FSM styles. FSM 的的 状 ...

  8. paper:synthesizable finite state machine design techniques using the new systemverilog 3.0 enhancements 之 standard verilog FSM conding styles(三段式)

    Three always block style with registered outputs(Good style)

  9. paper:synthesizable finite state machine design techniques using the new systemverilog 3.0 enhancements 之 standard verilog FSM conding styles(二段式)

    1.Two always block style with combinational outputs(Good Style) 对应的代码如下: 2段式总结: (1)the combinational ...

随机推荐

  1. [贪心]D. 【例题4】国王游戏

    D . [ 例 题 4 ] 国 王 游 戏 D. [例题4]国王游戏 D.[例题4]国王游戏 解析 贪心思想,考虑交换后的值比交换前的小. 然后数据规模用高精度 Code #include <b ...

  2. [状压DP]车II

    车 I I 车II 车II 题目描述 有一个 n ∗ m n*m n∗m的棋盘 ( n . m ≤ 80 , n ∗ m ≤ 80 ) (n.m≤80,n*m≤80) (n.m≤80,n∗m≤80)要 ...

  3. Python基础(九):字典的使用

    创建字典的5种方式 用{}创建字典 >>> a = {'name':'韩梅梅','age':18,'job':'teacher'} >>> print(a) {'n ...

  4. 阿里妈妈Java后端 社招5面(Offer已拿)

    最近由于个人原因, 由于前面两面的时间过去的有点久了,只能根据记忆大概写些记得问题.   阿里妈妈1面 40mins(2021-02-22) 1. 能简单介绍下自己和自己做的项目吗? 2. 关于项目的 ...

  5. 通过Dapr实现一个简单的基于.net的微服务电商系统

    本来想在Dpar 1.0GA时发布这篇文章,由于其他事情耽搁了放到现在.时下微服务和云原生技术如何如荼,微软也不甘示弱的和阿里一起适时推出了Dapr(https://dapr.io/),园子里关于da ...

  6. 2. IntelliJ Idea 常用快捷键列表

    Ctrl+E,最近的文件 Ctrl+Shift+E,最近更改的文件 Shift+Click,可以关闭文件 Ctrl+[ OR ],可以跑到大括号的开头与结尾 Ctrl+F12,可以显示当前文件的结构 ...

  7. golang面向对象分析

    说道面向对象(OOP)编程, 就不得不提到下面几个概念: 抽象 封装 继承 多态 其实有个问题Is Go An Object Oriented Language?, 随便谷歌了一下, 你就发现讨论这个 ...

  8. python 闭包函数与装饰器

    1.什么是闭包函数 (1):什么是闭包函数: #内部函数包含对外部作用域而非全局作用域的引用, 简而言之, 闭包的特点就是内部函数引用了外部函数中的变量. 在Python中,支持将函数当做对象使用,也 ...

  9. Django模板引擎

    Django作为Web框架,需要一种很便利的方法动态地生成 HTML 网页,因此有了模板这个概念.模板包含所需 HTML 的部分代码以及一些特殊语法,特殊语法用于描述如何将视图传递的数据动态插入HTM ...

  10. logstash收集springboot日志

    logstash收集springboot日志 maven依赖 <dependency> <groupId>net.logstash.logback</groupId> ...