SystemVerilog 编写FSM
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的更多相关文章
- 关于RiscV的一些资料整理
1. 基于RISC-V架构的开源处理器及SoC研究综述 https://mp.weixin.qq.com/s/qSD-q8y0_MY8R0MBA85ZZg 原文链接: https://blog.csd ...
- 《SystemVerilog验证-测试平台编写指南》学习 - 第3章 过程语句和子程序
<SystemVerilog验证-测试平台编写指南>学习 - 第3章 过程语句和子程序 3.1 过程语句 3.2 任务.函数以及void函数 3.3 任务和函数概述 3.4 子程序参数 3 ...
- 《SystemVerilog验证-测试平台编写指南》学习 - 第2章 数据类型
<SystemVerilog验证-测试平台编写指南>学习 - 第2章 数据类型 2.1 内建数据类型 2.2 定宽数组 2.2.1 声明 2.2.2 常量数组 2.2.3 基本的数组操作 ...
- 《SystemVerilog验证-测试平台编写指南》学习 - 第1章 验证导论
<SystemVerilog验证-测试平台编写指南>学习 - 第1章 验证导论 测试平台(testbench)的功能 方法学基础 1. 受约束的随机激励 2. 功能覆盖率 3. 分层的测试 ...
- 使用有限状态机(FSM)编写的敌人AI
using UnityEngine; using System.Collections; public class AttackState : FSMState { public AttackStat ...
- 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.
- 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 的的 状 ...
- 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)
- 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 ...
随机推荐
- [DFS]排列的生成
排列的生成 Time Limit:1000MS Memory Limit:65536K Total Submit:150 Accepted:95 Description 输出P(n,m)的排列(n,m ...
- HTML(一):语法结构
HTML语法规范 基本语法概述 HTML标签是由尖括号包围的关键词,例如<html>. 2HTML标签通常是成对出现的,例如<html>和</html> ,我们称为 ...
- [面试仓库]HTML面试题汇总
HTML这一块呢,说简单也简单,说难也不是那么容易.但我们在各个面试要求中,大部分都把HTML这一条摆在了第一位,重要性可想而知.这个位置算是有关HTML的一个汇总点了,亦会在这里及时补充. 1, ...
- JVM(一)内存结构
今日开篇 什么是JVM 定义 Java Virtual Machine,JAVA程序的运行环境(JAVA二进制字节码的运行环境) 好处 一次编写,到处运行 自动内存管理,垃圾回收机制 数组下标越界检查 ...
- 痞子衡嵌入式:在i.MXRT启动头FDCB里使能串行NOR Flash的DTR模式
大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是在FDCB里使能串行NOR Flash的DTR模式. 前两篇文章 <IS25WP系列Dummy Cycle设置> 与 < ...
- 4. Linux-startx命令
Linux系统startx命令的功能和使用方法 Linux系统命令startx的功能很简单,就是启动X Window的服务这一项,没有其他的了.其实startx命令启动的是xinit,然后再由xini ...
- centos7 中静态IP地址的配置
虚拟机中也可以像Windows系统那样从浏览器上下载文件,但在这之前,要必须保证虚拟机网络服务通畅.而配置网络服务其实就是在编辑网卡配置文件,具体步骤如下: 网卡配置文件位置:/etc/sysconf ...
- Redis持久化——AOF日志
最新:Redis内存--内存消耗(内存都去哪了?) 最新:Redis持久化--如何选择合适的持久化方式 最新:Redis持久化--AOF日志 更多文章... 上一篇文章Redis持久化--内存快照(R ...
- Summary: DOM modification techniques
Modifying an existing element We covered various ways that you can modify aspects of an existing ele ...
- Python脚本破解Linux口令(crypt模块)
环境 Kali Linux ,python版本2.7.13 . 我们利用Linux系统中的 crypt 模块模拟了Linux系统中用户密码的加密,在Windows中是不存在这个库的. 在Linux系统 ...