数电实验-电风扇_第1页
数电实验-电风扇_第2页
数电实验-电风扇_第3页
数电实验-电风扇_第4页
数电实验-电风扇_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、题目: 基于quartus制作的电风扇 姓 名 高英达 学 院 信息与通信工程 专 业 通信工程 班 级 学 号 班内序号 07 目录基于Quartus的电风扇制作 1一、设计任务要求4二、系统设计12.1 设计思路42.2 总体框图 12.2.1 总体结构框图42.2.2 逻辑划分框图52.2.3 模块划分图 52.2.4 程序流程图 52.2.5 MDS图 5三、仿真波形及分析1四、源程序4 4.1 程序代码4 4.2 程序分析4五、功能说明5六、元器件清单及资源利用情况6七、故障及问题分析1八、总结和结论4一、设计任务要求基本要求 :1、 用 88 点阵模拟风扇转动,并采用双色点阵显示。

2、2、 风扇转动方式如图 1 所示,包括四个点阵显示状态并按顺序循环显示。风扇转动速度根据环境温度分为 4 档,其中 1 档的四个显示状态之间的切换时间为 2 秒,2 档为 1 秒,3 档为 0.5 秒,4 档为静止不动。3、 环境温度通过 2 个 BTN 按键设置,一个用来增加,一个用来减少,温度可设置范围为 1040,温度精度为 1,并用两个数码管进行温度显示。风扇根据不同的温度自动采用不同的转动速度,其中 2024对应 1 档,2529对应 2 档,3040对应 3 档,1019对应 4 档,用一个数码管显示档位。4、 定时模式:在风扇不同转动速度下,可以通过按键切换进入定时模式。定时时间

3、可设置范围为 2059 秒,采用两个数码管进行倒计时显示,当倒计时结束后,风扇状态保持静止不动。5、 设置开关键。风扇开机初始状态为 20、1 档,并有不小于 5 秒的开机音乐。关机状态为点阵全灭。提高要求 :1、 设计 LED 风扇的其他工作模式。2、 利用实验板上的温度传感器代替按键直接获取温度数据, 实现对 LED 风扇四档转速的自动控制。3、 用数码管实时显示温度传感器的温度数据,精度为 0.1。4、 自拟其他功能。二、系统设计2.1设计思路采用分模块的设计思想,将整个程序主要分为三个模块:分频模块、控制模块以及显示模块。其中:1. 分频模块的作用是产生程序所需要的时钟频率。包括时钟及

4、点阵的扫描频率2000Hz、键盘扫描频率500Hz、控制数码管倒计时的频率1Hz、不同档位风扇转速对应的频率:20Hz、10Hz、5Hz。本实验采用了两种计时方式,分别是计数分频和时钟反转分频。2. 控制模块主要由BTN按键和拨档按键组成。BTN按键用来控制温度及时间的增减,拨档按键用来实现开关机功能以及倒计时开关功能。其中,”start“ 按键置一实现倒计时功能,同时BTN按键仍可控制时间加减。3. 显示模块包括数码管显示和点阵显示。点阵显示通过高频率逐次扫描然后利用视觉暂留效应产生静态显示;数码管利用片选信号每次选通一个数码管,然后根据输出控制单个七段数码管显示状态的信号实现数码管的显示。

5、点阵显示风扇图形,数码管显示风扇档位、倒计时时间以及当前温度。2.2 总体框图2.2.1 总体结构框图数码管88点阵控制器复位按键时钟按钮输入2.2.2逻辑设计框图88档位显示控制器按键输入及复位键温度到档位分频器时钟数码管显示计时器2.2.3 程序流程图开始点阵旋转3档温度24?温度30?温度上升?温度控制键是否按下时间控制键是否按下start键是否按下点阵旋转1档数码管显示温度20度显示时间30s否否否是是否是是否否是是否是是是否start=12.2.4 MDS图计时状态Time=0Temp44档 运行状态Temp3Temp4Temp1Clear=1Clear=03档1档关闭状态开启状态T

6、emp2Temp12档Temp3Temp210Temp12425Temp22930Temp340Temp410三、仿真波形及分析初始化:由这两个波形图可以看出数码管的初始值。Cat是数码管片选信号,代表导通的数码管dec是八段控制的数字,从图中看出,六个数码管从右到左依次显示为:33030,代表3档30摄氏度30秒。证明初始化正确。温度按键:从这三个波形图可以看出,当up_tem置1而其他置0,即只有升温按键一直按下的时候,在仿真358us左右,数码管最右边一位,即温度的个位显示从0变1,在774us左右,该处数值变成2。证明升温按键正常工作,温度降低按键检测原理同上。时间按键:从这两个波形图

7、可以看出,当low_time置1而其他置0,即只有减时按键一直按下的时候,在294us左右,数码管右边第三位,即时间的个位显示由0跳变至9,在777us左右,该处数码管显示8。证明减时按键正常工作,加时按键检测同理。四、源程序4.1程序代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity fan is port(clk_50M:in std_logic;clear:in std_logic;start:in std_logic;up_tem,low_tem,up_time,low_ti

8、me:in std_logic;-调节温度btn red:out std_logic_vector(0 to 7);-点阵 红 green:out std_logic_vector(0 to 7);-点阵 绿 row:out std_logic_vector(0 to 7);-点阵 行cat:out std_logic_vector(5 downto 0);-数码管 位数dec:out std_logic_vector(6 downto 0);t1,t2,t3,t4:in std_logic;spks: out std_logic );end fan;architecture arc of f

9、an issignal clk_r,clk_s:std_logic;signal clk_temp1,clk_temps,clk_temp2,clk_temp3,clk_temp4,clk_temp5,clk_temp6,clk_temp7:std_logic;signal temp1:integer range 0 to ;signal temps:integer range 0 to ;signal temp2,temp3,temp4,temp5:integer range 0 to 999;signal a:integer range 0 to 7;-点阵 行扫描signal c:int

10、eger range 0 to 3;-点阵 图案signal gear:std_logic_vector(1 downto 0);-档位signal gear_dec:std_logic_vector(3 downto 0);signal d:integer range 0 to 5;-数码管扫描signal d_temp:std_logic_vector(3 downto 0);signal tem_h:std_logic_vector(3 downto 0);-温度signal tem_l:std_logic_vector(3 downto 0);signal tem_f:std_logi

11、c_vector(7 downto 0);-温度signal time_h:std_logic_vector(3 downto 0);-timesignal time_l:std_logic_vector(3 downto 0);signal time_f:std_logic_vector(7 downto 0);signal clk_075M, fullspks:std_logic; signal count0:integer range 0 to 63;-change signal clk2:std_logic; signal tone0:integer range 0 to 2047;s

12、ignal index:std_logic_vector(15 downto 0); beginp1:process(clk_50M) -分频beginif clk_50Mevent and clk_50M=1 thenif temp1=24999 thentemp1=0;clk_temp1=NOT clk_temp1;-2000hzelsetemp1=temp1+1;end if;end if;end process p1;clk_r=clk_temp1;p111:process(clk_50M) -分频variable counts:integer:=0;beginif clear = 0

13、 thencounts := 0;elseif clk_50Mevent and clk_50M=1 thencounts := counts + 1;if counts = then clk_temps =0;elsif counts then clk_temps =1;else counts := 0;end if;end if;end if;end process p111;p11:process(clk_temp1)beginif clk_temp1event and clk_temp1=1 thenif temp2=24 thentemp2=0;clk_temp2=not clk_t

14、emp2;-80hzelsetemp2=temp2+1;end if;end if;end process p11;p12:process(clk_temp2)beginif clk_temp2event and clk_temp2=1 thenif temp3=1 thentemp3=0;clk_temp3=not clk_temp3;-40hzelsetemp3=temp3+1;end if;end if;end process p12;p13:process(clk_temp3)beginif clk_temp3event and clk_temp3=1 thenif temp4=1 t

15、hentemp4=0;clk_temp4=not clk_temp4;-20hzelsetemp4=temp4+1;end if;end if;end process p13;p14:process(clk_temp1)beginif clk_temp1event and clk_temp1=1 thenif temp5=24 thentemp5=0;clk_temp6=not clk_temp6;clk_temp7=not clk_temp7;-500分频elsetemp5=temp5+1;end if;end if;end process p14;p2:process(up_tem,low

16、_tem,clear,clk_temp6)-按键调节温度beginif clear=0 thentem_h=0011;tem_l=0000;elsif clk_temp6event and clk_temp6=1 and up_tem=1 thenif tem_h=0100 thentem_h=0100;tem_l=0000;elsif tem_l=1001 thentem_h=tem_h+1;tem_l=0000;else tem_l=tem_l+1;end if;elsif clk_temp6event and clk_temp6=1 and low_tem=1thenif tem_l=0

17、000 thenif tem_h=0001 thentem_h=0001;tem_l=0000;elsetem_h=tem_h-1;tem_l=1001;end if;else tem_l=tem_l-1;end if;end if;end process p2;tem_f=tem_h&tem_l;p22:process(up_time,low_time,clear,clk_temp7,start,clk_temps)-button control timebeginif clear=0 thentime_h=0011;time_l=0000;elsif clk_temp7event and

18、clk_temp7=1 and up_time=1thenif time_h=0110 thentime_h=0110;time_l=0000;elsif time_l=1001 thentime_h=time_h+1;time_l=0000;else time_l=time_l+1; end if;elsif clk_temp7event and clk_temp7=1 thenif low_time=1 or (start = 1 and clk_temps =1) thenif time_l=0000 thenif time_h=0000 thentime_h=0000;time_l=0

19、000;elsetime_h=time_h-1;time_l=1001;end if;else time_l=time_l-1;end if;end if;end if;end process p22;time_f=time_h&time_l;p3:process(tem_f)-wendu dao dangweibeginif time_f= thengear=00;elsif tem_f= thengear=00;elseif tem_f thengear=01;elseif tem_f thengear=10;else gearclk_temp5=0;gear_decclk_temp5=c

20、lk_temp4;gear_decclk_temp5=clk_temp3;gear_decclk_temp5=clk_temp2;gear_dec=0011;end case;end process p4;clk_s=clk_temp5;-数码管显示相关p5:process(clk_r)beginif clk_revent and clk_r=1then d=d+1; if d=5 thend=0;end if;end if;end process p5;p:process(d,tem_l,tem_h)beginif clear=0 thencatd_temp=tem_l;catd_temp=

21、tem_h;catd_temp=time_l;catd_temp=time_h;catd_temp=1111;catd_temp=gear_dec;catdecdecdecdecdecdecdecdecdecdecdec=;end case;end process p6;-双色点阵相关p7:process(clk_r)beginif clk_revent and clk_r=1then a=a+1; if a=7 thena=0;end if;end if;end process p7;p8:process(clk_s) beginif clk_sevent and clk_s=1thenc=

22、c+1;if c=3 thenc=0;end if;end if;end process p8;p9:process(a,c,clear) -双色点阵显示 beginif clear=0 thenrowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rownull;end case;elsif(c=1)thencase a iswhen 0=red=;green=;rowred=;green=;rowred=;

23、green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rownull;end case;elsif(c=2)thencase a iswhen 0=red=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rownull;end case;elsecase a iswhen 0=red=;green=;rowre

24、d=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rowred=;green=;rownull;end case;end if; end if; end process p9;end;4.2关键程序分析1.温度控制:process(up_tem,low_tem,clear,clk_temp6)beginif clear=0 thentem_h=0010;tem_l=0000;elsif clk_temp6event and clk_temp6=1 and up_tem=1 t

25、henif tem_h=0100 thentem_h=0100;tem_l=0000;elsif tem_l=1001 thentem_h=tem_h+1;tem_l=0000;else tem_l=tem_l+1;end if;elsif clk_temp6event and clk_temp6=1 and low_tem=1thenif tem_l=0000 thenif tem_h=0001 thentem_h=0001;tem_l=0000;elsetem_h=tem_h-1;tem_l=1001;end if;else tem_l=tem_l-1;end if;end if;end

26、process p2;tem_f=tem_h&tem_l;分析:CLK_TEMP6是500分频,扫描温度按键。Up_tem、low_tem分别控制温度上升和下降。Tem_h、tem_l分别代表数码管显示温度的高位和低位。开机温度是20,当检测到Up_tem=1时,温度上升;检测到low_tem=1时,温度下降。最后把温度复制给tem_f,用于之后温度对档位的控制。2.时间控制及倒计时:p22:process(up_time,low_time,clear,clk_temp7,start,clk_temps)-button control timebeginif clear=0 thentime_

27、h=0011;time_l=0000;elsif clk_temp7event and clk_temp7=1 and up_time=1thenif time_h=0110 thentime_h=0110;time_l=0000;elsif time_l=1001 thentime_h=time_h+1;time_l=0000;else time_l=time_l+1; end if;elsif clk_temp7event and clk_temp7=1 thenif low_time=1 or (start = 1 and clk_temps =1) thenif time_l=0000

28、 thenif time_h=0000 thentime_h=0000;time_l=0000;elsetime_h=time_h-1;time_l=1001;end if;else time_l=time_l-1;end if;end if;end if;end process p22;time_f=time_h&time_l;分析: clk_temp7是500分频,用于扫描时间控制按键的时钟; clk_temps是用于计时的时钟。up_time、low_time分别用于控制增时间、减时间;time_h、time_l分别表示数码管时间显示的高低位。Start是倒计时开启开关,当start=1

29、的时候开始倒计时。最后把时间复值给time_f,用于之后时间对档位的控制。4.时间及温度控制风扇旋转速度p3:process(tem_f)beginif time_f= thengear=00;elsif tem_f= thengear=00;elseif tem_f thengear=01;elseif tem_f thengear=10;else gear=11;end if;end if;end if;end process p3;分析:当倒计时结束时间为零时,gear=00风扇调至4档;如果倒计时时间不为零,温度小于10,gear=00风扇调至4档;温度大于10小于25,gear=01

30、风扇调至1档;温度大于24小于30,gear=10风扇调至2档;温度大于30小于40,gearclk_temp5=0;gear_decclk_temp5=clk_temp4;gear_decclk_temp5=clk_temp3;gear_decclk_temp5=clk_temp2;gear_dec=0011;end case;end process p4;clk_s=clk_temp5;分析:当gear=”00“时,clk_temp5=0,风扇停止旋转。当gear=”01“时,clk_temp5= clk_temp4,风扇以20Hz的转速旋转。当gear=”10“时,clk_temp5=

31、clk_temp3,风扇以40Hz的转速旋转。当gear=”11“时,clk_temp5= clk_temp2,风扇以80Hz的转速旋转。五、功能说明1.点阵显示风扇的四个状态,对点阵行列的控制,选择一列红色、二列绿色。通过时钟的扫描实现风扇的旋转。2.数码管从左到右分别显示风扇所在档位、倒计时和温度。3.BTN3和BTN2分别控制时间增加和时间减少;BTN1和BTN0分别控制温度的上升和下降。4.SW7控制风扇的开关,开启状态默认为温度是20一档运行,时间是30s。SW6控制倒计时的开关,开关开启倒计时开始。倒计时时间为零,倒计时结束,风扇停止旋转。六、元器件清单及资源利用情况1. 元器件清

32、单: 电脑一台、quartus仿真设计软件、数电实验开发板一块。2.资源利用情况七、故障及问题分析故障:quartus软件编译错误。在编译过程成主要遇到以下几个问题:1. 时钟的重复利用2. 变量的多进程赋值问题3. 如何检测按键问题分析:主要是对编程不够熟练,导致犯了一些基本性的错误。按键检测问题后来网上查询,根据自己的程序选择了一个比较适合的方法解决了这个问题。故障:将程序下载到实验板上之后,遇到以下几个问题:1. 控制时间的按键不能检测到2. 倒计时不能正常运行,调整后倒计时每秒改变4次。分析:控制时间按键的频率和控制温度的按键使用相同的频率检测的,一开始单独分出来两个相同的频率,分别用于检测时间和温度的按键。后来修改程序,将两个频率在同一个分频进程里完成:_ p14:process(clk_temp1)beginif clk_temp1event and clk_temp1=1 th

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论