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

📄 sdh_frame_synchro.vhd

📁 帧同步检测源码
💻 VHD
字号:
--{entity {sdh_frame_synchro_capture} architecture {sdh_frame_synchro_capture}}

library IEEE;
use IEEE.STD_LOGIC_1164.all;
use ieee.std_logic_unsigned.all;


entity sdh_frame_synchro_capture is
	 port(
		 clk 				: in STD_LOGIC;
		 reset 				: in STD_LOGIC;
		 sdh_din 			: in STD_LOGIC_VECTOR(7 downto 0);
		 synchro_flag 		: out STD_LOGIC;
		 line_cnt_out 		: out STD_LOGIC_VECTOR(8 downto 0);
		 column_cnt_out 	: out STD_LOGIC_VECTOR(3 downto 0)
	     );
end sdh_frame_synchro_capture;

--}} End of automatically maintained section

architecture sdh_frame_synchro_capture of sdh_frame_synchro_capture is			   
signal frame_state 					: std_logic_vector(2 downto 0);
signal line_cnt 					: std_logic_vector(8 downto 0);
signal column_cnt 					: std_logic_vector(3 downto 0);	 
signal syn_state					: std_logic_vector(1 downto 0);
signal catch_cnt,uncatch_cnt		: std_logic_vector(1 downto 0);
signal lose_cnt 					: std_logic_vector(2 downto 0);
begin	  
	synchro_flag <= '1' when syn_state="10" else '0';
	line_cnt_out <= line_cnt;
	column_cnt_out <= column_cnt;
		
  	process(reset,clk)
	begin
		if reset='0' then
			frame_state <= (others => '0');
			line_cnt <= (others => '0');	
			column_cnt <= (others => '0');	
			syn_state <= "00";
		elsif clk'event and clk='1' then	  
			case syn_state is
				when "00" =>
					case frame_state is
						when "000" => 
							if sdh_din="11110110" then
								frame_state	<= "001";
							end if;
						when "001" => 
							if sdh_din="11110110" then
								frame_state <= "010" ;
							else
								frame_state <= "000";
							end if;
						when "010" => 
							if sdh_din="11110110" then
								frame_state <= "011" ;
							else
								frame_state <= "000";
							end if;
						when "011" => 
							if sdh_din="00101000" then
								frame_state <= "100" ;
							else
								frame_state <= "000";
							end if;
						when "100" => 
							if sdh_din="00101000" then
								frame_state <= "101" ;
							else
								frame_state <= "000";
							end if;
						when "101" => 
							if sdh_din="00101000" then	  
								line_cnt <= "000000110";	
								column_cnt <= (others => '0');	 
								frame_state <= "110";
							else
								frame_state <= "000";
							end if;					 
						when "110" => 		 
							if column_cnt="1000" then
								if line_cnt="100001101" then 
									frame_state <= "000" ; 
									syn_state <= "01"; 
									column_cnt <= (others => '0');
									line_cnt <= (others => '0');	 
									catch_cnt <= (others => '0');
								else
									line_cnt <= line_cnt + "000000001";	   
								end if;	  
							else
								if line_cnt="100001101" then 
									line_cnt <= "000000000" ;	 
									column_cnt <= column_cnt + "0001"; 
								else
									line_cnt <= line_cnt + "000000001";
								end if;	   	   
							end if;
						when others => null;	
					end case;
				
				when "01" =>  
					if column_cnt = "0000" then
						if line_cnt <= "000000010" then
							if sdh_din = "11110110" then
								line_cnt <= line_cnt + "000000001";
							else
								syn_state <= "00";
							end if;
						elsif line_cnt <= "000000101" then
							if sdh_din = "00101000" then
								line_cnt <= line_cnt + "000000001";
							else
								syn_state <= "00";
							end if;	  
						elsif line_cnt = "100001101" then
							column_cnt <= column_cnt +"0001";
							line_cnt <= (others => '0');  
							catch_cnt <= catch_cnt +"01";
						else
							line_cnt <= line_cnt +"000000001";
						end if;
					elsif column_cnt="1000" then
						if line_cnt="100001101" then 
							if catch_cnt = "11" then
								syn_state <= "10"; 
								uncatch_cnt <= "00"; 
								lose_cnt <= "000";
							end if;
							column_cnt <= (others => '0');
							line_cnt <= (others => '0');
						else
							line_cnt <= line_cnt + "000000001";	   
						end if;	  
					else  
						if line_cnt="100001101" then 
							line_cnt <= "000000000" ;	 
							column_cnt <= column_cnt + "0001"; 
						else
							line_cnt <= line_cnt + "000000001";
						end if;	   	   
					end if;	 
					
				when "10" =>
					if column_cnt = "0000" then
						if line_cnt <= "000000010" then	  
							line_cnt <= line_cnt + "000000001";
							if sdh_din /= "11110110" then
								lose_cnt <= lose_cnt + "001";
							end if;
						elsif line_cnt <= "000000101" then
							line_cnt <= line_cnt + "000000001";
							if sdh_din /= "00101000" then
								lose_cnt <= lose_cnt + "001";
							end if;	  
						elsif line_cnt = "100001101" then	
							lose_cnt <= "000";
							column_cnt <= column_cnt +"0001";
							line_cnt <= (others => '0');  	
							if lose_cnt /= "000" then
								uncatch_cnt <= uncatch_cnt + "01";	
							else
								uncatch_cnt <= "00";
							end if;
						else
							line_cnt <= line_cnt + "000000001";
						end if;
					elsif column_cnt="1000" then
						if line_cnt="100001101" then 
							if uncatch_cnt = "11" then
								syn_state <= "00"; 		
							end if;
							column_cnt <= (others => '0');
							line_cnt <= (others => '0');
						else
							line_cnt <= line_cnt + "000000001";	   
						end if;	  
					else  
						if line_cnt="100001101" then 
							line_cnt <= "000000000" ;	 
							column_cnt <= column_cnt + "0001"; 
						else
							line_cnt <= line_cnt + "000000001";
						end if;	   	   
					end if;	 
				when others => null;
			end case;
		end if;	 		
	end process;
	 -- enter your statements here --

end sdh_frame_synchro_capture;

⌨️ 快捷键说明

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