Textbook Notes (290,000)
US (110,000)
LSU (20,000)
EE (300)
EE 2731 (60)
All (60)
Chapter

Elevator Verilog


Department
Electrical Engineering
Course Code
EE 2731
Professor
All

This preview shows pages 1-2. to view the full 8 pages of the document.
module Elevator (F1,F2,F3,F4,led1,led2,led3,led4,door,clk,d_switch);
input F1;
input F2;
input F3;
input F4;
input clk;
input d_switch;
output reg led1 = 1;
output reg led2 = 0;
output reg led3 = 0;
output reg led4 = 0;
output reg door = 0;
parameter [2:0]
A=3'b000,
B=3'b001,
C=3'b010,
D=3b011,
E=3'b100,
F=3'b101,
G=3'b110,
H=3'b111;
reg [2:0] x=3'b000;
reg [2:0] y=3'b000;
always @(posedge clk)
begin
case (y)
//First floor. Door open.
A :
if (d_switch)
begin
led1 <= 1;
door <= 1;
x <= 0;
end
else if (F1 && !F2 && !F3 && !F4)
begin
led1 <= 1;
led2 <= 0;
led3 <= 0;
led4 <= 0;
door <= 1;
x <= x+1;

Only pages 1-2 are available for preview. Some parts have been intentionally blurred.

if (x == 4)
begin
led1 <= 1;
door <= 0;
y <= E;
end
end
else if (!F1 && !F2 && !F3 && !F4)
begin
if (x < 4)
begin
x <= x+1;
led1 <= 1;
door <= 1;
end
else if (x == 4)
begin
led1 <= 1;
door <= 0;
y <= E;
end
end
//F2 open
B :
if (d_switch)
begin
led2 <= 1;
door <= 1;
x <= 0;
end
else if (!F1 && F2 && !F3 && !F4 )
begin
led1 <= 0;
led2 <= 1;
led3 <= 0;
led4 <= 0;
door <= 1;
x <= x+1;
if (x == 4)
begin
led2 <= 1;
door <= 0;
y <= F;
end
end
You're Reading a Preview

Unlock to view full version

Only pages 1-2 are available for preview. Some parts have been intentionally blurred.

else if (!F1 && !F2 && !F3 && !F4)
begin
if (x < 4)
begin
x <= x+1;
led2 <= 1;
door <= 1;
end
else if (x == 4)
begin
led2 <= 1;
door <= 0;
y <= F;
end
end
//F3 open
C :
if (d_switch)
begin
led3 <= 1;
door <= 1;
x <= 0;
end
else if (!F1 && !F2 && F3 && !F4 )
begin
led1 <= 0;
led2 <= 0;
led3 <= 1;
led4 <= 0;
door <= 1;
x <= x+1;
if (x == 4)
begin
led3 <= 1;
door <= 0;
y <= G;
end
end
else if (!F1 && !F2 && !F3 && !F4)
begin
if (x < 4)
begin
x <= x+1;
led3 <= 1;
door <= 1;
end
You're Reading a Preview

Unlock to view full version