数字系统设计(洗衣机控制器)(12页).doc
-数字系统设计(洗衣机控制器)-第 12 页实验报告 COURSE PAPER数字系统设计(洗衣机控制器)学院 :机电工程与自动化学院 学号: 学生姓名: 打印日期: 评分: 评语:一、实验目的: (1)学习系统电路设计; (2)巩固软件环境下的编程设计; 二、实验内容: (1) 实现以下系统功能:洗衣机控制器。 l 设计一个电子定时器,控制洗衣机作如下运转:定时启动>正转20秒>暂停10秒>反转20秒>暂停10秒>定时未到回到“正转20秒>暂停10秒>”,定时到则停止; l 若定时到,则停机发出音响信号; l 用两个数码管显示洗涤的预置时间(分钟数),按倒计时方式对洗涤过程作计时显示,直到时间到停机;洗涤过程由“开始”信号开始; l 三只LED灯表示“正转”、“反转”、“暂停”三个状态。 三、实验要求; l 在PC机上完成相应的设计输入,编译,仿真,对结果进行分析; l 完成下载,在实验板上对程序进行验证。 四、 实验步骤;(1) 实验分析 a.预设时间和编码电路(settime):接受用户通过按钮预置的时间信息,编码 成八位之后转给减法计数器。 b.减法计数器电路(counter):接收编码之后的预置时间信息,向电机运转控制电路传递运行信号,并将预置时间信息和剩余时间信息发给数码管显示电路进行实时显示。 c.数码管显示电路(showtime):接收减法计数器电路传来的时间信息,进行实时译码显示。 e.电机运转时序控制电路(analyse):接收运行起止信号,安排电机运行状态并编码输出。 f.译码器(move):接收电机运行状态信号,译码后实时控制电机的正传、反转和暂停。程序框图如下:(2) 程序编写a.预设时间和编码电路(settime):library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity timeset is port load:in std_logic; time_input:in std_logic_vector(3 downto 0); time_set:out std_logic_vector(7 downto 0)end timeset;architecture timeset of timeset is signal p1:std_logic_vector(7 downto 0); begin process(load) begin if(load'event and load='1') then case time_input is when "0000"=>p1<="00000000" when"0001"=>p1<="00000001" when"0010"=>p1<="00000010" when"0011"=>p1<="00000011" when"0100"=>p1<="00000100" when"0101"=>p1<="00000101" when"0110"=>p1<="00000110" when"0111"=>p1<="00000111" when"1000"=>p1<="00001000" when"1001"=>p1<="00001001" when others=>p1<="00000000" end case; end if; end process; time_set<=p1;end timeset;b.减法计数器电路(counter):library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity sub is port clk,start:in std_logic; time_set:in std_logic_vector(7 downto 0); time_remain:buffer std_logic_vector(7 downto 0); time_over:buffer std_logicend sub;architecture sub of sub is begin process(clk) variable time_second:integer range 0 to 59 ; begin if(clk'event and clk='1') then if(start='0') then if(time_remain(7 downto 0)=0) then time_remain<=time_set; else time_remain(7 downto 4)<=time_remain(3 downto 0); time_remain(3 downto 0)<=time_set(3 downto 0); end if; time_second:=59; time_over<='1' else if(time_over='1') then if(time_second=0 and time_remain(7 downto 0)=0) then time_over<='0' else if(time_second=0) then if(time_remain(3 downto 0)=0) then time_remain(7 downto 4)<=time_remain(7 downto 4)-1; time_remain(3 downto 0)<="1001" time_second:=59; else time_remain(7 downto 4)<=time_remain(7 downto 4); time_remain(3 downto 0)<=time_remain(3 downto 0)-1; time_second:=59; end if; else time_second:=time_second-1; end if; end if; end if; end if; end if; end process;end sub;c.数码管显示电路(showtime):library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity showtime is port time_remain:in std_logic_vector(7 downto 0); clk:in std_logic; minuteshi,minutege:out std_logic; a,b,c,d,e,f,g:out std_logicend showtime;architecture showtime of showtime is signal temp:std_logic_vector(6 downto 0); signal bcd:std_logic_vector(3 downto 0); signal choose:std_logic; begin process(clk) begin if(clk'event and clk='1') then choose<=not choose; if(choose='1') then minuteshi<='0'minutege<='1' bcd<= time_remain(7 downto 4); else minuteshi<='1'minutege<='0' bcd<= time_remain(3 downto 0); end if; end if; end process; process(bcd) begin case bcd is when "0000"=>temp<="1111110" when "0001"=>temp<="0110000" when "0010"=>temp<="1101101" when "0011"=>temp<="1111001" when "0100"=>temp<="0110011" when "0101"=>temp<="1011011" when "0110"=>temp<="1011111" when "0111"=>temp<="1110000" when "1000"=>temp<="1111111" when "1001"=>temp<="1111011" when others=>temp<="1111011" end case;a<=temp(6);b<=temp(5);c<=temp(4);d<=temp(3);e<=temp(2);f<=temp(1);g<=temp(0); end process;end showtime;e.电机运转时序控制电路(analyse):library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity analyse is port clk,start,time_over:in std_logic; out_1,out_2:out std_logicend analyse;architecture analyse of analyse is begin process(clk) variable state:std_logic; variable wash_time:integer range 0 to 20; variable wait_time:integer range 0 to 10; begin if(clk'event and clk='1') then if(start='0') then wash_time:=0; wait_time:=0; state:='0' out_1<='0'out_2<='0' else if(time_over='1') then if(wash_time=20) then if(wait_time=10) then wash_time:=0; state:=not state; else wait_time:=wait_time+1; end if; else wash_time:=wash_time+1; wait_time:=0; end if; end if; if (wash_time=20) then out_1<='0'out_2<='0' else if(state='0') then out_1<='1'out_2<='0' else out_1<='0'out_2<='1' end if; end if; end if; end if; end process; end analyse;f.译码器(move):library ieee;use ieee.std_logic_1164.all;entity threeyimaqi is port out_1,out_2:in std_logic; REV,RUN,PAUSE:buffer std_logicend threeyimaqi;architecture move of threeyimaqi is signal choose:std_logic_vector(1 downto 0); begin choose(1)<=out_1;choose(0)<=out_2; process(choose) begin case choose is when "00"=>REV<='0'RUN<='0'PAUSE<='1' when "10"=>REV<='0'RUN<='1'PAUSE<='0' when "01"=>REV<='1'RUN<='0'PAUSE<='0' when others=>REV<='0'RUN<='0'PAUSE<='0' end case; end process;end move;器件总电路图如下:仿真波形如下:实物图:五、 实验心得 通过这次的VHDL设计,我真的是受益匪浅。看到洗衣机控制器的题目,对于初次接触vhdl语言的我来说,头脑里几乎是没有任何概念的,根本就不知道该从何处下手。不过我并没有气馁,在老师的悉心指导以及同学们的热心帮助下,通过网上查阅相关资料,我渐渐有了眉目。 这次设计,让我初步掌握了VHDL的设计方法与一些技巧,让我对FPGA的编程、定时器和计数器的设计更加熟悉,也更加明白时序组合门电路设计思路和方法。在设计中也参了和查阅了很多资料,从中学到不少课本上没有的东西,这些对我的学习有很大的帮助。同时,我没那个明白了这次课程设计是一个理论与实际结合的过程,理论知识往往是不够的,只有把所学的理论与实际行动相结合,才能提高自己的综合实际能力和独立思考的能力。在设计过程中我们都会遇到很多的问题,但往往是一个小问题都会导致设计的失败,这就要我们花大量的时间区思索和改正,这是一个很艰辛的过程,但同时也是我收获最大的过程。考察我们的就是恒心与毅力。设计往往是一个苦中有乐的过程,如果从兴趣出发,则就会释然很多,通过这次设计,是我对数字电路实验产生了浓厚的兴趣,我希望在以后的学习中继续加深对这一个方面的学习。