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

📄 ad_cis.vhd

📁 line CCD sensor controller for ID card scanner
💻 VHD
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;


entity ad_cis is
	port(
		------------------------------------------------------------
		-- 矫胶袍 脚龋
		------------------------------------------------------------
		clock		: in std_logic;
		reset	: in std_logic;
		------------------------------------------------------------
		-- AD 函券扁(寇何)
		------------------------------------------------------------
		-- ADC clock
		cds_clk1	: out std_logic;
		cds_clk2	: out std_logic;
		adc_clk	: out std_logic;
		-- AD 单捞磐
		top_adc	: in std_logic_vector(7 downto 0);
		bot_adc  : in std_logic_vector(7 downto 0);
		------------------------------------------------------------
		-- LED 备悼(寇何)
		------------------------------------------------------------
		led_r	: out std_logic;
		led_g	: out std_logic;
		led_b	: out std_logic;
		------------------------------------------------------------
		-- CIS 备悼(寇何)
		------------------------------------------------------------
	   	cis_reset	: out std_logic;
		m		: out std_logic;
		rs		: out std_logic;
		------------------------------------------------------------
		-- 矫胶袍 力绢(command)
		------------------------------------------------------------
		-- ADC 备悼 胶鸥飘
		adc_reset : in std_logic;
		-- 傈价 夸没 努钒
		r_clk	: out std_logic;
		g_clk	: out std_logic;
		b_clk	: out std_logic;
		-- 拉搁 单捞磐
		top_rgb	: out std_logic_vector(7 downto 0);
		-- 关搁 单捞磐
		bot_rgb	: out std_logic_vector(7 downto 0)
		);
end ad_cis;

architecture Behavioral of ad_cis is
	type master_state is (
		idle,
		cis_m1,
		cis_m2,
		cis_m3,
		cis_m4,
		cis_m5,
		cis_m6,
		cis_m7,
		cis_m8,
		cis_m9,
		cis_m10,
		cis_m11,
		cis_m12,
		cis_m13,
		cis_m14,
		cis_m15,
		led_wait
		);
	signal current_cycle,next_cycle : master_state;
------------------------------------------------------------------------------
-- CIS 备悼 包访
signal sampling_count : std_logic_vector(2 downto 0);
signal cis_pixel_count : std_logic_vector(10 downto 0);
signal m_count : std_logic_vector(3 downto 0);
signal m_buff : std_logic;
signal m_buff_clk1 : std_logic;
signal led_select : std_logic_vector(1 downto 0);
signal temp_led_select : std_logic_vector(1 downto 0);
signal r_buf,g_buf,b_buf : std_logic;
signal temp_rgb : std_logic_vector(15 downto 0);
signal tx_count : std_logic_vector(9 downto 0);
-- 捞固瘤 历厘侩 皋葛府
signal rd_addr: std_logic_VECTOR(7 downto 0);
signal tx_addr: std_logic_VECTOR(7 downto 0);
signal addr: std_logic_VECTOR(7 downto 0);
signal din: std_logic_VECTOR(15 downto 0);
signal dout: std_logic_VECTOR(15 downto 0);
signal we1: std_logic;
signal rd_addr1: std_logic_VECTOR(7 downto 0);
signal tx_addr1: std_logic_VECTOR(7 downto 0);
signal addr1: std_logic_VECTOR(7 downto 0);
signal din1: std_logic_VECTOR(15 downto 0);
signal dout1: std_logic_VECTOR(15 downto 0);
signal we: std_logic;
signal memory_select : std_logic;
signal tx_memory_select : std_logic;
signal tx_flag : std_logic;
------------------------------------------------------------------------------
-- 捞固瘤 历厘侩 皋葛府
------------------------------------------------------------------------------
component image_memory
	port (
		addr: IN std_logic_VECTOR(7 downto 0);
		clk: IN std_logic;
		din: IN std_logic_VECTOR(15 downto 0);
		dout: OUT std_logic_VECTOR(15 downto 0);
		we: IN std_logic
		);
end component;
component image_memory1
	port (
		addr: IN std_logic_VECTOR(7 downto 0);
		clk: IN std_logic;
		din: IN std_logic_VECTOR(15 downto 0);
		dout: OUT std_logic_VECTOR(15 downto 0);
		we: IN std_logic
		);
end component;

begin
	m1 : image_memory
	port map(
		addr => addr,
		clk => clock,
		din => din,
		dout => dout,
		we => we
		);
	m2 : image_memory1
	port map(
		addr => addr1,
		clk => clock,
		din => din1,
		dout => dout1,
		we => we1
		);
	process(
			reset,
			clock,
			next_cycle
			)
	begin
		if(reset='1') then
			-- ADC 备悼 脚龋
			cds_clk1 <= '0';
			cds_clk2 <= '0';
			adc_clk  <= '0';
			-- 傈价 夸没 努钒 滚欺
			r_buf <= '0';
			g_buf <= '0';
			b_buf <= '0';
			-- 扁鸥 脚龋
			next_cycle <= idle;
			tx_count <= (others => '0');
			temp_led_select <= "10";
			memory_select <= '0';
			tx_memory_select <= '0';
			tx_flag <= '0';
			-- 皋葛府
			rd_addr <= (others => '0');
			tx_addr <= (others => '0');
			din <= (others => '0');
			we <= '0';
			rd_addr1 <= (others => '0');
			tx_addr1 <= (others => '0');
			din1 <= (others => '0');
			we1 <= '0';
		elsif(clock'event and clock='1') then
			m_buff_clk1 <= m_buff;
			r_clk <= r_buf;
			g_clk <= g_buf;
			b_clk <= b_buf;
			case current_cycle is
				when idle =>
					we <= '0';
					we1 <= '0';
					memory_select <= '0';
					tx_flag <= '0';
					if(adc_reset = '1' and cis_pixel_count = "00000000000" and led_select = "01")then
						rd_addr <= (others => '0');
						rd_addr1 <= (others => '0');
						sampling_count <= (others => '0');
						temp_led_select <= "10";
						next_cycle <= cis_m1;
					end if;
				when cis_m1 =>
					if(memory_select = '0')then
						we <= '0';
					else
						we1 <= '0';
					end if;
					if(m_buff_clk1 = '1' and m_buff = '0')then
						-- ADC 备悼 脚龋
						cds_clk1 <= '0';
						cds_clk2 <= '0';
						adc_clk  <= '0';
						next_cycle <= cis_m2;
					end if;
				when cis_m2 =>
					next_cycle <= cis_m3;
				when cis_m3 =>
					cds_clk1 <= '1';
					adc_clk  <= '1';
					next_cycle <= cis_m4;
				when cis_m4 =>
					cds_clk1 <= '0';
					temp_rgb <= top_adc & bot_adc;
					next_cycle <= cis_m5;
				when cis_m5 =>
					adc_clk  <= '0';
					next_cycle <= cis_m6;
				when cis_m6 =>
					next_cycle <= cis_m7;
				when cis_m7 =>
					adc_clk  <= '1';
					next_cycle <= cis_m8;
				when cis_m8 =>
					next_cycle <= cis_m9;
				when cis_m9 =>
					adc_clk  <= '0';
					next_cycle <= cis_m10;
				when cis_m10 =>
					next_cycle <= cis_m11;
				when cis_m11 =>
					adc_clk  <= '1';
					next_cycle <= cis_m12;
				when cis_m12 =>
					next_cycle <= cis_m13;
				when cis_m13 =>
					adc_clk  <= '0';
					cds_clk2 <= '1';
					next_cycle <= cis_m14;
				when cis_m14 =>
					next_cycle <= cis_m15;
					cds_clk2 <= '0';
				when cis_m15 =>
					if(cis_pixel_count = "10100011011")then
						if(adc_reset = '0')then
							next_cycle <= idle;
						else
							next_cycle <= led_wait;
						end if;
						rd_addr1 <= (others => '0');
						rd_addr <= (others => '0');
						memory_select <= not memory_select;
						tx_flag <= '1';
					else
						next_cycle <= cis_m1;
--						if(cis_pixel_count < "10001010001")then
							if(sampling_count = "101")then
								sampling_count <= (others => '0');
								if(memory_select = '0')then
									rd_addr <= rd_addr + 1;
									din(15 downto 8) <= "11111111" - temp_rgb(15 downto 8);
									din(7 downto 0) <= "11111111" - temp_rgb(7 downto 0);
									we <= '1';
								else
									rd_addr1 <= rd_addr1 + 1;
									din1(15 downto 8) <= "11111111" - temp_rgb(15 downto 8);
									din1(7 downto 0) <= "11111111" - temp_rgb(7 downto 0);
									we1 <= '1';
								end if;
--								if(cis_pixel_count(10) = '1')then
--									din <= "1111111111111111";
--								else
--									din <= top_adc & bot_adc;
--								end if;
							else
								sampling_count <= sampling_count + 1;
							end if;
--						end if;
					end if;
				when led_wait =>
					if(temp_led_select = "10")then
						if(cis_pixel_count = "00000000000" and led_select = "11")then
							if(memory_select /= tx_memory_select)then
								sampling_count <= (others => '0');
								temp_led_select <= "11";
								next_cycle <= cis_m1;
							end if;
						end if;
					elsif(temp_led_select = "11")then
						if(cis_pixel_count = "00000000000" and led_select = "01")then
							if(memory_select /= tx_memory_select)then
								sampling_count <= (others => '0');
								temp_led_select <= "01";
								next_cycle <= cis_m1;
							end if;
						end if;
					elsif(temp_led_select = "01")then
						if(cis_pixel_count = "00000000000" and led_select = "10")then
							if(memory_select /= tx_memory_select)then
								sampling_count <= (others => '0');
								temp_led_select <= "10";
								next_cycle <= cis_m1;
							end if;
						end if;
					end if;
		 	end case;
			if(tx_flag = '1')then
				if(tx_memory_select = '0')then
					if(tx_count = "0111101010")then
						if(tx_addr = "11011010")then
							tx_addr <= (others => '0');
							tx_memory_select <= '1';
						else
							tx_addr <= tx_addr + 1;
						end if;
						tx_count <= (others => '0');
						r_buf <= not r_buf;
						top_rgb <= dout(15 downto 8);
						bot_rgb <= dout(7 downto 0);
					else
						tx_count <= tx_count + 1;
					end if;
				else
					if(tx_count = "0111101010")then
						if(tx_addr1 = "11011010")then
							tx_addr1 <= (others => '0');
							tx_memory_select <= '0';
						else
							tx_addr1 <= tx_addr1 + 1;
						end if;
						tx_count <= (others => '0');
						r_buf <= not r_buf;
						top_rgb <= dout1(15 downto 8);
						bot_rgb <= dout1(7 downto 0);
					else
						tx_count <= tx_count + 1;
					end if;
				end if;
			else
				tx_addr <= (others => '0');
				tx_addr1 <= (others => '0');
				tx_memory_select <= '0';
			end if;
		end if;
		current_cycle <= next_cycle;
		addr <= rd_addr or tx_addr;
		addr1 <= rd_addr1 or tx_addr1;
	end process;
	------------------------------------------------------------------------------------
	-- CIS 备悼
	------------------------------------------------------------------------------------
	process(reset,clock)
	begin
		if(reset='1') then
			-- CIS 备悼 脚龋
			rs <= '1';
			cis_reset <= '1';
			-- M 脚龋 滚欺
			m_buff <= '0';
			-- M 脚龋 墨款磐
			m_count <= (others => '0');
			-- 侨伎 墨款磐
			cis_pixel_count <= (others => '0');
			-- LED 备悼
			led_r <= '0';
			led_g <= '0';
			led_b <= '0';
		elsif(clock'event and clock='1') then
			-- M, RS 脚龋 惯积
			if(m_buff = '0')then
				if(m_count = "1001")then
					m_count <= (others => '0');
					m_buff <= '1';
					if(cis_pixel_count = "10100011011")then
						cis_pixel_count <= (others => '0');
						if(led_select = "01")then
							led_select <= "10";
						elsif(led_select = "10")then
							led_select <= "11";
						else
							led_select <= "01";
						end if;
					else
						cis_pixel_count <= cis_pixel_count + 1;
					end if;
				else
					m_count <= m_count + 1;
					if(m_count = "0001")then
						rs <= '1';
					end if;
				end if;
			else
				if(m_count = "1001")then
					m_count <= (others => '0');
					m_buff <= '0';
					rs <= '0';
				else
					m_count <= m_count + 1;
				end if;
			end if;
			-- TR 脚龋 惯积
			if(cis_pixel_count = "10100001000")then
				cis_reset <= '0';
			elsif(cis_pixel_count = "10100010000")then
				cis_reset <= '1';
			end if;
			-- LED 备悼
			-- 利祸 LED on
			if(led_select = "01")then
				if(cis_pixel_count >= "00000010100" and cis_pixel_count <= "01000000000")then
					led_r <= '1';
				else
					led_r <= '0';
				end if;
				led_g <= '0';
				led_b <= '0';
			-- 踌祸 LED on
			elsif(led_select = "10")then
				led_r <= '0';
				if(cis_pixel_count >= "00000010100" and cis_pixel_count <= "01000000000")then
					led_g <= '1';
--					led_g <= '0';
				else
					led_g <= '0';
				end if;
				led_b <= '0';
			-- 没祸 LED on
			elsif(led_select = "11")then
				led_r <= '0';
				led_g <= '0';
				if(cis_pixel_count >= "00000010100" and cis_pixel_count <= "01000000000")then
					led_b <= '1';
--					led_b <= '0';
				else
					led_b <= '0';
				end if;
			-- LED off
			else
				led_r <= '0';
				led_g <= '0';
				led_b <= '0';
			end if;
		 end if;
	end process;
	m <= m_buff;
end Behavioral;

⌨️ 快捷键说明

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