Answered step by step
Verified Expert Solution
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 iclk
input irst
input ibuttonpressed,
input : ibuttonvalue,
output reg : ofloor
;
Define states for the FSM
localparam IDLE b;
localparam UP b;
localparam DOWN b;
Internal state register
reg : currentState;
reg : nextState;
Register to store requested floors
reg : requestedFloors;
always @posedge iclk or posedge irst begin
if irst begin
Reset on system reset
currentState IDLE;
requestedFloors ;
ofloor ;
end else begin
currentState nextState;
Update requested floors based on button press
if ibuttonpressed begin
requestedFloors ibuttonvalue;
end
case currentState
IDLE: begin
If a button is pressed, move to the appropriate direction
if ibuttonpressed begin
if ibuttonvalue ofloor 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:ofloor ofloor begin
nextState checkDirection;
else begin
nextState UP;
ofloor ofloor ;
requestedFloors requestedFloors & ~ ofloor; Clear visited floor
end
end
DOWN: begin
Move down until no more floors requested or ground floor reached
if ~requestedFloorsofloor: ofloor begin
nextState checkDirection;
else begin
nextState DOWN;
ofloor ofloor ;
requestedFloors requestedFloors & ~ ofloor; Clear visited floor
end
end
endcase
end
end
Function to check direction based on remaining requests
function reg : checkDirection;
begin
if requestedFloors begin
if requestedFloors 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started