1 ---------------------------------------------------------------------
2 -- vga_main.vhd Demo VGA configuration module.
3 ---------------------------------------------------------------------
4 -- Author: Barron Barnett
5 -- Copyright 2004 Digilent, Inc.
6 ---------------------------------------------------------------------
8 -- This project is compatible with Xilinx ISE or Xilinx WebPack tools.
11 -- mclk - System Clock
13 -- hs - Horizontal Sync
19 -- This module creates a three line pattern on a vga display using a
20 -- a vertical refresh rate of 60Hz. This is done by dividing the
21 -- system clock in half and using that for the pixel clock. This in
22 -- turn drives the vertical sync when the horizontal sync has reached
23 -- its reset point. All data displayed is done by basic value
25 ------------------------------------------------------------------------
27 -- 07/01/2004(BarronB): created
28 ------------------------------------------------------------------------
30 use IEEE.STD_LOGIC_1164.ALL;
31 use IEEE.STD_LOGIC_ARITH.ALL;
32 use IEEE.STD_LOGIC_UNSIGNED.ALL;
35 entity vgaController is
36 Port ( mclk : in std_logic;
44 architecture Behavioral of vgaController is
47 constant hpixels : std_logic_vector(9 downto 0) := "1100100000"; --Value of pixels in a horizontal line
48 constant vlines : std_logic_vector(9 downto 0) := "1000001001"; --Number of horizontal lines in the display
50 constant hbp : std_logic_vector(9 downto 0) := "0010010000"; --Horizontal back porch
51 constant hfp : std_logic_vector(9 downto 0) := "1100010000"; --Horizontal front porch
52 constant vbp : std_logic_vector(9 downto 0) := "0000011111"; --Vertical back porch
53 constant vfp : std_logic_vector(9 downto 0) := "0111111111"; --Vertical front porch
55 signal hc, vc : std_logic_vector(9 downto 0); --These are the Horizontal and Vertical counters
56 signal clkdiv : std_logic; --Clock divider
57 signal vidon : std_logic; --Tells whether or not its ok to display data
58 signal vsenable : std_logic; --Enable for the Vertical counter
61 --This cuts the 50Mhz clock in half
64 if(mclk = '1' and mclk'EVENT) then
69 --Runs the horizontal counter
72 if(clkdiv = '1' and clkdiv'EVENT) then
73 if hc = hpixels then --If the counter has reached the end of pixel count
74 hc <= "0000000000"; --reset the counter
75 vsenable <= '1'; --Enable the vertical counter to increment
77 hc <= hc + 1; --Increment the horizontal counter
78 vsenable <= '0'; --Leave the vsenable off
83 hs <= '1' when hc(9 downto 7) = "000" else '0'; --Horizontal Sync Pulse
87 if(clkdiv = '1' and clkdiv'EVENT and vsenable = '1') then --Increment when enabled
88 if vc = vlines then --Reset when the number of lines is reached
90 else vc <= vc + 1; --Increment the vertical counter
95 vs <= '1' when vc(9 downto 1) = "000000000" else '0'; --Vertical Sync Pulse
97 red <= '1' when (hc = "1010101100" and vidon ='1') else '0'; --Red pixel on at a specific horizontal count
98 grn <= '1' when (hc = "0100000100" and vidon ='1') else '0'; --Green pixel on at a specific horizontal count
99 blu <= '1' when (vc = "0100100001" and vidon ='1') else '0'; --Blue pixel on at a specific vertical count
101 vidon <= '1' when (((hc < hfp) and (hc > hbp)) or ((vc < vfp) and (vc > vbp))) else '0'; --Enable video out when within the porches