⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elevator_ctr.v

📁 這是一個Verilog的電梯控制程序碼,控制樓層為1~4樓,關開門...等
💻 V
📖 第 1 页 / 共 2 页
字号:
//*****************************************************
//Filename: elevator_ctr.v
//Author: Harva
//E_mail: hanweier@163.com
//Version: Sept. 3rd 2006
//Description: The simplified elevator control program for a four_storeyed building.
//             ********************************************************************
//             input: clk             //the system clock
//             input: clr             //the system clear signal
//             input: reset           //the reset signal
//             input: close           //the signal to close the door quickly
//             input: open            //the interupt signal to open the door before the elevator get ready to go up or down
//             input: overload        //the signal to show that the elevator is full and over loading
//             input: locked          //the signal to keep the elevator in storey 1 and keep the  door open and refuse all the requests
//             input: req_up1,req_up2,req_up3  //the request signal outside to go up
//             input: req_dn2,req_dn3,req_dn4  //the request signal outside to go down
//             input: req_in1,req_in2,req_in3,req_in4  //the request inside the elevator
//             input: getto1,getto2,getto3,getto4   //the signal to arrival at which storey
//
//             output: [1:0] door_ctr   //used to control the door opening and closing
//             output: [6:0] led_storey //the display of the place of the elevator
//             output: [2:0] led_req_up //the diaplay of the outside requests to go up
//             output: [2:0] led_req_dn //the display of the outside requests to get down
//             output: [3:0] led_reg_in //the display of the inside requests
//             output: [1:0] led_up_dn  //the display of the state of elevator, up,down or stay 
//             output: up               
//             output: down
//             output: alarm            //the alarm signal when the elevator is over loading
//             ************************************************************************

module elevator_ctr(
                     //input
                     clk,                  //????
                     reset,                //??????? 
                     close,                //???????????
                     open,                 //????????????
                     locked,               //????????????????????
                     overload,             //??????
                     req_up1,              //1???????????
                     req_up2,              //2???????????
                     req_up3,              //3???????????
                     req_dn2,              //2??????????? 
                     req_dn3,              //3???????????
                     req_dn4,              //4???????????
                     req_in1,              //???????1????
                     req_in2,              //???????2????
                     req_in3,              //???????3????
                     req_in4,              //???????4????
                     getto1,               //????1????
                     getto2,               //????2????
                     getto3,               //????3????
                     getto4,               //????4????
                     
                     //output
                     door_ctr,             //???????00????01??????11????10?????
                     led_storey,           //7?led?????????
                     led_req_up,           //?????????(1:????0?????
                     led_req_dn,           //?????????(1:????0?????
                     led_req_in,           //???????????(1:????0?????
                     led_up_dn,            //?????????01????10????00????
                     alarm,                //???????? 
                     up,                   //????????
                     down                  //????????
                    );
//input description
input clk;                 //posedge enable 
input reset;                 //negetive enable
input close;               //positive enable
input open;                //positive enable 
input overload;            //positive enable
input locked;              //positive enable
input req_up1,req_up2,req_up3;     //positive enable
input req_dn2,req_dn3,req_dn4;     //positive enable
input req_in1,req_in2,req_in3,req_in4;      //positive enable
input getto1,getto2,getto3,getto4;          //positive enable

//output description
output [1:0] door_ctr;    //the state of the door: 00: close; 01: prepare to open; 11: open; 10: prepare to close
output [6:0] led_storey;
output [2:0] led_req_up;
output [2:0] led_req_dn;
output [3:0] led_req_in;
output [1:0] led_up_dn;
output alarm;
output up;
output down;

reg [2:0] door_ctr;
reg [6:0] led_storey;
reg [1:0] led_up_dn;
reg alarm;
reg up;
reg down;

//internal signal description
reg req_up11,req_up22,req_up33;         //used to register the requests to go up in storey 1,2 and 3
reg req_dn22,req_dn33,req_dn44;         //used to register the requests to go down in storey 2,3 and 4
reg req_in11,req_in22,req_in33,req_in44;//used to register the requests inside in storey 1,2,3 and 4
wire [3:0] req_in_all;                   //all the requests inside
wire [2:0] req_out_up;                   //all the requests outside to go up
wire [2:0] req_out_dn;                   //all the requests outside to go down
wire [3:0] req_all;
reg updown;                             //the state of the elevator, 1: up; 0: down
reg en_up;                              //the signal used to prepare to go up
reg en_dn;                              //the signal used to prepare to go down
reg en_opendoor;                        //the signal used to prepare to open the door
reg [3:0] counter1;                    //the counter used to wait to close the door
reg [1:0] counter2;                    //the counter used to wait to open the door
reg [4:1] clear_in;                    //used to clear up the inside requests
reg [3:1] clear_up;                    //used to clear up the go_up requests
reg [4:2] clear_dn;                    //used to clear up the go_down requests

//This block is used to register all the reqests
//??10?always???????????????
//**********************************************************************
always@(posedge clk)                    //to register the go_up request in storey 1
begin
    if((~reset)||(locked==1))
        req_up11<=0;
    else if(req_up1==1)
        req_up11<=req_up1;
    else if(clear_up[1]==1)               
        req_up11<=0;
    else
        req_up11<=req_up11;
end
always@(posedge clk)                    //to register the inside requeset to storey 1
begin
    if((~reset)||(locked==1))
        req_in11<=0;
    else if(clear_in[1]==1)
        req_in11<=0;
    else if(req_in1==1)
        req_in11<=req_in1;
    else
        req_in11<=req_in11;
end 
always@(posedge clk)                   //to register the go_up request of storey 2
begin
    if((~reset)||(locked==1))
        req_up22<=0;
    else if(req_up2==1)
        req_up22<=req_up2;
    else if(clear_up[2]==1)
        req_up22<=0;
    else 
        req_up22<=req_up22;
end
always@(posedge clk)                  //to reqister the go_down request of storey 2
begin
    if((~reset)||(locked==1))
         req_dn22<=0;
    else if(req_dn2==1)
         req_dn22<=req_dn2;
    else if(clear_dn[2]==1)
         req_dn22<=0;
    else
         req_dn22<=req_dn22;
end
always@(posedge clk)
begin
    if((~reset)||(locked==1))
        req_in22<=0;
    else if(clear_in[2]==1)
        req_in22<=0;
    else if(req_in2==1)
        req_in22<=req_in2;
    else
        req_in22<=req_in22;
end
always@(posedge clk)                   //to register the go_up request of storey 2
begin
    if((~reset)||(locked==1))
        req_up33<=0;
    else if(req_up3==1)
        req_up33<=req_up3;
    else if(clear_up[3]==1)
        req_up33<=0;
    else 
        req_up33<=req_up33;
end
always@(posedge clk)                  //to reqister the go_down request of storey 3
begin
    if((~reset)||(locked==1))
         req_dn33<=0;
    else if(req_dn3==1)
         req_dn33<=req_dn3;
    else if(clear_dn[3]==1)
         req_dn33<=0;
    else
         req_dn33<=req_dn33;
end
always@(posedge clk)
begin
    if((~reset)||(locked==1))
        req_in33<=0;
    else if(clear_in[3]==1)
        req_in33<=0;
    else if(req_in3==1)
        req_in33<=req_in3;
    else
        req_in33<=req_in33;
end    
always@(posedge clk)                  //to reqister the go_down request of storey 4
begin
    if((~reset)||(locked==1))
         req_dn44<=0;
    else if(req_dn2==1)
         req_dn44<=req_dn4;
    else if(clear_dn[4]==1)
         req_dn44<=0;
    else
         req_dn44<=req_dn44;
end
always@(posedge clk)
begin
    if((~reset)||(locked==1))
        req_in44<=0;
    else if(clear_in[4]==1)
        req_in44<=0;
    else if(req_in4==1)
        req_in44<=req_in4;
    else
        req_in44<=req_in44;
end

assign req_in_all={req_in4,req_in3,req_in2,req_in1};
assign req_out_up={req_up3,req_up2,req_up1};
assign req_out_dn={req_dn4,req_dn3,req_dn2};
assign req_all=req_out_up|req_out_dn|req_in_all;  //????????

assign led_req_up=req_out_up;
assign led_req_dn=req_out_dn;
assign led_req_in=req_in_all;
//********************************************************************** 


//This block is used to operate all the requests
//??????????????????????
always@(posedge clk)
begin
    if(~reset)
    begin
        en_opendoor<=0;
        clear_up<=0;
        clear_dn<=0;
        clear_in<=0;
        en_up<=0;
        en_dn<=0;
    end
    else if(getto1==1)                   //when the elevator gets to storey 1
    begin
        if((req_in11==1)||(req_up11==1))   //??????????
        begin
            en_opendoor<=1;                //???? 
            clear_in[1]<=1;                //??????
            clear_up[1]<=1;                //??????
        end
        else if(req_all>4'b0001)       //there are requsets in storey 2,3,and/or 4
        begin                          //?????
            en_opendoor<=0;            
            en_up<=1;                  //??????????
        end
        else if(req_all==4'b0000)      //????????     
        begin
            en_up<=0;
            en_opendoor<=0;            //????? 
        end          
    end
    else if(getto2==1)               //when the elevator arrives at storey 2
    begin
        if(updown==1)        //the elevator is going up
        begin
            if((req_in22==1)||(req_up22==1))
            begin
                en_opendoor<=1;
                clear_in[2]<=1;
                clear_up[2]<=1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -