display on vga without sdram

17
Display on VGA without SDRAM The problem: I want to display dynamic characters on the screen. The normal work is to use a SDRAM to save the contents of the VGA matrix. If I will use 680 * 460 so I have to use matrix 680*460 of 3 bytes for the red and green and blue. But I will make it simple and will use 2 colors so I just need 1 bit. So I can design a matrix using VHDL which will be 680*640. Oh, there is another problem. It takes too much time to synthesize the code because every bit is connected as a signal. How can I solve this?? I had a nice idea. I will show the char in 10*10 bit. So the 680*460 matrix can be only 86*46. it will take no time in systemization. I considered the 86*46 matrix as a pointer which point at the small matrices. Why did I do that? I wanted to make a complete system which contain (keyboard, VGA, UART, GPIO, LCD and soft-processor). I have already design the rest of the system but I want to make it completely. Well, I don't like to talk much. Just look at the code. It is for Spartan 3E for simplification. You may notice some weird things. For example I wanted to divide an integer by 10 but this is a problem in VHDL. So I did it using for loop. By make a counter that count by 10 and notice the equalization. Anyway, this is the code. It is not the final code but you will see some alphabets in some places in the screen. You just have to get an input from outside to write on the screen wherever you want.

Upload: muhammad

Post on 14-Nov-2014

105 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Display on VGA without SDRAM

Display on VGA without SDRAM

The problem: I want to display dynamic characters on the screen. The normal work is to use a SDRAM to save the contents of the VGA matrix. If I will use 680 * 460 so I have to use matrix 680*460 of 3 bytes for the red and green and blue.

But I will make it simple and will use 2 colors so I just need 1 bit. So I can design a matrix using VHDL which will be 680*640. Oh, there is another problem. It takes too much time to synthesize the code because every bit is connected as a signal.

How can I solve this??

I had a nice idea. I will show the char in 10*10 bit. So the 680*460 matrix can be only 86*46. it will take no time in systemization. I considered the 86*46 matrix as a pointer which point at the small matrices.

Why did I do that?

I wanted to make a complete system which contain (keyboard, VGA, UART, GPIO, LCD and soft-processor). I have already design the rest of the system but I want to make it completely.

Well, I don't like to talk much. Just look at the code. It is for Spartan 3E for simplification.

You may notice some weird things. For example I wanted to divide an integer by 10 but this is a problem in VHDL. So I did it using for loop. By make a counter that count by 10 and notice the equalization.

Anyway, this is the code. It is not the final code but you will see some alphabets in some places in the screen. You just have to get an input from outside to write on the screen wherever you want.

Page 2: Display on VGA without SDRAM

------------------------------------------------------------------------------------ Company: -- Engineer: -- -- Create Date: 15:40:42 12/08/2008 -- Design Name: -- Module Name: Sync_XY_generator - Behavioral -- Project Name: -- Target Devices: -- Tool versions: -- Description: ---- Dependencies: ---- Revision: -- Revision 0.01 - File Created-- Additional Comments: ------------------------------------------------------------------------------------library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;use ieee.numeric_std.all;use ieee.math_real.all;---- Uncomment the following library declaration if instantiating---- any Xilinx primitives in this code.--library UNISIM;--use UNISIM.VComponents.all;

entity vga is Port ( CLK50_in : in STD_LOGIC; HS : out STD_LOGIC; VS : out STD_LOGIC; r,g,b : out std_logic);end vga;

architecture Behavioral of vga is

------- signals declarationssignal clk25: std_logic;signal H_counter_value : integer;--std_logic_vector(9 downto 0);signal V_counter_value : integer;--std_logic_vector(9 downto 0);signal x : integer range 0 to 640; --std_logic_vector(9 downto 0);signal y : integer range 0 to 640; -- std_logic_vector(9 downto 0);signal c:std_logic_vector(7 downto 0);signal xx,yy :integer;shared variable xd,yd:integer;

Page 3: Display on VGA without SDRAM

signal data:std_logic_vector(0 to 9);--constant c_x_l : integer := 320 ;--constant c_x_r: integer := 327;--constant c_y_u : integer := 150 ;--constant c_y_d: integer := 157 ;

--signal gdata: std_logic_vector(7 downto 0):="11110000";signal obj_rgb:std_logic_vector(2 downto 0) := "001";--signal obj2_rgb:std_logic_vector(2 downto 0) := "010";--signal ball_rgb:std_logic_vector(2 downto 0) := "011";--signal a_on,b_on,c_on:std_logic; --signal tick:std_logic;--signal counter2:integer:=0;--subtype tmp is integer; type memory_array is array ( 0 to 9 ) of std_logic_vector (0 to 9 ) ;

subtype tmp is std_logic_vector( 7 downto 0); type memory is array(integer range 0 to 64,integer range 0 to 48) of tmp; signal mem:memory;

constant am : memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110000110", -- "0110000110" , -- "0111111110", -- "0111111110", --"0110000110", -- "0110000110", -- "0000000000" );constant bm : memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110000110", -- "0110000110" , -- "0111111100", -- "0110000110", --"0110000110", -- "0111111110",-- "0000000000" );

constant cm: memory_array:= ("0000000000",

Page 4: Display on VGA without SDRAM

"0111111110", --"0111111110" , -- "0110000000", -- "0110000000" , -- "0110000000", -- "0110000000", --"0111111110", -- "0111111110", -- "0000000000" );

constant dm: memory_array:= ("0000000000","0111111100", --"0111111110" , -- "0110000110", -- "0110000110" , -- "0110000110", -- "0110000110", --"0111111110", -- "0111111100", -- "0000000000" );constant em: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110000000", -- "0111111110" , -- "0111111110", -- "0110000000", --"0111111110", -- "0111111110", -- "0000000000" );constant fm: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110000000", -- "0110000000" , -- "0111111110", -- "0111111110", --"0110000000", -- "0110000000", -- "0000000000" );constant gm: memory_array:= ("0000000000","0111111110", --

Page 5: Display on VGA without SDRAM

"0111111110" , -- "0110000000", -- "0110000000" , -- "0110011110", -- "0110011110", --"0111111110", -- "0111111110", -- "0000000000" );constant hm: memory_array:= ("0000000000","0110000110", --"0110000110" , -- "0110000110", -- "0111111110" , -- "0111111110", -- "0110000110", --"0110000110", -- "0110000110", -- "0000000000" );constant im: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110000000", -- "0110000000" , -- "0110000000", -- "0110000000", --"0111111110", -- "0111111110", -- "0000000000" );constant jm: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110110000", -- "0110110000" , -- "0110110000", -- "0000110000", --"0111111110", -- "0111111110", -- "0000000000" );constant km: memory_array:= ("0000000000","0110000110", --"0110001100" , -- "0110011000", --

Page 6: Display on VGA without SDRAM

"0110110000" , -- "0111100000", -- "0110011000", --"0110001100", -- "0110000110", -- "0000000000" );constant lm: memory_array:= ("0000000000","0110000000", --"0110000000" , -- "0110000000", -- "0110000000" , -- "0110000000", -- "0110000000", --"0111111110", -- "0111111110", -- "0000000000" );constant mm: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110110110", -- "0110110110" , -- "0110110110", -- "0110110110", --"0110110110", -- "0110110110", -- "0000000000" );constant nm: memory_array:= ("0000000000","0111000110", --"0111000110" , -- "0110110110", -- "0110110110" , -- "0110110110", -- "0110011110", --"0110001110", -- "0110001110", -- "0000000000" );constant om: memory_array:= ("0000000000","0011111100", --"0111111110" , -- "0110000110", -- "0110000110" , -- "0110000110", --

Page 7: Display on VGA without SDRAM

"0110000110", --"0111111110", -- "0011111100", -- "0000000000" );constant pm: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110000110", -- "0111111110" , -- "0111111110", -- "0110000000", --"0110000000", -- "0110000000", -- "0000000000" );constant qm: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110000110", -- "0110000110" , -- "0110000110", -- "0110110110", --"0101111010", -- "0001111000", -- "0000000000" );constant rm: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110000110", -- "0110000110" , -- "0111111110", -- "0110110000", --"0110001100", -- "0110000110", -- "0000000000" );constant sm: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0110000000", -- "0111111100" , -- "0011111110", -- "0000000110", --"0111111110", --

Page 8: Display on VGA without SDRAM

"0111111110", -- "0000000000" );constant tm: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0000110000", -- "0000110000" , -- "0000110000", -- "0000110000", --"0000110000", -- "0000110000", -- "0000000000" );constant um: memory_array:= ("0000000000","0110000110", --"0110000110" , -- "0110000110", -- "0110000110" , -- "0110000110", -- "0110000110", --"0111111110", -- "0111111110", -- "0000000000" );constant vm: memory_array:= ("0000000000","0110000110", --"0110000110" , -- "0110000110", -- "0011001100" , -- "0011001100", -- "0001101100", --"0001111000", -- "0000110000", -- "0000000000" );constant wm: memory_array:= ("0000000000","0110110110", --"0110110110" , -- "0110110110", -- "0110110110" , -- "0110110110", -- "0110110110", --"0111111110", -- "0111111110", -- "0000000000"

Page 9: Display on VGA without SDRAM

);constant xm: memory_array:= ("0000000000","0110000110", --"0110000110" , -- "0011001100", -- "0001111000" , -- "0001111000", -- "0011001100", --"0110001110", -- "0110000110", -- "0000000000" );constant ym: memory_array:= ("0000000000","0110000110", --"0110000110" , -- "0011001100", -- "0001111000" , -- "0000110000", -- "0000110000", --"0000110000", -- "0000110000", -- "0000000000" );constant zm: memory_array:= ("0000000000","0111111110", --"0111111110" , -- "0000011100", -- "0000111000" , -- "0001110000", -- "0011100000", --"0111111110", -- "0111111110", -- "0000000000" );constant spa: memory_array:= ("0000000000","0000000000", --"0000000000", -- "0000000000",-- "0000000000", -- "0000000000",-- "0000000000",--"0000000000",-- "0000000000", -- "0000000000" );begin

Page 10: Display on VGA without SDRAM

--a_on <=--'1' when (a_x_l <= x ) and (x <= a_x_r) and (a_y_u <=y) and (a_y_d >= y) else--'0';

--b_on <=--'1' when (b_x_l <= x ) and (x <= b_x_r) and (b_y_u <=y) and (b_y_d >= y) else--'0';

--c_on <=--'1' when (c_x_l <= x ) and (x <= c_x_r) and (c_y_u <=y) and (c_y_d >= y) else--'0';

-- generate a 25Mhz clock divide_by_two_counter :process (clk50_in) begin if clk50_in'event and clk50_in='1' thenclk25 <= not clk25;end if;end process;

-- generate the tick for the refreshment of the object position--counter :process (clk50_in) -- begin -- if clk50_in'event and clk50_in='1' then--counter2<=counter2 + 1;--tick<='0';--end if;--if counter2<=50000000 then --counter2<=0;--tick<='1';--end if;--end process;

--process(clk50_in,tick)--begin--if tick='1' then--ball_x_r <= ball_x_r + 1;--ball_x_l <= ball_x_l + 1;--end if;--if ball_x_r = 510 then--ball_x_r <=100;--ball_x_l <=107;--end if;--end process;

HS_VS_generator :process (clk25)

Page 11: Display on VGA without SDRAM

beginif clk25'event and clk25='1' thenH_counter_value <= H_counter_value +1;if (H_counter_value = 800)thenH_counter_value <= 0; V_counter_value <= V_counter_value +1;end if;if (V_counter_value = 521)thenV_counter_value <= 0;end if;

x <= H_counter_value-144;y <= V_counter_value-31;

--if (H_counter_value >=144 and H_counter_value < 783 and V_counter_value >=31 and V_counter_value <510) then-- if((x>=0)and(x<256)and(y>=0)and(y<256))then

-- addr<=addr+1;-- ena<='1';-- r<='0';b<='0';--g<=(others=>'0');-- g<='1';--else-- r<='1';b<='0';g<='0';addr<="0000000000000000";-- ena<='0';

-- end if;--else-- r<='0';g<='0';b<='0';addr<="0000000000000000";

--reed<='0';ena<='0';--end if;if (H_counter_value < 96)thenHS <= '0';else HS <= '1'; end if;if (V_counter_value < 2)thenVS <= '0';elseVS <= '1';end if;end if;end process;

-------process(clk25,a_on,b_on,c_on)--variable x_object,y_object :integer;--variable d:std_logic;

--variable mem:memory_array;--begin

Page 12: Display on VGA without SDRAM

--if clk25'event and clk25='0' then--if a_on ='1' then--x_object:= x - a_x_l ;--y_object:= y - a_y_u ;--data :=mem1(y_object);--c<= data (x_object);--mem(x)(y) <= mem1(x_object)(y_object);--elsif b_on ='1' then--x_object:= x - b_x_l;--y_object:= y - b_y_u;--data :=mem2(y_object);--c<= data (x_object);--mem(x)(y) <= mem2(x_object)(y_object);--elsif c_on='1' then--x_object:= x - c_x_l;--y_object:= y - c_y_u;--mem(x)(y) <= mem3(x_object)(y_object);--data :=mem3(y_object);--c<= data (x_object);--end if;--end if;--end process;

mem(0,0)<= "00000001";mem(1,0)<= "00000010";mem(0,3)<= "00000011";

mem(10,10)<= "00001100";mem(11,25)<= "00010110";mem(0,30)<= "00001011";

process(clk25,x,y)variable v,u:integer;begin

if clk25'event and clk25='1' thenfor n in 0 to 64 loopv:= n * 10;if v=x then xd:=n;end if;end loop;

for t in 0 to 64 loopu:= t * 10;if u=y then yd:=t;end if;end loop;

Page 13: Display on VGA without SDRAM

c<= mem (xd,yd);xx<= x - 10* xd;yy<=y - 10*yd;end if; end process;

with c select data<= am(yy) when "00000001", bm(yy) when "00000010", cm(yy) when "00000011", dm(yy) when "00000100", em(yy) when "00000101", fm(yy) when "00000110", gm(yy) when "00000111", hm(yy) when "00001000", im(yy) when "00001001",

jm(yy) when "00001010", km(yy) when "00001011",

lm(yy) when "00001100", mm(yy) when "00001101", nm(yy) when "00001110",

om(yy) when "00001111", pm(yy) when "00010000", qm(yy) when "00010001",

rm(yy) when "00010010", sm(yy) when "00010011",

tm(yy) when "00010100", um(yy) when "00010101", vm(yy) when "00010110", wm(yy) when "00010111",

xm(yy) when "00011000", ym(yy) when "00011001",

zm(yy) when "00011010", spa(yy) when others;

process(clk25,H_counter_value,V_counter_value,c)beginif (H_counter_value >=144 and H_counter_value < 783 and V_counter_value >=31 and V_counter_value <510) thenr<='0';b<=data(xx);g<='0';end if;end process;

end Behavioral;