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

📄 deco_t.vhd

📁 cpld实现的并行数据串行传输收发模块(类曼切斯特码)。最大2M并行码率。
💻 VHD
字号:
Library IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_unsigned.all;

ENTITY deco_t IS
	PORT(clr:in std_logic;
	en  :in	 std_logic;
	clk4x :in  std_logic;
	d	:in  std_logic;
	q	:buffer std_logic;
	fail:out std_logic;
	ready:out std_logic;   --数据准备好
	deco_o:out std_logic;
	jo_o  :out std_logic;
	den_o :out std_logic;
	count_k:out std_logic;
	clk1_o :out std_logic;
	clk2_o :out std_logic;
	count17o:out std_logic_vector(4 downto 0)
	);
END deco_t;

ARCHITECTURE deco_t of deco_t is
SIGNAL clk1,clk2,den,deco,jo,jo_count:std_logic;
signal clk_key:std_logic;
SIGNAL chk_r  :std_logic_vector(3 downto 0);
signal count_t:std_logic_vector(2 downto 0);
SIGNAL count_m17:std_logic_vector(4 downto 0);
begin

-----------------时钟跟随-----------------

process(clk4x,d)
begin

if(clk4x'event and clk4x='1')then
	if( d='1')then --时钟未打开,检测到高电平
		clk_key<='1';
		--count_t<="0100";
	elsif(count_m17 ="10010")then
		clk_key<='0';
	else
		clk_key<=clk_key;
	end if;
end if;

end process;

------------------分频器-------------------
process(clk4x,clr)
begin
	if(clk4x'event and clk4x='1')then
		if(count_t="111" or clr='1' or clk_key ='0')then
			count_t<="000";
		elsif(clk_key ='1')then
			count_t<=count_t+'1';
		end if;
	end if;
end process;

clk1<=clk_key and not(count_t(1));
clk2<=clk_key and not(count_t(2));
count_k<=clk_key;
clk1_o<=clk1;
clk2_o<=clk2;

------------------M18(0-17)---------------------
process(clk2,den,clr)      ---2(0)同步码+16(1-16)数据+1(17)奇偶+(1空闲)
begin
	if(clr='1') then
		count_m17<="00000";
	elsif(clk2'event and clk2='1')then
		if(count_m17="10010" )then
			count_m17<="00000";
		elsif(den='1')then
			count_m17<=count_m17+'1';
		end if;
	end if;
end process;

count17o<=count_m17;

-----------------同步码检测器--------------
process(clk4x,clk1,clk2,en,clr,d,count_m17)
begin
	if(clr='1' )then
		chk_r<="0000";
	elsif(clk1'event and clk1='1')then
		if(en='1')then
			chk_r<=chk_r(2 downto 0)&d;
		end if;
	end if;
	
	
	
	if(clk4x'event and clk4x='1')then   --及时变换用clk4x
		if(count_m17="10010")then
			den<='0';
		elsif(chk_r="1110")then    --同步成功
			den<='1';
		else
			den<=den;
		end if;
	end if;
end process;

den_o<=den;

----------------解码、奇偶校验-------------
process(clk1,clk2,den,d)
begin
	if(den='1')then
		deco<=not(clk2 xor d);	--解码
	else
		deco<='0';
	end if;
	
	if(count_m17="10010")then
		jo<='0';
	elsif(clk1'event and clk1='0')then --下降沿  !!
		if(clk2='1')then
			if(count_m17>="00001" and count_m17<="10000" and den='1')then --奇偶校验
				jo<=jo xor deco;
			end if;
		end if;
	end if;
	
	if(clk1'event and clk1='0')then  --下降沿  毛刺!!
		if(count_m17>="00001" and count_m17<="10000" and den='1')then --选择输出,消毛刺 count_m17<="01111"??
			q<=deco;   --因为正好采在毛刺上,取反正好 ???
			ready<=den;
		else
			q<='0';
			ready<='0';
		end if;
    end if;
	
										 --奇偶校验输出
		if(count_m17 ="10001")then
			fail<= jo xor deco;
			--jo<='0';
		else
			fail<= '0';
		end if;

		

end process;



deco_o<=deco;
jo_o  <=jo;

end deco_t;

⌨️ 快捷键说明

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