電子課程設計是電子技術學習中非常重要的壹個環節,是將理論知識和實踐能力相統壹的壹個環節,是真正鍛煉學生能力的壹個環節。
在許多領域中計時器均得到普遍應用,諸如在體育比賽,定時報警器、遊戲中的倒時器,交通信號燈、紅綠燈、行人燈、交通纖毫控制機、還可以用來做為各種藥丸,藥片,膠囊在指定時間提醒用藥等等,由此可見計時器在現代社會是何其重要的。
壹、設計任務(數字鐘的功能):
1.具有時、分、秒、計數顯示功能,以24小時循環計時;
2.具有清零,調節小時、分鐘功能;
3.具有整點報時功能,整點報時的同時LED燈花樣顯示。
擴展部分:在基礎功能上添加以下幾個功能:秒表,倒計時和鬧鐘。
目的是:掌握多位計數器相連的設計方法;掌握十進制,六進制,二十四進制計數器的設計方法;繼續鞏固多位***用級掃描顯示數碼管的驅動及編碼;掌握揚聲器的驅動;LED燈的花樣顯示;掌握EPLD技術的層次化設計方法。
而且需要以下硬件條件:
1,主芯片 EPF10K10LC84-4;
2 ,8個 LED燈;
3,揚聲器;
4,8位八段掃描***陰極數碼顯示管;
5,三個按鍵開關(清零,調小時,調分鐘)
二、實現方案:
把整個實驗分成如下電路模塊:
1.時鐘計數: 秒——60進制BCD碼計數:
分——60進制BCD碼計數:
時——24進制BCD碼計數:
模塊說明:
各種進制的計數及時鐘控制模塊( 10進制、 6進制、 24進制);
同時獲個計數器有清零,調分,調時功能。在接近整數時間能提供報時信號。
2.具有驅動8位八段***陰掃描數碼管的片選驅動信號輸出和八段字形譯碼輸出。
3.具有校時功能,可以分別對時及分進行單獨校時,使其校正到標準時間當重新接通電源或走時出現誤差時都需要對時間進行校正。通常,校正時間的方法是:首先截斷正常的計數通路,然後再進行人工出觸發計數或將頻率較高的方波信號加到需要校正的計數單元的輸入端,校正好後,再轉入正常計時狀態即可。
4.計時過程具有報時功能,當時間到達整點前10秒進行蜂鳴報時
5.LED燈按個人愛好在整點時有花樣顯示信號產生。
三、實現設計過程:.
秒個位計數單元為10進制計數器,無需進制轉換,我們采用的是VHDL語言編程實現的.
秒十位計數單元為6進制計數器,需要進制轉換。將10進制計數器的程序稍微修改為6進制計數器
分個位和分十位計數單元電路結構分別與秒個位和秒十位計數單元完全相同,只不過分個位計數單元的Q3作為向上的進位信號應與分十位計數單元的CPA相連,分十位計數單元的Q2作為向上的進位信號應與時個位計數單元的CPA相連。
時個位計數單元電路結構仍與秒或個位計數單元相同,但是要求,整個時計數單元應為24進制計數器,不是10的整數倍,因此需將個位和十位計數單元合並為壹個整體才能進行
24進制轉換.
1、十進制BCD碼計數器
library ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_signed.all;
ENTITY c6 IS
port(clk,clr : in std_logic;
q : out std_logic_vector(2 downto 0));
end c6;
architecture one of c6 is
signal count :std_logic_vector(2 downto 0);
begin
process(clk,clr)
begin
if clr='1' then
count<="000";
elsif clk'event and clk='1' then
if count="1001" then
count<="000";
else
count<=count+1;
end if;--for count
end if; --for clr
end process;
q<=count;
end ;
2、二十四進BCD制碼計數器:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
ENTITY count IS
port( clk,clr,count_en : in std_logic;
dout1,dout2 : out std_logic_vector(3 downto 0);
car:out std_logic);=count2+'1';
end if;
if count2="0010"and count1="0011" then
count2<="0000";car<='1';
else car<='0';
end if;
end if;
end if;
end process;
dout1<=count1;dout2<=count2 ;
end;
3、六十進制計數器:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_UNSIGNED.all;
entity c60 is
port(clk,clr,count_en:in std_logic;
dout1,dout2:out std_logic_vector(3 downto 0);
car:out std_logic);
end c60;
count1<="0000";count2<="0000";
elsif clk'event and clk='1' then
if count_en='0' then
count1<=count1+'1';
if count1 ="1001" then
count1<="0000";count2<=count2+1;
end if ;
if count2 ="0101" and count1 ="1001" then
count2<="0000";car<='1';
else car<='0';
end if ;
end if ;
end if ;
end process;
dout1<=count1;dout2<=count2;
end ;
4、實現報時器功能的程序:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_UNSIGNED.all;
entity bijiaoqi is
port(minu1,minu2,hour1,hour2,fen0,fen1,shi0,shi1:in std_logic_vector(3 downto 0);
baoshi:out std_logic);
end ;
architecture rtl of bijiaoqi is
begin
process(minu1,minu2,hour1,hour2,fen0,fen1,shi0,shi1)
begin
if hour1=shi0 and hour2=shi1 and minu1=fen0 and minu2=fen1 then
baoshi<='1';
else baoshi<='0';
end if;
end process;
end;
6、實現定時功能的程序:
library ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
ENTITY dingshi IS
PORT (hour,SET: IN STD_LOGIC;
hour0,hour1 : out std_logic_vector(3 downto 0));
END dingshi;
architecture rtl of dingshi is
signal n:std_logic;
signal count3,count4 :std_logic_vector(3 downto 0);
begin
process(set,hour,n)
begin
n<=hour and set;
if n' EVENT AND n='1' THEN
if count4>="0010" and count3="0011" then
count4<="0000";count3<="0000";
else count3<=count3+1;
if count3="1001" then
count4<=count4+1;
count3<="0000";
end if;
end if;
end if;
end process;
hour0<=count3;hour1<=count4;
end;