当前位置:网站首页>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框架实战:第五节 项目搭建及注册用户

配置V530交换机步骤

Verilog daily question (vl28 plus and minus counter)

mysql 最大建议行数2000w,靠谱吗?

Verilog daily question (vl29 single port RAM)

Introduction to vscade interface

Several methods of importing excel file data by C #

Realize the reset function of steering wheel UI with touch rotation and finger departure in unity

线性代数及矩阵论(九)

Verilog 每日一题 (VL28 加减计数器)
随机推荐
Jupyter notebook win installation record
异步电路设计--同步脉冲器原理及例题
Round 1A 2022 - Code jam 2022 c.weightlifting (interval DP)
微服务架构-服务注册中心和服务网关(6.8) (转载)
Games101 assignment04 job 04
Codeforces Round #750 (Div. 2) F.Korney Korneevich and XOR (easy&&hard version)(dp)
Modeling Semantics with Gated Graph Neural Networks for KBQA
Cf/atc/lc topic score website
Atcoder regular contest 133 d.range XOR (digital dp+ classification discussion)
使用阿里云免费的SSL证书
连接设计与测试平台——SystemVerilog 接口知识点总结
Application of Pegasus d200s UAV and airborne lidar in large-scale DEM construction
Verilog 每日一题(VL26 简易秒表)
我为什么选择使用Go语言?
Goweb开发之Beego框架实战:第四节 数据库配置及连接
Unity shader uses rendered texture to achieve glass effect
线性代数及矩阵论(八)
Gray code and binary conversion and typical examples (4bits gray code counter)
Verilog 每日一题(VL4 移位运算与乘法)
Differences between CNSA and CASC and CASIC