You have no items in your shopping cart.

Subtotal: 0.00

Abstract

In this project, we present the design and implementation of efficient hardware architecture for VGA monitor controllers based on Spartan3 FPGA Image Processing Kit. The design implement the bouncing ball in the VGA monitor using VHDL Code The ability to provide multiple display resolutions (up to WXGA 1280× 800) and a customizable internal FIFO make the proposed architecture suitable for several FPGA devices. The output of the display produce bouncing ball with different colour making contact at the four sides of the monitor.

Demonstration Video

 

Tool required

Software:

Xilinx ISE 10.1i or above

Language:

⇛VHDL

Hardware:

Spartan3 FPGA Image Processing Kit

⇛JTAG Cable

⇛Monitor

Block Diagram for VGA Based Bouncing Ball interface using Spartan3 FPGA Image Processing Kit



Introduction

VGA display port through DB15 connector, Connect this port directly to most PC monitors or flat-panel LCD displays using a standard monitor cable As shown in table, VGA signals: RED (R) its 1ST pin in connector, GREEN (G) its 2nd pin, BLUE (B) its 3rd pin, Horizontal Sync (HS) 13th pin, and Vertical Sync (VS) its 14th pin, all available on the VGA connector. The standard VGA monitor consists of 640x480 pixel values. To display image in the LCD Monitor, pixel values need to be continuously on/off at certain frame rate.

The following table describes pin details of DB15 VGA Connector

The following table describes the color production by 3-bit VGA monitor Signals.

Interfacing VGA with Spartan3 FPGA Development Kit

VGA interface with FPGA is performed by placing 270 OHM Resister value serial to FPGA pin R, G, B. The Remaining 2 pins, Horizontal Sync and Vertical Sync taking care of timing of scan rate. Horizontal Sync performs controlling operation for start and end of line pixel is displaying on the visible area of the monitor. Similarly Vertical Sync performs controlling operation for Start and End of Frame is displaying on the top and bottom visible area of the monitor.


Bouncing Ball Output Image

Bouncing Ball Output Image

 

Bouncing Ball Output Image

Bouncing Ball Output Image

Source Code

VHDL Code for VGA Bouncing Ball using Spartan3 FPGA Image Processing Kit

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity BouncingBall is
port ( CLK_50MHz: in std_logic;
VS: out std_logic;
HS: out std_logic;
RED: out std_logic_vector(2 downto 0);
GREEN: out std_logic_vector(2 downto 0);
BLUE: out std_logic_vector(2 downto 1);
RESET: in std_logic;
SQUAREWIDTH: in std_logic_vector(7 downto 0)
);
end BouncingBall;

architecture Behavioral of BouncingBall is
-- VGA Definitions starts
constant HDisplayArea: integer:= 800; -- horizontal display area
constant HLimit: integer:= 1040; -- maximum horizontal amount (limit)
constant HFrontPorch: integer:= 56; -- h. front porch
constant HBackPorch: integer:= 64;	-- h. back porch
constant HSyncWidth: integer:= 120;	-- h. pulse width
constant VDisplayArea: integer:= 600; -- vertical display area
constant VLimit: integer:= 666; -- maximum vertical amount (limit)
constant VFrontPorch: integer:= 37;	-- v. front porch
constant VBackPorch: integer:= 23;	-- v. back porch
constant VSyncWidth: integer:= 6;	-- v. pulse width       

signal HBlank, VBlank, Blank: std_logic := '0';
	 
signal CurrentHPos: std_logic_vector(10 downto 0) := (others => '0'); -- goes to 1100100000 = 800
signal CurrentVPos: std_logic_vector(10 downto 0) := (others => '0'); -- goes to 1000001101 = 525
signal ScanlineX, ScanlineY: std_logic_vector(10 downto 0);

signal ColorOutput: std_logic_vector(7 downto 0);
-- VGA Definitions end


signal SquareX: std_logic_vector(9 downto 0) := "0111000101";  
signal SquareY: std_logic_vector(9 downto 0) := "0001100010";  
signal SquareXMoveDir, SquareYMoveDir: std_logic := '0';

--signal SquareWidth: std_logic_vector(6 downto 0)      := "0011110";

constant SquareXmin: std_logic_vector(9 downto 0) := "0000000001";
signal SquareXmax: std_logic_vector(9 downto 0) := "1100100000"-SquareWidth;
constant SquareYmin: std_logic_vector(9 downto 0) := "0000000001";
signal SquareYmax: std_logic_vector(9 downto 0) := "1001011000"-SquareWidth;
signal ColorSelect: std_logic_vector(2 downto 0) := "001";
signal Prescaler: std_logic_vector(30 downto 0) := (others => '0');
signal Prescaler2: std_logic_vector(30 downto 0) := (others => '0');



begin

PrescalerCounter: process(CLK_50Mhz, RESET)
begin
if RESET = '1' then
Prescaler <= (others => '0');
SquareX <= "0111000101";
SquareY <= "0001100010";
SquareXMoveDir <= '0';
SquareYMoveDir <= '0';
ColorSelect <= "001";
elsif rising_edge(CLK_50Mhz) then
Prescaler <= Prescaler + 1;	 
if Prescaler = "11000011010100000" then  -- Activated every 0,002 sec (2 msec)
if SquareXMoveDir = '0' then
 if SquareX < SquareXmax then
	SquareX <= SquareX + 1;
 else
	SquareXMoveDir <= '1';
	ColorSelect <= ColorSelect(1 downto 0) & ColorSelect(2);
 end if;
else
 if SquareX > SquareXmin then
	SquareX <= SquareX - 1;
 else
	SquareXMoveDir <= '0';
	ColorSelect <= ColorSelect(1 downto 0) & ColorSelect(2);
 end if;	 
end if;

if SquareYMoveDir = '0' then
 if SquareY < SquareYmax then
	SquareY <= SquareY + 1;
 else
	SquareYMoveDir <= '1';
	ColorSelect <= ColorSelect(1 downto 0) & ColorSelect(2);
 end if;
else
 if SquareY > SquareYmin then
	SquareY <= SquareY - 1;
 else
	SquareYMoveDir <= '0';
	ColorSelect <= ColorSelect(1 downto 0) & ColorSelect(2);
 end if;	 
end if;		  


Prescaler <= (others => '0');
end if;
end if;
end process PrescalerCounter; 




VGAPosition: process (CLK_50MHz, RESET)
begin
if RESET = '1' then
CurrentHPos <= (others => '0');
CurrentVPos <= (others => '0');
elsif rising_edge(CLK_50MHz) then
if CurrentHPos < HLimit-1 then
CurrentHPos <= CurrentHPos + 1;
else
if CurrentVPos < VLimit-1 then
 CurrentVPos <= CurrentVPos + 1;
else
 CurrentVPos <= (others => '0'); -- reset Vertical Position
end if;
CurrentHPos <= (others => '0'); -- reset Horizontal Position
end if;
end if;
end process VGAPosition;

-- Timing definition for HSync, VSync and Blank (http://tinyvga.com/vga-timing/640x480@60Hz)
HS <= '0' when CurrentHPos < HSyncWidth else
  '1';

VS <= '0' when CurrentVPos < VSyncWidth else
  '1';

HBlank <= '0' when (CurrentHPos >= HSyncWidth + HFrontPorch) and (CurrentHPos < HSyncWidth + HFrontPorch + HDisplayArea) else
	  '1';
	  
VBlank <= '0' when (CurrentVPos >= VSyncWidth + VFrontPorch) and (CurrentVPos < VSyncWidth + VFrontPorch + VDisplayArea) else
	  '1';				  

Blank <= '1' when HBlank = '1' or VBlank = '1' else
	  '0';

ScanlineX <= CurrentHPos - HSyncWidth - HFrontPorch when Blank = '0' else
			(others => '0');

ScanlineY <= CurrentVPos - VSyncWidth - VFrontPorch when Blank = '0' else
			(others => '0');	

RED <= ColorOutput(7 downto 5) when Blank = '0' else
	"000";	  
GREEN <= ColorOutput(4 downto 2) when Blank = '0' else
	"000";				
BLUE <= ColorOutput(1 downto 0) when Blank = '0' else
	"00";								


ColorOutput <= "11100000" when ColorSelect(0) = '1' AND ScanlineX >= SquareX AND ScanlineY >= SquareY AND ScanlineX < SquareX+SquareWidth AND ScanlineY < SquareY+SquareWidth else          
		  "00011100" when ColorSelect(1) = '1' AND ScanlineX >= SquareX AND ScanlineY >= SquareY AND ScanlineX < SquareX+SquareWidth AND ScanlineY < SquareY+SquareWidth else          
		  "00000011" when ColorSelect(2) = '1' AND ScanlineX >= SquareX AND ScanlineY >= SquareY AND ScanlineX < SquareX+SquareWidth AND ScanlineY < SquareY+SquareWidth else          					  
		  "11111111";
		  
SquareXmax <= "1100100000"-SquareWidth;
SquareYmax <= "1001011000"-SquareWidth;			

end Behavioral;

User Constraint File for Bouncing Ball VHDL Code

NET "CLK_50MHz" LOC = "M6";

#NET "RST" LOC = "p71";

# Pin assignment for VGA NET "HS" LOC = "p93" ;

NET "VS" LOC = "p92" ;

NET "RED" LOC = "p95" ;

NET "GREEN" LOC = "p96" NET "BLUE" LOC = "p97" ;

NET "RESET" LOC = "p70";

NET "SQUAREWIDTH" LOC = "p82";

NET "SQUAREWIDTH" LOC = "p83";

NET "SQUAREWIDTH" LOC = "p84";

NET "SQUAREWIDTH" LOC = "p85";

NET "SQUAREWIDTH" LOC = "p86";

NET "SQUAREWIDTH" LOC = "p87";

NET "SQUAREWIDTH" LOC = "p89";

NET "SQUAREWIDTH" LOC = "p90";

Conclusion

As a result of implementation, the output of the display produce bouncing ball with different colour making contact at the four sides of the monitor. Able to meet different requirements of targeted applications.