报纸售卖机的投币器的实现

设计说明
设计一个简单的数字电路用于电子的报纸售卖机的投币器
电路要求有限状态机描述

报纸售卖机的投币器的实现

文章插图
摩尔型状态机三段式表示:第一个用来次态和现态的转换,第二个用于现态在输入情况下转换为次态的组合逻辑;第三个语句用于现态到输出的组合逻辑输出 。
`timescale 1ns / 1psmodule vend(input [1:0] coin,input clk,input reset,output newspaper);reg [1:0] state,next_state;reg reset1,reset2;parameter S0 = 2'b00, S5 = 2'b01, S10 = 2'b10, S15 = 2'b11;parameter X0 = 2'b00, X5 = 2'b01, X10 = 2'b10;assign newspaper = (state == S15)?1'b1:1'b0;always@(posedge clk or negedge clk)beginif(reset == 1'b0)beginreset1 <= 1'b0;reset2 <= 1'b0;endelse beginreset1 <= reset;reset2 <= reset1;endendalways@(posedge clk or negedge reset2)beginif(reset2 == 1'b0)beginstate = S0;endelse beginstate <= next_state;endendalways@(*)beginif(reset2 == 1'b0)beginnext_state <= S0;endelse begincase(state)S0:beginif(coin == X0)next_state <= S0;else if(coin == X5)next_state <= S5;else if(coin == X10)next_state <= S10;elsenext_state <= S0;endS5: beginif(coin == X0)next_state <= S5;else if(coin == X5)next_state <= S10;else if(coin == X10)next_state <= S15;elsenext_state <= S5;endS10: beginif(coin == X5 || coin == X10)next_state <= S15;else next_state <= S10;endS15: beginnext_state <= S0;endendcaseendendendmodule
报纸售卖机的投币器的实现

文章插图
`timescale 1ns / 1ps//// Company: // Engineer: // // Create Date: 2022/07/12 16:14:58// Design Name: // Module Name: vend_tb// Project Name: // Target Devices: // Tool Versions: // Description: // // Dependencies: // // Revision:// Revision 0.01 - File Created// Additional Comments:// //module vend_tb();reg clk;reg reset;reg [1:0] coin;wire newspaper;initial beginclk = 0;coin = 0;reset = 1;#20reset = 0;#50reset = 1'b1;@(posedge clk)#80 coin = 2'b01;#10 coin = 2'b00;#40 coin = 2'b10;#10 coin = 2'b00;#40 coin = 2'b10;#10 coin = 2'b00;#40 coin = 2'b10;#10 coin = 2'b00;#40 coin = 2'b10;#10 coin = 2'b00;#40 coin = 2'b01;#10 coin = 2'b00;endalwaysbegin#5 clk = ~clk;endvend inst_vend(.clk(clk),.reset(reset),.coin(coin),.newspaper(newspaper));endmodule
其中采用异步复位同步释放,但其中代码块中使用了两种边沿的检测电路,这是不规范的,可以看到状态转移正确 。
【报纸售卖机的投币器的实现】其中需要注意的点主要是状态图的正确迁移