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

📄 电梯.txt

📁 以FPGA技术为基础
💻 TXT
字号:
library ieee; 
use ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all; 
entity allof is
port( upjj,downjj:in std_logic_vector(2 downto 0);
     alarmlight,up,down:out std_logic;------------up、down为电梯的升降及用于升降的计时器的起停信号
     nei:in std_logic_vector(3 downto 0);
     clr,clr1,clru:out std_logic;
     delay:buffer std_logic;------------------delay为电梯的开关门计时器启动和停止信号
     downj,upj:buffer std_logic_vector(2 downto 0);
     neij:buffer std_logic_vector(3 downto 0);
     close,clk,c,b,unclose,weight,alarm:in std_logic ;
     a:in std_logic_vector(1 downto 0);
     led:out std_logic_vector(3 downto 0) );
end allof;
architecture behave_dianti of allof is
signal t:std_logic_vector(1 downto 0);
signal cn:integer:=0;
signal qinqiu:std_logic_vector(3 downto 0);
signal u,d:std_logic;
begin
process(clk)
begin
if rising_edge(clk) then  
    upj<=upjj or upj;downj<=downjj or downj;
    neij<=nei or neij;qinqiu<='0'&upj or downj&'0' or neij;
if t="00" then  up<='0';down<='0';
if weight='0' and alarm='0' then  alarmlight<='0';
if u='1' then  t<="01";u<='0';
elsif d='1' then  t<="10";d<='0';
end if;end if;
elsif t="01" then
if (weight='1' and a>=1) or alarm='1' then-----weight为输入的超载信号,alarm为故障信号
t<="00";alarmlight<='1';u<='1';
else alarmlight<='0';t<="01";u<='0';
end if;
elsif t="10" then  
if (weight='1' and a>=1) or alarm='1' then  t<="00";alarmlight<='1';d<='1';
else alarmlight<='0';t<="10";d<='0';
end if;end if;
if unclose='1' and a>=1 then  delay<='1';clr1<='1';clr<='0';-------- unclose为外部开门信号       
elsif close='1' or b='1' then  delay<='0';clr1<='0';clr<='1'; ----------close为提前关门信号
else clr1<='0';clr<='0';
end if;
if t="01" then
if c='1' then  cn<=cn+1;up<='0';clru<='1';
else clru<='0';
end if;
elsif t="10" then
if c='1' then  cn<=cn-1;down<='0';clru<='1';
else clru<='0';
end if;end if;
if alarm='0' and weight='0' then
if cn=0 then  led<="0001";
if qinqiu=0 then  t<="00";
elsif (upj(0)='1' or neij(0)='1') then  
delay<='1';upj(0)<='0';neij(0)<='0';up<='0';down<='0';------------到达指定楼层后将请求信号消除,电梯自动开门
elsif qinqiu>"0001" and delay<='0' then  t<="01";up<='1';down<='0';
end if;
elsif cn=1 then  led<="0010";
if t="01" then
if upj(1)='1' or neij(1)='1' then  delay<='1';upj(1)<='0';neij(1)<='0';up<='0';down<='0';
elsif qinqiu>"0011" and delay<='0' then  t<="01";up<='1';down<='0';
elsif qinqiu<="0010" and delay<='0' then  t<="10";down<='1';up<='0';
elsif qinqiu=0 and delay<='0' then  t<="10";down<='1';up<='0';
end if;
elsif t="10" then
if downj(0)='1' or neij(1)='1' then  delay<='1';downj(0)<='0';neij(1)<='0';up<='0';down<='0';
elsif qinqiu>"0011" and delay<='0' then  t<="01";up<='1';down<='0';
elsif qinqiu<="0010" and delay<='0' then  t<="10";down<='1';up<='0';
elsif qinqiu=0 and delay<='0' then  t<="10";down<='1';up<='0';
end if;end if;
elsif cn=2 then  led<="0011";
if t="01" then
if upj(2)='1' or neij(2)='1' then  delay<='1';upj(2)<='0';neij(2)<='0';up<='0';down<='0';
elsif qinqiu>"0111" and delay<='0' then  t<="01";up<='1';down<='0';
elsif qinqiu<="0100" and delay<='0' then  t<="10";down<='1';up<='0';
elsif qinqiu=0 and delay<='0' then  t<="10";down<='1';up<='0';
end if;
elsif t="10" then
if downj(1)='1' or neij(2)='1' then  delay<='1';downj(1)<='0';neij(2)<='0';up<='0';down<='0';
elsif qinqiu>"0111" and delay<='0' then  t<="01";up<='1';down<='0';
elsif qinqiu<="0100" and delay<='0' then  t<="10";down<='1';up<='0';
elsif qinqiu=0 and delay<='0' then  t<="10";down<='1';up<='0';
end if;end if;
elsif cn=3 then  led<="0100";
if qinqiu=0 and delay<='0' and t/="00"then  t<="10";down<='1';up<='0';
elsif (downj(2)='1' or neij(3)='1') then
    delay<='1';downj(2)<='0';neij(3)<='0';up<='0';down<='0';
elsif qinqiu<="1000" and delay<='0' then  t<="10";down<='1';up<='0';
end if;end if;end if;end if;
end process;
end behave_dianti;
    由于设计该电梯所需的输入、输出引脚较多,而DE2芯片上的引脚数不足,因此我将设计的电梯改为总数只有4层的电梯。
	上述程序的第26到27行代码用于存储和显示电梯内外的升降请求,第28到42行代码是用于超重和故障警报发生时的处理以及警报消除后的恢复。而接下来的第43到46行代码则用于处理电梯的开关门,第47到55行代码是用于控制电梯升降、楼层数加减的部分,第56行到最后则是用于判断是否到达指定楼层,并控制电梯何时开门何时升降等。
	在最后的那部分程序中,按楼层数4层将程序分为4部分来设计,除了底楼没有下楼信号和顶楼没有上楼信号外,每个部分程序的结构大体相同,并且每一部分还可划分为上升和下降两小部分,这样划分的原因是因为要使得电梯在上升状态时,上楼请求优先,在下降状态时,下楼请求优先,满足了先执行完所有的上楼请求再执行下楼请求,抑或先执行完所有的下楼请求再执行上楼请求的要求。
    由于实验还要求在执行完最后一个请求信号后电梯停在l层,因此在最后一部分程序的每小部分中都添加了elsif qinqiu=0 and delay<='0' then  t<="10";down<='1';up<='0';这样便可在没有请求信号的情况下使电梯返回底楼。
    除了上述的核心程序之外,还需设计2个计数器,即用于开门到关门这段时间的计数器以及电梯从一层楼升降到相邻楼层所需时间的计数器。
3:根据实验要求,即当电梯到达选择的楼层时,经过l S电梯门打开,开门指示灯亮,开门3s后,电梯关闭,指示灯灭,电梯继续运行。设计出如下计时代码:
library ieee; 
use ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all; 
entity kaimeng is
port(
    clk,en,clr,clr1:in std_logic;
    kai,b:out std_logic;
    a:buffer std_logic_vector(1 downto 0));
end kaimeng;
architecture behave_kaimeng of kaimeng is
begin
process(clk,clr)
begin
if clr='1' then  b<='0';
elsif rising_edge(clk) then
if clr1='1' then  a<="01";b<='0';
end if;
if en='0' then  kai<='0';
elsif en='1' then
if a=3 then  a<="00";
else a<=a+"01";
end if;
if a=0 then kai<='0';b<='1';--------计时计满后电梯关门,指示灯灭
else kai<='1';b<='0';-------------当计时大于或等于1S时,开门指示灯亮,即经过l S电梯门打开
end if;end if;end if;
end process;
end behave_kaimeng;
4:设计用于电梯从一层楼升降到相邻楼层所需时间的计数器,代码如下:
library ieee; 
use ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all; 
entity updown is
port(clk,up,down,clru:in std_logic;
     c:out std_logic);
end updown;
architecture behave_updown of updown is
signal a:integer:=0;
begin
process(clk,clru)
begin
if clru='1' then  c<='0';
elsif rising_edge(clk) then
if up='1' or down='1' then
if a=4 then  a<=0;c<='1';---------计时计满后使c='1’,反馈给核心电路allof,使楼层进行相应的加减
else a<=a+1;c<='0';
end if;end if;end if;
end process;
end behave_updown;

⌨️ 快捷键说明

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