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

📄 op1.vhd

📁 可以受上位机控制的通过fpga的视频信号发生器程序
💻 VHD
字号:
LIBRARY ieee ;USE ieee.std_logic_1164.ALL;USE ieee.std_logic_unsigned.ALL;ENTITY op2 IS PORT( clk    : IN std_logic;  vcount : IN std_logic_vector(11 DOWNTO 0);  hcount : IN std_logic_vector(10 DOWNTO 0);  clken_fcount: IN std_logic;  pattern : IN std_logic_vector(3  DOWNTO 0);  distance: IN std_logic_vector(3  DOWNTO 0);  wren    : IN std_logic;  sel       : IN  std_logic_vector(7 DOWNTO 0);  address   : IN  std_logic_vector(7 DOWNTO 0);  date      : IN  std_logic_vector(7 DOWNTO 0);  out_r_e   : OUT std_logic_vector(7 DOWNTO 0);  out_g_e   : OUT std_logic_vector(7 DOWNTO 0);  out_b_e   : OUT std_logic_vector(7 DOWNTO 0);  out_r_o   : OUT std_logic_vector(7 DOWNTO 0);  out_g_o   : OUT std_logic_vector(7 DOWNTO 0);  out_b_o   : OUT std_logic_vector(7 DOWNTO 0));CONSTANT HAC:integer:=640;   -- horizontal active pixels 1448*1151CONSTANT HSY:integer:=20;     -- horizontal sync width (negative polarity)CONSTANT HBP:integer:=20;     -- horizontal back porchCONSTANT VAC:integer:=1024;    -- vertical active pixelsCONSTANT VSY:integer:=25;      -- vertical sync width (negative polarity)CONSTANT VBP:integer:=25;     -- vertical back porchEND op2;ARCHITECTURE rtl OF op2 IS	SIGNAL speed,dist,cmax,h_dis: integer;	SIGNAL nn:integer;	signal hz: std_logic;	SIGNAL color    : std_logic_vector(1 DOWNTO 0);	SIGNAL address_a: STD_LOGIC_VECTOR(10 DOWNTO 0);	SIGNAL address_b: STD_LOGIC_VECTOR(10 DOWNTO 0);	SIGNAL address1_a: STD_LOGIC_VECTOR(10 DOWNTO 0);	SIGNAL address1_b: STD_LOGIC_VECTOR(10 DOWNTO 0);	signal count: std_logic_vector(9 downto 0);	signal idate: STD_LOGIC_VECTOR(7 DOWNTO 0);	signal ada:STD_LOGIC_VECTOR(8 DOWNTO 0);	signal adb:STD_LOGIC_VECTOR(8 DOWNTO 0);	signal ada1:STD_LOGIC_VECTOR(7 DOWNTO 0);	signal adb1:STD_LOGIC_VECTOR(7 DOWNTO 0);	SIGNAL q_a:STD_LOGIC_VECTOR(7 DOWNTO 0);    SIGNAL q_b:STD_LOGIC_VECTOR(7 DOWNTO 0);    SIGNAL q1_a:STD_LOGIC_VECTOR(7 DOWNTO 0);    SIGNAL q1_b:STD_LOGIC_VECTOR(7 DOWNTO 0);    SIGNAL front:STD_LOGIC_VECTOR(7 DOWNTO 0);    SIGNAL back:STD_LOGIC_VECTOR(7 DOWNTO 0);COMPONENT ram3 ISPORT	(		data		: IN STD_LOGIC_VECTOR (7 DOWNTO 0);		wraddress		: IN STD_LOGIC_VECTOR (8 DOWNTO 0);		rdaddress_a		: IN STD_LOGIC_VECTOR (8 DOWNTO 0);		rdaddress_b		: IN STD_LOGIC_VECTOR (8 DOWNTO 0);		wren		: IN STD_LOGIC  := '1';		clock		: IN STD_LOGIC ;		qa		: OUT STD_LOGIC_VECTOR (7 DOWNTO 0);		qb		: OUT STD_LOGIC_VECTOR (7 DOWNTO 0)	);END COMPONENT;COMPONENT ram4 ISPORT	(		data		: IN STD_LOGIC_VECTOR (7 DOWNTO 0);		wraddress		: IN STD_LOGIC_VECTOR (7 DOWNTO 0);		rdaddress_a		: IN STD_LOGIC_VECTOR (7 DOWNTO 0);		rdaddress_b		: IN STD_LOGIC_VECTOR (7 DOWNTO 0);		wren		: IN STD_LOGIC  := '1';		clock		: IN STD_LOGIC ;		qa		: OUT STD_LOGIC_VECTOR (7 DOWNTO 0);		qb		: OUT STD_LOGIC_VECTOR (7 DOWNTO 0)	);END COMPONENT;BEGINu1: ram3port map(  data=>idate,wraddress=>count(8 downto 0),rdaddress_a=>ada,rdaddress_b=>adb,wren=>'1',clock=>clk,qa=>q_a,qb=>q_b);u2: ram4port map(  data=>date,wraddress=>address,rdaddress_a=>ada1,rdaddress_b=>adb1,wren=>wren,clock=>clk,qa=>q1_a,qb=>q1_b);PROCESS(clk,hz)BEGINIF clk'event AND clk='1' THENif hz='1' then count<="0000000000";else count<=count+1;end if;end if;end process;hz<='1' when count=cmax else '0';cmax<=250+dist+dist+dist+dist+dist;process(clk)BEGINIF clk'event AND clk='1' THENif count<50 or (count>=50+dist and count<100+dist) or(count>=100+dist+dist and count<150+dist+dist) or (count>=150+dist+dist+dist and count<200+dist+dist+dist) or (count>=200+dist+dist+dist+dist and count<250+dist+dist+dist+dist) thenidate<=front;else idate<=back;end if;end if;end process;PROCESS(distance)BEGINCASE distance IS	WHEN  "0000"=>dist<=42;	              h_dis<=15;	WHEN  "0001"=>dist<=36;	              h_dis<=30;	WHEN  "0010"=>dist<=30;	              h_dis<=45;	WHEN  "0011"=>dist<=24;	              h_dis<=60;    WHEN  "0100"=>dist<=18;                  h_dis<=75;    WHEN  "0101"=>dist<=12;                  h_dis<=90;    WHEN  "0110"=>dist<=6;                  h_dis<=105;    When others =>dist<=48;                  h_dis<=0;END CASE;END PROCESS;PROCESS(sel)BEGINCASE sel IS    WHEN  "00000000"=>back<="00000000";                  front<="00110010";	WHEN  "00000001"=>back<="00000000";	              front<="01001110";	WHEN  "00000010"=>back<="00000000";	              front<="01101111";    WHEN  "00000011"=>back<="00000000";                  front<="10010110";    WHEN  "00000100"=>back<="00000000";                  front<="11000100";    WHEN  "00000101"=>back<="00000000";                  front<="11111111";        WHEN  "00000110"=>back<="00110010";                  front<="01001110";    WHEN  "00000111"=>back<="00110010";                  front<="01101111";    WHEN  "00001000"=>back<="00110010";                  front<="10010110";    WHEN  "00001001"=>back<="00110010";                  front<="11000100";    WHEN  "00001010"=>back<="00110010";                  front<="11111111";    WHEN  "00001011"=>back<="01001110";                  front<="01101111";    WHEN  "00001100"=>back<="01001110";                  front<="10010110";     WHEN  "00001101"=>back<="01001110";                  front<="11000100";    WHEN  "00001110"=>back<="01001110";                  front<="11111111";     WHEN  "00001111"=>back<="01101111";                  front<="10010110"; WHEN  "00010000"=>back<="01101111";                  front<="11000100"; WHEN  "00010001"=>back<="01101111";                  front<="11111111"; WHEN  "00010010"=>back<="10010110";                  front<="11000100"; WHEN  "00010011"=>back<="10010110";                  front<="11111111";WHEN  "00010100"=>back<="11000100";                  front<="11111111";    When others=>back<="00000000";                 front<="00000000";END CASE;END PROCESS;ada<=address_a(8 downto 0);adb<=address_b(8 downto 0);speed<=conv_integer(pattern);process(clk)BEGINIF clk'event AND clk='1' THENif hcount+hcount-HBP-HSY-HBP-HSY>=nn+395+h_dis and hcount+hcount-HBP-HSY-HBP-HSY<885-h_disthen address_a<=hcount+hcount-HBP-HSY-HBP-HSY-nn-395-h_dis;address_b<=hcount+hcount-HBP-HSY-HBP-HSY-nn-394-h_dis;elsif hcount+hcount-HBP-HSY-HBP-HSY>=395+h_dis and hcount+hcount-HBP-HSY-HBP-HSY<nn+395+h_disthenaddress_a<=hcount+hcount-HBP-HSY-HBP-HSY-nn-395+490-h_dis-h_dis-h_dis;address_b<=hcount+hcount-HBP-HSY-HBP-HSY-nn-394+490-h_dis-h_dis-h_dis;else address_a<="00000111000";address_b<="00000111000";end if;end if;	end process;ada1<=address1_a(7 downto 0);adb1<=address1_b(7 downto 0);process(clk)BEGINIF clk'event AND clk='1' THENif hcount+hcount-HBP-HSY-HBP-HSY-390>=0 and hcount+hcount-HBP-HSY-HBP-HSY-390<100thenaddress1_a<=hcount+hcount-HBP-HSY-HBP-HSY-390;address1_b<=hcount+hcount-HBP-HSY-HBP-HSY-389;elsif hcount+hcount-HBP-HSY-HBP-HSY-390>=100 and hcount+hcount-HBP-HSY-HBP-HSY-390<200thenaddress1_a<=hcount+hcount-HBP-HSY-HBP-HSY-490;address1_b<=hcount+hcount-HBP-HSY-HBP-HSY-489;elsif hcount+hcount-HBP-HSY-HBP-HSY-390>=200 and hcount+hcount-HBP-HSY-HBP-HSY-390<300thenaddress1_a<=hcount+hcount-HBP-HSY-HBP-HSY-590;address1_b<=hcount+hcount-HBP-HSY-HBP-HSY-589;elsif hcount+hcount-HBP-HSY-HBP-HSY-390>=300 and hcount+hcount-HBP-HSY-HBP-HSY-390<400thenaddress1_a<=hcount+hcount-HBP-HSY-HBP-HSY-690;address1_b<=hcount+hcount-HBP-HSY-HBP-HSY-689;elsif hcount+hcount-HBP-HSY-HBP-HSY-390>=400 and hcount+hcount-HBP-HSY-HBP-HSY-390<500thenaddress1_a<=hcount+hcount-HBP-HSY-HBP-HSY-790;address1_b<=hcount+hcount-HBP-HSY-HBP-HSY-789;else address1_a<="00000000000";address1_b<="00000000000";end if;end if;end process;PROCESS(clk)BEGINIF clk'event AND clk='1' THENIF vcount>=187+VBP+VSY AND vcount<487+VBP+VSY and hcount>=195+HBP+HSY and hcount<HBP+HSY+445thencolor<="01";ELSIF vcount>=537+VBP+VSY AND vcount<837+VBP+VSY thencolor<="10";elsecolor<="00";END IF;END IF;END PROCESS;PROCESS(clk)BEGINIF clk'event AND clk='1' THENIF clken_fcount='1' THENIF nn>=(490-h_dis-h_dis) THEN nn<=0;ELSEnn<=(nn+speed+speed);END IF;END IF;END IF;END PROCESS;PROCESS(clk)BEGINIF clk'event AND clk='1' THENIF color="01" THENout_r_e<=q1_a;out_g_e<=q1_a;out_b_e<=q1_a;out_r_o<=q1_b;out_g_o<=q1_b;out_b_o<=q1_b;ELSIF color="10" THENout_r_e<=q_a;out_g_e<=q_a;out_b_e<=q_a;out_r_o<=q_b;out_g_o<=q_b;out_b_o<=q_b;ELSEout_r_e<=back;out_g_e<=back;out_b_e<=back;out_r_o<=back;out_g_o<=back;out_b_o<=back;END IF;END IF;END PROCESS;END rtl;  

⌨️ 快捷键说明

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