Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i got given this code but it has errors. i am using vivado verilog. module ElevatorController ( input i _ clk , input i _

i got given this code but it has errors. i am using vivado verilog.
module ElevatorController (
input i_clk,
input i_rst,
input i_button_pressed,
input [2:0] i_button_value,
output reg [2:0] o_floor
);
// Define states for the FSM
localparam IDLE =3'b000;
localparam UP =3'b001;
localparam DOWN =3'b010;
// Internal state register
reg [2:0] currentState;
reg [2:0] nextState;
// Register to store requested floors
reg [7:0] requestedFloors;
always @(posedge i_clk or posedge i_rst) begin
if (i_rst) begin
// Reset on system reset
currentState = IDLE;
requestedFloors =0;
o_floor =0;
end else begin
currentState = nextState;
// Update requested floors based on button press
if (i_button_pressed) begin
requestedFloors |=(1 i_button_value);
end
case (currentState)
IDLE: begin
// If a button is pressed, move to the appropriate direction
if (i_button_pressed) begin
if (i_button_value > o_floor) begin
nextState = UP;
else begin
nextState = DOWN;
end
end else begin
nextState = IDLE;
end
end
UP: begin
// Move up until no more floors requested or top floor reached
if (~requestedFloors[7:o_floor+1]|| o_floor ==7) begin
nextState = checkDirection();
else begin
nextState = UP;
o_floor = o_floor +1;
requestedFloors = requestedFloors & ~(1 o_floor); // Clear visited floor
end
end
DOWN: begin
// Move down until no more floors requested or ground floor reached
if (~requestedFloors[o_floor-1:0]|| o_floor ==0) begin
nextState = checkDirection();
else begin
nextState = DOWN;
o_floor = o_floor -1;
requestedFloors = requestedFloors & ~(1 o_floor); // Clear visited floor
end
end
endcase
end
end
// Function to check direction based on remaining requests
function reg [2:0] checkDirection;
begin
if (|requestedFloors) begin
if (requestedFloors[7]) begin
return UP;
end else begin
return DOWN;
end
end else begin
return IDLE;
end
end
endfunction
endmodule can u make sure when i run the simulation it passes.
still has errors
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions