⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vhdl-ysw.txt

📁 基于CPLD的棋类比赛计时时钟,第一个CNT60实现秒钟计时功能
💻 TXT
字号:
第一个CNT60实现秒钟计时功能,第二个CNT60实现分钟的计时功能,CTT3完成两小时的计时功能。秒钟计时模块的进位端和开关K1相与提供分钟的计时模块使能,当秒种计时模块计时到59时向分种计时模块进位,同时自己清零。同理分种计时模块到59时向CTT3小时计时模块进位,到1小时59分59秒时,全部清零。同时,开关K1可以在两小时内暂停秒钟计时模块,分钟计时模块和小时计时模块。各模块的VHDL语言描述如下:

(1).六十进制计数器
我们采用VHDL语言编写,该计数器具有使能,异位复位的功能的8位加法计数器,其语言描述如下:

六十进制记数
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cnt60 is
port(clk:in std_logic;
    rst:in std_logic;
     ena:in std_logic;
     qn:in std_logic_vector(7 downto 0);
     out0:out std_logic_vector(3 downto 0);
     out1:out std_logic_vector(3 downto 0);
     cout:out std_logic);
end cnt60;                            
architecture behav of cnt60 is
signal cqi:std_logic_vector(7 downto 0);
begin
     cout<='1' when (cqi=X"59"and ena='1') else'0';   
process(clk,rst,ena)
 begin
if(rst='0')then                         
cqi<=X"00";
elsif clk'event and clk='1' then 
  if(ena='0')then                              
   cqi<=qn;
   elsif (ena='1') then 
   if  cqi(3 downto 0)=9  then
       cqi(3 downto 0)<="0000";
   if  cqi(7 downto 4)=5  then
       cqi(7 downto 4)<="0000";
else
    cqi(7 downto 4)<=cqi(7 downto 4)+1;        
    end if;
       else
    cqi(3 downto 0)<=cqi(3 downto 0)+1;
 end if;
   end if;
end if;
end process ;
out0<=cqi(3 downto 0);
out1<=cqi(7 downto 4);
end behav;

其管脚定义为:
CLK:       时钟;
RST:       复位;
RNA:       使能;
QN[7..0]:  预置数控制;
OUT0[3..0]:个位数据输出;
OUT1[3..0]:十位数据输出;
COUT:      进位输出。

其仿真波形如下:
 

(2).三进制计数器:
同理,我们也用VHDL语言实现,该计数器具有使能,异位复位的功能的4位加法计数器,其语言描述如下:

三进制计数
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all; 
entity ctt3 is
  port(cp,rd,ld,en:in std_logic;
                co:out std_logic;
                 q:out std_logic_vector(3 downto 0));
end ctt3;                             
architecture god of ctt3 is
signal qn:std_logic_vector(3 downto 0);
begin
co<='1' when (qn=X"1"and en='1') else'0';
process(cp,rd)
 begin
if(rd='0')then
qn<=X"0";
elsif (cp'event and cp='1') then 
  if(ld='0')then
   qn<=X"0";
   elsif (en='1') then 
   if  qn(3 downto 0)=1 then
       qn(3 downto 0)<="0000";
   else
   qn(3 downto 0)<=qn(3 downto 0)+1;
       end if;
   end if;
end if;
end process;
q(3 downto 0)<=qn(3 downto 0);
end god;

其管脚定义为:
CLK:       时钟;
RST:       复位;
RNA:       使能;
LD:        预置数控制;
CO:        进位输出;
Q[3..0]:   数据输出。

其仿真波形如下:
 
2. 倒记时模块
该模块主要由三十进制减计数器和分组模块组成,三十进制减计数器的使能信号由时钟模块的进位和开关K1提供。当两小时计时结束后,启动倒计时模块,K1开关可以控制在三十秒内停止计时,否则向借位端借位(即启动报警模块)。分组模块是为了控制显示甲方或乙方的倒计时时钟。

(1).三十进制减计数器的VHDL语言如下,该计数器具有使能,异位复位的功能的8位减法计数器:

倒记时30倒数
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cnt30 is
    port(cp,ld,rd,en:in std_logic;
                  co:out std_logic;
                  q1:out std_logic_vector(3 downto 0);
q2:out std_logic_vector(3 downto 0));
end cnt30;                                 
architecture mine of cnt30 is
signal qn:std_logic_vector(7 downto 0);
begin 
co<='1' when (qn=X"00"and en='1') else '0';    
process(cp,rd)
 begin
if(rd='0')then
qn<=X"00";
elsif (cp'event and cp='1') then
if(ld='0')then
qn<=X"29";                             
  elsif (en='1') then 
   if  qn(3 downto 0)=0  then
       qn(3 downto 0)<="1001";
   if  qn(7 downto 4)=0  then
       qn(7 downto 4)<="0010";
   else
    qn(7 downto 4)<=qn(7 downto 4)-1;       
    end if;
       else
    qn(3 downto 0)<=qn(3 downto 0)-1;
       end if;
   end if;
end if;
end process;
q1<=qn(3 downto 0);
q2<=qn(7 downto 4);
end mine;

其生成的三十进制减法计数器的电路模块如下:
 

其管脚定义为:
CP:        时钟;
RD:        复位;
EN:        使能;
LD:        预置数控制;
CO:        进位输出;
Q1[3..0]:  个位数据输出;
Q2[3..0]:  十位数据输出。

其仿真波形如下:
 

(2). 分组倒记时模块
该模块用于显示甲方或乙方的倒计时时间,其VHDL语言描述如下:

brary ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cel is
  port(        en: in std_logic;
               d0: in std_logic_vector(3 downto 0);
               d1: in std_logic_vector(3 downto 0);
                q: out std_logic_vector(3 downto 0));
end cel;
architecture bhv of cel is
begin
process(en,d0,d1)
   begin
if en='1' then 
  q<=d0;                   
  else 
 q<=d1;                    
end if;
end process;
end bhv;

3. 输出显示模块
该模块由选择输出显示模块,转换模块,选择显示管模块以及七段显示模块组成。选择输出显示模块选择显示两方的分钟的各位,十位,小时的各位还是倒计时时钟的各位,十位。转换模块用于预置选择显示管模块的输入初值。选择显示管模块分配显示管显示分钟的各位,十位,小时的各位和倒计时时钟的各位,十位。七段显示模块用于驱动显示译码器。

(1). 选择输出显示模块
其VHDL语言描述如下:
当输入的SEL信号不同时,输出显示不同的位数。
library ieee;
use ieee.std_logic_1164.all;
entity cho is
port(fen1,fen0,sec1,sec0:in std_logic_vector(3 downto 0);
     dao1,dao0,h1,h0:in std_logic_vector(3 downto 0);
      sel:in std_logic_vector(2 downto 0);
        q:out std_logic_vector(3 downto 0));
end cho;                              
architecture bbb_arc of cho is
begin
process(sel)
begin
case sel is
when "000"=>q<=ge0;       
when "001"=>q<=shi0;                
when "010"=>q<=h0;                 
when "011"=>q<=ge1;             
when "100"=>q<=shi1;           
when "101"=>q<=h1;                
when "110"=>q<=dao0;                
when "111"=>q<=dao1;              
when others=>q<="1111";
end case;
end process;
end bbb_arc;


(2).转换模块
该模块主要是针对我们实验箱上八段数码显示管是串行输出,而我们显示时间时必须采用并行输出,所以我们需要对其进行转换,当频率很高时,可以看到8个八段数码显示管动态显示时间与倒计时时间。其输出送入选择输出显示模块和选择显示管模块实现这两个模块的选择。

其VHDL描述如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sel is
port(clk:in std_logic;
     q:out std_logic_vector(2 downto 0));
end sel;
architecture sel_arc of sel is
begin
process(clk)
variable cnt:std_logic_vector(2 downto 0);     
begin
if clk'event and clk='1' then 
cnt:=cnt+1;                                  
end if;
q<=cnt;
end process;
end sel_arc;

(3). 选择显示管模块
    该模块对八段数码显示管进行分配,分别显示甲,乙时间和倒计时时间。
其VHDL语言描述如下:

library ieee;
use ieee.std_logic_1164.all;
entity xuan is
  port (sel:in std_logic_vector(2 downto 0);
        cout:out std_logic_vector(7 downto 0));
 end xuan;
architecture one of xuan is
  begin 
  process(sel)
begin  
  case sel is
  when "000"=>cout<="00000001";     
  when "001"=>cout<="00000010";
  when "010"=>cout<="00000100";
  when "011"=>cout<="00001000";
  when "100"=>cout<="00010000";
  when "101"=>cout<="00100000";
  when "110"=>cout<="01000000";
  when "111"=>cout<="10000000";
  when others=>cout<="00000000";
 end case;
 end process;
end one;

(4). 七段显示模块
   该模块用于驱动八段显示管。其VHDL语言描述如下:

library ieee;
use ieee.std_logic_1164.all;
entity dec7s is
port(d:in std_logic_vector(3 downto 0);
  led7s:out std_logic_vector(6 downto 0));
end ;
architecture one of dec7s is
begin
  process(d)
  begin
  case d is
   when"0000"=>led7s<="0111111";     
   when"0001"=>led7s<="0000110";
   when"0010"=>led7s<="1011011";
   when"0011"=>led7s<="1001111";
   when"0100"=>led7s<="1100110";
   when"0101"=>led7s<="1101101";
   when"0110"=>led7s<="1111101";
   when"0111"=>led7s<="0000111";
   when"1000"=>led7s<="1111111";
   when"1001"=>led7s<="1101111";
   when others=>null;
  end case;
 end process;
end ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -