当前位置: 首页 > news >正文

「Verilog学习笔记」自动贩售机1

专栏前言

本专栏的内容主要是记录本人学习Verilog过程中的一些知识点,刷题网站用的是牛客网

自动贩售机中可能存在的几种金额:0,0.5,1,1.5,2,2.5,3。然后直接将其作为状态机的几种状态,并根据投币面额确定状态转移。

需要注意的是:根据时序图,可以发现在找零时,out2输出的结果是找零数额的两倍,即找零0.5应输出1,找零1应输出2,以此类推。

`timescale 1ns/1ns
module seller1(input wire clk  ,input wire rst  ,input wire d1 ,input wire d2 ,input wire d3 ,output reg out1,output reg [1:0]out2
);
//*************code***********//parameter S0 = 0, S0_5 = 1, S1 = 2, S1_5 = 3, S2 = 4, S2_5 = 5, S3 = 6 ; reg [2:0] state, nstate ;always @ (posedge clk or negedge rst) begin if (~rst) state <= S0 ; else state <= nstate ; endalways @ (*) begin case (state) S0 : nstate = d1 ? S0_5 : d2 ? S1 : d3 ? S2 : nstate ;S0_5 : nstate = d1 ? S1 : d2 ? S1_5 : d3 ? S2_5 : nstate ; S1 : nstate = d1 ? S1_5 : d2 ? S2 : d3 ? S3 : nstate ; S1_5, S2, S2_5, S3 : nstate = S0 ; default : nstate = S0 ; endcase endalways @ (*) begin if (~rst) out1 <= 'd0 ; else out1 <= state == S1_5 || state == S2 || state == S2_5 || state == S3 ; endalways @ (*) begin if (~rst) out2 <= 'd0 ; else case (state) S0, S0_5, S1, S1_5 : out2 <= 1'd0 ; S2 : out2 <= 1'd1 ; S2_5 : out2 <= 2'd2 ; S3 : out2 <= 2'd3 ; default : out2 <= 'd0 ; endcaseend 	//*************code***********//
endmodule
http://www.lryc.cn/news/251226.html

相关文章:

  • 【大模型】更强的 ChatGLM3-6B 来了,开源可商用
  • Maxscript到Python转换工具教程
  • Spark_日期参数解析参数-spark.sql.legacy.timeParserPolicy
  • C语言之结构体
  • 【蓝桥杯软件赛 零基础备赛20周】第5周——高精度大数运算与队列
  • C#:程序发布的大小控制
  • Python中的split()、rsplit()、splitlines()的区别
  • 上位机开发框架:QT与winform/wpf对比
  • Halcon tiff 点云读取以及平面矫正
  • 详解Spring中基于注解的Aop编程以及Spring对于JDK和CGLIB代理方式的切换
  • 百度/抖音/小红书/微信搜索品牌形象优化怎么做?
  • 爬虫学习(三)用beautiful 解析html
  • OSG编程指南<十四>:OSG纹理渲染之普通纹理、多重纹理、Mipmap多级渐远纹理及TextureRectangle矩阵纹理
  • Langchain-Chatchat的安装过程
  • Windows系列:Windows Server 2012 R2 安装VMware Tools的正确姿势(实现物理机和虚拟机文件互传)
  • 最长连续递增序列
  • FreeRTOS入门--任务
  • 4个解决特定的任务的Pandas高效代码
  • 【已解决】AttributeError: module ‘gradio‘ has no attribute ‘Image‘
  • 高级软件工程15本书籍
  • 计网Lesson3 - 计算机网络评价指标与封包解包
  • 深度学习好文记录,反复学习
  • CSS浅谈动画性能
  • 万能的视频格式播放器
  • 设计模式---第五篇
  • .NET8构建统计Extreme Optimization Numerical Libraries
  • 07-原型模式-C语言实现
  • 深度学习与深度迁移学习有什么区别?
  • 创建Asp.net MVC项目Ajax实现视图页面数据与后端Json传值显示
  • 1089 Insert or Merge (插入排序,相邻归并排序,附模拟实现)