前言
小編最近在學(xué)習(xí)時(shí)序電路的VHDL設(shè)計(jì),通過此文對(duì)觸發(fā)器和VHDL相關(guān)知識(shí)進(jìn)行總結(jié),以便日后進(jìn)行復(fù)習(xí)、查閱。本文首先回顧了各類觸發(fā)器的基本知識(shí)包括特性方程、狀態(tài)圖等,最后通過VHDL來實(shí)現(xiàn)各類觸發(fā)器。
一、觸發(fā)器知識(shí)回顧
在實(shí)際的數(shù)字系統(tǒng)中往往包含大量的存儲(chǔ)單元,而且經(jīng)常要求他們?cè)谕粫r(shí)刻同步動(dòng)作,為達(dá)到這個(gè)目的,在每個(gè)存儲(chǔ)單元電路上引入一個(gè)時(shí)鐘脈沖(CLK)作為控制信號(hào),只有當(dāng)CLK到來時(shí)電路才被“觸發(fā)”而動(dòng)作,并根據(jù)輸入信號(hào)改變輸出狀態(tài)。把這種在時(shí)鐘信號(hào)觸發(fā)時(shí)才能動(dòng)作的存儲(chǔ)單元電路稱為觸發(fā)器,常見的觸發(fā)器有D觸發(fā)器、RS觸發(fā)器、JK觸發(fā)器、T觸發(fā)器,它們是構(gòu)成時(shí)序邏輯電路的基本單元。
名稱 | 特性方程 | 邏輯符號(hào) | 狀態(tài)圖 |
D觸發(fā)器 | ![]() |
![]() |
|
RS觸發(fā)器(或非門實(shí)現(xiàn)) | (約束條件) |
![]() |
![]() |
JK觸發(fā)器 | ![]() |
![]() |
|
T觸發(fā)器 | ![]() |
![]() |
D觸發(fā)器真值表:
D | ||
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 1 |
1 | 1 | 1 |
RS觸發(fā)器真值表:
S | R | ||
0 | 0 | 0 | 0 |
0 | 0 | 1 | 1 |
0 | 1 | 0 | 0 |
0 | 1 | 1 | 0 |
1 | 0 | 0 | 1 |
1 | 0 | 1 | 1 |
1 | 1 | 0 | 不確定 |
1 | 1 | 1 | 不確定 |
RS觸發(fā)器真值表:
J | K | ||
0 | 0 | 0 | 0 |
0 | 0 | 1 | 1 |
0 | 1 | 0 | 0 |
0 | 1 | 1 | 0 |
1 | 0 | 0 | 1 |
1 | 0 | 1 | 1 |
1 | 1 | 0 | 1 |
1 | 1 | 1 | 0 |
T觸發(fā)器真值表:
Y | ||
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
二、VHDL實(shí)現(xiàn)
在VHDL中完整的條件語句只能構(gòu)成組合邏輯電路,例如下面的二選一數(shù)據(jù)選擇器。
entity select1of2 is
port (a, b, s : in bit;
y : out bit);
end entity select1of2;
architecture bhv of select1of2 is
begin
process(a,b,s)
begin
if(s='1') then y<=a; else y<=b;
end if;
end process;
end architecture bhv;
可以觀察到二選一數(shù)據(jù)選擇器的RTL電路沒有觸發(fā)器或者鎖存器,即沒有存儲(chǔ)功能。
在VHDL實(shí)現(xiàn)時(shí)序電路的核心思想就是通過不完整條件語句。為了實(shí)現(xiàn)記憶、存儲(chǔ)功能,對(duì)于不滿足條件的的語句,VHDL綜合器解釋為不予執(zhí)行,即信號(hào)保持前一次的值,不發(fā)生改變。對(duì)于數(shù)字電路來說,當(dāng)輸入改變后仍能保持原值不變,就意味著使用了具有存儲(chǔ)功能的元件,其中輸出不僅僅取決于輸入,還取決于所處的狀態(tài)。
D觸發(fā)器代碼實(shí)現(xiàn)
library ieee;
use ieee.std_logic_1164.all;
entity dff2 is
port(CLK, RST, EN, D : in std_logic;
Q : out std_logic);
end entity dff2;
architecture bhv of dff2 is
signal Q1 : std_logic;
begin
process(CLK, Q1, RST, EN)
begin
if RST = '1' then Q1 <= '0';
elsif CLK'EVENT and CLK = '1' then
if EN = '1' then Q1 <= D;
end if;
end if;
end process;
Q <= Q1;
end architecture bhv;
? ? ??
D觸發(fā)器仿真波形
RS觸發(fā)器代碼實(shí)現(xiàn)
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity SR is
port(S, R, CLK : in std_logic;
Q : buffer std_logic);
end entity SR;
architecture bhv of SR is
signal Q_TEMP : std_logic;
begin
process(CLK)
begin
if CLK'EVENT and CLK = '1' then --或非門構(gòu)成的SR觸發(fā)器
if S = '0' and R = '1' then
Q_TEMP <= '0';
elsif S = '1' and R = '0' then
Q_TEMP <= '1';
end if;
end if;
Q <= Q_TEMP;
end process;
end architecture bhv;
RS觸發(fā)器仿真波形
JK觸發(fā)器代碼實(shí)現(xiàn)
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity JK is
port(CLK,J, K : in std_logic;
Q, NQ : out std_logic);
end entity JK;
architecture bhv of JK is
signal Q_TEMP : std_logic;
signal NQ_TEMP: std_logic;
begin
process(CLK, J, K)
begin
if CLK'EVENT and CLK = '1' then
if (J = '0') and (K = '1') then
Q_TEMP <= '0';
NQ_TEMP <= '1';
elsif (J = '1') and (K ='0') then
Q_TEMP <= '1';
NQ_TEMP <= '0';
elsif (J = '1') and (K = '1') then
Q_TEMP <= not Q_TEMP;
NQ_TEMP <= not NQ_TEMP;
end if;
end if;
Q <= Q_TEMP;
NQ <= NQ_TEMP;
end process;
end architecture bhv;
JK觸發(fā)器仿真波形
T觸發(fā)器代碼實(shí)現(xiàn)
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity t_ff is
port(CLK, T : in std_logic;
Q: buffer std_logic);
end entity t_ff;
architecture bhv of t_ff is
signal Q_TEMP : std_logic;
begin
process(CLK)
begin
if CLK'EVENT and CLK = '1' then
if T = '1' then
Q_TEMP <= not Q_TEMP;
else
Q_TEMP <= Q_TEMP;
end if;
end if;
Q <= Q_TEMP;
end process;
end architecture bhv;
T觸發(fā)器仿真波形
文章來源:http://www.zghlxwxcb.cn/news/detail-766573.html
總結(jié)
以上就是本文的全部?jī)?nèi)容,非常感謝你能看到這里(仿真波形有一定的延遲)。文章來源地址http://www.zghlxwxcb.cn/news/detail-766573.html
到了這里,關(guān)于FPGA開發(fā)——VHDL實(shí)現(xiàn)各類觸發(fā)器的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!