1、四层电梯控制器的设计主要是对实体和结构体的设计,它的VHDL描述模块流程如图3.1所示:图3.1 四层电梯控制器的VHDL描述模块流程VHDL源代码说明:library IEEE; -库的说明use IEEE.std_logic_1164.all; -程序包的说明use IEEE.std_logic_unsigned.all;use IEEE.std_logic_arith.all; -(arith)entity fourlift is -实体名称fourlift port(clk1:in std_logic; -按键读取时钟信号 clk2: -led_7数码管显示扫描时钟信号 reset:
2、-异步复位端口 close: -关门请求 f1upbutton: -一层上升请求端口 f2upbutton: -二层上升请求端口 f2dnbutton: -二层下降请求端口 f3dnbutton: -三层下降请求端口 f3upbutton: -三层上升请求端口 f4dnbutton: -四层下降请求端口 stop1button: -一层停站请求端口 stop2button: -二层停站请求端口 stop3button: -三层停站请求端口 stop4button: -四层停站请求端口 stair:buffer integer range 1 to 4; -电梯位置信号 udsig:buffer
3、 std_logic; -电梯运行模式(上升1或下降0 fuplight,fdnlight,stoplight:buffer std_logic_vector(4 downto 1);-上升、下降、停站请求寄存信号 doorlight:out std_logic; -开门状态 (1为开门状态) dout:out std_logic_vector(6 downto 0); - 数码管显示楼层段码 s:out std_logic_vector(2 downto 0); -数码管显示楼层位码end entity fourlift;architecture chi of fourlift is -结构
4、体type lift_state is -定义十个状态(stop_on_1,door_open,door_close,door_wait1,door_wait2,door_wait3,door_wait4,up,down,stop);signal state:lift_state;signal clr_up:std_logic; -上升和停站请求清除信号signal clr_dn: -下降和停站请求清除信号signal q:std_logic_vector(3 downto 0); -分频进程中需要的信号signal buttonclk,liftclk: -分频后的电梯时钟和按键读取控制时钟b
5、eginclklift:process(clk1) -分频产生电梯控制时钟liftclk和按键读取控制时钟buttonclk begin if (clk1event and clk1=1) then if q=1111 then q=0000; else q=q+1; end if; end if; buttonclk=q(0); liftclk=q(3); end process clklift;statelift:process(reset,liftclk) -状态机进程variable position:integer range 4 downto 1;if reset= then -异
6、步复位,电梯的初始状态为一层开门状态 state=stop_on_1; clr_up=0 clr_dn doorlight -开门 stair if(close=) then state=door_close;-如果有关门信号,则转至关门状态 else state if(close=door_wait3;等待第三秒 when door_wait3= if(close= else state when door_close= -关门,判定电梯下一个运行方式 if udsig= then -电梯处在上升模式 if stair=4 then if fuplight= and fdnlight= an
7、d stoplight= then -没有请求信号时,电梯停 在当前层 udsig -电梯处于上升状态=stair+1; -电梯楼层数加一=position+1; if position -电梯处在下降状态=stair-1; -电梯楼层数减一=position-1; if position1 and (stoplight(position)= and fdnlight(position)= elsif position=1 and (stoplight(position)= when stop= when door_open= if stair1 and (fdnlight(position)
8、= -清除当前层下降和停站请求 end case;end if;end process statelift;ctrlight:process(reset,buttonclk) -信号灯控制进程 then -复位,寄存信号清零 fuplight fdnlight stoplight if buttonclkevent and buttonclk= if f1upbutton= then -记忆各层上升请求 fuplight(1) if f2upbutton= fuplight(2) if f3upbutton= fuplight(3) if clr_up= then -上升和停站请求清零 fup
9、light(stair) stoplight(stair) if f2dnbutton= then -记忆各层下降请求 fdnlight(2) if f3dnbutton= fdnlight(3) if f4dnbutton= fdnlight(4) if clr_dn= then -下降和停站请求清零 fdnlight(stair) if stop1button= then -记忆各层停站请求 stoplight(1) if stop2button= stoplight(2) if stop3button= stoplight(3) if stop4button= stoplight(4)e
10、nd process ctrlight;showlift:process(stair,clk2) -楼层显示进程s000if stair=1 then dout0110000elsif stair=2 then1101101elsif stair=3 then1111001elsif stair=4 then0110011end process showlift;end architecture chi;四层电梯控制器的仿真:在波形仿真中,根据实际,我们有必要做一些假设,即是:外部请求上升的乘客,进入电梯后一定是按更高层的停站按钮;外部请求下降的乘客,进入电梯后一定是按更低层的停站按钮;如果有
11、乘客进入电梯,则一定有停站请求;同一时刻有很多人按键的概率很小,所以我们认为请求信号都有一定的先后顺序。设定仿真时间长度为60s,liftclk信号为周期1s的时钟信号,buttonclk信号为周期0.1s的时钟信号。doorlight信号逻辑1表示开门,逻辑0表示关门。udsig信号为逻辑1表示电梯处在上升模式,逻辑0表示处在下降模式。fuplight,fdnlight,stoplight是四位二进制向量,波形图中的0001表示一层有请求,0010表示二层有请求,0100表示三层有请求,1000表示四层有请求。图1所示的波形是在一层有上升请求的仿真波形,在reset信号产生一个脉冲时,电梯回复初始状态,即stopon_1状态,然后等待4s,关门检测没有请求信号,于是电梯此时停在一层。当电梯时钟上升沿检测到一层上升请求信号fuplight(1)为1时,电梯开门,fuplight(1)清零,等待4s,关门检测到二层停站请求,于是电梯上升到二层停止,开门stoplight(2)清零,stair信号由001变为010,电梯最终停在二层。 图1 有上升请求的仿真波形 图2所示的波形是三层有下降请求的
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1