Advertisement
AnatolySharapov

VHDL_VGA

Oct 3rd, 2021
1,535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.74 KB | None | 0 0
  1. --Please maintain this header statement
  2. --     http://www.pyroelectro.com
  3. --if you use this code. Thank You!!!!!
  4. --Created by Chris @ PyroElectro.com
  5.     --Necessary Header Files
  6. LIBRARY IEEE;
  7. USE IEEE.STD_LOGIC_1164.ALL;
  8. USE IEEE.STD_LOGIC_ARITH.ALL;
  9. USE IEEE.STD_LOGIC_UNSIGNED.ALL;
  10.  
  11.     --Define The Core Entity
  12. ENTITY VHDL_VGA IS
  13. PORT(  
  14.         --Counter/VGA Timing
  15.         clk     : IN STD_LOGIC;
  16.        
  17.         --VGA Signals/Pins (Outputs)
  18.         hsync,
  19.         vsync,
  20.         red,
  21.         green,
  22.         blue    : OUT STD_LOGIC;
  23.        
  24.         --Sync Counters
  25.         row,
  26.         column  : OUT STD_LOGIC_VECTOR(9 DOWNTO 0));
  27. end VHDL_VGA;
  28.  
  29.     --Define The Architecture Of The Entity
  30. ARCHITECTURE behavior of VHDL_VGA IS
  31.        
  32.             --Sync Signals
  33. SIGNAL  h_sync, v_sync  :   STD_LOGIC;
  34.             --Video Enables
  35. SIGNAL  video_en,
  36.         horizontal_en,
  37.         vertical_en : STD_LOGIC;
  38.             --Color Signals
  39. SIGNAL  red_signal,
  40.         green_signal,
  41.         blue_signal : STD_LOGIC;
  42.             --Sync Counters
  43. SIGNAL  h_cnt,
  44.         v_cnt : STD_LOGIC_VECTOR(9 DOWNTO 0);
  45.        
  46.        
  47. BEGIN
  48.    
  49.     video_en <= horizontal_en AND vertical_en;
  50.    
  51. PROCESS
  52. variable cnt: integer range 0 to 25175000;
  53.  
  54. BEGIN
  55.  
  56.     WAIT UNTIL(clk'EVENT) AND (clk = '1');
  57.    
  58.     IF(cnt = 25175000)THEN     
  59.    
  60.     cnt := 0;
  61.     ELSE
  62.     cnt := cnt  + 1;
  63.     END IF;
  64.    
  65.     --Horizontal Sync
  66.    
  67.         --Reset Horizontal Counter
  68.     IF (h_cnt = 799) THEN
  69.         h_cnt <= "0000000000";
  70.     ELSE
  71.         h_cnt <= h_cnt + 1;
  72.     END IF;
  73.  
  74.         --Generate Horizontal Data
  75.                 --160 Rows Of Red
  76.     IF (v_cnt >= 0) AND (v_cnt <= 159) THEN
  77.         red_signal <= '1';
  78.         green_signal <= '0';
  79.         blue_signal <= '0';
  80.     END IF;
  81.                 --160 Rows Of Green
  82.     IF (v_cnt >= 160) AND (v_cnt <= 319) THEN
  83.         red_signal <= '0';
  84.         green_signal <= '1';
  85.         blue_signal <= '0';
  86.     END IF;
  87.                 --160 Rows Of Blue
  88.     IF (v_cnt >= 320) AND (v_cnt <= 479) THEN
  89.         red_signal <= '0';
  90.         green_signal <= '0';
  91.         blue_signal <= '1';        
  92.     END IF;
  93.    
  94.    
  95.    
  96.         --Generate Horizontal Sync
  97.     IF (h_cnt <= 755) AND (h_cnt >= 659) THEN
  98.         h_sync <= '0';
  99.     ELSE
  100.         h_sync <= '1';
  101.     END IF;
  102.    
  103.     --Vertical Sync
  104.  
  105.         --Reset Vertical Counter
  106.     IF (v_cnt >= 524) AND (h_cnt >= 699) THEN
  107.         v_cnt <= "0000000000";
  108.     ELSIF (h_cnt = 699) THEN
  109.         v_cnt <= v_cnt + 1;
  110.     END IF;
  111.    
  112.         --Generate Vertical Sync
  113.     IF (v_cnt <= 494) AND (v_cnt >= 493) THEN
  114.         v_sync <= '0'; 
  115.        
  116.     ELSE
  117.         v_sync <= '1';
  118.     END IF;
  119.    
  120.         --Generate Horizontal Data
  121.     IF (h_cnt <= 639) THEN
  122.         horizontal_en <= '1';
  123.         column <= h_cnt;
  124.     ELSE
  125.         horizontal_en <= '0';
  126.     END IF;
  127.    
  128.         --Generate Vertical Data
  129.     IF (v_cnt <= 479) THEN
  130.         vertical_en <= '1';
  131.         row <= v_cnt;
  132.     ELSE
  133.         vertical_en <= '0';
  134.     END IF;
  135.    
  136.     --Assign Physical Signals To VGA
  137.     red     <= red_signal AND video_en;
  138.     green   <= green_signal AND video_en;
  139.     blue    <= blue_signal AND video_en;
  140.    
  141.     hsync   <= h_sync;
  142.     vsync   <= v_sync;
  143.    
  144. END PROCESS;
  145. END behavior;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement