Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.73 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    10:28:38 01/15/2019
  6. -- Design Name:
  7. -- Module Name:    vgaControler - 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.  
  23. -- Uncomment the following library declaration if using
  24. -- arithmetic functions with Signed or Unsigned values
  25. use IEEE.NUMERIC_STD.ALL;
  26.  
  27. -- Uncomment the following library declaration if instantiating
  28. -- any Xilinx primitives in this code.
  29. --library UNISIM;
  30. --use UNISIM.VComponents.all;
  31.  
  32. entity vgaControler is
  33.     Port ( CLK_50MHz : in  STD_LOGIC;
  34.            RGB : in  STD_LOGIC_VECTOR (2 downto 0);
  35.            VGA_R : out  STD_LOGIC;
  36.            VGA_G : out  STD_LOGIC;
  37.            VGA_B : out  STD_LOGIC;
  38.            VGA_HS : out  STD_LOGIC;
  39.            VGA_VS : out  STD_LOGIC;
  40.            PIX_X : out  STD_LOGIC_VECTOR (9 downto 0);
  41.            PIX_Y : out  STD_LOGIC_VECTOR (8 downto 0));
  42. end vgaControler;
  43.  
  44. architecture Behavioral of vgaControler is
  45.     signal clk_25 : STD_LOGIC := '0';
  46.     signal h_cnt : integer := 0;
  47.     signal v_cnt : integer := 0;
  48.    
  49.     signal hor_sync : STD_LOGIC := '0';
  50.     signal ver_sync : STD_LOGIC := '0';
  51.    
  52. begin
  53.  
  54.     clk_div : process(CLK_50MHz)
  55.     begin
  56.         if (rising_edge(CLK_50MHZ)) then
  57.             clk_25 <= not clk_25;
  58.         end if;
  59.     end process clk_div;
  60.    
  61.     counters : process(clk_25)
  62.     begin
  63.         if (rising_edge(clk_25)) then
  64.             if (h_cnt < 800) then
  65.                 h_cnt <= h_cnt + 1;
  66.             else
  67.                 h_cnt <= 0;
  68.                
  69.                 if (v_cnt < 521) then
  70.                     v_cnt <= v_cnt + 1;
  71.                 else
  72.                     v_cnt <= 0;
  73.                 end if;
  74.             end if;
  75.         end if;
  76.     end process counters;
  77.    
  78.     h_sync : process(h_cnt)
  79.     begin
  80.         if (h_cnt = 800) then
  81.             hor_sync <= not hor_sync;
  82.         end if;
  83.        
  84.         VGA_HS <= hor_sync;
  85.     end process h_sync;
  86.    
  87.     v_sync : process(v_cnt)
  88.     begin
  89.         if (v_cnt = 521) then
  90.             ver_sync <= not ver_sync;
  91.         end if;
  92.        
  93.         VGA_VS <= ver_sync;
  94.     end process v_sync;
  95.    
  96.     color_pixel : process(h_cnt, v_cnt, RGB)
  97.     begin
  98.         if ((h_cnt < 640) and (v_cnt < 480)) then
  99.             -- color
  100.             VGA_R <= RGB(2);
  101.             VGA_G <= RGB(1);
  102.             VGA_B <= RGB(0);
  103.            
  104.             -- pixel
  105.             PIX_X <= std_logic_vector(to_unsigned(h_cnt, 10));
  106.             PIX_Y <= std_logic_vector(to_unsigned(v_cnt, 9));
  107.         else
  108.             -- color
  109.             VGA_R <= '0';
  110.             VGA_G <= '0';
  111.             VGA_B <= '0';
  112.            
  113.             -- pixel
  114.             PIX_X <= std_logic_vector(to_unsigned(640, 10));
  115.             PIX_Y <= std_logic_vector(to_unsigned(480, 9));
  116.         end if;
  117.     end process color_pixel;
  118.    
  119. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement