-- -- Generates a color pattern of 4096 distinc colors to test a 4-bit DAC -- for VGA screen -- -- 2007 Javier Valcarce García, -- library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_ARITH.all; use IEEE.STD_LOGIC_UNSIGNED.all; entity dac_test is port ( reset : in std_logic; clk50MHz : in std_logic; R : out std_logic_vector(3 downto 0); G : out std_logic_vector(3 downto 0); B : out std_logic_vector(3 downto 0); hsync : out std_logic; vsync : out std_logic; refgnd : out std_logic); end dac_test; architecture arch of dac_test is signal R_int : std_logic_vector(03 downto 0); signal G_int : std_logic_vector(03 downto 0); signal B_int : std_logic_vector(03 downto 0); signal color : std_logic_vector(11 downto 0); signal row : std_logic_vector(05 downto 0); signal col : std_logic_vector(05 downto 0); signal min : std_logic; signal hctr : integer range 1586 downto 0; signal vctr : integer range 0524 downto 0; signal blank : std_logic; signal hsync_dummy : std_logic; signal vsync_dummy : std_logic; begin hsync <= hsync_dummy; vsync <= vsync_dummy; -- Horizontal counter process (reset, clk50MHz) begin if reset = '1' then hctr <= 0; elsif rising_edge(clk50MHz) then if hctr = 1586 then hctr <= 0; else hctr <= hctr + 1; end if; end if; end process; -- Vertical counter process (reset, clk50MHz) begin if reset = '1' then vctr <= 0; elsif rising_edge(clk50MHz) then if hctr = 1326 then if vctr = 524 then vctr <= 0; else vctr <= vctr + 1; end if; end if; end if; end process; -- HSYNC generation (active at low level) process (reset, clk50MHz) begin if reset = '1' then hsync_dummy <= '1'; elsif rising_edge(clk50MHz) then if hctr = 1326 then hsync_dummy <= '0'; end if; if hctr = 1514 then hsync_dummy <= '1'; end if; end if; end process; -- VSYNC generation (active at low level) process (clk50MHz, reset, vctr) begin if reset = '1' then vsync_dummy <= '1'; elsif rising_edge(clk50MHz) then if vctr = 500 then vsync_dummy <= '0'; end if; if vctr = 502 then vsync_dummy <= '1'; end if; end if; end process; -- blank signal generation, used for draw the white rectangle around the screen process (hctr, vctr) begin if ((hctr >= 1280) and (hctr <= 1586)) or ((vctr >= 0480) and (vctr <= 0524)) then blank <= '0'; else blank <= '1'; end if; end process; process (clk50MHz, reset) begin if reset = '1' then R <= "0000"; -- 4-bit DAC! G <= "0000"; -- 4-bit DAC! B <= "0000"; -- 4-bit DAC! elsif rising_edge(clk50MHz) then R <= R_int; G <= G_int; B <= B_int; end if; end process; -- Are we inside the mosaic of colors? min <= '1' when ((hctr > 0191) and (hctr < 1088) and (vctr > 0015) and (vctr < 464)) else '0'; -- What column are we? Each square of color is 7x7 pixels col <= "000000" when ((hctr >= 191) and (hctr < 205)) else "000001" when ((hctr >= 205) and (hctr < 219)) else "000010" when ((hctr >= 219) and (hctr < 233)) else "000011" when ((hctr >= 233) and (hctr < 247)) else "000100" when ((hctr >= 247) and (hctr < 261)) else "000101" when ((hctr >= 261) and (hctr < 275)) else "000110" when ((hctr >= 275) and (hctr < 289)) else "000111" when ((hctr >= 289) and (hctr < 303)) else "001000" when ((hctr >= 303) and (hctr < 317)) else "001001" when ((hctr >= 317) and (hctr < 331)) else "001010" when ((hctr >= 331) and (hctr < 345)) else "001011" when ((hctr >= 345) and (hctr < 359)) else "001100" when ((hctr >= 359) and (hctr < 373)) else "001101" when ((hctr >= 373) and (hctr < 387)) else "001110" when ((hctr >= 387) and (hctr < 401)) else "001111" when ((hctr >= 401) and (hctr < 415)) else "010000" when ((hctr >= 415) and (hctr < 429)) else "010001" when ((hctr >= 429) and (hctr < 443)) else "010010" when ((hctr >= 443) and (hctr < 457)) else "010011" when ((hctr >= 457) and (hctr < 471)) else "010100" when ((hctr >= 471) and (hctr < 485)) else "010101" when ((hctr >= 485) and (hctr < 499)) else "010110" when ((hctr >= 499) and (hctr < 513)) else "010111" when ((hctr >= 513) and (hctr < 527)) else "011000" when ((hctr >= 527) and (hctr < 541)) else "011001" when ((hctr >= 541) and (hctr < 555)) else "011010" when ((hctr >= 555) and (hctr < 569)) else "011011" when ((hctr >= 569) and (hctr < 583)) else "011100" when ((hctr >= 583) and (hctr < 597)) else "011101" when ((hctr >= 597) and (hctr < 611)) else "011110" when ((hctr >= 611) and (hctr < 625)) else "011111" when ((hctr >= 625) and (hctr < 639)) else "100000" when ((hctr >= 639) and (hctr < 653)) else "100001" when ((hctr >= 653) and (hctr < 667)) else "100010" when ((hctr >= 667) and (hctr < 681)) else "100011" when ((hctr >= 681) and (hctr < 695)) else "100100" when ((hctr >= 695) and (hctr < 709)) else "100101" when ((hctr >= 709) and (hctr < 723)) else "100110" when ((hctr >= 723) and (hctr < 737)) else "100111" when ((hctr >= 737) and (hctr < 751)) else "101000" when ((hctr >= 751) and (hctr < 765)) else "101001" when ((hctr >= 765) and (hctr < 779)) else "101010" when ((hctr >= 779) and (hctr < 793)) else "101011" when ((hctr >= 793) and (hctr < 807)) else "101100" when ((hctr >= 807) and (hctr < 821)) else "101101" when ((hctr >= 821) and (hctr < 835)) else "101110" when ((hctr >= 835) and (hctr < 849)) else "101111" when ((hctr >= 849) and (hctr < 863)) else "110000" when ((hctr >= 863) and (hctr < 877)) else "110001" when ((hctr >= 877) and (hctr < 891)) else "110010" when ((hctr >= 891) and (hctr < 905)) else "110011" when ((hctr >= 905) and (hctr < 919)) else "110100" when ((hctr >= 919) and (hctr < 933)) else "110101" when ((hctr >= 933) and (hctr < 947)) else "110110" when ((hctr >= 947) and (hctr < 961)) else "110111" when ((hctr >= 961) and (hctr < 975)) else "111000" when ((hctr >= 975) and (hctr < 989)) else "111001" when ((hctr >= 989) and (hctr < 1003)) else "111010" when ((hctr >= 1003) and (hctr < 1017)) else "111011" when ((hctr >= 1017) and (hctr < 1031)) else "111100" when ((hctr >= 1031) and (hctr < 1045)) else "111101" when ((hctr >= 1045) and (hctr < 1059)) else "111110" when ((hctr >= 1059) and (hctr < 1073)) else "111111" when ((hctr >= 1073) and (hctr < 1087)) else "XXXXXX"; -- What row are we? Each square of color is 7x7 pixels row <= "000000" when ((vctr >= 15) and (vctr < 22)) else "000001" when ((vctr >= 22) and (vctr < 29)) else "000010" when ((vctr >= 29) and (vctr < 36)) else "000011" when ((vctr >= 36) and (vctr < 43)) else "000100" when ((vctr >= 43) and (vctr < 50)) else "000101" when ((vctr >= 50) and (vctr < 57)) else "000110" when ((vctr >= 57) and (vctr < 64)) else "000111" when ((vctr >= 64) and (vctr < 71)) else "001000" when ((vctr >= 71) and (vctr < 78)) else "001001" when ((vctr >= 78) and (vctr < 85)) else "001010" when ((vctr >= 85) and (vctr < 92)) else "001011" when ((vctr >= 92) and (vctr < 99)) else "001100" when ((vctr >= 99) and (vctr < 106)) else "001101" when ((vctr >= 106) and (vctr < 113)) else "001110" when ((vctr >= 113) and (vctr < 120)) else "001111" when ((vctr >= 120) and (vctr < 127)) else "010000" when ((vctr >= 127) and (vctr < 134)) else "010001" when ((vctr >= 134) and (vctr < 141)) else "010010" when ((vctr >= 141) and (vctr < 148)) else "010011" when ((vctr >= 148) and (vctr < 155)) else "010100" when ((vctr >= 155) and (vctr < 162)) else "010101" when ((vctr >= 162) and (vctr < 169)) else "010110" when ((vctr >= 169) and (vctr < 176)) else "010111" when ((vctr >= 176) and (vctr < 183)) else "011000" when ((vctr >= 183) and (vctr < 190)) else "011001" when ((vctr >= 190) and (vctr < 197)) else "011010" when ((vctr >= 197) and (vctr < 204)) else "011011" when ((vctr >= 204) and (vctr < 211)) else "011100" when ((vctr >= 211) and (vctr < 218)) else "011101" when ((vctr >= 218) and (vctr < 225)) else "011110" when ((vctr >= 225) and (vctr < 232)) else "011111" when ((vctr >= 232) and (vctr < 239)) else "100000" when ((vctr >= 239) and (vctr < 246)) else "100001" when ((vctr >= 246) and (vctr < 253)) else "100010" when ((vctr >= 253) and (vctr < 260)) else "100011" when ((vctr >= 260) and (vctr < 267)) else "100100" when ((vctr >= 267) and (vctr < 274)) else "100101" when ((vctr >= 274) and (vctr < 281)) else "100110" when ((vctr >= 281) and (vctr < 288)) else "100111" when ((vctr >= 288) and (vctr < 295)) else "101000" when ((vctr >= 295) and (vctr < 302)) else "101001" when ((vctr >= 302) and (vctr < 309)) else "101010" when ((vctr >= 309) and (vctr < 316)) else "101011" when ((vctr >= 316) and (vctr < 323)) else "101100" when ((vctr >= 323) and (vctr < 330)) else "101101" when ((vctr >= 330) and (vctr < 337)) else "101110" when ((vctr >= 337) and (vctr < 344)) else "101111" when ((vctr >= 344) and (vctr < 351)) else "110000" when ((vctr >= 351) and (vctr < 358)) else "110001" when ((vctr >= 358) and (vctr < 365)) else "110010" when ((vctr >= 365) and (vctr < 372)) else "110011" when ((vctr >= 372) and (vctr < 379)) else "110100" when ((vctr >= 379) and (vctr < 386)) else "110101" when ((vctr >= 386) and (vctr < 393)) else "110110" when ((vctr >= 393) and (vctr < 400)) else "110111" when ((vctr >= 400) and (vctr < 407)) else "111000" when ((vctr >= 407) and (vctr < 414)) else "111001" when ((vctr >= 414) and (vctr < 421)) else "111010" when ((vctr >= 421) and (vctr < 428)) else "111011" when ((vctr >= 428) and (vctr < 435)) else "111100" when ((vctr >= 435) and (vctr < 442)) else "111101" when ((vctr >= 442) and (vctr < 449)) else "111110" when ((vctr >= 449) and (vctr < 456)) else "111111" when ((vctr >= 456) and (vctr < 463)) else "XXXXXX"; -- Draw the image color <= "111111111111" when (((hctr = 0) or (hctr = 1279)) and (blank = '1')) else "111111111111" when (((vctr = 0) or (vctr = 0479)) and (blank = '1')) else (col & row) when (min = '1') else "000000000000"; -- Ground terminal, this is not stricly necesary. We can also connect the VGA GND pin to some GND point in FPGA board, -- like the power connector refgnd <= '0'; R_int <= color(11 downto 8); G_int <= color(07 downto 4); B_int <= color(03 downto 0); end arch;