-- Monitor.vhd -- -- Displays different colored vertical bars. Each bar is one pixel in with -- and 480 pixles in length. Resolution 640x480 -- -- It is our intent to provide a simple, ready to use, -- module (the code your looking at) to control the monitor. -- The VGA monitor is controled by ONLY TWO outputs: a horizontal sync -- and a vertical sync. Other than those two signals the monitor, does -- everything else on its own. IT IS YOUR DUTY piolet to fire the Red, -- Green and Blue outputs at the apropriate time to create the picture -- on the screen, BY NO MEANS is the monitor going to wait for you. -- -- The vertical sync (active low) will send the electron beam to the top left most -- corner of the screen. The Horizontal sycn (active low) will send the electron -- beam to the next line (or row, for you spredsheet people). Timing -- documentation can be viewed in the, Altera University Program Design Laboratory -- Package (you thing they could have found a longer name?) -- -- Good luck (the way this code is written, your going to need it ;) ) -- Uses Flex 10K20 Device -- -- Oginial code (razzle.vhd) by Jim Hamblen, -- Georgia Tech School of ECE -- -- Modified for use in the Arkanoid project by Tyler Brandon, Chris Blasco and Kevin Lister -- -- Again, modified by Shaun Luong, Patrick Asiedu-Ampem, Jon-Paul Kansky and Clifton Yeung -- on the date of November 5,1998. -- This modification is for the use of displaying a distance from the ultra-sonic device -- calculation module. -- University of Alberta -- library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity monitor is generic ( N : positive := 10 ); port ( Clock, reset : in std_logic; Red,Green,Blue : out std_logic; Horiz_sync,Vert_sync : out std_logic; Distance_in : in std_logic_vector(N*3+7 downto 0); dummy_out :out std_logic_vector(N*3+7 downto 0) ); end monitor; architecture behavior of monitor is -- Video Display Signals signal H_count,V_count: std_logic_vector(N-1 Downto 0); signal Red_Data, Green_Data, Blue_Data : std_logic; constant H_max : std_logic_vector(N-1 Downto 0) := "1100011111";--799 -- 799 is max horiz count constant V_max : std_logic_vector(N-1 Downto 0) := "1000001100";--524 -- 524 is max vert count signal video_on, video_on_H, video_on_V: std_logic; signal line_dist, Dist_in : integer; component video generic ( N : positive := 10 ); port ( H_count, V_count: in std_logic_vector( N-1 downto 0 ); line_dist : in integer; video_on_H : out std_logic ); end component video; begin -- Colors for pixel data on video signal (Unrelated to the actual -- generation of output on a VGA monitor.) -- -- *This just determines "what" to display* -- -- (in this case, it displays vertical bars of color) process( Clock ) variable sum : std_logic_vector( 2 downto 0); begin wait until rising_edge( Clock ); if reset = '0' then sum := "000"; else sum := "111"; end if; Red_Data <= sum(2); Green_Data <= sum(1); Blue_Data <= sum(0); end process; -- -- -- Dummy_out variable for ensuring all bits are used in distance_out dummy_out(N*3+7 downto 0) <= Distance_in(N*3+7 downto 0); -- Convert Distance_in into a 32 bit number so that it can be converted into -- an integer for use latter on. Dist_in <= conv_integer(Distance_in(N*3+1 downto 0)); -- Makes sure the electron beam in the monitor isn't trying to display -- colors outside of the view area (i.e. on your lab partners forhead). Red <= Red_Data and video_on; Green <= Green_Data and video_on; Blue <= Blue_Data and video_on; -- video_on turns off pixel data when not in the view area video_on <= video_on_H and video_on_V; -- Generate Video on Screen Signals for Pixel Data display : video port map ( H_count => H_count, V_count=> V_count, line_dist => line_dist, video_on_H => video_on_H); --Generate Horizontal and Vertical Timing Signals for Video Signal VIDEO_DISPLAY: process begin Wait until rising_edge ( Clock ); if reset = '0' Then H_count <= (others => '0'); V_count <= (others => '0'); -- Video_on_H <= '0'; Video_on_V <= '0'; else -- H_count counts pixels (640 + extra time for sync signals) -- -- <-Clock out RGB Pixel Row Data -> <-H Sync-> -- ------------------------------------__________-------- -- 0 640 659 755 799 -- if (H_count >= H_max) then H_count <= (others => '0'); else H_count <= H_count + '1'; end if; --Generate Horizontal Sync Signal if (H_count <= 755) and (H_count >= 659) Then Horiz_Sync <= '0'; else Horiz_Sync <= '1'; end if; --V_count counts rows of pixels (480 + extra time for sync signals) -- -- <---- 480 Horizontal Syncs (pixel rows) --> ->V Sync<- -- -----------------------------------------------_______--------- -- 0 480 493-494 524 -- if (V_count >= V_max) and (H_count >= 699) then V_count <= (others => '0'); else If (H_count = 699) Then V_count <= V_count + '1'; end if; end if; -- Generate Vertical Sync Signal if (V_count <= 494) and (V_count >= 493) Then Vert_Sync <= '0'; else Vert_Sync <= '1'; end if; -- Has the beam reached the bottom of the viewing area? if (V_count <= 479) Then video_on_V <= '1'; else video_on_V <= '0'; end if; end if; -- End Wait until clock end process VIDEO_DISPLAY; calculation : process ( Clock ) -- This section does the calculation for the horizontal line display -- for the distance. variable dist_temp : integer; begin wait until rising_edge( Clock ); dist_temp := (Dist_in/8192); line_dist <= dist_temp; end process calculation; end behavior;