logo资料库

VHDL语言的洗衣机控制器设计.doc

第1页 / 共15页
第2页 / 共15页
第3页 / 共15页
第4页 / 共15页
第5页 / 共15页
第6页 / 共15页
第7页 / 共15页
第8页 / 共15页
资料共15页,剩余部分请下载后查看
课 程 设 计 课程设计名称: 洗衣机控制器设计 专 业 班 级 : 姓名、学号 : 指 导 教 师 : 课程设计时间:
设计任务及要求 利用可编程逻辑器件丰富的内部资源,借助 EDA(电子设计自动化)工具把家电控制 器电路集成在一片 FPGA(现场可编程门阵列)芯片内,这样就无需专门的单片机和外部逻 辑电路。从而减小了电路的体积、提高了系统的稳定性。本次电路设计是洗衣机控制器设计。 设计的主要内容是: (1)设计一个洗衣机控制器,使洗衣机作如下运转:定时启动—〉正转 20 秒—〉暂 停 10 秒—〉反转 20 秒—〉暂停 10 秒—〉定时不到,重复上面过程。 (2)若定时到,则停止,并发出音响信号。 (3)用两个数码管显示洗涤的预置时间(分钟数),按倒计时方式对洗涤过程作计时 显示,直到时间到停机;洗涤过程由开始信号开始。 (4)三只 LED 灯表示正转、反转、暂停三个状态。 设计的主要要求是: (1)根据设计题目要求编写相应程序代码 (2)对编写的 VHDL 程序代码进行编译和仿真 (3)利用实验箱完成硬件验证 (4)总结设计内容,完成课程设计说明书 设计原理及总体框图 洗衣机控制器的设计主要是定时器的设计,由一片 FPGA 和外围电路构成了电器控制 部分。FPGA 接收键盘的控制命令,控制洗衣机的进水、排水、水位和洗衣机的工作状态、 并控制显示工作状态以及设定直流电机速度、正反转控制、制动控制、起停控制和运动状态 控制。对 FPGA 芯片的编程采用模块化的 VHDL (硬件描述语言)进行设计,设计分为三层实 现,顶层实现整个芯片的功能。顶层和中间层多数是由 VHDL 的元件例化语句实现。中间层 由无刷直流电机控制、运行模式选择、洗涤模式选择、定时器、显示控制、键盘扫描、水位 控制以及对直流电机控制板进行速度设定、正反转控制、启停控制等模块组成,它们分别调
用底层模块。 定时启动 正转 暂停 反转 暂停 定时到 停止(或转入下一 个程序) 定时未到 图 1,流程图 洗衣机控制器电路主要有五大部分组成,包括:减法计数器、时序控制电路、预置时 间和编码电路、数码管显示、译码器组成。具体电路如图 2 所示: 图 2,洗衣机控制器总体设计图 程序设计 ⑴数码管显示 1 实现数码管显示 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity showtime is port(remain_time:in std_logic_vector(7 downto 0); cp:in std_logic; q1,q2:out std_logic;--q1 为低位 a,b,c,d,e,f,g:out std_logic --数码管段码 );
end showtime; architecture rtl 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(cp) begin if(cp'event and cp='1') then choose<=not choose; if(choose='1') then q1<='0';q2<='1'; bcd<=remain_time(7 downto 4);--倒计时数码管十位(分钟) else q1<='1';q2<='0'; bcd<=remain_time(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 rtl; ○2 数码管显示编码 --bcd 编码为数码管显示编码 library ieee; use ieee.std_logic_1164.all; entity encode is port( bcd : in std_logic_vector(3 downto 0); a,b,c,d,e,f,g: out std_logic ); end encode; architecture rtl of encode is signal temp:std_logic_vector(6 downto 0); begin table bcd => temp; "0000"=> "1111110" ; "0001"=> "0110000" ; "0010"=> "1101101" ; "0011"=> "1111001" ; "0100"=> "0110011" ; "0101"=> "1011011" ; "0110"=> "1011111" ; "0111"=> "1110000" ;
"1000"=> "1111111" ; "1001"=> "1111011" ; end table; a<=temp(6);b<=temp(5);c<=temp(4);d<=temp(3);e<=temp(2);f<=temp(1);g<=temp(0); end rtl; ⑵时序电路 控制洗衣机按 20 秒正转,停十秒。20 秒反转,停十秒的顺序运行,直到时间结束信号的到 来 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity shixu is port(cp,en,rd:in std_logic; q1,q2:out std_logic--00 为停机,10 为正转,01 为反转 ); end shixu; architecture rtl of shixu is begin process(cp) variable wash_time:integer range 0 to 19; variable wait_time:integer range 0 to 9; variable state:std_logic; --0 代表正转,1 代表反转 variable wash_time:integer := 21; variable wait_time:integer := 9; begin if(en='0') wash_time:='19'; wait_time:='9'; state:='0';
end if; if(en='0') then wash_time:=21; Q1<='0';Q2<='0';--停机状态 else if(cp'event and cp='1') then if(rd='1') then if(wash_time>0) then wash_time:=wash_time-1; wait_time:=9;--等待时间恢复 else if(wait_time>0)--运行时间结束,等待时间未到 then wait_time:=wait_time-1; --等待时间减 1 else wash_time:=20; --等待时间结束,继续运行 state:=not state; end if; end if; -- end if; 将译码也加入同步时序,可以减少毛刺 if(wash_time=0) then Q1<='0';Q2<='0';--暂停 else if(state='0')--正转 then Q1<='1';Q2<='0'; else Q1<='0';Q2<='1';--反转 end if; end if; else Q1<='0';Q2<='0';--暂停 end if; end if; end if; end process; end rtl;
⑶预置时间和编码电路 --预置时间与编码寄存电路,将输入的 1-10 分钟编为 2 个 4 位的 BCD 码 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity settime is port(load:in std_logic; k:in std_logic_vector(9 downto 0); o:out std_logic_vector(7 downto 0) ); end settime; architecture rtl of settime is signal p1:std_logic_vector(7 downto 0); begin process(load) begin if(load'event and load='1') then --开始译码 case k is --将时间分钟 when "1000000000"=>p1<="00000001"; when "0100000000"=>p1<="00000010"; when "0010000000"=>p1<="00000011"; when "0001000000"=>p1<="00000100"; when "0000100000"=>p1<="00000101"; when "0000010000"=>p1<="00000110"; when "0000001000"=>p1<="00000111"; when "0000000100"=>p1<="00001000"; when "0000000010"=>p1<="00001001"; when "0000000001"=>p1<="00010000";
分享到:
收藏