1 |
2 |
lfmunoz |
----------------------------------------------------------------------------------
|
2 |
|
|
-- Company: ISI/Nallatech
|
3 |
|
|
-- Engineer: Luis Munoz
|
4 |
|
|
-- Email: lfmunoz4@gmail.com
|
5 |
|
|
--
|
6 |
|
|
-- Create Date: 09:09:53 07/07/2011
|
7 |
|
|
--
|
8 |
|
|
-- Module Name: patternGen - Behavioral
|
9 |
|
|
--
|
10 |
|
|
-- Project Name: Video Pattern Generator
|
11 |
|
|
--
|
12 |
|
|
-- Target Devices: Xilinx Spartan-LX150T-2 using Xilinx ISE 13.1 and ISIM 13.1
|
13 |
|
|
--
|
14 |
|
|
-- Description: This module is meant to generate a video output
|
15 |
|
|
-- pattern 1-pixel at time to test any
|
16 |
|
|
-- form of video output stream. It uses simple counters
|
17 |
|
|
-- to generate the output.
|
18 |
|
|
--
|
19 |
|
|
--
|
20 |
|
|
-- Revision: 1.0 Initial Release
|
21 |
|
|
--
|
22 |
|
|
-- To do list: Automatically calculate the bar widths and counter register size
|
23 |
|
|
-- depending on the frame width and frame height. Right now this is
|
24 |
|
|
-- is a manual process and depeding on your frame size the strips
|
25 |
|
|
-- of the pattern might be too thin or too wide.
|
26 |
|
|
--
|
27 |
|
|
----------------------------------------------------------------------------------
|
28 |
|
|
library IEEE;
|
29 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
30 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
31 |
|
|
use IEEE.numeric_std.all;
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
entity patternGen is
|
35 |
|
|
generic(
|
36 |
|
|
FrameWidth : integer := 640; -- # of pixels per line
|
37 |
|
|
FrameHeight : integer := 512; -- # of lines in a frame
|
38 |
|
|
PIXEL_SIZE : integer := 8; -- # of bits each pixel has
|
39 |
|
|
REG_SIZE : integer := 16 -- # size of register to store width count and heigh count
|
40 |
|
|
);
|
41 |
|
|
port(
|
42 |
|
|
CLK_i : in std_logic; -- input clk
|
43 |
|
|
RST_i : in std_logic; -- reset module
|
44 |
|
|
SEL_i : in std_logic_vector(2 downto 0); -- select pattern to generate
|
45 |
|
|
CLKen_i : in std_logic; -- enables output or used to stall output
|
46 |
|
|
VALID_o : out std_logic; -- high on a valid pixel
|
47 |
|
|
ENDline_o : out std_logic; -- high on last pixel of a line
|
48 |
|
|
ENDframe_o : out std_logic; -- high on last pixel of a frame
|
49 |
|
|
PIXEL_o : out std_logic_vector(PIXEL_SIZE-1 downto 0) -- the actual pixel
|
50 |
|
|
);
|
51 |
|
|
|
52 |
|
|
end patternGen;
|
53 |
|
|
|
54 |
|
|
architecture Behavioral of patternGen is
|
55 |
|
|
-- constant declaration section
|
56 |
|
|
constant WIDTH : std_logic_vector(REG_SIZE-1 downto 0) :=
|
57 |
|
|
std_logic_vector(to_unsigned(FrameWidth, REG_SIZE)) - 1;
|
58 |
|
|
constant HEIGHT : std_logic_vector(REG_SIZE-1 downto 0) :=
|
59 |
|
|
std_logic_vector(to_unsigned(FrameHeight, REG_SIZE)) - 1;
|
60 |
|
|
constant BLACK : std_logic_vector(PIXEL_SIZE-1 downto 0) := (others=>'1');
|
61 |
|
|
constant WHITE : std_logic_vector(PIXEL_SIZE-1 downto 0) := (others=>'0');
|
62 |
|
|
-- signal declaration section
|
63 |
|
|
signal line_cnt : std_logic_vector(HEIGHT'length-1 downto 0);
|
64 |
|
|
signal frame_end : std_logic;
|
65 |
|
|
signal frame_end_temp : std_logic;
|
66 |
|
|
signal pixel_cnt : std_logic_vector(WIDTH'length-1 downto 0);
|
67 |
|
|
signal line_end : std_logic;
|
68 |
|
|
signal line_end_temp : std_logic;
|
69 |
|
|
signal left_cnt : std_logic_vector(WIDTH'length-1 downto 0);
|
70 |
|
|
signal down_cnt : std_logic_vector(HEIGHT'length-1 downto 0);
|
71 |
|
|
signal diag_cnt : std_logic_vector(WIDTH'length-1 downto 0);
|
72 |
|
|
signal pixel_cnt_off : std_logic_vector(WIDTH'length-1 downto 0);
|
73 |
|
|
signal line_cnt_off : std_logic_vector(HEIGHT'length-1 downto 0);
|
74 |
|
|
signal pixel : std_logic_vector(PIXEL_SIZE-1 downto 0);
|
75 |
|
|
signal valid : std_logic;
|
76 |
|
|
-- registered outputs signals
|
77 |
|
|
signal pixel_r : std_logic_vector(PIXEL_SIZE-1 downto 0);
|
78 |
|
|
signal line_end_r : std_logic;
|
79 |
|
|
signal frame_end_r : std_logic;
|
80 |
|
|
signal valid_r : std_logic;
|
81 |
|
|
signal color_sel : std_logic;
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
begin
|
85 |
|
|
------------------------------------------------------
|
86 |
|
|
--------------------------------------------------
|
87 |
|
|
-- register all output signals
|
88 |
|
|
--------------------------------------------------
|
89 |
|
|
process(CLK_i, RST_i)
|
90 |
|
|
begin
|
91 |
|
|
if rising_edge(CLK_i) then
|
92 |
|
|
if(RST_i = '1') then
|
93 |
|
|
pixel_r <= "10101010"; -- unmistakble reset value
|
94 |
|
|
line_end_r <= '0';
|
95 |
|
|
frame_end_r <= '0';
|
96 |
|
|
valid_r <= '0';
|
97 |
|
|
else
|
98 |
|
|
pixel_r <= pixel;
|
99 |
|
|
line_end_r <= line_end and CLKen_i;
|
100 |
|
|
frame_end_r <= frame_end and CLKen_i;
|
101 |
|
|
valid_r <= valid;
|
102 |
|
|
end if;
|
103 |
|
|
end if;
|
104 |
|
|
end process;
|
105 |
|
|
|
106 |
|
|
PIXEL_o <= pixel_r;
|
107 |
|
|
ENDline_o <= line_end_r;
|
108 |
|
|
ENDframe_o <= frame_end_r;
|
109 |
|
|
VALID_o <= valid_r;
|
110 |
|
|
--------------------------------------------------
|
111 |
|
|
-- pixel count within a line
|
112 |
|
|
--------------------------------------------------
|
113 |
|
|
pixel_counter: entity work.xcounter
|
114 |
|
|
generic map(
|
115 |
|
|
XVAL => WIDTH
|
116 |
|
|
)
|
117 |
|
|
port map(
|
118 |
|
|
CLK_i => CLK_i,
|
119 |
|
|
RST_i => RST_i,
|
120 |
|
|
CLKen_i => CLKen_i,
|
121 |
|
|
COUNT_o => pixel_cnt,
|
122 |
|
|
DONE_o => line_end_temp --signals last pixel of a line
|
123 |
|
|
);
|
124 |
|
|
-- only let line_end go high when enable is high,
|
125 |
|
|
-- this is needed because when you stalling the output
|
126 |
|
|
-- the pixel valid should go low.
|
127 |
|
|
line_end <= line_end_temp and CLKen_i;
|
128 |
|
|
--------------------------------------------------
|
129 |
|
|
-- line count within a frame
|
130 |
|
|
--------------------------------------------------
|
131 |
|
|
line_counter: entity work.xcounter
|
132 |
|
|
generic map(
|
133 |
|
|
XVAL => HEIGHT
|
134 |
|
|
)
|
135 |
|
|
port map(
|
136 |
|
|
CLK_i => CLK_i,
|
137 |
|
|
RST_i => RST_i,
|
138 |
|
|
CLKen_i => line_end, -- increment only when each line ends
|
139 |
|
|
COUNT_o => line_cnt,
|
140 |
|
|
DONE_o => frame_end_temp
|
141 |
|
|
);
|
142 |
|
|
-- this makes it so the frame_end signal goes
|
143 |
|
|
-- high only on the last pixel and not stay
|
144 |
|
|
-- high for the entire last line
|
145 |
|
|
frame_end <= frame_end_temp and line_end;
|
146 |
|
|
|
147 |
|
|
--------------------------------------------------
|
148 |
|
|
-- pattern select
|
149 |
|
|
--------------------------------------------------
|
150 |
|
|
|
151 |
|
|
with SEL_i select
|
152 |
|
|
color_sel <= '1' when "000", -- always black
|
153 |
|
|
pixel_cnt(4) when "001", -- vertical lines
|
154 |
|
|
line_cnt(5) when "010", -- horizontal lines
|
155 |
|
|
pixel_cnt_off(3) when "011", -- moving vertical lines
|
156 |
|
|
line_cnt_off(5) when "100", -- moving horizontal lines
|
157 |
|
|
pixel_cnt(3) and line_cnt(5) when "101", -- checker pattern (Not Completed)
|
158 |
|
|
diag_cnt(3) when "110", -- diagonal lines (Not Completed)
|
159 |
|
|
pixel_cnt(0) when OTHERS; -- rotate white / black
|
160 |
|
|
|
161 |
|
|
pixel <= WHITE when color_sel = '1' else BLACK;
|
162 |
|
|
valid <= '1' when RST_i = '0' else '0';
|
163 |
|
|
----------------------------------------------------
|
164 |
|
|
-- experimental diagonal pattern (place holder)
|
165 |
|
|
----------------------------------------------------
|
166 |
|
|
diag_cnt <= pixel_cnt + line_cnt;
|
167 |
|
|
--------------------------------------------------
|
168 |
|
|
-- counter to shift frame horizontally
|
169 |
|
|
--------------------------------------------------
|
170 |
|
|
left_shift_counter: entity work.xcounter
|
171 |
|
|
generic map(
|
172 |
|
|
XVAL => WIDTH
|
173 |
|
|
)
|
174 |
|
|
port map(
|
175 |
|
|
CLK_i => CLK_i,
|
176 |
|
|
RST_i => RST_i,
|
177 |
|
|
CLKen_i => frame_end, -- count at end of each frame
|
178 |
|
|
COUNT_o => left_cnt,
|
179 |
|
|
DONE_o => open
|
180 |
|
|
);
|
181 |
|
|
-- here we offset the pixel counter by 1 every frame
|
182 |
|
|
-- this causes a horizontal moving effect
|
183 |
|
|
pixel_cnt_off <= pixel_cnt + left_cnt;
|
184 |
|
|
--------------------------------------------------
|
185 |
|
|
-- counter to shift frame vertically
|
186 |
|
|
--------------------------------------------------
|
187 |
|
|
down_shift_counter: entity work.xcounter
|
188 |
|
|
generic map(
|
189 |
|
|
XVAL => HEIGHT
|
190 |
|
|
)
|
191 |
|
|
port map(
|
192 |
|
|
CLK_i => CLK_i,
|
193 |
|
|
RST_i => RST_i,
|
194 |
|
|
CLKen_i => frame_end, -- count at end of each frame
|
195 |
|
|
COUNT_o => down_cnt,
|
196 |
|
|
DONE_o => open
|
197 |
|
|
);
|
198 |
|
|
-- here we offset the line counter by 1 every frame
|
199 |
|
|
-- this causes vertical moving effect
|
200 |
|
|
line_cnt_off <= line_cnt + down_cnt;
|
201 |
|
|
|
202 |
|
|
-----------------
|
203 |
|
|
end Behavioral;
|
204 |
|
|
-----------------
|