library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_misc.all;
use IEEE.std_logic_unsigned.all;
entity vgatest is
port(clk :in std_logic;
hs : out std_logic;
vs : out std_logic;
red1 : out std_logic;
green2 : out std_logic;
reset : in std_logic;
blue2: out std_logic
);
end vgatest;
Architecture vga_arch of vgatest is
signal clkout : std_logic;
begin
process (clk)
variable counter : integer :=1 ;
variable clktemp : std_logic:= '0';
begin
if(clk'event and clk ='1') then
if(counter /= 2) then
counter := counter + 1;
clkout <= clktemp;
elsif(counter =2) then
if(clktemp = '0')then
clktemp :='1';
counter := 1 ;
elsif(clktemp = '1') then
clktemp := '0';
counter := 1;
end if;
end if;
end if;
end process;
process(clkout,reset)
variable count: integer := 0;
variable vert : std_logic_vector (8 downto 0) := "000000000";
variable horiz :std_logic_vector (9 downto 0) := "0000000000";
variable countv : integer := 0;
begin
if (reset = '1') then
count := 0;
countv := 0;
vert := "000000000";
horiz := "0000000000";
red1 <= '0';
green2<= '0';
blue2<= '0';
hs <= '0';
vs <='0';
elsif(clkout'event and clkout ='1') then
if(vert = "111011111") then
vert := "000000000" ;
end if;
count := count +1;
if( count <= 96)then
red1 <= '0';
green2<= '0';
blue2<= '0';
hs <= '0';
elsif(count>=97 and count <=144)then
hs <= '1';
red1 <= '0';
green2<= '0';
blue2<= '0';
elsif(count >= 145 and count<=784) then
horiz := horiz + "0000000001";
hs <='1';
elsif(count >=785 and count < 800) then
horiz := "0000000000";
hs <='1';
red1 <= '0';
green2<= '0';
blue2<= '0';
elsif(count >= 800)then
countv := countv + 1;
vert := vert + "000000001";
count := 0;
end if;
if(countv < 2) then
vs <= '0';
red1 <= '0';
green2<= '0';
blue2<= '0';
elsif(countv >=2 and countv < 31 ) then
vs <='1';
red1 <= '0';
green2<= '0';
blue2<= '0';
elsif(countv >= 31 and countv < 511) then
vs <='1';
red1 <= '1';
green2<= '0';
blue2<= '0';
elsif(countv >= 511 and countv < 521) then
vs <='1';
red1 <= '0';
green2<= '0';
blue2<= '0';
elsif (countv > 521) then
countv :=0 ;
end if;
end if;
end process;
end vga_arch;