基于VHDL的四層電梯控制器_第1頁
基于VHDL的四層電梯控制器_第2頁
基于VHDL的四層電梯控制器_第3頁
基于VHDL的四層電梯控制器_第4頁
基于VHDL的四層電梯控制器_第5頁
已閱讀5頁,還剩21頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、 四層電梯控制器姓名:徐志聰學(xué)號:030902529指導(dǎo)老師:趙彥敏電梯控制器的功能模塊如圖2.1所示,包括主控制器、分控制器、樓層選擇器、狀態(tài)顯示器、譯碼器和樓層顯示器。乘客在電梯中選擇所要到達(dá)的樓層,通過主控制器的處理,電梯開始運行,狀態(tài)顯示器顯示電梯的運行狀態(tài),電梯所在樓層數(shù)通過譯碼器譯碼從而在樓層顯示器中顯示。分控制器把有效的請求傳給主控制器進行處理,同時顯示電梯的運行狀態(tài)和電梯所在樓層數(shù)。由于分控制器相對簡單很多,所以主控制器是核心部分。狀態(tài)顯示器主控制器樓層選擇器分控制器譯碼器樓層顯示器 圖2.1 電梯控制器原理圖第二節(jié) 電梯控制器的流程圖外部按鍵請求信號寄存器狀態(tài)寄存器內(nèi)部軟件執(zhí)

2、行機構(gòu)外部硬件執(zhí)行機構(gòu)圖2.2 總流程圖初始化判定電梯運行方向是否有請求?等待電梯運行樓層檢測否電梯停止目標(biāo)層與本層是否同層?是是否目標(biāo)層?開門延時關(guān)門是否停止運行?是否是否是否停止圖2.3 電梯控制主流程圖第三章 三層電梯控制器的具體設(shè)計本設(shè)計嘗試用硬件描述語言VHDL來實現(xiàn)對三層電梯的控制,源程序經(jīng)A1tera公司的MAX+plus II軟件仿真,保證了設(shè)計的正確性。使用VHDL進行電梯控制器的設(shè)計,主要就是對電梯軟件部分的設(shè)計,使用VHDL中的邏輯關(guān)系建立電梯的升降模式,開門,關(guān)門達(dá)到動作,而外部器件的硬件設(shè)備基本上保持不變。使用VHDL硬件描述語言設(shè)計電梯控制器可以為電梯實現(xiàn)智能控制奠

3、定基礎(chǔ)。第一節(jié) 三層電梯控制器實現(xiàn)的功能及運行規(guī)則電梯一層入口處設(shè)有上升請求開關(guān),二層入口處設(shè)有上、下請求開關(guān),三層入口處設(shè)有下降請求開關(guān),電梯內(nèi)部設(shè)有顧客到達(dá)樓層的停站請求開關(guān)。每層電梯入口處設(shè)有位置指示裝置及電梯運行模式 (上升或下降)指示裝置。電梯初始狀態(tài)為一層開門狀態(tài)。電梯每秒上升(下降)一層樓。電梯到達(dá)需要停止的樓層,經(jīng)過1秒電梯門打開,開門指示燈亮,開門4秒后,電梯門關(guān)閉(開門指示燈滅),電梯繼續(xù)運行,直至執(zhí)行完最后一個請求信號后停留在當(dāng)前層。電梯需要寄存器來記憶電梯內(nèi)外所有請求,并按照電梯運行規(guī)則按順序響應(yīng),每個請求信號保留至執(zhí)行后消除。電梯的運行規(guī)則:當(dāng)電梯處于上升模式時,只響

4、應(yīng)比電梯所在位置高的上樓請求信號和停站請求信號,由下而上逐個執(zhí)行,直到最后一個上樓請求執(zhí)行完畢;如果高層有下樓請求,則直接上升到有下樓請求的最高層,然后進入下降模式。當(dāng)電梯處于下降模式時則與上升模式相反。第二節(jié) 三層電梯控制器的綜合設(shè)計一、三層電梯控制器的設(shè)計思路電梯控制器設(shè)計兩個進程相互配合,狀態(tài)機進程作為主要進程,信號燈控制進程作為輔助進程。根據(jù)電梯的實際工作情況,可以為狀態(tài)機設(shè)置十個狀態(tài),它們分別是“電梯停在一層”“開門”“關(guān)門”“開門等待第一秒”“開門等待第二秒”“開門等待第三秒”“開門等待第四秒”“上升”“下降”和“停止”。由于電梯每秒上升或下降一層,則可以用周期為1s的信號來作為電

5、梯狀態(tài)轉(zhuǎn)換的觸發(fā)時鐘。狀態(tài)機進程中的很多判斷條件是以信號燈控制進程產(chǎn)生的信號燈信號為依據(jù),而信號燈控制進程中信號燈的熄滅又是由狀態(tài)機進程中傳出的信號來控制。三層電梯控制器的設(shè)計主要是對實體和結(jié)構(gòu)體的設(shè)計,它的VHDL描述模塊流程如圖3.1所示:元件庫的說明定義實體結(jié)構(gòu)體端口狀態(tài)機進程信號燈控制進程結(jié)束按鍵信號燈圖3.1 三層電梯控制器的VHDL描述模塊流程二、實體設(shè)計實體設(shè)計即是對端口名、端口模式及數(shù)據(jù)類型的說明。首先考慮輸入端口,一個異步復(fù)位端口“reset”,用于當(dāng)電梯出現(xiàn)非正常情況時回到初始狀態(tài);在電梯外部,一層入口處設(shè)有上升請求端,二層入口處設(shè)有上升和下降請求端,三層入口處設(shè)有下降請求

6、端;在電梯內(nèi)部,應(yīng)設(shè)有各層停站請求端口;一個電梯時鐘輸入端口,它提供周期為1s的時鐘信號,用作電梯狀態(tài)轉(zhuǎn)換的觸發(fā)時鐘;還有一個頻率很高的按鍵時鐘輸入端口。其次考慮輸出端口,當(dāng)有各層上升或下降請求時,各層入口處應(yīng)該有端口顯示請求是否被響應(yīng),有請求時端口輸出邏輯1,被執(zhí)行后則恢復(fù)成邏輯0;同樣的,電梯內(nèi)部也應(yīng)有各層停站請求是否被響應(yīng)的指示端口;一個開關(guān)門指示端口,當(dāng)門開著時,它為邏輯1,門關(guān)著時,則為邏輯0;還需要端口來顯示電梯所處的位置和模式(上升或下降)。三、結(jié)構(gòu)體設(shè)計在結(jié)構(gòu)體中,首先說明了狀態(tài)機設(shè)置的十個狀態(tài),分別是:電梯停在1層(stopon1)、開門(dooropen)、關(guān)門(doorc

7、lose)、開門等待第1秒(doorwait1)、開門等待第2秒(doorwait2)、開門等待第3秒(doorwait3)、開門等待第4秒(doorwait4)、上升(up)、下降(down)和停止(stop)。在結(jié)構(gòu)體最前端用如下的定義語句,來定義狀態(tài)機。type lift_state is(stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,up,down,stop);接著描述電梯內(nèi)部功能實現(xiàn),在結(jié)構(gòu)體中設(shè)計了兩個進程,一個狀態(tài)機進程(ctrlift),它是以reset和liftclk作為敏感信號,控制電梯

8、的狀態(tài)轉(zhuǎn)移;另外一個是信號燈控制進程(ctrlight),它是以reset和buttonclk作為敏感信號,控制寄存信號的邏輯值。在狀態(tài)機進程中,電梯關(guān)門后根據(jù)信號燈的情況,來決定下一個狀態(tài)是上升、下降還是停止;在信號燈控制進程中,由于使用了專門的頻率較高的按鍵時鐘,所以使得按鍵的靈敏度大,但是時鐘頻率不能過高,否則容易使按鍵過于靈敏,而信號燈的熄滅是由狀態(tài)機進程中傳出clearup和cleardn信號來控制。四、VHDL源代碼語法的簡單說明本程序設(shè)計調(diào)用了ieee庫,ieee庫是VHDL設(shè)計中最為常用的庫,它包含有ieee標(biāo)準(zhǔn)的程序包和其他一些支持工業(yè)標(biāo)準(zhǔn)的程序包。本設(shè)計采用std-logi

9、c-1164、std-logic-unsigned、std-logic-arith程序包。以關(guān)鍵詞entity引導(dǎo),end entity threelift結(jié)尾的部分是程序的實體部分。VHDL的實體描述了電路器件的外部情況,本設(shè)計定義了關(guān)于三層電梯控制器用到的各類時鐘、異步復(fù)位按鍵、信號燈指示端口、電梯的請求端口。它描述了端口模式主要有in、buffer、out,以及各端口信號的數(shù)據(jù)類型主要有std-logic、std-logic-vector、integer。(3)以關(guān)鍵詞architecture引導(dǎo),end architecture one結(jié)尾的語句部分是結(jié)構(gòu)體部分,結(jié)構(gòu)體描述電路器件的內(nèi)

10、部邏輯功能。五、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:in std_logic; -led_7數(shù)碼管顯示掃描時鐘信號 reset:in std_logic; -異步復(fù)位端口close:in std_logic;-關(guān)門請求 f1up

11、button:in std_logic; -一層上升請求端口 f2upbutton:in std_logic; -二層上升請求端口 f2dnbutton:in std_logic; -二層下降請求端口 f3dnbutton:in std_logic; -三層下降請求端口 f3upbutton:in std_logic; -三層上升請求端口 f4dnbutton:in std_logic;-四層下降請求端口 stop1button:in std_logic; -一層停站請求端口 stop2button:in std_logic; -二層停站請求端口 stop3button:in std_logi

12、c; -三層停站請求端口 stop4button:in std_logic;-四層停站請求端口 stair:buffer integer range 1 to 4; -電梯位置信號 udsig:buffer std_logic; -電梯運行模式(上升1或下降0 fuplight,fdnlight,stoplight:buffer std_logic_vector(4 downto 1); -上升、下降、停站請求寄存信號doorlight:out std_logic; -開門狀態(tài) (1為開門狀態(tài)) dout:out std_logic_vector(6 downto 0); - 數(shù)碼管顯示樓層段

13、碼s:out std_logic_vector(2 downto 0); -數(shù)碼管顯示樓層位碼end entity fourlift;architecture chi of fourlift is -結(jié)構(gòu)體type lift_state is -定義十個狀態(tài)(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:std_lo

14、gic; -下降和停站請求清除信號signal q:std_logic_vector(3 downto 0); -分頻進程中需要的信號signal buttonclk,liftclk:std_logic; -分頻后的電梯時鐘和按鍵讀取控制時鐘beginclklift:process(clk1) -分頻產(chǎn)生電梯控制時鐘liftclk和按鍵讀取控制時鐘buttonclk begin if (clk1'event and clk1='1') then if q="1111" then q<="0000"elseq<=q+1;

15、end if; end if; buttonclk<=q(0); liftclk<=q(3); end process clklift;statelift:process(reset,liftclk) -狀態(tài)機進程variable position:integer range 4 downto 1;beginif reset='1' then -異步復(fù)位,電梯的初始狀態(tài)為一層開門狀態(tài) state<=stop_on_1; clr_up<='0' clr_dn<='0'else if liftclk'event

16、and liftclk='1' then -每個上升沿 case state is when stop_on_1=> doorlight<='1' -開門 stair<=1; position:=1; state<=door_wait1; -電梯等待4s when door_wait1=> clr_up<='0' clr_dn<='0'if(close='1') then state<=door_close;-如果有關(guān)門信號,則轉(zhuǎn)至關(guān)門狀態(tài)elsestate<=

17、door_wait2;-等待第二秒end if; when door_wait2=> if(close='1') then state<=door_close; elsestate<=door_wait3;等待第三秒end if; when door_wait3=>if(close='1') then state<=door_close;else state<=door_wait4;等待第四秒end if; when door_wait4=> state<=door_close; when door_close=&

18、gt; -關(guān)門,判定電梯下一個運行方式 doorlight<='0' if udsig='1' then -電梯處在上升模式 if stair=4 then if fuplight="0000" and fdnlight="0000" and stoplight="0000" then -沒有請求信號時,電梯停 在當(dāng)前層 udsig<='0' state<=door_close;elsif fdnlight(4)='1' or stoplight(4)=

19、'1' then -本層有請求信號時,電梯開門 udsig<='0'- 轉(zhuǎn)為下降 state<=door_open;else -否則下降 udsig<='0' state<=down;end if; elsif stair=3 then if fuplight="0000" and fdnlight="0000" and stoplight="0000" then udsig<='1' state<=door_close;elsif f

20、uplight(3)='1' or stoplight(3)='1' then -本層有上升或停站請求時,電梯開門 udsig<='1' state<=door_open; elsif fuplight="0000" and stoplight="0000" and fdnlight="0100" then -只有3層有下降請求時,電梯開門 udsig<='0' state<=door_open; elsif stoplight(4)='1

21、' or fdnlight(4)='1' then -4層有停站請求或下降請求,則上升 udsig<='1' state<=up; else udsig<='0' state<=down; end if; elsif stair=2 then if fuplight="0000" and fdnlight="0000" and stoplight="0000" then udsig<='1' state<=door_close;

22、elsif fuplight(2)='1' or stoplight(2)='1' then -本層有上升或停站請求時,電梯開門 udsig<='1' state<=door_open; elsif fuplight="0000" and stoplight="0000" and fdnlight="0010" then -只有2層有下降請求時,電梯開門 udsig<='0' state<=door_open; elsif stoplight(4)

23、='1' or fdnlight(4)='1' or stoplight(3)='1' or fdnlight(3)='1' or fuplight(3)='1' then -4層有停站請求或下降請求,則上升 udsig<='1' state<=up; else udsig<='0' state<=down; end if; elsif stair=1 then if fuplight="0000" and fdnlight="0

24、000" and stoplight="0000" then udsig<='1' state<=door_close; elsif stoplight(1)='1' or fuplight(1)='1' then udsig<='1' state<=door_open; else udsig<='1' state<=up; end if; end if; elsif udsig='0' then -電梯處在下降模式 if stair

25、=4 then if fuplight="0000" and fdnlight="0000" and stoplight="0000" then udsig<='0' state<=door_close; elsif fdnlight(4)='1' or stoplight(4)='1' then udsig<='0' state<=door_open; else udsig<='0' state<=down; end

26、if; elsif stair=3 then if fuplight="0000" and fdnlight="0000" and stoplight="0000" then udsig<='0' state<=door_close; elsif fdnlight(3)='1' or stoplight(3)='1' then udsig<='0' state<=door_open; elsif fdnlight="0000"

27、and stoplight="0000" and fuplight="0100" then udsig<='1' state<=door_open; elsif fuplight(1)='1' or stoplight(1)='1' or fuplight(2)='1' or fdnlight(2)='1' or stoplight(2)='1' then -一層有停站請求或上升請求,則下降 udsig<='0' state&

28、lt;=down; else udsig<='1' state<=up; end if; elsif stair=2 then if fuplight="0000" and fdnlight="0000" and stoplight="0000" then udsig<='0' state<=door_close; elsif fdnlight(2)='1' or stoplight(2)='1' then udsig<='0'

29、; state<=door_open; elsif fdnlight="0000" and stoplight="0000" and fuplight="0010" then udsig<='1' state<=door_open; elsif fuplight(1)='1' or stoplight(1)='1' then -一層有停站請求或上升請求,則下降 udsig<='0' state<=down; else udsig<=&#

30、39;1' state<=up; end if; elsif stair=1 then if fuplight="0000" and fdnlight="0000" and stoplight="0000" then udsig<='1' state<=door_close; elsif stoplight(1)='1' or fuplight(1)='1' then udsig<='1' state<=door_open; else

31、 udsig<='1' state<=up; end if; end if; end if; when up=> -電梯處于上升狀態(tài) stair<=stair+1; -電梯樓層數(shù)加一 position:=position+1; if position<4 and (stoplight(position)='1' or fuplight(position)='1') then state<=stop; -電梯在1 2 3 層,本層有停站或上升請求時,則停止 elsif position=4 and (stopli

32、ght(position)='1' or fdnlight(position)='1') then state<=stop; -電梯處在4層,并且有4層停站或下降請求,則停止 else state<=door_close; end if; when down=> -電梯處在下降狀態(tài) stair<=stair-1; -電梯樓層數(shù)減一 position:=position-1; if position>1 and (stoplight(position)='1' and fdnlight(position)='1

33、') then state<=stop; elsif position=1 and (stoplight(position)='1' or fuplight(position)='1') then state<=stop; else state<=door_close; end if; when stop=> state<=door_open; when door_open=> doorlight<='1' if udsig='1' then if stair<4 and (

34、fuplight(position)='1' or stoplight(position)='1') then clr_up<='1' -清除當(dāng)前層上升和停站請求 else clr_up<='1' clr_dn<='1' end if; elsif udsig='0' then if stair>1 and (fdnlight(position)='1' or stoplight(position)='1') then clr_dn<=&

35、#39;1' -清除當(dāng)前層下降和停站請求 else clr_up<='1' clr_dn<='1' end if; end if; state<=door_wait1; end case; end if;end if;end process statelift;ctrlight:process(reset,buttonclk) -信號燈控制進程beginif reset='1' then -復(fù)位,寄存信號清零 fuplight<="0000" fdnlight<="0000&qu

36、ot; stoplight<="0000"else if buttonclk'event and buttonclk='1' then if f1upbutton='1' then -記憶各層上升請求 fuplight(1)<='1' end if; if f2upbutton='1' then fuplight(2)<='1' end if; if f3upbutton='1' thenfuplight(3)<='1'end if

37、; if clr_up='1' then -上升和停站請求清零 fuplight(stair)<='0' stoplight(stair)<='0' end if; if f2dnbutton='1' then -記憶各層下降請求 fdnlight(2)<='1' end if; if f3dnbutton='1' then fdnlight(3)<='1' end if; if f4dnbutton='1' thenfdnlight(4)&l

38、t;='1' end if; if clr_dn='1' then -下降和停站請求清零 fdnlight(stair)<='0' stoplight(stair)<='0' end if; if stop1button='1' then -記憶各層停站請求 stoplight(1)<='1' end if; if stop2button='1' then stoplight(2)<='1' end if; if stop3button=

39、9;1' then stoplight(3)<='1' end if; if stop4button='1' thenstoplight(4)<='1' end if; end if;end if;end process ctrlight;showlift:process(stair,clk2) -樓層顯示進程begins<="000"if stair=1 then dout<="0110000"elsif stair=2 then dout<="110110

40、1"elsif stair=3 then dout<="1111001"elsif stair=4 then dout<="0110011"end if;end process showlift;end architecture chi;第三節(jié) 本章小結(jié)本設(shè)計運用有限狀態(tài)機的方法,在結(jié)構(gòu)體最前端首先定義了十個狀態(tài);然后在結(jié)構(gòu)體中設(shè)計了兩個進程,狀態(tài)機進程作為主要進程,信號燈控制進程作輔助進程。在狀態(tài)機進程中,電梯關(guān)門后根據(jù)信號燈的情況,來決定下一個狀態(tài)是上升、下降還是停止;在信號燈控制進程中,而信號燈的熄滅是由狀態(tài)機進程中傳出cle

41、arup和cleardn信號來控制。第四章 三層電梯控制器的調(diào)試及仿真第一節(jié) 程序的調(diào)試在程序編寫完成并保存于工程文件夾后,可以把它置頂進行編譯,看是否出現(xiàn)錯誤。在第一次編譯時出現(xiàn)了很多問題,主要是由于沒有注意到文件名必須與實體名相同,并且后綴是.vhd,還有粗心所造成的端口名書寫錯誤,以及有的if語句結(jié)束時忘了寫end if。在波形仿真中,發(fā)現(xiàn)一個錯誤,在狀態(tài)進程中,在當(dāng)前狀態(tài)為doorclose,討論次態(tài)的過程中,忽略了對本層請求的考慮,即當(dāng)電梯停在某層時,當(dāng)前層入口處有上升或下降請求時,無法響應(yīng)。經(jīng)過思考,我添加了本層請求響應(yīng)語句,最終實現(xiàn)了三層電梯控制器的功能。第一節(jié) 波形仿真在波形仿

42、真中,根據(jù)實際,我們有必要做一些假設(shè),即是:外部請求上升的乘客,進入電梯后一定是按更高層的停站按鈕;外部請求下降的乘客,進入電梯后一定是按更低層的停站按鈕;如果有乘客進入電梯,則一定有停站請求;同一時刻有很多人按鍵的概率很小,所以我們認(rèn)為請求信號都有一定的先后順序。設(shè)定仿真時間長度為60s,liftclk信號為周期1s的時鐘信號,buttonclk信號為周期0.1s的時鐘信號。doorlight信號邏輯1表示開門,邏輯0表示關(guān)門。udsig信號為邏輯1表示電梯處在上升模式,邏輯0表示處在下降模式。fuplight,fdnlight,stoplight是三位二進制向量,波形圖中的1代表“001”

43、,表示一層有請求,2代表“010”,表示二層有請求,4代表“100”,表示三層有請求。圖4.1所示的波形是在一層有上升請求的仿真波形,在reset信號產(chǎn)生一個脈沖時,電梯回復(fù)初始狀態(tài),即stopon1狀態(tài),然后等待4s,關(guān)門檢測沒有請求信號,于是電梯此時停在一層。當(dāng)電梯時鐘上升沿檢測到一層上升請求信號fuplight(1)為1時,電梯開門,fuplight(1)清零,等待4s,關(guān)門檢測到二層停站請求,于是電梯上升到二層停止,開門stoplight(2)清零,position信號由1變?yōu)?,電梯最終停在二層。 圖4.1 有上升請求的仿真波形 圖4.2所示的波形是三層有下降請求的波形,當(dāng)電梯在一層關(guān)門后,檢測到fdnlight為“100”,則上升到三層,開門等待4s,關(guān)門檢測到stoplight為1,于是電梯下降到一層,最終停在一層。 圖4.2 有下降請求的仿真波形圖4.3所示的波形是二層和三層都有下降請求的仿真波形,當(dāng)電梯在一層關(guān)門后,檢測到fdnlight為“110”,則直接上升到三層,開門后fdnlight(3)清零,等待4s后,關(guān)門下降到二層停止,開門后fdnlight(2)和stoplight(2

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論