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

📄 cmos_control.vhd

📁 infra pen controller, cmos sensor control and sdram control
💻 VHD
📖 第 1 页 / 共 3 页
字号:
									y_sum <= y_sum + t_y_count;
									if(max_y < t_cmos_y)then
										max_y <= t_cmos_y;
									end if;
								end if;
								x_numer <= x_sum;
								x_denom <= no_count;
								y_numer <= y_sum;
								y_denom <= no_count;
							end if;
							case t_x_count(4 downto 1) is
								when "0000" => buff_data(127 downto 120) <= t_cmos_y;
								when "0001" => buff_data(119 downto 112) <= t_cmos_y;
								when "0010" => buff_data(111 downto 104) <= t_cmos_y;
								when "0011" => buff_data(103 downto  96) <= t_cmos_y;
								when "0100" => buff_data( 95 downto  88) <= t_cmos_y;
								when "0101" => buff_data( 87 downto  80) <= t_cmos_y;
								when "0110" => buff_data( 79 downto  72) <= t_cmos_y;
								when "0111" => buff_data( 71 downto  64) <= t_cmos_y;
								when "1000" => buff_data( 63 downto  56) <= t_cmos_y;
								when "1001" => buff_data( 55 downto  48) <= t_cmos_y;
								when "1010" => buff_data( 47 downto  40) <= t_cmos_y;
								when "1011" => buff_data( 39 downto  32) <= t_cmos_y;
								when "1100" => buff_data( 31 downto  24) <= t_cmos_y;
								when "1101" => buff_data( 23 downto  16) <= t_cmos_y;
								when "1110" => buff_data( 15 downto   8) <= t_cmos_y;
								when others => buff_data(  7 downto   0) <= t_cmos_y;
							end case;
							if(t_x_count(4 downto 1) = "1111")then
								buff_wrreq <= '1';
							end if;
						else
							buff_wrreq <= '0';
						end if;
					else
						buff_wrreq <= '0';
						if(hs_flag = '1')then
							hs_flag <= '0';
						else
							buff_data <= blk_color & blk_color & blk_color & blk_color;
						end if;
					end if;
					if(t1_cmos_vs = '1' and t_cmos_vs = '0')then
						buff_acer <= '1';
						buff_reset <= '1';
						next_state <= page_reset;
					end if;
				-- 320 * 240
				when detect_pen1 =>
--					if(t_cmos_hs = '1')then
--						hs_flag <= '1';
--						if(t_x_count(0) = '1')then
--							if(t_y_count(0) = '0')then
--								case t_x_count(5 downto 1) is
--									when "00000" => buff_data(127 downto 120) <= t_cmos_y;
--									when "00001" => buff_data(119 downto 112) <= t_cmos_y;
--									when "00010" => buff_data(111 downto 104) <= t_cmos_y;
--									when "00011" => buff_data(103 downto  96) <= t_cmos_y;
--									when "01000" => buff_data( 95 downto  88) <= t_cmos_y;
--									when "01001" => buff_data( 87 downto  80) <= t_cmos_y;
--									when "01010" => buff_data( 79 downto  72) <= t_cmos_y;
--									when "01011" => buff_data( 71 downto  64) <= t_cmos_y;
--									when "10000" => buff_data( 63 downto  56) <= t_cmos_y;
--									when "10001" => buff_data( 55 downto  48) <= t_cmos_y;
--									when "10010" => buff_data( 47 downto  40) <= t_cmos_y;
--									when "10011" => buff_data( 39 downto  32) <= t_cmos_y;
--									when "11000" => buff_data( 31 downto  24) <= t_cmos_y;
--									when "11001" => buff_data( 23 downto  16) <= t_cmos_y;
--									when "11010" => buff_data( 15 downto   8) <= t_cmos_y;
--									when "11011" => buff_data(  7 downto   0) <= t_cmos_y;
--									when others  => t1_cmos_y <= t_cmos_y;
--								end case;
--								if(t_x_count(5 downto 1) = "11011")then
--									buff_wrreq <= '1';
--								end if;
--							end if;
--						else
--							buff_wrreq <= '0';
--						end if;
--					else
--						buff_wrreq <= '0';
--						if(hs_flag = '1')then
--							hs_flag <= '0';
--						else
--							buff_data <= blk_color & blk_color & blk_color & blk_color;
--						end if;
--					end if;
--					if(t1_cmos_vs = '1' and t_cmos_vs = '0')then
--						buff_acer <= '1';
--						buff_reset <= '1';
						next_state <= page_reset;
--					end if;
				-- 160 * 120
				when detect_pen2 =>
					if(t_cmos_hs = '1')then
						hs_flag <= '1';
						if(t_x_count(0) = '1')then
							if(t_y_count(1 downto 0) = "00")then
								case t_x_count(6 downto 1) is
									when "000000" => buff_data(127 downto 120) <= t_cmos_y;
									when "000001" => buff_data(119 downto 112) <= t_cmos_y;
									when "000010" => buff_data(111 downto 104) <= t_cmos_y;
									when "000011" => buff_data(103 downto  96) <= t_cmos_y;
									when "010000" => buff_data( 95 downto  88) <= t_cmos_y;
									when "010001" => buff_data( 87 downto  80) <= t_cmos_y;
									when "010010" => buff_data( 79 downto  72) <= t_cmos_y;
									when "010011" => buff_data( 71 downto  64) <= t_cmos_y;
									when "100000" => buff_data( 63 downto  56) <= t_cmos_y;
									when "100001" => buff_data( 55 downto  48) <= t_cmos_y;
									when "100010" => buff_data( 47 downto  40) <= t_cmos_y;
									when "100011" => buff_data( 39 downto  32) <= t_cmos_y;
									when "110000" => buff_data( 31 downto  24) <= t_cmos_y;
									when "110001" => buff_data( 23 downto  16) <= t_cmos_y;
									when "110010" => buff_data( 15 downto   8) <= t_cmos_y;
									when "110011" => buff_data(  7 downto   0) <= t_cmos_y;
									when others  => t1_cmos_y <= t_cmos_y;
								end case;
								if(t_x_count(6 downto 1) = "110011")then
									buff_wrreq <= '1';
								end if;
							end if;
						else
							buff_wrreq <= '0';
						end if;
					else
						buff_wrreq <= '0';
						if(hs_flag = '1')then
							hs_flag <= '0';
						else
							buff_data <= blk_color & blk_color & blk_color & blk_color;
						end if;
					end if;
					if(t1_cmos_vs = '1' and t_cmos_vs = '0')then
						buff_acer <= '1';
						buff_reset <= '1';
						next_state <= page_reset;
					end if;
				-- 160 * 120 center
				when detect_pen3 =>
					if(t1_cmos_hs = '1')then
						hs_flag <= '1';
						if(t_x_count(0) = '1')then
							if(t_y_count >= y_ref and t_y_count < (y_ref + "000001111000"))then
								if(t_x_count >= x_ref and t_x_count < (x_ref + "00001010000000"))then
									case t_x_count(4 downto 1) is
										when "0000" => buff_data(127 downto 120) <= t_cmos_y;
										when "0001" => buff_data(119 downto 112) <= t_cmos_y;
										when "0010" => buff_data(111 downto 104) <= t_cmos_y;
										when "0011" => buff_data(103 downto  96) <= t_cmos_y;
										when "0100" => buff_data( 95 downto  88) <= t_cmos_y;
										when "0101" => buff_data( 87 downto  80) <= t_cmos_y;
										when "0110" => buff_data( 79 downto  72) <= t_cmos_y;
										when "0111" => buff_data( 71 downto  64) <= t_cmos_y;
										when "1000" => buff_data( 63 downto  56) <= t_cmos_y;
										when "1001" => buff_data( 55 downto  48) <= t_cmos_y;
										when "1010" => buff_data( 47 downto  40) <= t_cmos_y;
										when "1011" => buff_data( 39 downto  32) <= t_cmos_y;
										when "1100" => buff_data( 31 downto  24) <= t_cmos_y;
										when "1101" => buff_data( 23 downto  16) <= t_cmos_y;
										when "1110" => buff_data( 15 downto   8) <= t_cmos_y;
										when others => buff_data(  7 downto   0) <= t_cmos_y;
									end case;
									if(t_x_count(4 downto 1) = "1111")then
										buff_wrreq <= '1';
									end if;
								end if;
							end if;
						else
							buff_wrreq <= '0';
						end if;
					else
						buff_wrreq <= '0';
						if(hs_flag = '1')then
							hs_flag <= '0';
						else
							buff_data <= blk_color & blk_color & blk_color & blk_color;
						end if;
					end if;
					if(t1_cmos_vs = '1' and t_cmos_vs = '0')then
						buff_acer <= '1';
						buff_reset <= '1';
						next_state <= page_reset;
					end if;
				when page_reset =>
					buff_wrreq <= '0';
					next_state <= page_reset_1;
				when page_reset_0 =>
					next_state <= page_reset_1;
				when page_reset_1 =>
					x_pos <= x_quotient(11 downto 0);
					y_pos <= y_quotient(11 downto 0);
					next_state <= page_reset_2;
				when page_reset_2 =>
					if(image_count(5) = '1')then
						buff_acer <= '0';
						buff_reset <= '0';
						image_count <= (others => '0');
						if(send_image(0) = '1')then
							width_count <= (others => '0');
							next_state <= send_image_data;
						else
							com_tx_data <= max_y & x_pos & y_pos;
							com_tx_req <= '1';
							next_state <= tx_position;
						end if;
					else
						image_count <= image_count + 1;
					end if;
				when tx_position =>
					if(com_tx_ack = '1')then
						com_tx_req <= '0';
						if(image_pos = '1')then
							image_pos_req <= '1';
							next_state <= image_position;
						else
							x_pos <= (others => '0');
							y_pos <= (others => '0');
							max_y <= (others => '0');
							no_count <= (others => '0');
							x_sum <= (others => '0');
							y_sum <= (others => '0');
							next_state <= idle;
						end if;
					end if;
				when image_position =>
					if(image_pos_ack = '1')then
						x_pos <= (others => '0');
						y_pos <= (others => '0');
						max_y <= (others => '0');
						no_count <= (others => '0');
						x_sum <= (others => '0');
						y_sum <= (others => '0');
						image_pos_req <= '0';
						next_state <= idle;
					end if;
				when send_image_data =>
					buff_rdreq <= '1';
					next_state <= send_image_data1;
				when send_image_data1 =>
					if(buff_rdack = '1')then
						buff_rdreq <= '0';
						if(width_count = "00000000")then
							if(image_count = "0000000000000000")then
								image_tx_req <= "01";
							else
								image_tx_req <= "10";
							end if;
						else
							image_tx_req <= "11";
						end if;
						image_tx_no <= width_count(3 downto 0);
						next_state <= send_image_data2;
					end if;
				when send_image_data2 =>
					if(image_tx_ack = '1')then
						image_tx_req <= "00";
						if(image_count = "1001011000000000" and send_image(2 downto 1) = "00")then	-- 38400 = x(640) * y(480) / 8
							image_count <= (others => '0');
							buff_acer <= '1';
							buff_reset <= '1';
							next_state <= send_image_data3;
--						elsif(image_count = "0010010110000000" and send_image(2 downto 1) = "01")then	-- 9600 = x(320) * y(240) / 8
--							image_count <= (others => '0');
--							buff_acer <= '1';
--							buff_reset <= '1';
--							next_state <= send_image_data3;
						elsif(image_count = "0000100101100000" and send_image(2 downto 1) = "10")then	-- 2400 = x(160) * y(120) / 8
							image_count <= (others => '0');
							buff_acer <= '1';
							buff_reset <= '1';
							next_state <= send_image_data3;
						elsif(image_count = "0000100101100000" and send_image(2 downto 1) = "11")then	-- 2400 = x(160) * y(120) / 8
							image_count <= (others => '0');
							buff_acer <= '1';
							buff_reset <= '1';
							next_state <= send_image_data3;
						else
							image_count <= image_count + 1;
							next_state <= send_image_data;
						end if;
						if(width_count = "01001111" and send_image(2 downto 1) = "00")then
							width_count <= (others => '0');
--						elsif(width_count = "00100111" and send_image(2 downto 1) = "01")then
--							width_count <= (others => '0');
						elsif(width_count = "00010011" and send_image(2 downto 1) = "10")then
							width_count <= (others => '0');
						elsif(width_count = "00010011" and send_image(2 downto 1) = "11")then
							width_count <= (others => '0');
						else
							width_count <= width_count + 1;
						end if;
					end if;
				when send_image_data3 =>
					if(image_count(5) = '1')then
						buff_acer <= '0';
						buff_reset <= '0';
						image_count <= image_count + 1;
					elsif(image_count(6) = '1')then
						image_count <= (others => '0');
						buff_data(127 downto 64) <= (others => '0');
						buff_data(63 downto 0) <= (others => '1');
						--buff_wrreq <= '1';
						next_state <= send_image_data4;
					else
						image_count <= image_count + 1;
					end if;
				when send_image_data4 =>

⌨️ 快捷键说明

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