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

📄 cmos_control.vhd

📁 infra pen controller, cmos sensor control and sdram control
💻 VHD
📖 第 1 页 / 共 3 页
字号:
--============================================================================
-- Project 		: On Screen Display
-- Programmer	: Byungchan Son
-- Function		: 
-- Language		: VHDL
--============================================================================
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
--============================================================================
-- 涝免仿 器飘 沥狼
--============================================================================
entity cmos_control is
	port(
		-- system signal
		reset : in std_logic;
		clock : in std_logic;
		-- ir pen main
		cmos_y : in std_logic_vector(7 downto 0);
		cmos_vs : in std_logic;
		cmos_hs : in std_logic;
		cmos_mclk : out std_logic;
		cmos_reset : out std_logic;
		-- 促捞坷靛 力绢
		led_connect : out std_logic;
		led_power : out std_logic;
		-- uart
		com_rx_data : in std_logic_vector(31 downto 0);
		com_rx_req : in std_logic;
		com_rx_ack : out std_logic;
		com_tx_data : out std_logic_vector(31 downto 0);
		com_tx_req : out std_logic;
		com_tx_ack : in std_logic;
		image_tx_req : out std_logic_vector(1 downto 0);
		image_tx_ack : in std_logic;
		image_tx_no : out std_logic_vector(3 downto 0);
		sync_image_tx_req : out std_logic;
		pos_image_tx_req : out std_logic;
		pos_image_tx_ack : in std_logic;
		-- data control
		write_addr : out std_logic_vector(11 downto 0);
		write_data : out std_logic_vector(7 downto 0);
		read_data : in std_logic_vector(7 downto 0);
		write_data_req : out std_logic;
		write_data_ack : in std_logic;
		read_data_req : out std_logic;
		read_data_ack : in std_logic;
		-- sdram control
		buff_data : out std_logic_vector(127 downto 0);
		buff_wrreq : out std_logic;
		buff_rdreq : out std_logic;
		buff_rdack : in std_logic;
		buff_acer : out std_logic;
		buff_reset : out std_logic;
		pos_image_address : out std_logic_vector(23 downto 0);
		pos_image_read_req : out std_logic;
		pos_image_read_ack : in std_logic;
		-- test
		wdt0_signal : in std_logic;
		test_out : out std_logic
		);
end cmos_control;
--============================================================================
-- 备炼 沥狼
--============================================================================
architecture cmos_control_a of cmos_control is
--------------------------------------------------------------------
-- 郴何 葛碘
--------------------------------------------------------------------
component divider
	PORT
	(
		clock		: IN STD_LOGIC ;
		denom		: IN STD_LOGIC_VECTOR (23 DOWNTO 0);
		numer		: IN STD_LOGIC_VECTOR (23 DOWNTO 0);
		quotient	: OUT STD_LOGIC_VECTOR (23 DOWNTO 0);
		remain		: OUT STD_LOGIC_VECTOR (23 DOWNTO 0)
	);
end component;
--------------------------------------------------------------------
-- 郴何 脚龋
--------------------------------------------------------------------
-- 惑怕扁拌
type coms_control_state is( 
	idle,
	detect_pen,
	detect_pen1,
	detect_pen2,
	detect_pen3,
	page_reset,
	page_reset_0,
	page_reset_1,
	page_reset_2,
	tx_position,
	image_position,
	send_image_data,
	send_image_data1,
	send_image_data2,
	send_image_data3,
	send_image_data4
	);
signal current_state, next_state : coms_control_state;
type com_rx_state is(
	init_cmos,
	init_cmos_0,
	init_cmos_1,
	init_cmos_2,
	init_cmos_3,
	init_cmos_4,
	init_cmos_5,
	init_cmos_6,
	init_cmos_7,
	idle,
	rx_accept_delay,
	rx_write_data,
	rx_read_data
	);
signal rx_current_state, rx_next_state : com_rx_state;
type image_tx_state is(
	idle,
	read_pos_image,
	tx_pos_image,
	tx_pos_image_1
	);
signal tx_current_state, tx_next_state : image_tx_state;
-- 郴何脚龋
signal t_cmos_reset : std_logic;
signal rx_delay_count : std_logic_vector(1 downto 0);
signal t_cmos_y : std_logic_vector(7 downto 0);
signal t1_cmos_y : std_logic_vector(7 downto 0);
signal t_cmos_vs : std_logic;
signal t_cmos_hs : std_logic;
signal t1_cmos_vs : std_logic;
signal t1_cmos_hs : std_logic;
signal t_x_count : std_logic_vector(13 downto 0);
signal t_y_count : std_logic_vector(11 downto 0);
signal x_pos : std_logic_vector(11 downto 0);
signal y_pos : std_logic_vector(11 downto 0);
signal reset_count : std_logic_vector(15 downto 0);
signal mclk_count : std_logic_vector(1 downto 0);
signal max_y : std_logic_vector(7 downto 0);
signal t_max_y : std_logic_vector(7 downto 0);
signal limit_y : std_logic_vector(7 downto 0);
signal detect_on : std_logic;
signal send_flag : std_logic;
signal t_send_flag : std_logic;
signal hs_flag : std_logic;
signal send_image : std_logic_vector(2 downto 0);
signal image_count : std_logic_vector(15 downto 0);
signal set_data : std_logic_vector(7 downto 0);
signal x_ref : std_logic_vector(13 downto 0);
signal y_ref : std_logic_vector(11 downto 0);
signal image_pos : std_logic;
signal image_pos_req : std_logic;
signal image_pos_ack : std_logic;
-- 困摹 拌魂
signal no_count : std_logic_vector(23 downto 0);
signal x_sum : std_logic_vector(23 downto 0);
signal y_sum : std_logic_vector(23 downto 0);

signal x_denom		: STD_LOGIC_VECTOR (23 DOWNTO 0);
signal x_numer		: STD_LOGIC_VECTOR (23 DOWNTO 0);
signal x_quotient	: STD_LOGIC_VECTOR (23 DOWNTO 0);
signal y_denom		: STD_LOGIC_VECTOR (23 DOWNTO 0);
signal y_numer		: STD_LOGIC_VECTOR (23 DOWNTO 0);
signal y_quotient	: STD_LOGIC_VECTOR (23 DOWNTO 0);

-- 捞固瘤 器瘤记 傈价
signal image_pos_x : std_logic_vector(11 downto 0);
signal image_pos_y : std_logic_vector(11 downto 0);
signal image_x_count : std_logic_vector(1 downto 0);
signal image_y_count : std_logic_vector(3 downto 0);
signal width_count : std_logic_vector(7 downto 0);
signal page_sync : std_logic;
-- 闰祸
constant blk_color : std_logic_vector(31 downto 0) := "10000000000100001000000000010000";
signal watchdog_count : std_logic_vector(19 downto 0);
signal t0_wdt0_signal : std_logic;
signal t1_wdt0_signal : std_logic;
signal test : std_logic;
--============================================================================
-- 橇肺技辑 矫累
--============================================================================
begin
	----------------------------------------------------------------
	-- 郴何 葛碘 搬急
	----------------------------------------------------------------
	m0 : divider
	port map(
		clock		=> clock,
		denom		=> x_denom,
		numer		=> x_numer,
		quotient	=> x_quotient
		);
	m1 : divider
	port map(
		clock		=> clock,
		denom		=> y_denom,
		numer		=> y_numer,
		quotient	=> y_quotient
		);
	----------------------------------------------------------------
	-- 皋牢 橇肺技辑
	----------------------------------------------------------------
	main : process(
		reset,
		clock,
		next_state,
		t_cmos_vs,
		t_cmos_hs,
		t1_cmos_vs,
		t1_cmos_hs,
		t_x_count,
		t_y_count
		)
	begin
		if(reset = '1')then
			-- 郴何脚龋
			next_state <= idle;
			t_cmos_y <= (others => '0');
			t_cmos_vs <= '0';
			t_cmos_hs <= '0';
			t1_cmos_vs <= '0';
			t1_cmos_hs <= '0';
			com_tx_data <= (others => '0');
			com_tx_req <= '0';
			t_y_count <= (others => '0');
			t_x_count <= (others => '0');
			x_pos <= (others => '0');
			y_pos <= (others => '0');
			max_y <= (others => '0');
			t_max_y <= (others => '0');
			t_send_flag <= '0';
			buff_data <= (others => '0');
			buff_wrreq <= '0';
			buff_rdreq <= '0';
			buff_acer <= '0';
			buff_reset <= '0';
			image_count <= (others => '0');
			hs_flag <= '0';
			no_count <= (others => '0');
			x_sum <= (others => '0');
			y_sum <= (others => '0');
			image_pos_req <= '0';
			x_denom <= (others => '0');
			x_numer <= (others => '0');
			y_denom <= (others => '0');
			y_numer <= (others => '0');
			width_count <= (others => '0');
			image_tx_req <= "00";
		elsif(clock'event and clock = '1')then
			t_cmos_y <= cmos_y;
			t_cmos_vs <= cmos_vs;
			t_cmos_hs <= cmos_hs;
			t1_cmos_vs <= t_cmos_vs;
			t1_cmos_hs <= t_cmos_hs;
			-- 悼扁 墨款磐
			if(t1_cmos_hs = '0' and t_cmos_hs = '1')then
				t_y_count <= t_y_count + 1;
				t_x_count <= (others => '0');
			else
				t_x_count <= t_x_count + 1;
				if(t1_cmos_vs = '0' and t_cmos_vs = '1')then
					t_y_count <= (others => '0');
				end if;
			end if;
			case current_state is
				when idle =>
					buff_wrreq <= '0';
					if(detect_on = '1')then
						buff_data <= blk_color & blk_color & blk_color & blk_color;
						hs_flag <= '0';
						if(send_image(0) = '0')then
							next_state <= detect_pen;
						else
							-- 640 * 480
							if(send_image(2 downto 1) = "00")then
								next_state <= detect_pen;
							-- 320 * 240
							elsif(send_image(2 downto 1) = "01")then
								next_state <= detect_pen1;
							-- 160 * 120
							elsif(send_image(2 downto 1) = "10")then
								next_state <= detect_pen2;
							-- 160 * 120 center
							else
								next_state <= detect_pen3;
							end if;
						end if;
					else
						if(t_send_flag /= send_flag)then
							t_send_flag <= send_flag;
							com_tx_data <= "111111110000000000000000" & read_data;
							com_tx_req <= '1';
							next_state <= tx_position;
						end  if;
					end if;
				-- 640 * 480
				when detect_pen =>
					if(t1_cmos_hs = '1')then
						hs_flag <= '1';
						if(t_x_count(0) = '1')then
							if(t_x_count(1) = '1')then
								if(t_cmos_y >= limit_y)then
									no_count <= no_count + 1;
									x_sum <= x_sum + t_x_count(13 downto 2);

⌨️ 快捷键说明

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