Thursday, 14 November 2013

verilog code for washing machine

hello guys....

i am providing u a verilog code for washing machine with testbench....




WASHING MACHINE

module wm(clk,rst,coin, lid_r, d_wash, T, soak,rinse, spin, wash,pause,break);
 input clk,rst,coin,lid_r,d_wash,T;
 output reg soak,rinse,spin,wash,pause,break;
 reg[2:0] cst, nst;

 // state assignment
 parameter IDLE = 3'b000,
           SOAK = 3'b001,
             WASH=3'b010,
             RINSE=3'b011,
             WASH2=3'b100,
             RINSE2=3'b101,
             SPIN=3'b110,
             PAUSH=3'b111;

always @(cst or coin or d_wash or lid_r or T)
begin
   case (cst)
     IDLE:
if(coin==1)
          begin
          nst=SOAK;
          soak=1;
          rinse=0;
          spin=0;
          wash=0;
          pause=0;
          break=0;
          end
else

          begin
          nst=cst;
          soak=0;
          rinse=0;
          spin=0;
          wash=0;
          pause=0;
          break=0;
          end

SOAK:
if(T==1)

          begin
          nst=WASH;
          soak=0;
          rinse=0;
          spin=0;
          wash=1;
          pause=0;
          break=0;
          end
else
          begin
          nst=cst;
          soak=1;
          rinse=0;
          spin=0;
          wash=0;
          pause=0;
          break=0;
          end
     WASH:
if(T==1)

          begin
          nst=RINSE;
          soak=0;
          rinse=1;
          spin=0;
          wash=0;
          pause=0;
          break=0;
          end
else
          begin
          nst=cst;
          soak=0;
          rinse=0;
          spin=0;
          wash=1;
          pause=0;
          break=0;
          end
RINSE:
if(T==1 && d_wash==1)

          begin
          nst=WASH2;
          soak=0;
          rinse=0;
          spin=0;
          wash=1;
          pause=0;
          break=0;
          end
else if(T==1 && d_wash==0)

          begin
          nst=SPIN;
          soak=0;
          rinse=0;
          spin=1;
          wash=0;
          pause=0;
          break=0;
          end
else
          begin
          nst=cst;
          soak=0;
          rinse=1;
          spin=0;
          wash=0;
          pause=0;
          break=0;
          end
WASH2:
if(T==1)

          begin
          nst=RINSE2;
          soak=0;
          rinse=1;
          spin=0;
          wash=0;
          pause=0;
          break=0;
          end
else
          begin
          nst=cst;
          soak=0;
          rinse=0;
          spin=0;
          wash=1;
          pause=0;
          break=0;
          end

RINSE2:
if(T==1)
          begin
          nst=SPIN;
          soak=0;
          rinse=0;
          spin=1;
          wash=0;
          pause=0;
          break=0;
          end
else
          begin
          nst=cst;
          soak=0;
          rinse=1;
          spin=0;
          wash=0;
          pause=0;
          break=0;
          end
SPIN:
if(T==0 && lid_r==1)
          begin
          nst=PAUSH;
          soak=0;
          rinse=0;
          spin=0;
          wash=0;
          pause=1;
          break=0;
          end
else if(T==1)
          begin
          nst=IDLE;
          soak=0;
          rinse=0;
          spin=0;
          wash=0;
          pause=0;
          break=0;
          end
else
          begin
          nst=cst;
          soak=0;
          rinse=0;
          spin=1;
          wash=0;
          pause=0;
          break=0;
          end
PAUSH:
if(lid_r==0)
          begin
          nst=SPIN;
          soak=0;
          rinse=0;
          spin=1;
          wash=0;
          pause=0;
          break=0;
          end
else
          begin
          nst=cst;
          soak=0;
          rinse=0;
          spin=0;
          wash=0;
          pause=1;
          break=0;
          end
     default:
nst=IDLE;
   endcase
  end
always @(posedge clk or negedge rst)
begin
   if (rst)
     cst <= IDLE;
    else
     cst <= nst;
 end
/*
  assign soak = (cst == SOAK);
  assign rinse = (cst == RINSE) | (cst == RINSE2);
  assign brake = (cst == PAUSE);
  assign spin = (cst == SPIN);
  assign wash = (cst == WASH) | (cst == WASH2);
*/
endmodule

TEST BENCH

module wm_tb;
reg clk,reset,coin,lid_r,d_wash,T;
wire soak,rinse,spin,wash,pause,break;
wm m1(clk,reset,coin,lid_r,d_wash,T,soak,rinse,spin,wash,pause,break);
initial
begin

$monitor($time, ,,"c=%b",clk,,"t=%b",coin,,"l=%b",lid_r,,"d=%b",d_wash,,"T=%b",T,,"s=%b",soak,,"r=%b",rinse,,"S=%b",spin,,"w=%b",wash,,"p=%b",pause,,"b=%b",break);
reset=0       ;clk=0;coin=0;lid_r=0;d_wash=0;T=0;
#10 coin=1;
#10 T=1;coin=0;
#20 d_wash=1;
#30 lid_r=1;d_wash=0;T=0;
#10 lid_r=0;T=0;
#10 T=1;lid_r=0;
#10 T=1;
#10 coin=1;T=0;
//#10 T=1;
//#10 T=1;
//#5 reset=1;
//#5 reset=0;
end
always
#5 clk=~clk;
initial
#100 $finish ;

endmodule

17 comments:

  1. Gud one...modify your code for standard design :
    If you use logic high for reset then use posedge reset statement in always block...!!!
    define task in test-bench for repetitive control signal.
    always disable all control signal in start of always block in FSM design.

    ReplyDelete
    Replies
    1. ya...i tried during practice...........but during upload i changed it....so sorry for that....i put reset on neg edge during practice.....

      Delete
    2. i put here only for reference purpose....u can modify accordingly.......

      Delete
    3. dear dhaval,
      i have an urgent requirement ,if u dont mind plz send to my mail id (yedunath.k@gmail.com) following details as per above verilog
      1-state diagram
      2-transition table
      3-excitation table
      4-kmap
      5-circuit

      Delete
  2. how can i implement it in FPGA development board

    ReplyDelete
    Replies
    1. I had implement it on Xilinx FPGA board. In your case you need to configure toggle button for input and for output u can watch out led pin number from your respective FPGA board and then dump code through any JTAG connector.

      Delete
  3. Replies
    1. Nst - next state
      Cst - current state

      Delete
    2. Nst - next state
      Cst - current state

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  5. Can you pls provide me vhdl code for washing machine controller for my project on my email id ramayadav1970@gmail.com its urgent.

    ReplyDelete
  6. nice work dhaval keep doing bro

    ReplyDelete
  7. hey I am trying to implement md5 in my code please help me getting some wrong hash value for more please contact me on akshayamj4@gmail.com

    ReplyDelete