Verilog Mealy State Machine, торговый автомат - PullRequest
0 голосов
/ 19 апреля 2020

Я пытаюсь создать торговый автомат, который выдает газировку, когда вы получаете доллар, и он принимает долларовые купюры и кварталы. Я сталкиваюсь с проблемой, хотя, что, когда я перехожу от Cstate до Dstate, 50 центов к 75 центам, это распределяет газировку по некоторой причине. Все, что я понял, это в Dstate, при D = 0 и Q = 1, если я изменяю газировку <= 1'b1 на 1'b0, это устраняет проблему, но также устраняет газировку при переходе от Dstate к Astate , что составляет 75 центов за доллар, который должен производить газировку. Я работаю в vivado, программирую плату BASYS3. Кроме того, если есть какие-либо советы о том, как получить на семи сегментных дисплеях надпись SODA при выдаче соды, это также было бы очень полезно. </p>

module Final2(reset, Q, D, clk, a, b, c, d, e, f, g, anode0, anode1, anode2, anode3, dp, soda);

    input D,Q,clk;


    output reg a, b, c, d, e, f, g;

    output anode0, anode1, anode2, anode3, dp;

    output reg soda; 

    reg [1:0] Spresent, Snext;

    parameter Astate = 2'b00, Bstate = 2'b01, Cstate = 2'b10, Dstate = 2'b11; 

    reg [27:0] counter; 
    reg enable; 
    input reset;

    //combinational circuit 

    always @ (Spresent) 

    case (Spresent) 

        Astate: if (D == 0 & Q == 0)
            begin  
            Snext = Astate;  
            soda <=1'b0;
            end
    else if (D == 0 & Q == 1) 
            begin 
            Snext = Bstate; 
            soda <=1'b0;
            end
    else if (D == 1  & Q == 0)
            begin
            Snext =Astate; 
            soda <=1'b1;
            end
    else if (D == 1 & Q == 1)
            begin 
            Snext = Bstate;
            soda <=1'b1;
            end

    Bstate: if (D == 0 & Q == 0) 
            begin 
            Snext = Bstate; 
            soda <=1'b0;
            end 
    else if (D == 0 & Q == 1) 
            begin 
            Snext = Cstate; 
            soda <=1'b0;
            end
    else if (D == 1  & Q == 0)
            begin 
            Snext =Bstate;
            soda <=1'b1;
            end
    else if (D == 1 & Q == 1) 
            begin
            Snext = Cstate;
            soda <=1'b1;
            end
    else if ( reset == 1) Snext = Astate;

    Cstate: if (D == 0 & Q == 0)
            begin 
            Snext = Cstate;
            soda <=1'b0;
            end 
    else if (D == 0 & Q == 1)
            begin 
            Snext = Dstate;
            soda <=1'b0;
            end
    else if (D == 1  & Q == 0)
            begin 
            Snext = Cstate;
            soda <=1'b1;
            end
    else if (D == 1 & Q == 1)
            begin 
            Snext = Dstate;
            soda <=1'b1;
            end
    else if (reset == 1) Snext = Astate;

   Dstate: if (D == 0 & Q == 0) 
             begin 
             Snext = Dstate;
             soda <=1'b0;
             end 
    else if (D == 0 & Q == 1) 
            begin 
            Snext = Astate;
            soda <=1'b1;
            end
    else if (D == 1  & Q == 0)
            begin 
            Snext =Dstate;
            soda <=1'b1;
            end
    else if (D == 1 & Q == 1) 
            begin 
            Snext = Astate;
            soda <=1'b1;
            end 
    else if (reset == 1) Snext = Astate;
    endcase 


    //sequential circuit 


    always @ (posedge clk) 

    begin 

    if(counter == 28 'd0) counter <= 28 'd25_000_000; 
        else counter <= counter - 1 'd1; 

    enable <= counter == 28 'd0; 

    end 

  always @ (posedge clk) 

  begin

   if (reset ==1) 

    Spresent <= Astate; 

    else 

    if (enable==1)
    Spresent <= Snext;

    end

   always @ (Spresent) 

   if (soda == 1)

   case ({Spresent}) 

    anode3: {a,b,c,d,e,f,g} = 'b0100100; 
    anode2: {a,b,c,d,e,f,g} = 'b1100010; 
    anode1: {a,b,c,d,e,f,g} = 'b1000010; 
    anode0: {a,b,c,d,e,f,g} = 'b0001000;

   endcase 

   else 

   case ({Spresent})

        2 'b00: {a,b,c,d,e,f,g} = 'b0001000; 
        2 'b01: {a,b,c,d,e,f,g} = 'b1100000; 
        2 'b10: {a,b,c,d,e,f,g} = 'b1110010; 
        2 'b11: {a,b,c,d,e,f,g} = 'b1000010;

        endcase

     assign anode0 = 0;
     assign anode1 = 0; 
     assign anode2 = 0;
    assign anode3 = 0; 

    endmodule
...