Verilog刷题笔记60

server/2024/10/10 19:33:29/

题目:
Exams/2013 q2bfsm
Consider a finite state machine that is used to control some type of motor. The FSM has inputs x and y, which come from the motor, and produces outputs f and g, which control the motor. There is also a clock input called clk and a reset input called resetn.

The FSM has to work as follows. As long as the reset input is asserted, the FSM stays in a beginning state, called state A. When the reset signal is de-asserted, then after the next clock edge the FSM has to set the output f to 1 for one clock cycle. Then, the FSM has to monitor the x input. When x has produced the values 1, 0, 1 in three successive clock cycles, then g should be set to 1 on the following clock cycle. While maintaining g = 1 the FSM has to monitor the y input. If y has the value 1 within at most two clock cycles, then the FSM should maintain g = 1 permanently (that is, until reset). But if y does not become 1 within two clock cycles, then the FSM should set g = 0 permanently (until reset).

(The original exam question asked for a state diagram only. But here, implement the FSM.)

解题:

module top_module (input clk,input resetn,    // active-low synchronous resetinput x,input y,output f,output g
); parameter s0=0,s1=1,s2=2,s3=3,s4=4,s5=5,s6=6,s7=7,s8=8;reg [3:0]state,next_state;always@(posedge clk)beginif(!resetn)state=s0;elsestate=next_state;endalways@(*)begincase(state)s0:next_state=s8;s8:next_state=s1;s1:next_state=x?s2:s1;s2:next_state=x?s2:s3;s3:next_state=x?s4:s1;s4:next_state=y?s6:s5;s5:next_state=y?s6:s7;s6:next_state=s6;s7:next_state=s7;endcaseendassign f=(state==s8);assign g=(state==s4)|(state==s5)|(state==s6);endmodule

结果正确:
在这里插入图片描述

注意点:
专门用一个状态,来表示f置为1 只有一个时钟周期。


http://www.ppmy.cn/server/107664.html

相关文章

【YOLOv8改进[Conv]】 感受野注意力卷积RFAConv(2024.3)| 使用RFAConv改进C2f + 含全部代码和详细修改方式

本文将进行在YOLOv8中使用 感受野注意力卷积RFAConv改进C2f 的实践,助力YOLOv8目标检测效果,文中含全部代码、详细修改方式。助您轻松理解改进的方法。

C++练习题:进阶算法——二分查找

第一部分:考点与作答区 考点: 查找算法的概念二分查找的原理二分查找的实现 作答区: 编写一个C程序,完成以下要求: 使用二分查找算法在一个整型数组中查找一个元素。打印查找结果。 请在下方空白处编写代码&#…

景芯SoC A72实战反馈

先说结论: 内容非常全面,讲解到位,会有专门的工程师一对一答疑,整个项目跑下来提升非常大,绝对物超所值! 一些细节: 本人微电子专业研一在读,有过两次简单的数字芯片流片经历&…

Systemc example based on VCS

README VCS example path: $VCS_HOME/doc/examples/systemc/ SYSTEMC_HOME: module load systemc(or 自己download systemc, VCS_HOME下应该也有:$VCS_HOME/include/systemc233/tlm_utils) gcc需要是7.3.0版本,module load gcc/7.3.0 注意事项 vcs …

MYSQL:简述对B树和B+树的认识

MySQL的索引使用B树结构。 1、B树 在说B树之前,先说说B树,B树是一个多路平衡查找树,相较于普通的二叉树,不会发生极度不平衡的状况,同时也是多路的。 B树的特点是:他会将数据也保存在非叶子节点。而这个…

AI智能大数据分析足球AIAutoPrediction,提高足球比赛预测准确度的新方法

本文摘要:一、I智能大数据分析足球的原理I智能大数据分析足球的原理是利用机器学习和大数据分析技术,对足球比赛的各种数据进行分析和预测。这些数据包括球队历史成绩、球员数据、场地... 一、I智能大数据分析足球的原理 I智能大数据分析足球的原理是利…

基于yolov8的火焰烟雾检测系统python源码+onnx模型+评估指标曲线+精美GUI界面

【算法介绍】 基于YOLOv8的火焰烟雾检测系统是一款高效、实时的智能安全监控解决方案。该系统利用YOLOv8这一先进的深度学习模型,以其卓越的速度和准确性,能够在复杂环境中快速定位并分类火焰与烟雾,即使是微小的火源或稀薄的烟雾也能被精准…

揭秘欧美Affiliate流量变现:Outbrain广告投放的非凡优势

揭秘欧美Affiliate流量变现:Outbrain广告投放的非凡优势 在数字化营销日益激烈的今天,欧美市场的Affiliate流量变现成为了众多品牌与商家的关注焦点。如何精准地触达目标用户,实现高效的流量转化,成为了摆在广告主面前的重要课题…