建立网站的程序,迅速编程做网站,网店设计图片,wordpress主题空白专栏前言 本专栏的内容主要是记录本人学习Verilog过程中的一些知识点#xff0c;刷题网站用的是牛客网 自动贩售机中可能存在的几种金额#xff1a;0#xff0c;0.5#xff0c;1#xff0c;1.5#xff0c;2#xff0c;2.5#xff0c;3。然后直接将其作为状态机的几种状… 专栏前言 本专栏的内容主要是记录本人学习Verilog过程中的一些知识点刷题网站用的是牛客网 自动贩售机中可能存在的几种金额00.511.522.53。然后直接将其作为状态机的几种状态并根据投币面额确定状态转移。 需要注意的是根据时序图可以发现在找零时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 1d0 ; S2 : out2 1d1 ; S2_5 : out2 2d2 ; S3 : out2 2d3 ; default : out2 d0 ; endcaseend //*************code***********//
endmodule