Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- `timescale 1ns / 100ps
- module pump_fsm (
- input wire [0:0] clk,
- input wire [0:0] reset,
- input wire [0:0] update,
- input wire [1:0] command,
- output reg [0:0] pump,
- output reg [0:0] led
- );
- /* Define state parameters */
- localparam
- off = 0,
- standby = 1,
- working = 2;
- /* Define command values */
- localparam
- turnoff = 2'b00,
- turnon = 2'b01,
- stoppump = 2'b10,
- startpump = 2'b11;
- // Add your own code here
- reg [1:0] cur_state;
- reg [1:0] next_state;
- reg prev_update;
- reg cur_led;
- reg cur_pump;
- always @(posedge clk) begin
- cur_state<=next_state;
- prev_update<=update;
- led <= cur_led;
- pump <= cur_pump;
- end
- always @(*) begin
- if(reset) begin next_state=0;
- cur_led=1'b0;
- cur_pump=1'b0;
- end
- else if(update||update!=prev_update) begin
- case(cur_state)
- off: begin if(command==turnon) begin next_state=standby;
- cur_led=1'b1;
- cur_pump=1'b0;
- end
- else begin
- next_state=off;
- cur_led=1'b0;
- cur_pump=1'b0;
- end
- end
- standby:begin if(command==turnoff)begin next_state=off;
- cur_led=1'b0;
- cur_pump=1'b0;
- end
- else if(command==startpump) begin next_state=working;
- cur_led=1'b1;
- cur_pump=1'b1;
- end
- else begin next_state = standby;
- cur_led=1'b1;
- cur_pump=1'b0;
- end
- end
- working:begin if(command==turnoff)begin next_state=off;
- cur_led=1'b0;
- cur_pump=1'b0;
- end
- else if(command==stoppump)begin next_state=standby;
- cur_led=1'b1;
- cur_pump=1'b0;
- end
- else begin next_state = working;
- cur_led=1'b1;
- cur_pump=1'b1;
- end
- end
- default:
- begin
- next_state=off;
- cur_led=1'b0;
- cur_pump=1'b0;
- end
- endcase
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement