Advertisement
Guest User

Untitled

a guest
Jan 11th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.64 KB | None | 0 0
  1. LIBRARY  ieee;
  2. USE ieee.std_logic_1164.all;
  3.  
  4. entity vga_driver is
  5.     port(
  6.         in_clk_50 : in std_logic;      -- vga clock
  7.         out_xSync : out std_logic;  -- horizontal sync
  8.         out_ySync : out std_logic;  -- vertical sync
  9.         out_R :  out std_logic_vector(9 downto 0);
  10.         out_G :  out std_logic_vector(9 downto 0);
  11.         out_B :  out std_logic_vector(9 downto 0);
  12.         out_blank : out std_logic;
  13.         out_sync : out std_logic;
  14.         out_clk : out std_logic
  15.         );
  16. end vga_driver;
  17.  
  18. architecture driver of vga_driver is
  19.     signal half_clock: std_logic;
  20.     signal x_full: integer range 0 to 800 := 0;
  21.     signal y_full: integer range 0 to 525 := 0;
  22.     signal xSyncEnable: std_logic;
  23.     signal ySyncEnable: std_logic;
  24.     signal x: integer range 0 to 639 := 0;
  25.     signal video_on: std_logic;
  26.     signal y: integer range 0 to 479 := 0;
  27.    
  28.     --horizontal constants
  29.     constant x_visible_area : natural := 640; -- horizontal visible area
  30.     constant x_front_porch : natural := 16;  -- horizontal front porch
  31.     constant x_sync_pulse : natural := 96;  -- horizontal sync pulse
  32.     constant x_back_porch : natural := 48;  -- horizontal back porch
  33.     constant x_total : natural := 800;
  34.  
  35.     --vertical constants
  36.     constant y_visible_area : natural := 480;
  37.     constant y_front_porch : natural := 10;
  38.     constant y_back_porch : natural := 33;
  39.     constant y_sync_pulse : natural := 2;
  40.     constant y_total : natural := 525;
  41.    
  42.     begin
  43.         out_sync <= '0';
  44.         out_blank <= '1';
  45.         out_xSync <= xSyncEnable;
  46.         out_ySync <= ySyncEnable;
  47.         out_clk <= half_clock;
  48.        
  49.         -- HALFING THE CLOCK --
  50.         clockScale: process(in_clk_50)
  51.         begin
  52.             if in_clk_50'event and in_clk_50 = '1' then
  53.                 half_clock <= not half_clock;
  54.             end if;
  55.         end process clockScale;
  56.        
  57.         -- SIGNALS TIMING --
  58.         sig_timing: process(half_clock)
  59.         begin
  60.             if half_clock'event and half_clock = '1' then
  61.                 if x_full = x_total then
  62.                    
  63.                     x_full <= 0;
  64.                     y_full <= y_full + 1;
  65.                    
  66.                     if y_full = y_total then
  67.                         y_full <= 0;
  68.                     else
  69.                         y_full <= y_full + 1;
  70.                     end if;
  71.                 else
  72.                     x_full <= x_full + 1;
  73.                 end if;
  74.             end if;
  75.         end process sig_timing;
  76.        
  77.        
  78.         -- SYNC VGA SIGNAL --
  79.         vga_sync: process (half_clock)
  80.         begin
  81.        
  82.             if half_clock'event and half_clock = '1' then
  83.                 if x_full >= (x_visible_area + x_front_porch) and x_full < (x_visible_area + x_front_porch + x_sync_pulse)  then --96 points
  84.                     xSyncEnable <= '0';
  85.                 else
  86.                     xSyncEnable <= '1';
  87.                 end if;
  88.                
  89.                 if y_full >= (y_visible_area + y_front_porch) and y_full < (y_visible_area + y_front_porch + y_sync_pulse) then --2 points
  90.                     ySyncEnable <= '0';
  91.                 else
  92.                     ySyncEnable <= '1';
  93.                 end if;
  94.             end if;
  95.         end process vga_sync;
  96.        
  97.                
  98.  
  99.         foreground: process(half_clock)
  100.             begin
  101.                 if half_clock'event and half_clock = '1' then
  102.                     if( x_full > 120 and x_full < 240 and y_full > 150 and y_full < 250) then
  103.                         out_R(9) <= '0';
  104.                         out_G(9) <= '1';
  105.                         out_B(9) <= '1';
  106.                    
  107.                     else
  108.                         out_R(9) <= '0';
  109.                         out_G(9) <= '0';
  110.                         out_B(9) <= '0';
  111.                     end if;
  112.                 end if;
  113.             end process foreground;
  114.            
  115. end driver;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement