当前位置:网站首页>Verilog daily question (vl14 vending machine 1 -- FSM common question types)
Verilog daily question (vl14 vending machine 1 -- FSM common question types)
2022-07-28 17:23:00 【Don't make any more errors】
Vending machines

Title Description :
Design an automatic vending machine , There are three kinds of input currencies , by 0.5/1/2 element , What is the price of the drink 1.5 element , Ask for change , Change will only pay 0.5 element .
ps: The input currency will automatically pass through the edge detection and output one from the rising edge of the clock to 1, On the falling edge to 0 Pulse signal of
Be careful rst by Low level reset
Signal schematic diagram :

d1 0.5 element
d2 1 element
d3 2 element
out1 drinks
out2 small change
The first thought of this problem is the state machine , So first put State diagram Draw out :

It seems a little complicated ... It's much easier to write code according to the state diagram .
The details of the successfully compiled code are as follows :( But there are doubts in the period of state change )
//A:nstate <= (d1)? B:(d2)?C:(d3)?E:nstate;
// Here is a point that I don't understand , If you put the last nstate It's written in A Will report a mistake ,out1 Some values will be lost , But clearly d1d2d3 All for 0 when , Is to keep A Keep it the same ,nstate=A No problem, it should .( See the answer to change nstate)
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***********//
// This question should use FSM To do it
// Statement 7 Status
parameter A=0,B=1,C=2,D=3,E=4,F=5,G=6;
reg [2:0] state,nstate;
// Logical change
always @(*) begin
case(state)
A:nstate <= (d1)? B:(d2)?C:(d3)?E:nstate;
// Here is a point that I don't understand , If you put the last nstate It's written in A Will report a mistake , But clearly d1d2d3 All for 0 when , Is to keep A Keep it the same ,nstate=A No problem, it should
B:nstate <= (d1)? C:(d2)?D:(d3)?F:nstate;
C:nstate <= (d1)? D:(d2)?E:(d3)?G:nstate;
D:nstate <= A;
E:nstate <= A;
F:nstate <= A;
G:nstate <= A;
default: nstate <= A;
endcase
end
// Timing changes
always @(posedge clk or negedge rst)begin
if(!rst) state<=A;
else state<=nstate;
end
// Output decision
always @(*)begin
case(state) // Output only when there is a rising edge of the answer , And press nstate To make output judgment
D: begin out1<=1;out2<=0; end
E: begin out1<=1;out2<=1; end
F: begin out1<=1;out2<=2; end
G: begin out1<=1;out2<=3; end
default: begin out1<=0;out2<=0; end
endcase
end
//*************code***********//
endmoduleIn the answer, you can also see that simple registers are used to determine , That is, to judge by adding and counting , It seems to be a good idea , And the code will be much simpler .

边栏推荐
- Goweb开发之Beego框架实战:第一节 Beego框架介绍
- Verilog 每日一题 (VL27 可置位计数器)
- Verilog 每日一题(VL6 数据串转并电路)
- 批量下载文件
- Unity3d simple implementation of water surface shader
- MySQL数据库增删改查(基础操作命令详解)
- 高速电路中电阻的选择
- 我为什么选择使用Go语言?
- The practice of the beego framework of goweb development: Section II project initialization configuration
- valarray数值库学习
猜你喜欢

高速电路中电阻的选择

Goweb开发之Beego框架实战:第一节 Beego框架介绍

高速电路中电感的选型和应用

【CDH】通过 ClouderaManager 配置CDH组件用 prometheus 监控采集JMX信息

【atlas】atlas 编译报错整理(全)

Using SQL server agent job to restore the database regularly

Goweb开发之Beego框架实战:第五节 项目搭建及注册用户

Introduction to vscade interface

微服务架构-服务注册中心和服务网关(6.8) (转载)

【kibana】问题整理 kibana 7.x No indices match pattern “apm-*“
随机推荐
2021年4月份自考
线性代数及矩阵论(八)
Why do I choose to use go language?
Verilog 每日一题(VL4 移位运算与乘法)
Use Alibaba cloud's free SSL certificate
Codeforces round 770 (Div. 2) e. fair share
How to protect image security during construction
Net framework
Ugui learning notes (VI) get the information of the clicked UI
wpf命令按钮透明样式
Verilog daily question (vl26 simple stopwatch)
Analysis of kubernetes service principle
QR code generation of wechat applet with parameters
使用阿里云免费的SSL证书
Jupyter notebook win installation record
Verilog daily question (vl24 multi bit MUX synchronizer cross time domain output)
Unity shader procedural texture
How do we do full link grayscale on the database?
Goweb开发之Beego框架实战:第四节 数据库配置及连接
数据库故障容错之系统时钟故障