数字电路与逻辑设计实验电子节拍器的设计与实现-综合实验报告_第1页
数字电路与逻辑设计实验电子节拍器的设计与实现-综合实验报告_第2页
数字电路与逻辑设计实验电子节拍器的设计与实现-综合实验报告_第3页
数字电路与逻辑设计实验电子节拍器的设计与实现-综合实验报告_第4页
数字电路与逻辑设计实验电子节拍器的设计与实现-综合实验报告_第5页
已阅读5页,还剩23页未读 继续免费阅读

下载本文档

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

文档简介

数字电路与逻辑设计实验电子节拍器的设计与实现综合实验报告学院:信息与通信工程学院班级:2013211124姓名:曹爽学号:2013210640班内序号:062015年11月12日目 录一、实验题目和任务要求2(一)实验题目2(二)基本要求2(三)提高要求2二、系统设计2(一)设计思路2(二)总体框图3(三)分块设计6三、仿真波形及波形分析6(一)encode文件仿真6(二)change文件仿真7(三)fangdou文件仿真7四、源程序8(一)connect.vhd8(二)beat.vhd10(三)change.vhd12(四)chw.vhd12(五)cnta.vhd13(六)cora.vhd14(七)encode.vhd17(八)fangdou.vhd18(九)fenpin.vhd18(十)jibenpinlv.vhd20(十一)voice.vhd21(十二)xianshi.vhd22五、功能说明及资源利用情况23(一)功能说明23(二)资源占用情况24六、故障及问题分析24七、总结和结论25八、参考文献26一、 实验题目和任务要求(一) 实验题目电子节拍器的设计与实现,设计并实现一个具有声光显示的电子节拍器。(二) 基本要求1、速度在40120次/分钟范围内连续可调,通过2个按键进行速度调节,一个用来增加,一个用来减少,当长按按键时,按5次/秒的速度连续增加或减少,用3个数码管显示当前速度。2、节拍有1/4、2/4、3/4、4/4、3/8、6/8可选,通过一个按键选择,用2个数码管显示。3、通过一个按键开始和停止打节拍,开始后按照设置好的节拍和速度打节拍。4、要求有声音和灯光提示,声音要有强弱区别,灯光可用不同颜色的发光二极管表示强弱。(三) 提高要求1、通过一个按键选择时值(节奏类型),并在用点阵显示,如下图。2、自拟其他功能。二、 系统设计(一) 设计思路最开始,我的想法是先设置速度,让高频时钟经过分频器,分出40120次/分钟(即周期在0.5s1.5s之间,因为只有统一到周期上才能用数时钟沿的方式进行分频),分频系数随速度变化而变化,大概呈反比例关系。下一步是设计节拍类型,题目中要求的六种节拍类型含义如下:(其中表示强拍,表示次强拍,表示弱拍,| 表示小节线。)1/4拍:以四分音符为一拍,每小节一拍,节奏类型:|2/4拍:以四分音符为一拍,每小节二拍,节奏类型:|3/4拍:以四分音符为一拍,每小节三拍,节奏类型:|4/4拍:以四分音符为一拍,每小节四拍,节奏类型:|3/8拍:以八分音符为一拍,每小节三拍,节奏类型:|6/8拍:以八分音符为一拍,每小节六拍,节奏类型:|从乐理的角度来说,两拍之间的时间间隔是由速度控制的。而如果没有指定以哪种音符为基准,那么3/4拍和3/8拍的节奏是完全一样的,如果指定了以某种音符为基准,则3/4拍和3/8拍的节奏是二倍的关系。题目中没有给出以哪种音符作为速度的基准,所以按理说3/4拍和3/8拍应该是一样的节奏,为了加以区分,我把3/8拍的节奏设置成了强,次强,弱(),以示区分。经过了速度和节拍类型的设置之后,节拍器其实就已经确定了工作方式。在确定速度和节拍类型的同时,将设定的速度和节拍类型显示在数码管上,用两个按键控制速度的增减,用另一个按键控制节拍类型的切换。之后,在节拍器正常工作的同时,设置蜂鸣器强、次强、弱三种蜂鸣频率作为每拍提示音,并且讲三个二极管提示灯设置成红、黄、绿三种颜色跟随节奏闪烁,以对应强、次强、弱三种节拍强度。整个节拍器可以通过一个拨码开关控制工作和停止工作,只要设置一个信号,1时工作,0时停止工作即可。整个思路可以由以下框图表示:蜂鸣器(含频率设置)buttonbuttonbuttonclear选择节拍类型分频器(选择速度)clkLED灯(含颜色设置)数码管显示图2.1.1 初步设计框图这是我最初的设计思路,在之后的实际设计中,又添加了许多模块(如防抖模块、点阵显示模块等),这些内容会在后文叙述。(二) 总体框图由于我采用的是用代码连接各模块的方式,所以在整个节拍器设计并调试完毕之后,我用Quartus II自带的RTL Viewer功能,将各模块的连接绘制成了整体框图,如图2.2.1和图2.2.2所示。图2.2.1 RTL Viewer总体框图 图2.2.2 RTL Viewer总体框图(续)从整体框图可以看出,整个节拍器由13个模块组成,外部信号包括:clearin(开关)、clkin(高频时钟)、button a、button b、button c三个控制按钮组成;输出包括数码管显示、LED显示、蜂鸣器、点阵显示等。模块包括防抖模块、数码管显示模块、分频器模块、节奏选择模块等。(三) 分块设计根据流程图的内容,可以进行逐步细化的分块设计。首先,分频器速度选择模块要求能在40120次/分钟这81种状态中任意选择,状态转移图就有81个结点,每种状态(即每两拍的时间间隔)是通过计算得到的,满足反比例函数关系。比如用30MHz的高频时钟时,经过理论推导和实验计时,每两拍的时间间隔就满足如下关系式:每个时间间隔持续的时钟沿数= 1500000000/速度-1利用这个公式可以计算出每个状态需要数出的时钟沿个数,从而设置速度。之后,节拍类型模块包括6个状态,每种状态需要设定好各自的节奏强弱,并将节奏强弱变成信号交给数码管、LED灯、蜂鸣器等。LED灯和蜂鸣器对节奏强弱进行解析,转变成发声频率和闪烁颜色,这都需要在不同的文件中编写程序,再通过信号连接实现。最后,我还设置了防抖模块和点阵显示模块,防抖模块用来防止按键瞬间的抖动,点阵显示用来显示具体的音符,这些也需要分文件分模块进行设计。三、 仿真波形及波形分析由于本程序中分频器的系数是用一个除法式表示的(1500000000/tmp-1,其中tmp取40到120之间的任意整数),如果把式中的1500000000改小,则它除以tmp之后的值将变得无法明显分辨,失去其分频的意义;而现在这个系数又无法在短时间内仿真出来。所以无法通过更改分频系数进行整体仿真,只能进行分模块仿真。下面我就几个主要的模块进行分模块仿真并分析。(一) encode文件仿真本程序用于设置蜂鸣器的脉冲断开,使其发出的声音间断,便于识别拍子。仿真波形如图3.1.1所示。图中ai、bi、ci是三种输入频率。从仿真波形可以看出,输入频率连续不变的时候,输出并不是连续的频率,而是随着时钟clkin=1的时候才有相应的频率输出,达到了脉冲断开的功能,避免了蜂鸣器输出连续的声音不能分清节拍的问题。图3.1.1 encode文件仿真波形图(二) change文件仿真本程序可将强、次强、弱三种拍子转化成蜂鸣器可识别的频率强弱形式。为了便于仿真观察,在原有的change.vhd文件中加入了时钟,以展示仿真效果。仿真波形如图3.2.1所示,a、b、c表示强、次强、弱三种拍子,在外部时钟clk的作用下,输出为clkout。并且,clkout的频率由a、b、c决定,a频率最高,c频率最低,实现了三种强弱拍子到时钟频率的转化。图3.2.1 change文件仿真波形图(三) fangdou文件仿真本程序为防抖模块,仿真波形如图3.3.1所示。button是我按下的按键,我随意设置了几段0值,从仿真波形可以看出,不论我按键时间多长,每次只会在按下按键(button=1)后遇到第一个clk上升沿时,输出buout才为1,其他时刻均为0(毛刺除外)。最后的波形尤为明显,button恒等于1后,buout仍然只在clk第一个上升沿开始到再次遇到下降沿这区间内等于1,而在此后的时间均为0,这便起到了防抖的作用。图3.3.1 fangdou文件仿真波形图其他的模块,或是无法改小分频系数仿真(如基本频率模块,改小分频系数之后就失去了其原有的功能),或是改小参数后会失去仿真的意义(如分频器模块,如果把1500000000改小,则它除以tmp之后的值将变得无法明显分辨,失去其分频的意义),或是数组过多分频效果不明显(如点阵显示模块定义数组过多,即使仿真也不易看出其图形)。基于以上原因,其他不易或不必仿真的模块便没有给出仿真波形图。四、 源程序(一) connect.vhd本程序是主体,用于接口和信号的说明,以及各模块之间的连接,具体信号和连接方式可参见总体框图部分图2.2.1和图2.2.2。library IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_unsigned.all;use IEEE.std_logic_arith.all;entity connect isport(clkin,clearin : in std_logic; buttona,buttonb,buttonc : in std_logic; bout : out std_logic_vector (6 downto 0); ct :out std_logic_vector(5 downto 0); o1,o2,o3: out std_logic; dout :out std_logic; col:out std_logic_vector(7 downto 0); row:OUT STD_LOGIC_VECTOR(7 DOWNTO 0);end connect;architecture connect_arch of connect is component jibenpinlv isport(clk , clear: in std_logic; clkout1,clkout2,clkout3 : out std_logic);end component;component beat isport(a:in std_logic; clk,clk3:in std_logic; o,y,z:out std_logic; n:out integer);end component;component fenpin isport(clk,clk3,clear: in std_logic; button1 , button2: in std_logic; temp: out integer; clkout : out std_logic);end component;component fangdou isport(clk: in std_logic; button : in std_logic; buout : out std_logic);end component;component xianshi isport(clk2: in std_logic; tmp,d: in integer; num:out std_logic_vector(6 downto 0); cat:out std_logic_vector(5 downto 0);end component;component encodeport(ai,bi,ci,clk:in std_logic; ao,bo,co,ao1,bo1,co1:out std_logic);end component;component voice is port(clk :in std_logic; bin :in std_logic_vector(1 downto 0); clkout:out std_logic); end component; component change is port(a,b,c:in std_logic; cout: out std_logic_vector(1 downto 0);end component;component chw is port (clk:in std_logic; br: in std_logic; qr:out std_logic_vector(2 downto 0); end component;component cora is port (ch:in std_logic_vector(2 downto 0); sel:in std_logic_vector(2 downto 0); q:out std_logic_vector(7 downto 0); ROW:OUT STD_LOGIC_VECTOR(7 DOWNTO 0);end component;component cnta is port(clk: in std_logic; qe:out std_logic_vector(2 downto 0);end component;signal d1,d2,d3,t : std_logic;signal A,B,C:std_logic;signal i1,i2,i3,e1,e2,e3:std_logic;signal e:std_logic_vector(1 downto 0);signal qw,qt:std_logic_vector(2 downto 0);signal w1,w2:integer;beginu1 : jibenpinlv port map(clk=clkin,clear=clearin,clkout1=d1,clkout2=d2,clkout3=d3);u2 : fangdou port map(clk=d1,button=buttona,buout=A);u3 : fangdou port map(clk=d1,button=buttonb,buout=B);u4 : fangdou port map(clk=d1,button=buttonc,buout=C);u5 : fenpin port map(clk=clkin,clk3=d3,clear=clearin,button1=B,button2=C,temp=w2,clkout=t);u6 : beat port map(a=A,clk=t,clk3=d3,o=i1,y=i2,z=i3,n=w1);u7 : xianshi port map(clk2=d2,tmp=w2,d=w1,num=bout,cat=ct);u8 : encode port map(ai=i1, bi=i2 ,ci=i3, clk=t,ao=o1,bo=o2,co=o3,ao1=e1,bo1=e2,co1=e3);u9 : change port map(a=e1,b=e2,c=e3,cout=e);u10 : voice port map(clk=clkin,bin=e,clkout=dout);u11 : chw port map(clk=d3,br=A,qr=qw);u12 : cnta port map(clk=clkin,qe=qt);u13 : cora port map(ch=qw,sel=qt,q=col,ROW=row);end;(二) beat.vhd本程序用于设置节奏和节拍,并用二进制形式表示。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity beat isport(a:in std_logic; -_vector(2 downto 0); clk,clk3:in std_logic; o,y,z:out std_logic; n:out integer); end entity;architecture behav of beat is signal count:integer range 0 to 5 :=0; signal tmp:integer range 0 to 10; signal b:integer range 0 to 6; begin process(clk,a) begin if clk3event and clk3 = 1 then if a=1 then b = b+1; end if; if b=6 then b = 0; end if; n tmp tmp tmp tmp tmp tmp tmp = 0; end case; if clkevent and clk = 1 then count = count + 1; if count=tmp then count = 0; end if; if count =0 then o = 1; y = 0; z = 0; end if; if count =1 then o = 0; if b=4 then y = 0;z=1; else z = 0; y=1; end if; end if; if count =2 then o = 0; y = 1; z = 0; end if; if count =3 then o = 0; if b=5 then y = 0;z=1; else z=0; y=1; end if; end if; if count =4 then o = 0; y = 1; z = 0; end if; if count =5 then o = 0; y = 1; z = 0; end if; end if; end process;end architecture;(三) change.vhd本程序可将强、次强、弱三种拍子转化成蜂鸣器可识别的频率强弱形式,并用二进制的形式表示出来。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity change is port(a,b,c:in std_logic; cout: out std_logic_vector(1 downto 0); end entity; architecture behave of change is beginprocess(a,b,c)beginif a=1 then cout = 00; -abc对应强、次强、弱三种拍子elsif b=1 then cout = 01;elsif c=1 then cout = 10; else cout = 11; end if;end process;end;(四) chw.vhd本程序和cnta.vhd程序均用于点阵扫描。library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity chw is port (clk:in std_logic; br: in std_logic; qr:out std_logic_vector(2 downto 0); end chw; architecture chw_arc of chw is signal tmp:std_logic_vector(2 downto 0); begin process(clk) begin if (clkevent and clk = 1) then -六个节拍对应六种图形 if br=1 then If tmp=101then tmp=000; else tmp=tmp+1; end if; end if; end if; qr=tmp; end process; end chw_arc;(五) cnta.vhdlibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnta isport(clk: in std_logic; qe:out std_logic_vector(2 downto 0);end entity;architecture cnt_arc of cnta isbegin process(clk) variable cnt:integer:=0; variable tmp:std_logic_vector(2 downto 0); begin if clkevent and clk=1 then if cnt25000 then cnt:=cnt+1; if cnt=1 then if tmp=111 then -点阵扫描 tmp :=000; else tmp := tmp+1; end if; end if; else cnt:=0; end if; end if; qe-第一种图像 case sel is when 000=q=01111110; ROWq=00001000; ROWq=00001000; ROWq=00001000; ROWq=00001000; ROWq=00001000; ROWq=00011000; ROWq=00000000; ROW-第二种图像 case sel is when 000=q=01111110; ROWq=00011000; ROWq=00011000; ROWq=00011000; ROWq=00011000; ROWq=00011000; ROWq=00111000; ROWq=00000000; ROW-第三种图像 case sel is when 000=q=01111110; ROWq=00111000; ROWq=00111000; ROWq=00111000; ROWq=00111000; ROWq=00111000; ROWq=01111000; ROWq=00000000; ROW-第四种图像 case sel is when 000=q=01111110; ROWq=00111100; ROWq=00111100; ROWq=00111100; ROWq=00111100; ROWq=00111100; ROWq=01111100; ROWq=00000000; ROW-第五种图像 case sel is when 000=q=01111110; ROWq=01111110; ROWq=00111000; ROWq=00111000; ROWq=00111000; ROWq=00111000; ROWq=01111000; ROWq=00000000; ROW-第六种图像 case sel is when 000=q=11111111; ROWq=11111111; ROWq=01111110; ROWq=01111110; ROWq=01111110; ROWq=01111110; ROWq=11111110; ROWq=00000000; ROWq ao = ai; ao1=ai; -脉冲为了让蜂鸣器发出的声音断开 bo = bi; bo1 = bi; co = ci; co1 ao = 0; ao1 = 0; bo = 0; bo1 = 0; co = 0; co1 = 0; end case; end process;end architecture;(八) fangdou.vhd本程序为防抖模块,目的是防止按键瞬间的抖动对状态转移的影响。library IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_unsigned.all;entity fangdou isport(clk: in std_logic; button : in std_logic; buout : out std_logic); end fangdou;architecture behave of fangdou is signal ip1,ip2:std_logic;beginprocess(clk)begin if (clkevent and clk = 1) then ip2=ip1; ip1=button; end if; buout = clk and (not ip2) and ip1;end process;end;(九) fenpin.vhd本程序为分频器,可将高频时钟频率分频成指定的速度对应的频率。library IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_unsigned.all;entity fenpin isport(clk,clk3,clear: in std_logic; button1 , button2: in std_logic; temp: out integer; clkout : out std_logic); end fenpin;architecture div10_arch of fenpin issignal t : std_logic;signal count: integer range 0 to 50000000; signal tmp : integer range 39 to 121 := 40;signal status : integer range 0 to 6;signal a1,b1,c1: integer range 0 to 9;beginprocess(clk,clk3,clear)begin if clk3event and clk3=1 then -add if button1=1 then tmp = tmp+1; end if; if button2=1 then -sub tmp = tmp-1; end if; if tmp = 121 then tmp

温馨提示

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

评论

0/150

提交评论