1 -------------------------------------------------------------------------------
3 -- File : rgb3sx8_to_gs.vhd
6 -- Author(s) : stephane Domas (sdomas@univ-fcomte.fr)
8 -- Creation Date : 2017/10/16
10 -- Description : This IP does a conversion from rgb24 (8 bits/serial) to grayscale
12 -- Note : rgb24 (8 bits/serial) pixels are composed of three 8 bits
13 -- values that are consumed on port rgb_in, in the following
14 -- order : blue, green, red.
15 -- output value on gs_out is computed with (red+green+blue)/3
17 -------------------------------------------------------------------------------
20 use IEEE.std_logic_1164.all;
21 use IEEE.numeric_std.all;
23 entity rgb3sx8_to_gs is
25 dsp_in_width : natural := 18;
26 dsp_out_width : natural := 36
31 rgb_in : in std_logic_vector(7 downto 0);
32 rgb_in_enb : in std_logic;
33 gs_out : out std_logic_vector(7 downto 0);
34 gs_out_enb : out std_logic
40 architecture rtl of rgb3sx8_to_gs is
43 signal do_mult : std_logic;
44 signal do_out : std_logic;
45 signal count : unsigned (2 downto 0);
46 signal accum : unsigned(dsp_in_width-1 downto 0);
47 signal result : unsigned(dsp_out_width-1 downto 0);
48 signal cst_mult : unsigned(dsp_in_width-1 downto 0); -- eq. 87382 to do /3
52 cst_mult <= to_unsigned(87382, 18);
54 accum_process : process (clk, reset)
57 count <= to_unsigned(0, 3);
58 accum <= to_unsigned(0, dsp_in_width);
61 elsif rising_edge(clk) then
65 if rgb_in_enb = '1' then
68 accum <= resize(unsigned(rgb_in), dsp_in_width);
69 count <= to_unsigned(1, 3);
71 accum <= accum + resize(unsigned(rgb_in), dsp_in_width);
72 count <= to_unsigned(2, 3);
74 accum <= accum + resize(unsigned(rgb_in), dsp_in_width);
75 count <= to_unsigned(0, 3);
81 end process accum_process;
83 mult_process : process (clk, reset)
86 result <= to_unsigned(0, dsp_out_width);
88 elsif rising_edge(clk) then
92 result <= accum * cst_mult;
96 end process mult_process;
98 gs_out <= std_logic_vector(result(dsp_in_width+7 downto dsp_in_width));