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

📄 lift.vhd

📁 用fpga控制电梯,实现五层电梯的升降控制,运用vhdl编辑程序.
💻 VHD
字号:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;

entity lift is
	port (
		clkin:in STD_LOGIC;
		upin:in STD_LOGIC;
		downin:in STD_LOGIC;
		st_ch:in STD_LOGIC;
		close:in STD_LOGIC;
		delay:in STD_LOGIC;
		run_stop:in STD_LOGIC;
		lamp:out STD_LOGIC;
		run_wait:out STD_LOGIC_VECTOR(3 downto 0);
		st_out:out STD_LOGIC_VECTOR(3 downto 0);
		direct:out STD_LOGIC_VECTOR(3 downto 0)
	);
end lift;
		
architecture lift_arch of lift is
signal ur,dr:std_logic_vector(6 downto 1);	--上升或下降楼层请求寄存器
signal dir,liftor:std_logic_vector(2 downto 0);	--楼选指示及楼层数计数器
signal wai_t:std_logic_vector(2 downto 0);	--运行或等待计数器
signal divide,hand:std_logic;						--时钟2分频和楼选复位变量
signal ladd:std_logic_vector(1 downto 0);	--电梯运行状态变量
signal closex,delayx:std_logic;						--提前关门及延时变量

begin
	direct<='0'&dir+1;
	st_out<='0'&liftor+1;
	run_wait<='0'&wai_t;
	lamp<=ladd(1);
	hand<=wai_t(2) and (not wai_t(1)) and wai_t(0);
	closex<=close and (not ladd(1));
	delayx<=delay and (not ladd(1));
	
	p1:process(clkin)
	begin
		if (clkin'event and clkin='1') then
			divide<=not divide;
			if(dir="101") then dir<="000";
			else dir<=dir+1;
			end if;
		end if;
	end process p1;
	
	p2:process(ur,dr,dir,upin,downin,st_ch,liftor,wai_t,run_stop,hand)--该进程完成楼层请求寄存器的置位与复位
	variable num,t:integer;
	begin
		num:=conv_integer(liftor)+1;
		t:=conv_integer(dir)+1;
		if (run_stop='1') then
			if(((t>num) and (st_ch='1')) or (upin='1')) then ur(t)<='1';
			elsif (hand='1') then ur(num)<='0';
			end if;
			if(((t<num) and (st_ch='1')) or (downin='1')) then dr(t)<='1';
			elsif (hand='1') then dr(num)<='0';
			end if;
		else ur<="000000";
			dr<="000000";
		end if;
	end process p2;
	
	p3:process(ur,dr,liftor,ladd,wai_t,run_stop)--该进程完成电梯将来运行状态的判断输出
	begin
		if (run_stop='1') then 
			if (wai_t="110") then
				if ((ur or dr)="000000") then ladd(1)<='0';
				else
					case liftor is
						when "000"=>if ((ur(1) or dr(1))>'0') then ladd(1)<='0';
							else ladd<="11";
							end if;
						when "001"=>if ((ur(2) or dr(2))>'0') then ladd(1)<='0';
							elsif(((ladd(0)='1') and ((ur(6 downto 3) or dr(6 downto 3))>"0000")) or ((ur(1) or dr(1))='0')) then ladd<="11";
							else ladd<="10";
							end if;
						when "010"=>if ((ur(3) or dr(3))>'0') then ladd(1)<='0';
							elsif(((ladd(0)='1') and ((ur(6 downto 4) or dr(6 downto 4))>"000")) or ((ur(2 downto 1) or dr(2 downto 1))="00")) then ladd<="11";
							else ladd<="10";
							end if;
						when "011"=>if ((ur(4) or dr(4))>'0') then ladd(1)<='0';
							elsif(((ladd(0)='1') and ((ur(6 downto 5) or dr(6 downto 5))>"00")) or ((ur(3 downto 1) or dr(3 downto 1))="000")) then ladd<="11";
							else ladd<="10";
							end if;
						when "100"=>if ((ur(5) or dr(5))>'0') then ladd(1)<='0';
							elsif(((ladd(0)='1') and ((ur(6) or dr(6))>'0')) or ((ur(4 downto 1) or dr(4 downto 1))="0000")) then ladd<="11";
							else ladd<="10";
							end if;
						when "101"=>if ((ur(6) or dr(6))>'0') then ladd(1)<='0';
							else ladd<="10";
							end if;
						when others=>null;
					end case;
				end if;
			end if;
			else ladd<="00";
		end if;
	end process p3;
	
	p4:process(wai_t,ladd,closex,delayx)--该进程完成随电梯运行楼层的相应增减,并响应提前关门和延时关门请求
	begin
		if (divide'event and divide='1') then
			if(wai_t="000" or closex='1') then wai_t<="110";
			else
				if (delay='0') then wai_t<=wai_t-1;
				else wai_t<="010";
				end if;
				if (wai_t="001") then 
					if(ladd="11") then liftor<=liftor+1;
					elsif(ladd="10") then liftor<=liftor-1;
					end if;
				end if;
			end if;
		end if;
	end process p4;
end lift_arch;

⌨️ 快捷键说明

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