L
Lukáš Král
Hello everybody , i am new to VHDL and i need somebody to verify that my code will work. It should draw 6 squares (different colors) on VESA 800x600 @72Hz monitor. Pix.clock is 50 MHz. Please ignore comments (they are in my native language). Squares should be 100x100px. I need to know if this code would work when i use it on Spartan 3E Starter board. If you need more information then tell me. Thanks all who are willing to help and sorry for my imperfect English.
CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity kral_roc_cit is
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
Red : out STD_LOGIC;
Green : out STD_LOGIC;
Blue : out STD_LOGIC;
hs : out STD_LOGIC;
vs : out STD_LOGIC);
end kral_roc_cit;
architecture Behavioral of kral_roc_cit is
signal count_pixel : STD_LOGIC_VECTOR (10 downto 0) := (others=>'0') ;
signal count_radek : STD_LOGIC_VECTOR (9 downto 0) := (others=>'0');
signal R : STD_LOGIC := '0';
signal G : STD_LOGIC := '0';
signal B : STD_LOGIC := '0';
signal h_sync : STD_LOGIC := '0';
signal v_sync : STD_LOGIC := '0';
constant h_active : integer := 800;
constant h_front_porch : integer := 56;
constant h_back_porch : integer := 64;
constant h_total : integer := 1040;
constant v_active : integer := 600;
constant v_front_porch : integer := 37;
constant v_back_porch : integer := 23;
constant v_total : integer := 666;
begin
-- PoÄÃtánà pozice na řádku
process (clk)
begin
if reset = '1' then
count_pixel <= (others=>'0');
elsif clk'event and clk = '1' then
if count_pixel = (h_total - 1) then
count_pixel <= (others=>'0');
else
count_pixel <= count_pixel + 1;
end if;
end if;
end process;
-- Synchronizace řádku
process (clk)
begin
if reset = '1' then
h_sync <= '0';
elsif clk'event and clk = '1' then
if count_pixel = (h_active + h_front_porch -1) then
h_sync <= '1';
elsif count_pixel = (h_total - h_back_porch - 1) then
h_sync <= '0';
end if;
end if;
end process;
-- PoÄÃtánà pozice v rámci
process (clk)
begin
if reset = '1' then
count_radek <= (others=>'0');
elsif clk'event and clk = '1' then
if ((count_radek = v_total - 1) and (count_pixel = h_total - 1)) then
count_radek <= (others=>'0');
elsif count_pixel = (h_total - 1) then
count_radek <= count_radek + 1;
end if;
end if;
end process;
-- Synchronizace rámců
process (clk)
begin
if reset = '1' then
v_sync <= '0';
elsif clk'event and clk = '1' then
if count_radek = (v_active + v_front_porch -1) and
count_pixel = (h_total - 1) then
v_sync <= '1';
elsif count_radek = (v_total - v_back_porch - 1) and
count_pixel = (h_total - 1) then
v_sync <= '0';
end if;
end if;
end process;
-- Barvenà Ätverců
process (clk)
begin
if clk'event and clk = '1' then
-- Barvenà Ätverce (1. - green - tÅ™età řádek )
if (count_pixel >= "00010011011" ) -- 100 + h_front_porch -1 (155)
and (count_pixel <= "00011111111" ) -- 200 + h_front_porch -1 (255)
and (count_radek >= "0101100100" ) -- 320 + v_front_porch -1 (356)
and (count_radek <= "0111001000" ) -- 420 + v_front_porch -1 (456)
then
G <= '1';
-- Barvenà Ätverce (2. - yellow - prvnà řádek)
elsif (count_pixel >= "00011111111" ) -- 200 + h_front_porch -1 (255)
and (count_pixel <= "00101100011" ) -- 300 + h_front_porch -1 (355)
and (count_radek >= "0001001100" ) -- 40 + v_front_porch -1 (76)
and (count_radek <= "0010110000" ) -- 140 + v_front_porch -1 (176)
then
R <= '1';
G <= '1';
-- Barvenà Ätverce (3. - white - druhý řádek)
elsif (count_pixel >= "00101100011" ) -- 300 + h_front_porch -1 (355)
and (count_pixel <= "00111000111" ) -- 400 + h_front_porch -1 (455)
and (count_radek >= "0011011000" ) -- 180 + v_front_porch -1 (216)
and (count_radek <= "0100111100" ) -- 280 + v_front_porch -1 (316)
then
R <= '1';
G <= '1';
B <= '1';
-- Barvenà Ätverce (4. - cyan - prvnà řádek)
elsif (count_pixel >= "00111000111" ) -- 400 + h_front_porch -1 (455)
and (count_pixel <= "01000101011" ) -- 500 + h_front_porch -1 (555)
and (count_radek >= "0001001100" ) -- 40 + v_front_porch -1 (76)
and (count_radek <= "0010110000" ) -- 140 + v_front_porch -1 (176)
then
G <= '1';
B <= '1';
-- Barvenà Ätverce (5. - white - Ätvrtý řádek)
elsif (count_pixel >= "01000101011" ) -- 500 + h_front_porch -1 (555)
and (count_pixel <= "01010001111" ) -- 600 + h_front_porch -1 (655)
and (count_radek >= "0111110000" ) -- 460 + v_front_porch -1 (496)
and (count_radek <= "1001010100" ) -- 560 + v_front_porch -1 (596)
then
G <= '1';
B <= '1';
R <= '1';
-- Barvenà Ätverce (6. - green - druhý řádek)
elsif (count_pixel >= "01010001111" ) -- 600 + h_front_porch -1 (655)
and (count_pixel <= "01011110011" ) -- 700 + h_front_porch -1 (755)
and (count_radek >= "0011011000" ) -- 180 + v_front_porch -1 (216)
and (count_radek <= "0100111100" ) -- 280 + v_front_porch -1 (316)
then
G <= '1';
else
G <= '0';
B <= '0';
R <= '0';
end if;
end if;
end process;
-- Připojenà výstupů
Red <= R ;
Green <= G ;
Blue <= B ;
hs <= h_sync ;
vs <= v_sync ;
end Behavioral;
CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity kral_roc_cit is
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
Red : out STD_LOGIC;
Green : out STD_LOGIC;
Blue : out STD_LOGIC;
hs : out STD_LOGIC;
vs : out STD_LOGIC);
end kral_roc_cit;
architecture Behavioral of kral_roc_cit is
signal count_pixel : STD_LOGIC_VECTOR (10 downto 0) := (others=>'0') ;
signal count_radek : STD_LOGIC_VECTOR (9 downto 0) := (others=>'0');
signal R : STD_LOGIC := '0';
signal G : STD_LOGIC := '0';
signal B : STD_LOGIC := '0';
signal h_sync : STD_LOGIC := '0';
signal v_sync : STD_LOGIC := '0';
constant h_active : integer := 800;
constant h_front_porch : integer := 56;
constant h_back_porch : integer := 64;
constant h_total : integer := 1040;
constant v_active : integer := 600;
constant v_front_porch : integer := 37;
constant v_back_porch : integer := 23;
constant v_total : integer := 666;
begin
-- PoÄÃtánà pozice na řádku
process (clk)
begin
if reset = '1' then
count_pixel <= (others=>'0');
elsif clk'event and clk = '1' then
if count_pixel = (h_total - 1) then
count_pixel <= (others=>'0');
else
count_pixel <= count_pixel + 1;
end if;
end if;
end process;
-- Synchronizace řádku
process (clk)
begin
if reset = '1' then
h_sync <= '0';
elsif clk'event and clk = '1' then
if count_pixel = (h_active + h_front_porch -1) then
h_sync <= '1';
elsif count_pixel = (h_total - h_back_porch - 1) then
h_sync <= '0';
end if;
end if;
end process;
-- PoÄÃtánà pozice v rámci
process (clk)
begin
if reset = '1' then
count_radek <= (others=>'0');
elsif clk'event and clk = '1' then
if ((count_radek = v_total - 1) and (count_pixel = h_total - 1)) then
count_radek <= (others=>'0');
elsif count_pixel = (h_total - 1) then
count_radek <= count_radek + 1;
end if;
end if;
end process;
-- Synchronizace rámců
process (clk)
begin
if reset = '1' then
v_sync <= '0';
elsif clk'event and clk = '1' then
if count_radek = (v_active + v_front_porch -1) and
count_pixel = (h_total - 1) then
v_sync <= '1';
elsif count_radek = (v_total - v_back_porch - 1) and
count_pixel = (h_total - 1) then
v_sync <= '0';
end if;
end if;
end process;
-- Barvenà Ätverců
process (clk)
begin
if clk'event and clk = '1' then
-- Barvenà Ätverce (1. - green - tÅ™età řádek )
if (count_pixel >= "00010011011" ) -- 100 + h_front_porch -1 (155)
and (count_pixel <= "00011111111" ) -- 200 + h_front_porch -1 (255)
and (count_radek >= "0101100100" ) -- 320 + v_front_porch -1 (356)
and (count_radek <= "0111001000" ) -- 420 + v_front_porch -1 (456)
then
G <= '1';
-- Barvenà Ätverce (2. - yellow - prvnà řádek)
elsif (count_pixel >= "00011111111" ) -- 200 + h_front_porch -1 (255)
and (count_pixel <= "00101100011" ) -- 300 + h_front_porch -1 (355)
and (count_radek >= "0001001100" ) -- 40 + v_front_porch -1 (76)
and (count_radek <= "0010110000" ) -- 140 + v_front_porch -1 (176)
then
R <= '1';
G <= '1';
-- Barvenà Ätverce (3. - white - druhý řádek)
elsif (count_pixel >= "00101100011" ) -- 300 + h_front_porch -1 (355)
and (count_pixel <= "00111000111" ) -- 400 + h_front_porch -1 (455)
and (count_radek >= "0011011000" ) -- 180 + v_front_porch -1 (216)
and (count_radek <= "0100111100" ) -- 280 + v_front_porch -1 (316)
then
R <= '1';
G <= '1';
B <= '1';
-- Barvenà Ätverce (4. - cyan - prvnà řádek)
elsif (count_pixel >= "00111000111" ) -- 400 + h_front_porch -1 (455)
and (count_pixel <= "01000101011" ) -- 500 + h_front_porch -1 (555)
and (count_radek >= "0001001100" ) -- 40 + v_front_porch -1 (76)
and (count_radek <= "0010110000" ) -- 140 + v_front_porch -1 (176)
then
G <= '1';
B <= '1';
-- Barvenà Ätverce (5. - white - Ätvrtý řádek)
elsif (count_pixel >= "01000101011" ) -- 500 + h_front_porch -1 (555)
and (count_pixel <= "01010001111" ) -- 600 + h_front_porch -1 (655)
and (count_radek >= "0111110000" ) -- 460 + v_front_porch -1 (496)
and (count_radek <= "1001010100" ) -- 560 + v_front_porch -1 (596)
then
G <= '1';
B <= '1';
R <= '1';
-- Barvenà Ätverce (6. - green - druhý řádek)
elsif (count_pixel >= "01010001111" ) -- 600 + h_front_porch -1 (655)
and (count_pixel <= "01011110011" ) -- 700 + h_front_porch -1 (755)
and (count_radek >= "0011011000" ) -- 180 + v_front_porch -1 (216)
and (count_radek <= "0100111100" ) -- 280 + v_front_porch -1 (316)
then
G <= '1';
else
G <= '0';
B <= '0';
R <= '0';
end if;
end if;
end process;
-- Připojenà výstupů
Red <= R ;
Green <= G ;
Blue <= B ;
hs <= h_sync ;
vs <= v_sync ;
end Behavioral;