广西南宁网站建设排行榜,建设一个视频网站己18,特价网站建设官网,企业的漏沟设计公司自动贩售机1
题目描述#xff1a;
设计一个自动贩售机#xff0c;输入货币有三种#xff0c;为0.5/1/2元#xff0c;饮料价格是1.5元#xff0c;要求进行找零#xff0c;找零只会支付0.5元。 ps: 投入的货币会自动经过边沿检测并输出一个在时钟上升沿到1#xff0c;在…自动贩售机1
题目描述
设计一个自动贩售机输入货币有三种为0.5/1/2元饮料价格是1.5元要求进行找零找零只会支付0.5元。 ps: 投入的货币会自动经过边沿检测并输出一个在时钟上升沿到1在下降沿到0的脉冲信号 注意rst为低电平复位
信号示意图
timescale 1ns/1nsmodule seller1(input wire clk ,input wire rst ,input wire d1 ,input wire d2 ,input wire d3 ,output reg out1,output reg [1:0]out2
);parameter S0 d0, S1 d1, S2 d2, S3 d3 , S4 d4, S5 d5 , S6 d6;reg [2:0] current_state;reg [2:0] next_state;wire [2:0] input_state;//将输入组合起来assign input_state {d1,d2,d3};always(posedge clk or negedge rst)beginif(rst 1b0)begincurrent_state S0;endelse begincurrent_state next_state;endend always(*)begincase(current_state)S0:begincase(input_state)3b100:next_state S1 ;3b010:next_state S2 ;3b001:next_state S4 ;default:next_state next_state;endcase endS1:begincase(input_state)3b100:next_state S2 ;3b010:next_state S3 ;3b001:next_state S5 ;default:next_state next_state; endcaseendS2:begincase(input_state)3b100:next_state S3 ;3b010:next_state S4 ;3b001:next_state S6 ;default:next_state next_state;endcase enddefault:beginnext_state S0;endendcaseendalways(posedge clk or negedge rst)beginif(rst 1b0)beginout1 1b0;out2 2b0;endelse begincase(next_state)S3: begin out1 1b1;out2 2b0; end S4: begin out1 1b1;out2 2b1; end S5: begin out1 1b1;out2 2b10; end S6: begin out1 1b1;out2 2b11; end default: begin out1 1b0;out2 2b0; end endcase endendendmodule