Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. ---------------------------------------------------
  2. -- School: University of Massachusetts Dartmouth
  3. -- Department: Computer and Electrical Engineering
  4. -- Engineer: 368 TA
  5. --
  6. -- Create Date:
  7. -- Module Name: VGA Sync Generator
  8. -- Project Name: VGA
  9. -- Target Devices: Spartan-3E
  10. -- Tool versions: Xilinx ISE 14.7
  11. -- Description: Driver a VGA display
  12. -- Display out an resolution of 800x600@60Hz
  13. -- Notes:
  14. -- For more information on a VGA display:
  15. -- https://eewiki.net/pages/viewpage.action?pageId=15925278
  16. -- http://digilentinc.com/Data/Documents/Reference%20Designs/VGA%20RefComp.zip
  17. -- Always read the data sheets
  18. ---------------------------------------------------
  19. library IEEE;
  20. use IEEE.STD_LOGIC_1164.ALL;
  21. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  22. use IEEE.numeric_std.all; --needed for to_integer
  23.  
  24. entity vga_controller is
  25. Port ( RST : in std_logic;
  26. PIXEL_CLK : in std_logic;
  27. HS : out std_logic;
  28. VS : out std_logic;
  29. HCOUNT : out std_logic_vector(10 downto 0);
  30. VCOUNT : out std_logic_vector(10 downto 0);
  31. BLANK : out std_logic);
  32. end vga_controller;
  33.  
  34. architecture Behavioral of vga_controller is
  35.  
  36.  
  37.  
  38. --Constants for testing
  39. --constant TdispV : integer range 0 to 521 := 20;
  40. --constant TpwV : integer range 0 to 521 := 3;
  41. --constant TfpV : integer range 0 to 521 := 2;
  42. --constant TbpV : integer range 0 to 521 := 4;
  43. --constant TsV : integer range 0 to 521 := TdispV+TpwV+TfpV+TbpV;
  44. --
  45. --
  46. --constant TdispH : integer range 0 to 800 := 30;
  47. --constant TpwH : integer range 0 to 800 := 5;
  48. --constant TfpH : integer range 0 to 800 := 4;
  49. --constant TbpH : integer range 0 to 800 := 6;
  50. --constant TsH : integer range 0 to 800 := TdispH+TpwH+TfpH+TbpH;
  51.  
  52. -- constants for real life
  53. -- todo you must fill these in for this to work
  54. constant TsV : integer range 0 to 521 := 521 ;
  55. constant TdispV : integer range 0 to 521 := 480 ;
  56. constant TpwV : integer range 0 to 521 := 2;
  57. constant TfpV : integer range 0 to 521 := 10;
  58. constant TbpV : integer range 0 to 521 := 29;
  59.  
  60. constant TsH : integer range 0 to 800 := 800;
  61. constant TdispH : integer range 0 to 800 := 640;
  62. constant TpwH : integer range 0 to 800 := 96;
  63. constant TfpH : integer range 0 to 800 := 16;
  64. constant TbpH : integer range 0 to 800 := 48;
  65.  
  66.  
  67. --0 HLINES HFP HSP HMAX
  68. --| | | | |
  69. --________________ _____
  70. -- XXXX|___|XXXX
  71.  
  72.  
  73. constant HLINES : integer range 0 to 800 := TdispH;
  74. constant HFP : integer range 0 to 800 := TdispH + TfpH;
  75. constant HSP : integer range 0 to 800 := TdispH + TfpH + TpwH;
  76. constant HMAX : integer range 0 to 800 := TsH;
  77.  
  78. constant VLINES : integer range 0 to 521 := TdispV;
  79. constant VFP : integer range 0 to 521 := TdispV + TfpV;
  80. constant VSP : integer range 0 to 521 := TdispV + TfpV + TpwV;
  81. constant VMAX : integer range 0 to 521 := TsV;
  82.  
  83. -- polarity of the horizontal and vertical synch pulse
  84. -- todo figure out if the pulse is high or low
  85. --if high put a '1'
  86. --if low put a '0'
  87. constant SPP : std_logic := '1';
  88.  
  89. signal hcounter : integer range 0 to 800;
  90. signal vcounter : integer range 0 to 521;
  91. signal video_enable: std_logic;
  92.  
  93. begin
  94.  
  95. hcount <= std_logic_vector(to_unsigned(hcounter,11));
  96. vcount <= std_logic_vector(to_unsigned(vcounter,11));
  97. blank <= not video_enable;
  98. video_enable <= '1' when (hcounter <= HLINES and vcounter <= VLINES) else '0';
  99.  
  100. -- horizontal counter
  101. h_count: process(PIXEL_CLK)
  102. begin
  103. if(rising_edge(PIXEL_CLK)) then
  104. if(rst = '1') then
  105. hcounter <= 0;
  106. elsif(hcounter = HMAX) then
  107. hcounter <= 0;
  108. else
  109. hcounter <= hcounter + 1;
  110. end if;
  111. end if;
  112. end process h_count;
  113.  
  114. -- vertical counter
  115. -- todo you must write this here
  116. v_count: process(PIXEL_CLK)
  117. begin
  118. if(rising_edge(PIXEL_CLK)) then
  119. if(rst = '1') then
  120. vcounter <= 0;
  121. elsif(vcounter = VMAX) then
  122. vcounter <= 0;
  123. else
  124. vcounter <= vcounter + 1;
  125. end if;
  126. end if;
  127. end process v_count;
  128.  
  129. -- horizontal synch pulse
  130. -- todo you must fill in this process
  131. do_hs: process(hcounter)
  132. begin
  133. if(hcounter > HFP and hcounter <= HSP) then
  134. HS <= SPP;
  135. else
  136. HS <= not SPP;
  137. end if;
  138. end process do_hs;
  139.  
  140. -- generate vertical synch pulse
  141. do_vs: process(vcounter)
  142. begin
  143. if(vcounter > VFP and vcounter <= VSP) then
  144. VS <= SPP;
  145. else
  146. VS <= not SPP;
  147. end if;
  148. end process do_vs;
  149.  
  150. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement