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 ...
随机推荐
- React 错误边界组件
这是React16的内容,并不是最新的技术,但是用很少被讨论,直到通过文档发现其实也是很有用的一部分内容,还是总结一下- React中的未捕获的 JS 错误会导致整个应用的崩溃,和整个组件树的卸载.从 ...
- 使用python制作大数据词云
1 from wordcloud import WordCloud 2 import PIL.Image as image 3 import numpy as np 4 import jieba 5 ...
- 数栈SQL优化案例:隐式转换
MySQL是当下最流行的关系型数据库之一,互联网高速发展的今天,MySQL数据库在电商.金融等诸多行业的生产系统中被广泛使用. 在实际的开发运维过程中,想必大家也常常会碰到慢SQL的困扰.一条性能不好 ...
- 安卓安装kali linux之Termux
解决安装kali无模组问题 https://blog.csdn.net/weixin_44690490/article/details/108599693?utm_source=app 步骤 1.获取 ...
- 闲暇时光里最好的挖矿体验——CPU挖乌龟币
我之前其实是不玩加密货币的,主要是没有钱取投资(tou ji),也没有钱去投资矿机. 不过前几天CSDN推送了一个短文,<黑客用GitHub服务器挖矿,三天跑了3万个任务,代码惊现中文> ...
- Linux+MicroPython+esp8233 YES!
MicPython MicroPython是澳大利亚程序员和物理学家Damien George在2013年一次成功的众筹活动后最初创建的.MicroPython 和 CPython 在 Python ...
- 008-Java中方法的使用(进阶篇)
目录 一.方法的重载(overload) 一.什么是方法的重载 二.方法执行时的内存变化 一.JVM主要三块内存空间 二.关于栈的数据结构(如图) 三.方法执行过程内存变化(用以下代码演示) 三.方法 ...
- 博客之初体验-----python初了解
---恢复内容开始--- 1.python2.x与python3.x的区别 (1) 2.x的默认编码是ASSIC码,不支持中文 (2) 3.x的默认编码是UNICODE,支持中文 (3) 2.x版本与 ...
- OO Unit3 总结
OO Unit3 总结 OO课Unit3人际关系网JML应用技术回顾 BUAA.1823.邓新宇 2020/5/23 梳理JML语言的理论基础.应用工具链情况 方法规格 JML中,同一个方法在不同的条 ...
- Tomcat配置及网站创建教程(IDEA)
Tomcat在本机的配置 解压 解压Tomcat压缩包后就算安装完成,解压完成生成文件夹 配置环境变量 1.配置JAVA_HOME 控制面板--系统--查看高级系统设置--环境变量--系统环境变量 新 ...