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

📄 复件 code.vhd

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

ENTITY code IS
	PORT(en:in std_logic;
	d  :in std_logic;
	clk:in std_logic;
	clr:in std_logic;
	q  :out std_logic;
	clk1x:out std_logic;
	clk2x:out std_logic;
	mo_o :out std_logic
	);
END code;

ARCHITECTURE code OF code IS
SIGNAL clk_count   :std_logic;
SIGNAL clk1,clk2,jo,mo:std_logic;
SIGNAL count_m40   :std_logic_vector(5 downto 0);
SIGNAL shift_r     :std_logic_vector(2 downto 0);

begin
----------------分频器--------------------------
process(clk)
begin
	if(clk'event and clk='1')then
		if(clr='1') then
			clk2<='0';
		elsif(en ='1')then
			clk2<=not(clk2);
		end if;
	end if;
end process;

clk1<=NOT(Not(clk));
clk1x<=clk1;
clk2x<=clk2;


---------------M40计数器----------------------

process(clk1,en,clr)
begin
	if(clr='1')then
		count_m40<=(others=>'0');
	elsif(clk1'event and clk1='1')then
		if(count_m40="100111")then       --0-39 40次
			count_m40<=(others=>'0');
		elsif(en='1')then
			count_m40<=count_m40+'1';
		end if;
	end if;
end process;

------------------三位移位寄存器---------------

process(clk2,en,clr)
begin
	if(clr='1')then
		shift_r<=(others=>'0');
	elsif(clk2'event and clk2='1')then
		if(en='1')then
			shift_r<=shift_r(1 downto 0)&d;
		end if;
	end if;
end process;

-----------------奇偶校验器-----------------------

process(clk2,en,clr,count_m40)
begin
	if(clr='1')then
		jo<='0';
	elsif(clk2'event and clk2='1')then
		if(en='1')then
			if(count_m40>="000000" and count_m40<="000100")then  --0-4
				jo<='0';	--清零
			elsif(count_m40>="000101" and count_m40<="100100")then --5-36
				jo<=jo xor shift_r(2);
			end if;
		end if;
	end if;
end process;

--------------------编码器-------------------------

process(clk1,clk2,en,clr,count_m40,jo,shift_r)
begin
	if(clr='1')then
		mo<='0';
	elsif(count_m40>="000001" and count_m40<="000010")then  --1-2
		mo<='1';
	elsif(count_m40>="000011" and count_m40<="000100")then --3-4
		mo<='0';
	elsif(count_m40>="000101" and count_m40<="100100")then --5-36
		mo<=NOT(shift_r(2) xor clk2);
	elsif(count_m40>="100101" and count_m40<="100110" )then --37-38
		mo<=NOT(jo xor clk2);
	else
		mo<='0';
	end if;
	mo_o<=mo;
	
	if(clr='1')then    --D触发器消除毛刺
	elsif(clk1'event and clk1='1')then
		if(en='1')then
			q<=mo;
		end if;
	end if;
end process;

END ARCHITECTURE;

⌨️ 快捷键说明

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