?? hdb3.vhd
字號:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity hdb3 is
port(reset,clk,codein: in std_logic;
codeout: out std_logic_vector(1 downto 0));
end hdb3;
architecture behave of hdb3 is
component hdb3_v is --------------調用hdb3_v函數
port(reset,clk,codein: in std_logic;
codeout: out std_logic_vector(1 downto 0));
end component;
component hdb3_b is --------------調用hdb3_b函數
port(reset,clk: in std_logic;
codein: in std_logic_vector(1 downto 0);
codeout: out std_logic_vector(1 downto 0));
end component;
component hdb3_0 is --------------調用hdb3_0函數
port(reset,clk: in std_logic;
codein: in std_logic_vector(1 downto 0);
codeout: out std_logic_vector(1 downto 0));
end component;
signal d1,d2:std_logic_vector(1 downto 0);
begin
A: hdb3_v port map(reset,clk,codein,d1);
B: hdb3_b port map(reset,clk,d1,d2);
C: hdb3_0 port map(reset,clk,d2,codeout);
end behave;
-------------------插V實現----------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity hdb3_v is
port(reset,clk,codein: in std_logic;
codeout: out std_logic_vector(1 downto 0));
end hdb3_v;
architecture behave of hdb3_v is
signal count_0:integer range 0 to 3;
begin
process(reset,clk,codein) is
begin
if (reset='1') then
count_0<=0;codeout<="00"; ---------低電平有效
elsif(clk'event and clk='1') then
if (codein='0') then
count_0<=count_0+1; ---------count_0是0計數器
if (count_0=3) then ---------連4個0了
codeout<="11";
count_0<=0;
else
codeout<="00"; ---------沒連4個0
end if;
else
codeout<="01"; ----------------輸出1 碼
count_0<=0; -------------------計數器置0
end if;
end if;
end process;
end behave;
------------------插B實現----------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity hdb3_b is
port(reset,clk: in std_logic;
codein: in std_logic_vector(1 downto 0);
codeout: out std_logic_vector(1 downto 0));
end hdb3_b;
architecture behave of hdb3_b is
signal D1,D0 : std_logic_vector(3 downto 0);
signal count_1: integer range 0 to 1;
begin
process(clk,codein)is
begin
if(clk'event and clk='1')then
D1(3)<=codein(1);
D0(3)<=codein(0);
D1(2 downto 0)<=D1(3 downto 1);
D0(2 downto 0)<=D0(3 downto 1);
end if;
end process;
process(reset,clk,D1,D0) is
begin
if (reset='1') then
count_1<=0; ------------count_1是1計數器
elsif(clk'event and clk='1')then
if(D1(0)='0' and D0(0)='1')then ------------輸入為1時
count_1<=count_1+1;
elsif(D1(0)='1' and D0(0)='1')then ------------輸入為V時
count_1<=0;
end if;
end if;
end process;
process(reset,clk) is
begin
if (reset='1') then
codeout<="00";
elsif(clk'event and clk='1') then
if(count_1=0 and D1(3)='1' and D0(3)='1') then
codeout<="10"; -----------輸出為B
else
codeout<=D1(0)&D0(0);
end if;
end if;
end process;
end behave;
------------------極性轉換實現----------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity hdb3_0 is
port(reset,clk: in std_logic;
codein: in std_logic_vector(1 downto 0);
codeout: out std_logic_vector(1 downto 0));
end hdb3_0;
architecture behave of hdb3_0 is
signal even:integer range 0 to 1;
begin
process(reset,clk,codein)is
begin
if (reset='1') then
even<=0;
codeout<="00";
elsif(clk'event and clk='1')then
if (codein="11" and even=1)then ------輸入為V,并且前一個非0符號為“-”
codeout<="11"; even<=1;
elsif(codein="11" and even=0) then ------輸入為V,并且前一個非0符號為“+”
codeout<="01"; even<=0;
elsif(codein="01" and even=1) then ------輸入為1,并且前一個非0符號為“-”
codeout<="01";even<=0;
elsif(codein="01" and even=0) then ------輸入為1,并且前一個非0符號為“+”
codeout<="11";even<=1;
elsif(codein="10" and even=1) then ------輸入為B,并且前一個非0符號為“-”
codeout<="01";even<=0;
elsif(codein="10" and even=0) then ------輸入為B,并且前一個非0符號為“+”
codeout<="11";even<=1;
else
codeout<="00";
end if;
end if;
end process;
end behave;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -