HDLBits 系列(36)Arbitration circuit implemented by FSM
目录
原题复现
审题
我的设计
设计解释
原题复现
原题复现:
Consider the FSM described by the state diagram shown below:
This FSM acts as an arbiter circuit, which controls access to some type of resource by three requesting devices. Each device makes its request for the resource by setting a signal r[i] = 1, where r[i] is either r[1], r[2], or r[3]. Each r[i] is an input signal to the FSM, and represents one of the three devices. The FSM stays in state A as long as there are no requests. When one or more request occurs, then the FSM decides which device receives a grant to use the resource and changes to a state that sets that device’s g[i] signal to 1. Each g[i] is an output from the FSM. There is a priority system, in that device 1 has a higher priority than device 2, and device 3 has the lowest priority. Hence, for example, device 3 will only receive a grant if it is the only device making a request when the FSM is in state A. Once a device, i, is given a grant by the FSM, that device continues to receive the grant as long as its request, r[i] = 1.
Write complete Verilog code that represents this FSM. Use separate always blocks for the state table and the state flip-flops, as done in lectures. Describe the FSM outputs, g[i], using either continuous assignment statement(s) or an always block (at your discretion). Assign any state codes that you wish to use.
审题
一看描述一大堆,我们提取出关键的一句话:
The FSM stays in state A as long as there are no requests.
我的设计
之后,看着状态转移图就可以实现设计:
module top_module (input clk,input resetn, // active-low synchronous resetinput [3:1] r, // requestoutput [3:1] g // grant
); localparam A = 0, B = 1, C = 2, D = 3;reg [1:0] state, next_state;always@(*) beginnext_state = A;case(state)A: beginif(r[1]) next_state = B;else if(r == 3'b000) next_state = A;else if(r[2:1] == 2'b10) next_state = C;else if(r == 3'b100) next_state = D;endB: beginif(r[1] == 0) next_state = A;else if(r[1]) next_state = B; endC: beginif(r[2] == 1) next_state = C;else if(r[2] == 0) next_state = A;endD: beginif(r[3]) next_state = D;else if(~r[3]) next_state = A;endendcaseendalways@(posedge clk) beginif(~resetn) state <= A;else state <= next_state;endreg [3:1] g_mid;assign g = g_mid;always@(*) begincase(state)A: beging_mid = 0;endB: beging_mid = 3'b001;endC: beging_mid = 3'b010;endD: beging_mid = 3'b100;enddefault: beging_mid = 0;endendcaseendendmodule
测试成功。
设计解释
r代表请求,从低位到高位,优先级依次递减,就是这个意思。
值得一提的是,那句关键描述:The FSM stays in state A as long as there are no requests.
没有请求时,状态机的状态保持在A状态,我们实现的方式就是通过在always块的第一条语句加上默认语句:
always@(*) begin
next_state = A;
case(state)
A: begin
if(r[1]) next_state = B;
else if(r == 3'b000) next_state = A;
else if(r[2:1] == 2'b10) next_state = C;
else if(r == 3'b100) next_state = D;
end
B: begin
if(r[1] == 0) next_state = A;
else if(r[1]) next_state = B;
end
C: begin
if(r[2] == 1) next_state = C;
else if(r[2] == 0) next_state = A;
end
D: begin
if(r[3]) next_state = D;
else if(~r[3]) next_state = A;
end
endcase
end
HDLBits 系列(36)Arbitration circuit implemented by FSM相关推荐
- HDLBits 系列(0)专题目录
本篇博文是近来总结HDLBits系列的目录,点击蓝色字体即可进入查看具体内容. HDLBits 系列(1)从HDLBits中获取灵感,整顿自己,稳步前行 HDLBits 系列(2)如何避免生成锁存器? ...
- HDLBits 系列(31)Serial Receiver and Datapath
目录 序言 原题复现 我的设计 序言 上篇博文: HDLBits 系列(30)Serial Receiver 写了串行接收器如何接收8位串行数据,正确接收8位串行数据后给一个接收完毕标志信号,这篇博文 ...
- HDLBits 系列(29)PS/2 mouse protocol(PS/2 packet parser and datapath)
目录 序言 原题传送 题目解释 我的设计 序言 上篇博客: HDLBits 系列(28)PS/2 mouse protocol(PS/2 packet parser) 只对PS/2 mouse pro ...
- ABLIC Inc.推出汽车用S-19192系列3-6芯串联电池监测IC
日本千叶--(美国商业资讯)--ABLIC Inc.(总裁:Nobumasa Ishiai:总部:千叶县千叶市,以下简称"ABLIC")今日推出汽车用S-19192系列3-6芯串联 ...
- HDLBits 系列(34)Serial two's complememter(Mealy and Moore FSM)
目录 Mealy 状态机 原题复现 我的设计 Moore 状态机 原题复现 状态转移图 我的设计 Mealy 状态机 原题复现 原题复现: The following diagram is a Mea ...
- HDLBits 系列(33)Sequence Recognition with Mealy FSM
目录 原题复现 状态转移图 我的设计 测试 原题复现 原题重现: Implement a Mealy-type finite state machine that recognizes the seq ...
- HDLBits 系列(27)孰对孰错 之 Fsm onehot?
目录 前言 原题复现 审题 我的设计 测试吐槽 最后的解决方案 前言 今天的这个问题,并没有满意的解决,路过的朋友,看出问题所在的,可以给个评论,谢谢. 原题复现 Fsm onehot 下面是一个最基 ...
- HDLBits 系列(24)进入FSM(有限状态机)的世界入口
目录 Fsm1 Fsm1s Fsm2 Fsm3comb Fsm1 This is a Moore state machine with two states, one input, and one o ...
- HDLBits 系列(44)状态机补录
文章目录 前言 原题复现 题目解析 状态转移图 设计文件 前言 今天补一个状态机的题目,也是这个系列的题目之一,但是由于之前对题目有点疑惑,今天得到博友反馈,让我明白了这个题目的意思,记录一下. 原题 ...
最新文章
- List(JDK1.7)(1)
- linux存储--从内核文件系统看文件读写过程(四)
- 建立STM32的工程步骤(版本1)
- 7 php程序的调试方法_php程序调试方法总结
- 物料分类账的基本原理
- boost::regex模块部分正则表达式相关的测试程序
- Effective Java~9. try-with-resource 优先于 try-catch
- 12月19日绝地求生服务器维护公告,绝地求生12月19日更新到几点 绝地求生正式服更新维护公告...
- 汇编中NEG和NOT的区别(汇编初学者简单笔记)
- Windows jmeter安装
- PLSQL 14.0.6 安装使用教程
- java 异步编程 CompletableFuture
- AI 考古比胡八一更高效
- 网络流媒体(四)———TS流
- 网易云音乐视频全屏无法关闭
- RPM打包之spec示例
- python数据结构基础(单链表,多链表,二叉树)
- 如何获得CSDN积分(转)
- Avaya Aura System Manager 8.1.3.x Hot Fix for Log4j vulnerabilities.
- 合肥高考成绩怎么查询2021,2021合肥高考成绩查询系统
热门文章
- [转]用 jQuery 实现页面滚动(Scroll)效果的完美方法
- Storm集群安装部署步骤【详细版】
- 通过注册表修改默认浏览器设置
- 抗侧力构件弹性位移如何计算_穿心棒法盖梁施工计算书(工字钢)
- jsp页面取整数 和Java页面取整数
- android xml ui编辑器,Android Studio(八):使用Layout Editor设计UI
- linux那个目录存放用户密码信息,linux试题及答案
- php无法加载dll插件,php无法加载动态库怎么办
- 关于全国大学生智能汽车竞赛有关问题的建议
- 如何用C语音实现传递函数?