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

📄 cpld

📁 《CPLD开发实例》的配套光盘文件
💻
字号:
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;
ENTITY videocpt IS
PORT
(
	cdao : out std_logic_vector(7 downto 0); -- 验证视频数据输出口
	cps : out std_logic; 	-- 视频数据输出像素 Pixel SYN Signal
	cfs : out std_logic; 	-- 视频数据输出帧
	caclk: out std_logic;
	cclk : in std_logic; 	--主时钟 24M
	cdi : in std_logic_vector(7 downto 0); 	--视频数据输入口
	pclk : in std_logic; 	-- 采集时钟 4M
	ccs : in std_logic; 	-- 视频信号选择
	avf : in std_logic; 	--有效场同步帧
	avh : in std_logic;		--有效行同步帧
	vd : in std_logic 		--场同步信号
);
END videocpt;
ARCHITECTURE a OF videocpt IS
	constant StartWidPix : integer range 0 to 1023 := 0; --起始宽度像素常量
	constant StartHiPix : integer range 0 to 288 := 0; 	 --起始高度像素常量
	constant EndWidPix : integer range 0 to 1023 := 704; --末端宽度像素常量
	constant EndHiPix : integer range 0 to 288 := 287; 	 --末端高度像素常量
	signal pclk1 : std_logic := '0';
	signal demodata : std_logic_vector(7 downto 0) := "01111001";
	signal readline : std_logic := '0';
	signal read : std_logic := '0';
	signal done : std_logic := '0';
BEGIN
	process (cclk)
		variable ccount : integer range 0 to 3 :=0;
	begin
	  if cclk='1' and cclk'event then
		if ccount < 3 then
			ccount := ccount+1; caclk <= '1';
		else
			ccount := 0; caclk <= '0';
		end if;
	  end if;
	end process;
	process (cclk, ccs )
		variable HPCnt : integer range 0 to 288 := 0;
		variable WPCnt : integer range 0 to 1023 := 0;
		variable avh1 : std_logic; 		-- avh延迟1个周期
		variable vd1 : std_logic; 		-- vd延迟1个周期
		variable frame : boolean; 		-- 搜索起始帧
	begin
		if ccs = '1' then
			read <='0';
			frame := FALSE;
			HPCnt:=0;
			WPCnt:=0;
			done <='0';
		elsif cclk='1' and cclk'event then
			pclk1<=pclk;
			if vd1='1' and vd='0' and done='0' then
				done<='1';
				frame :=TRUE;
				HPCnt:=0;
				WPCnt:=0;
			end if;
			if frame and avh1='0' and avh='1' then
				if HPCnt < 288 then
					HPCnt:=HPCnt+1;
				end if;
				WPCnt:=0;
			end if;
			if frame and avh='1' and avf='1' then
				readline<='1';
			else
				readline<='0';
			end if;
			if(readline='1' and pclk='0'and pclk1='1')then
				WPCnt:=WPCnt+1;
			end if;
--此处如果用if frame and HPCnt>3-HiPix and HPCnt<=HiPix and avh='1' and avf = '1' then 就会出现毛刺
			if frame and HPCnt>StartHiPix and HPCnt<=EndHiPix and WPCnt>=StartWidPix and WPCnt<EndWidPix then
				if avh='1' and avf = '1' then
					read <='1';
					demodata<=cdi;
				else
					read<='0';
				end if;
			else
				read <='0';
			end if;
			vd1:=vd;
			avh1:=avh;
		end if;
	end process;
	cdao <= demodata WHEN read = '1' ELSE (OTHERS=>'1') ;
	cps <= not pclk1 WHEN read = '1' ELSE '1' ;
	cfs <= '1';
END a;

⌨️ 快捷键说明

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