Projekt z kursu Układy cyfrowe i systemy wbudowane 2 na PWr
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date: 13:11:03 05/28/2018
  6. -- Design Name:
  7. -- Module Name: VGACompass - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. -- Uncomment the following library declaration if using
  23. -- arithmetic functions with Signed or Unsigned values
  24. use IEEE.NUMERIC_STD.ALL;
  25. -- Uncomment the following library declaration if instantiating
  26. -- any Xilinx primitives in this code.
  27. --library UNISIM;
  28. --use UNISIM.VComponents.all;
  29. entity VGACompass is
  30. Port ( DRX : in STD_LOGIC_VECTOR (15 downto 0);
  31. DRY : in STD_LOGIC_VECTOR (15 downto 0);
  32. Reset : in STD_LOGIC;
  33. Clk : in STD_LOGIC;
  34. V_R : out STD_LOGIC_VECTOR (4 downto 0);
  35. V_G : out STD_LOGIC_VECTOR (5 downto 0);
  36. V_B : out STD_LOGIC_VECTOR (4 downto 0);
  37. H_SYNC : out STD_LOGIC;
  38. V_SYNC : out STD_LOGIC);
  39. end VGACompass;
  40. architecture Behavioral of VGACompass is
  41. constant h_pulse : integer := 80; -- Horiztonal sync pulse width in pixels
  42. constant h_bp : integer := 160; -- Horiztonal back porch width in pixels
  43. constant h_pixels : integer := 800; -- Horiztonal display width in pixels
  44. constant h_fp : integer := 16; -- Horiztonal front porch width in pixels
  45. constant h_pol : STD_LOGIC := '1'; -- Horizontal sync pulse polarity (1 = positive, 0 = negative)
  46. constant v_pulse : integer := 3; -- Vertical sync pulse width in rows
  47. constant v_bp : integer := 21; -- Vertical back porch width in rows
  48. constant v_pixels : integer := 600; -- Vertical display width in rows
  49. constant v_fp : integer := 1; -- Vertical front porch width in rows
  50. constant v_pol : STD_LOGIC := '1'; -- Vertical sync pulse polarity (1 = positive, 0 = negative)
  51. constant h_period : integer := h_pulse + h_bp + h_pixels + h_fp; -- Total number of pixel clocks in a row
  52. constant v_period : integer := v_pulse + v_bp + v_pixels + v_fp; -- Total number of rows in column
  53. signal disp_ena : STD_LOGIC; -- Display enable ('1' = display time, '0' = blanking time)
  54. signal column : integer; -- Horizontal pixel coordinate
  55. signal row : integer; -- Vertical pixel coordinate
  56. signal DataX : signed (15 downto 0) := signed(DRX);
  57. signal DataY : signed (15 downto 0) := signed(DRY);
  58. signal Color : unsigned (15 downto 0) := unsigned((abs(DataX) + abs(DataY)) / 2);
  59. begin
  60. process(Clk, Reset)
  61. variable h_count : integer range 0 to h_period - 1 := 0; -- Horizontal counter (counts the columns)
  62. variable v_count : integer range 0 to v_period - 1 := 0; -- Vertical counter (counts the rows)
  63. begin
  64. if rising_edge(Clk) then
  65. if(Reset = '1') then -- Reset asserted
  66. h_count := 0; -- Reset horizontal counter
  67. v_count := 0; -- Reset vertical counter
  68. H_SYNC <= not h_pol; -- Deassert horizontal sync
  69. V_SYNC <= not v_pol; -- Deassert vertical sync
  70. disp_ena <= '0'; -- Disable display
  71. column <= 0; -- Reset column pixel coordinate
  72. row <= 0; -- Reset row pixel coordinate
  73. end if;
  74. -- Counters
  75. if(h_count < h_period - 1) then
  76. -- Horizontal counter (pixels)
  77. h_count := h_count + 1;
  78. else
  79. h_count := 0;
  80. if(v_count < v_period - 1) then
  81. -- Veritcal counter (rows)
  82. v_count := v_count + 1;
  83. else
  84. v_count := 0;
  85. end if;
  86. end if;
  87. -- Horizontal sync signal
  88. if(h_count < h_pixels + h_fp or h_count >= h_pixels + h_fp + h_pulse) then
  89. H_SYNC <= not h_pol; -- Deassert horiztonal sync pulse
  90. else
  91. H_SYNC <= h_pol; -- Assert horiztonal sync pulse
  92. end if;
  93. -- Vertical sync signal
  94. if(v_count < v_pixels + v_fp or v_count >= v_pixels + v_fp + v_pulse) then
  95. V_SYNC <= not v_pol; -- Deassert vertical sync pulse
  96. else
  97. V_SYNC <= v_pol; -- Assert vertical sync pulse
  98. end if;
  99. -- Set pixel coordinates
  100. if(h_count < h_pixels) then -- Horiztonal display time
  101. column <= h_count; -- Set horiztonal pixel coordinate
  102. end if;
  103. if(v_count < v_pixels) then -- Vertical display time
  104. row <= v_count; -- Set vertical pixel coordinate
  105. end if;
  106. -- Set display enable signal
  107. if(h_count < h_pixels and v_count < v_pixels) then
  108. -- Display time
  109. disp_ena <= '1';
  110. else
  111. -- Blanking time
  112. disp_ena <= '0';
  113. end if;
  114. end if;
  115. end process;
  116. process(disp_ena, row, column, DataX, DataY, Color)
  117. begin
  118. if(disp_ena = '1') then
  119. -- Display time
  120. if(row > 295 - shift_right(DataX, 3) and column > 395 - shift_right(DataY, 3) and row < 305 - shift_right(DataX, 3) and column < 405 - shift_right(DataY, 3)) then
  121. -- Northern marker (red)
  122. V_R <= (others => '1');
  123. V_G <= STD_LOGIC_VECTOR(Color(10 downto 5));
  124. V_B <= (others => '0');
  125. elsif(row > 295 + shift_right(DataX, 3) and column > 395 + shift_right(DataY, 3) and row < 305 + shift_right(DataX, 3) and column < 405 + shift_right(DataY, 3)) then
  126. -- Southern marker (blue)
  127. V_R <= (others => '0');
  128. V_G <= STD_LOGIC_VECTOR(Color(10 downto 5));
  129. V_B <= (others => '1');
  130. elsif(row = 300 or column = 400) then
  131. -- Axes (yellow)
  132. V_R <= (others => '1');
  133. V_G <= (others => '1');
  134. V_B <= (others => '0');
  135. else
  136. -- Background (black)
  137. V_R <= (others => '0');
  138. V_G <= (others => '0');
  139. V_B <= (others => '0');
  140. end if;
  141. else
  142. -- Blanking time
  143. V_R <= (others => '0');
  144. V_G <= (others => '0');
  145. V_B <= (others => '0');
  146. end if;
  147. end process;
  148. end Behavioral;