加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

实验三 EDA时钟的设计

(2012-06-05 09:00:05)
标签:

杂谈

分类: EDA作业

实验三    EDA时钟的设计

 

姓名:王林强

学号:2009230123

班级:09级通信工程

实验组别:周五下午

同组人员:王林强黄泽斌李贺伟

日期:2012 06 04

 

一、实验目的:

设计并实现具有一定功能的数字钟

二、实验仪器:

计算机 一台,FPGA实验箱 一台

三、实验原理:

 

 

通过时钟、分钟、秒钟模块组合,来完成整体的计时功能。 

四、实验内容与步骤:

     实验内容1正常的时、分、秒计时功能,分别由6个数码管显示24小时、60分钟、60秒钟的计数器显示。

     实验内容2按键实现“校时”“校分”功能;

     实验内容3用扬声器做整点报时。当计时到达5950”时鸣叫。

  

      实现的方法:通过PORT MAP 语句来实现。

 

程序代码如下:

SECOND:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity SECOND is
           port(clk,clr,secset:in std_logic;----时钟/清零信号
                sechdata:in std_logic_vector(3 downto 0);----加载分钟的高位
                secldata:in std_logic_vector(3 downto 0);----加载分钟的低位
                sec1,sec0:out std_logic_vector(3 downto 0);----秒高位/低位
                co:out std_logic);-------输出/进位信号
end SECOND;

architecture SEC of SECOND is
begin
     process(clk,clr,secset)
             variable cnt1,cnt0:std_logic_vector(3 downto 0);---计数
             begin
              
             
                   if clr='1' then----当ckr为1时,高低位均为0
                      cnt1:="0000";
                      cnt0:="0000";
                   elsif  secset='1' then
                            cnt0:=secldata;----加载秒的设定值
                            cnt1:=sechdata;                      
                   elsif clk'event and clk='1' then
                         if cnt1="0101" and cnt0="1001" then----当记数为58(实际是经过59个记时脉冲)
                            co<='1';----进位
                            cnt0:="0000";----低位为9
                            cnt1:="0000";
                         elsif cnt0<"1001" then----小于9时
                            cnt0:=cnt0+1;----计数
                            co<='0';
                         else
                            cnt0:="0000";
                            if cnt1<"0101" then----高位小于5时
                               cnt1:=cnt1+1;                           
                            else
                               cnt1:="0000";
                               co<='0';
                            end if;
                         end if;
                    end if;
                    sec1<=cnt1;
                    sec0<=cnt0;                  
     end process;

end SEC;

 

MINUTE:

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity MINUTE is
           port(setclk,clk,clr,minset:in std_logic;----时钟/清零信号
                minhdata:in std_logic_vector(3 downto 0);----加载分钟的高位
                minldata:in std_logic_vector(3 downto 0);----加载分钟的低位
                min1,min0:out std_logic_vector(3 downto 0);----minute高位/低位
                co:out std_logic);-------输出/进位信号
end MINUTE;


architecture MIN of MINUTE is
   
begin 
     process(clk,clr,minset)
            variable cnt1,cnt0:std_logic_vector(3 downto 0);---计数
             begin              
                   if clr='1' then----当ckr为1时,高低位均为0
                      cnt1:="0000";
                      cnt0:="0000";
                   elsif minset='1' then
                      cnt0:=minldata;----加载秒的设定值
                      cnt1:=minhdata;
                   elsif clk'event and clk='1' then
                         if cnt1="0101" and cnt0="1001" then----当记数为58(实际是经过59个记时脉冲)
                            co<='1';----进位
                            cnt0:="0000";----低位为9
                            cnt1:="0000";
                         elsif cnt0<"1001" then----小于9时
                               cnt0:=cnt0+1;----计数
                               co<='0';
                         else
                               cnt0:="0000";
                               if cnt1<"0101" then----高位小于5时
                                  cnt1:=cnt1+1;
                               else
                                  cnt1:="0000";
                                  co<='0';
                               end if;
                         end if;
                   end if;
                 min1<=cnt1;
                 min0<=cnt0;                                
             end process;
                 
end MIN;

 

HOUR:

 

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity HOUR is
         port(clr,clk,hset : in std_logic;
              hhdata:in std_logic_vector(3 downto 0);----
              hldata:in std_logic_vector(3 downto 0);----
              h1,h0 : out std_logic_vector(3 downto 0));
end HOUR;


architecture behav of HOUR is
begin
     
      process(clr,clk,hset)
          variable cnt1,cnt0:std_logic_vector(3 downto 0);---计数
          begin
               if clr='1' then
                  cnt0:="0000";
                  cnt1:="0000";
               elsif  hset='1' then
                   cnt0:=hldata;----
                   cnt1:=hhdata;

               elsif(clk'event and clk='1') then
                    if (cnt1<2) then
                       if (cnt0=9) then
                          cnt0:="0000";
                          cnt1:=cnt1 + 1;
                       else
                          cnt0:=cnt0+1;
                       end if;
                    else
                       if (cnt0=3) then
                          cnt0:="0000";
                          cnt1:="0000";
                       else
                          cnt0:=cnt0+1;
                       end if;  
                    end if;
               end if;
          
           h1<=cnt1;
           h0<=cnt0;
     end process;
          
end behav;

SPEAKER:

 

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity SPEAKER is
         port(frq,spin : in std_logic;
              spsignal : out std_logic);
end SPEAKER;


architecture behav of SPEAKER is
begin
      process(spin)
          begin
              if spin='1' then
                 spsignal<=frq;
              else
                 spsignal<='0';
              end if;
      end process;
end behav;

 

 

时钟设计的顶层实现:

 

 

library ieee;
use ieee.std_logic_1164.all;

entity CLOCK is
         port(crest,cclk,csecset,cminset,chset,cspeakfrq : in std_logic;
              chdata:in std_logic_vector(3 downto 0);----
              cldata:in std_logic_vector(3 downto 0);----
              cs1,cs0,cm1,cm0,ch1,ch0 : out std_logic_vector(3 downto 0);
              cspeaker :out std_logic);
end CLOCK;


architecture behav of CLOCK is
      component SECOND
             port(clk,clr,secset:in std_logic;----时钟/清零信号
                sechdata:in std_logic_vector(3 downto 0);----加载分钟的高位
                secldata:in std_logic_vector(3 downto 0);----加载分钟的低位
                sec1,sec0:out std_logic_vector(3 downto 0);----秒高位/低位
                co:out std_logic);-------输出/进位信号
      end component;
            
      component MINUTE
             port(clk,clr,minset:in std_logic;----时钟/清零信号
                minhdata:in std_logic_vector(3 downto 0);----加载分钟的高位
                minldata:in std_logic_vector(3 downto 0);----加载分钟的低位
                min1,min0:out std_logic_vector(3 downto 0);----minute高位/低位
                co:out std_logic);-------输出/进位信号
      end component;


      component HOUR
             port(clr,clk,hset : in std_logic;
                  hhdata:in std_logic_vector(3 downto 0);----
                  hldata:in std_logic_vector(3 downto 0);----
                  h1,h0 : out std_logic_vector(3 downto 0));
      end component;

      component SPEAKER
             port(frq,spin : in std_logic;
                  spsignal : out std_logic);
      end component;

 
               signal seccarry,mincarry:std_logic;
          begin
               u1: SECOND port map(clk=>cclk,clr=>crest,secset=>csecset,sechdata=>chdata,secldata=>cldata,sec1=>cs1,sec0=>cs0,co=>seccarry);
               u2: MINUTE port map(clk=>seccarry,clr=>crest,minset=>cminset,minhdata=>chdata,minldata=>cldata,min1=>cm1,min0=>cm0,co=>mincarry);
               u3: HOUR   port map(clk=>mincarry,clr=>crest,hset=>chset,hhdata=>chdata,hldata=>cldata,h1=>ch1,h0=>ch0);
               u4: SPEAKER port map(frq=>cspeakfrq,spin=>mincarry,spsignal=>cspeaker);
end behav;

 

    

 

1.建立工作文件夹G:/2009230123/exp3/clock和编辑设计文件.

2.创建工程,并选择目标芯片。

3.创建VHDL文件,输入前面所示代码。

4.编译成功后,进行时序仿真。打开波形编辑器File--New--Vector Waveform File;设置仿真时间区域Edit--End Time将整个仿真域的时间设定为50us;波形文件存盘;将工程addr8的端口信号节点选入波形编辑器中;编辑输入波形,设置端口信号;启动仿真器并观察仿真结果。

5.引脚锁定。Assignments--Assignment Editor命令进入编辑窗口,将信号加进后开始引脚锁定(选择合适的硬件模式)。

6.完成引脚锁定后再次全程编译。

7.编译文件下载。将编译产生的SOF格式配置文件配置进FPGA中,进行硬件测试。

五、实验结果:

实验三的路径创建:http://s10/middle/64fc6b14gc1af60b49379&690EDA时钟的设计" TITLE="实验三 EDA时钟的设计" />

clock的顶层文件:

http://s16/middle/64fc6b14gc1af645a13bf&690EDA时钟的设计" TITLE="实验三 EDA时钟的设计" />

clock编译成功:

http://s4/middle/64fc6b14g79c4bd8975d3&690EDA时钟的设计" TITLE="实验三 EDA时钟的设计" />

clock仿真成功:

http://s11/middle/64fc6b14gc1af6a3cfe5a&690EDA时钟的设计" TITLE="实验三 EDA时钟的设计" />

clock引脚绑定:

http://s6/middle/64fc6b14g79c4be12c935&690EDA时钟的设计" TITLE="实验三 EDA时钟的设计" />

clock下载成功:

http://s12/middle/64fc6b14gc1af6ece631b&690EDA时钟的设计" TITLE="实验三 EDA时钟的设计" />

六:本次实验心得:

 

(1):要有良好的层次化设计的思想,合理的组织工程的层次框架。

(2):根据实际的硬件电路情况,合理的设计程序,及组织硬件电路。

(3):实验前要对这次的实验有一个整体的了解和构思.

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有