-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixel_counter.vhd
142 lines (120 loc) · 3.75 KB
/
pixel_counter.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
library ieee;
use ieee.std_logic_1164.all;
library util;
-- TODO: Both implementations yield worse resource usage than the original implementation inside several modules.
-- Figure out why this is the case. It would be cleaner to handle the counting in a separate module.
entity pixel_counter is
generic (
C_HEIGHT : integer;
C_WIDTH : integer;
C_CHANNEL : integer;
C_CHANNEL_INCREMENT : integer range 1 to C_CHANNEL := 1
);
port (
isl_clk : in std_logic;
isl_reset : in std_logic;
isl_valid : in std_logic;
oint_pixel : out integer range 0 to C_HEIGHT * C_WIDTH - 1;
oint_row : out integer range 0 to C_HEIGHT - 1;
oint_column : out integer range 0 to C_WIDTH - 1;
oint_channel : out integer range 0 to C_CHANNEL - 1
);
end entity pixel_counter;
architecture submodules of pixel_counter is
signal sl_channel_maximum : std_logic := '0';
signal sl_column_maximum : std_logic := '0';
begin
i_channel_count : entity util.basic_counter
generic map (
C_MAX => C_CHANNEL,
C_INCREMENT => C_CHANNEL_INCREMENT
)
port map (
isl_clk => isl_clk,
isl_reset => isl_reset,
isl_valid => isl_valid,
oint_count => oint_channel,
osl_maximum => sl_channel_maximum
);
i_column_count : entity util.basic_counter
generic map (
C_MAX => C_WIDTH
)
port map (
isl_clk => isl_clk,
isl_reset => isl_reset,
isl_valid => sl_channel_maximum,
oint_count => oint_column,
osl_maximum => sl_column_maximum
);
i_row_count : entity util.basic_counter
generic map (
C_MAX => C_HEIGHT
)
port map (
isl_clk => isl_clk,
isl_reset => isl_reset,
isl_valid => sl_column_maximum,
oint_count => oint_row,
osl_maximum => open
);
-- TODO: function to convert between rows/cols and pixel
i_pixel_count : entity util.basic_counter
generic map (
C_MAX => C_HEIGHT * C_WIDTH
)
port map (
isl_clk => isl_clk,
isl_reset => isl_reset,
isl_valid => sl_channel_maximum,
oint_count => oint_pixel,
osl_maximum => open
);
end architecture submodules;
architecture single_process of pixel_counter is
signal int_pixel : integer range 0 to C_HEIGHT * C_WIDTH - 1 := 0;
signal int_row : integer range 0 to C_HEIGHT - 1 := 0;
signal int_column : integer range 0 to C_WIDTH - 1 := 0;
signal int_channel : integer range 0 to C_CHANNEL - 1 := 0;
begin
proc_cnt : process (isl_clk) is
begin
if (rising_edge(isl_clk)) then
if (isl_reset = '1') then
int_pixel <= 0;
int_channel <= 0;
int_column <= 0;
int_row <= 0;
else
if (isl_valid = '1') then
if (int_channel /= C_CHANNEL - C_CHANNEL_INCREMENT) then
int_channel <= int_channel + C_CHANNEL_INCREMENT;
else
int_channel <= 0;
-- row and column count
if (int_column /= C_WIDTH - 1) then
int_column <= int_column + 1;
else
int_column <= 0;
if (int_row /= C_HEIGHT - 1) then
int_row <= int_row + 1;
else
int_row <= 0;
end if;
end if;
-- pixel count
if (int_pixel /= C_HEIGHT * C_WIDTH - 1) then
int_pixel <= int_pixel + 1;
else
int_pixel <= 0;
end if;
end if;
end if;
end if;
end if;
end process proc_cnt;
oint_pixel <= int_pixel;
oint_channel <= int_channel;
oint_column <= int_column;
oint_row <= int_row;
end architecture single_process;