数字系统设计与硬件描述语言
期末考试作业
题目: 洗衣机控制器的设计
学院: 电子信息工程学院 专业: 电子信息工程 学号: 3011204295 姓名: 邹雪强
2013-11-06
设计原理及功能介绍
以EDA技术的基本理论为指导, 用EDA方法去设计并完成特定功能的电子电路的仿真、调试,本设计为基于VHDL的EDA设计——洗衣机控制器的设计,同时要掌握常用仿真开发软件,比如: Quartus II和MaxplusII等EDA常用软件(本次试用使用的软件为QuartusII 9.1)。
基本要求:可选择工作模式;可设定工作时间;具有报警功能等。
设计指标:控制洗衣机作如下运转:定时启动正转20秒暂停10秒反转20秒暂停10秒定时未到回到“正转20秒暂停10秒……”,定时到则停止;若定时到,则停机发出音响警报信号;用两个数码管显示洗涤的预置时间(分钟数),按倒计时方式对洗涤过程作计时显示,直到时间到停机;洗涤过程由“开始”信号开始;三只LED灯表示“正转”、“反转”、“暂停”三个状态。
原理:洗衣机控制器的设计主要是定时器的设计,由一片FPGA和外围电路构成了电器控制部分。FPGA接收键盘的控制命令,控制洗衣机的进水、排水、水位和洗衣机的工作状态、并控制显示工作状态以及设定直流电机速度、正反转控制、制动控制、起停控制和运动状态控制。对FPGA芯片的编程采用模块化的VHDL进行设计,设计分为三层实现,顶层实现整个芯片的功能。顶层和中间层多数是由VHDL的元件例化语句实现。中间层由运行模式选择、洗涤模式选择、定时器、显示控制、键盘扫描、水位控制以及对直流电机控制板进行速度设定、正反转控制、启停控制等模块组成,它们分别调用底层模块。用LED显示正转20秒,暂停10秒,反转20秒,暂停10秒,60秒为一周期。
总之洗衣机控制器设计的关键是计数器和定时器的设计。
洗衣机控制器电路由五部分组成: 1预置时间和编码电路:定时洗涤时间 2减法计数器: 计时
3时序控制电路: 控制洗涤过程的正转、暂停和反转
4译码器: 译出Q1Q2=00时,为暂停,Q1Q2=10时,为正转,Q1Q2=01时为反转 5数码管显示: 显示电路显示时间
- - 2
程序源代码及说明
洗衣机控制器的源程序如下:
一 数码管显示
library ieee;
use ieee.std_logic_11.all; use ieee.std_logic_unsigned.all;
entity showtime is
port(remain_time:in std_logic_vector(3 downto 0); cp:in std_logic;
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); begin
process(remain_time) begin
case remain_time is
when \"0000\"=> temp<= \"1111110\" ; when \"0001\"=> temp<= \"0110000\" ; when \"0010\"=> temp<= \"1101101\" ; when \"0011\"=> temp<= \"1111001\" ; when \"0100\"=> temp<= \"0010011\" ; when \"0101\"=> temp<= \"1011011\" ; when \"0110\"=> temp<= \"1011111\" ; when \"0111\"=> temp<=\"1110000\" ; when \"1000\"=> temp<=\"1111111\" ; when \"1001\"=> temp<= \"1111011\" ; when others=> null; end case; end process;
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_11.all; use ieee.std_logic_unsigned.all;
- -
3
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 state:std_logic; --0代表正转,1代表反转 variable wash_time:integer := 21; variable wait_time:integer := 9; begin 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; 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-6分钟编为BCD码 library ieee;
- -
4
use ieee.std_logic_11.all; use ieee.std_logic_unsigned.all; entity settime is
port(load:in std_logic;
k:in std_logic_vector(5 downto 0); o:out std_logic_vector(3 downto 0) );
end settime;
architecture rtl of settime is
signal p1:std_logic_vector(3 downto 0); begin process(k) begin
case k is --将时间分钟
when \"100000\"=>p1<=\"0001\"; when \"010000\"=>p1<=\"0010\"; when \"001000\"=>p1<=\"0011\"; when \"000100\"=>p1<=\"0100\"; when \"000010\"=>p1<=\"0101\"; when \"000001\"=>p1<=\"0110\"; when others=>p1<=\"0000\"; end case; end process; o<=p1; end rtl;
[4]、将时序电路的信号翻译为暂停,正转,反转 library ieee;
use ieee.std_logic_11.all;
entity decoder is port(
Q1,Q2: in std_logic;
REV,RUN,PAUSE: out std_logic--rev反转,run正转,pause暂停 ); end decoder;
architecture rtl of decoder is begin
REV<=Q2;RUN<=Q1;PAUSE<=not(Q1 OR Q2); end rtl;
- -
5
[5]、-十进制BCD码减法计数器,实现输入的为分钟数,每隔60秒计数器减1 library ieee;
use ieee.std_logic_11.all; use ieee.std_logic_unsigned.all;
entity counter is
port(clk,start:in std_logic;
k:in STD_LOGIC_VECTOR(3 downto 0);
time_remain:BUFFER STD_LOGIC_VECTOR(3 DOWNTO 0); time_is_up:out std_logic );
end counter;
architecture rtl of counter is begin
process(clk)
variable time_second:integer:=0; begin
if(clk'event and clk='1') then
if(start='0') then
time_remain<=k; time_second:=0; else
if(time_second=0)
then if(time_remain>0)--防止时间无限计数 then
time_remain<=time_remain-1;
time_second:=59; end if;
else
if(time_remain=0)--时间是否结束的判定 then time_is_up<='0'; else time_is_up<='1';
time_second:=time_second-1;--秒表计数的实现 end if; end if; end if; end if; end process;
- -
6
end rtl;
[6]、元件声明与例化 library ieee;
use ieee.std_logic_11.all; use ieee.std_logic_unsigned.all; PACKAGE my_componets Is COMPONENT showtime Is
port(remain_time:in std_logic_vector(3 downto 0); cp:in std_logic;
a,b,c,d,e,f,g:out std_logic );
end COMPONENT;
COMPONENT shixu is port(cp,en,rd:in std_logic;
q1,q2:out std_logic--00为停机,10为正转,01为反转 );
end COMPONENT;
COMPONENT settime is port(load:in std_logic;
k:in std_logic_vector(5 downto 0); o:out std_logic_vector(3 downto 0) );
end COMPONENT;
COMPONENT decoder is port(
Q1,Q2: in std_logic;
REV,RUN,PAUSE: out std_logic--rev反转,run正转,pause暂停 );
end COMPONENT;
COMPONENT counter is port(clk,start:in std_logic;
k:in STD_LOGIC_VECTOR(3 downto 0);
time_remain:BUFFER STD_LOGIC_VECTOR(3 DOWNTO 0); time_is_up:out std_logic );
end COMPONENT; End my_componets;
- -
7
library ieee;
use ieee.std_logic_11.all; use ieee.std_logic_unsigned.all; use work.my_componets.all; entity xiyiji is
port(clk,start,clk_fast:in std_logic; load:in std_logic;
k:in std_logic_vector(5 downto 0);
REV,RUN,PAUSE: out std_logic;--rev反转,run正转,pause暂停 rd:buffer std_logic;
a,b,c,d,e,f,g:out std_logic);--q1为低位 end xiyiji;
architecture xiyiji of xiyiji is signal x,y,t:std_logic;
signal z,j:std_logic_vector(3 downto 0); begin
U1:settime port map (load,k,z);
U2:counter port map (clk,start,z,j,rd); U3:shixu port map (clk,start,rd,x,y); U4:decoder port map(x,y,rev,run,pause);
U5:showtime port map(j,clk_fast,a,b,c,d,e,f,g); end xiyiji;
控制器仿真结果及数据分析
时钟信号CLK和CLKFAST是同步时钟,可以只设一个,再启动START以前先设置定时时间。
- - 8
总结
设计过程中遇到的问题及解决方法:还是基础知识不牢固的问题,对eda设计的概念并没有能够深入的去了解,不过在看书查找资料的过程中逐步的理解了eda设计的流程,知道从何下手。至于其他的编程序上的一些问题,还是得精学vhdl。
个人体会:这学期我包括这门课程选修了两门选修,都是教授VHDL语言的,我觉得这样还是很有好处的。
我觉得eda设计是培养我们综合运用所学知识,发现,提出,分析和解决实际问题,锻炼实践能力的重要环节。
通过这次课程的设计自己对vhdl更加熟悉,对定时器和计数器的设计,让我更加明白时序组合门电路设计。而且自已设计,使我初步掌握了VHDL的设计方法与一些技巧,我从中受益匪浅。通过这个实验设计,从中学到不少课本上没有的东西
这次设计也使我懂得了一定要把理论和实际结合起来,从理论得出结论,才能真正弄懂知识。同时,在这次设计中我发现了自己的不足之处,对以前所学知识理解的不够深刻,掌握的不够牢固。
对课程的建议:老师在给定题目的时候只给了三种,虽然可以从别的电器入手,但还
- -
9
是发现自己已开始选择要做的不是那么合适,希望老师能为以后的同学提供更多的选择吧。
参考
1 王国栋,潘松等.VHDL实用教程.成都:电子科技大学出版社,2000
2 侯伯亨等VHDL硬件语言描述与数字逻辑电路设计 西安:西安电子科技大学出版社2009
- - 10
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- awee.cn 版权所有 湘ICP备2023022495号-5
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务