OpenCores
URL https://opencores.org/ocsvn/dct_idct/dct_idct/trunk

Subversion Repositories dct_idct

[/] [dct_idct/] [trunk/] [dct/] [Bench/] [dct_beh.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 unicore
---------------------------------------------------------------------
2
----                                                             ----
3
----  DCT IP core                                                ----
4
----                                                             ----
5
----  Authors: Anatoliy Sergienko, Volodya Lepeha                ----
6
----  Company: Unicore Systems http://unicore.co.ua              ----
7
----                                                             ----
8
----  Downloaded from: http://www.opencores.org                  ----
9
----                                                             ----
10
---------------------------------------------------------------------
11
----                                                             ----
12
---- Copyright (C) 2006-2010 Unicore Systems LTD                 ----
13
---- www.unicore.co.ua                                           ----
14
---- o.uzenkov@unicore.co.ua                                     ----
15
----                                                             ----
16
---- This source file may be used and distributed without        ----
17
---- restriction provided that this copyright statement is not   ----
18
---- removed from the file and that any derivative work contains ----
19
---- the original copyright notice and the associated disclaimer.----
20
----                                                             ----
21
---- THIS SOFTWARE IS PROVIDED "AS IS"                           ----
22
---- AND ANY EXPRESSED OR IMPLIED WARRANTIES,                    ----
23
---- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED                  ----
24
---- WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT              ----
25
---- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.        ----
26
---- IN NO EVENT SHALL THE UNICORE SYSTEMS OR ITS                ----
27
---- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,            ----
28
---- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL            ----
29
---- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT         ----
30
---- OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,               ----
31
---- DATA, OR PROFITS; OR BUSINESS INTERRUPTION)                 ----
32
---- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,              ----
33
---- WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT              ----
34
---- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING                 ----
35
---- IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,                 ----
36
---- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.          ----
37
----                                                             ----
38
---------------------------------------------------------------------
39
 
40
library IEEE;
41
use IEEE.std_logic_1164.all;
42
use IEEE.std_logic_arith.all;
43
 
44
entity DCT_BEH is
45
        generic(  SIGNED_DATA: integer);
46
        port (
47
                DATAIN: in STD_LOGIC_VECTOR (7 downto 0);
48
                CLK: in STD_LOGIC;
49
                RST: in STD_LOGIC;
50
                EN: in STD_LOGIC;
51
                START: in STD_LOGIC;
52
                READY : out STD_LOGIC:='0';
53
                DATAOUT: out STD_LOGIC_VECTOR ( 11 downto 0)  --:=x"0000"
54
                );
55
end DCT_BEH;
56
 
57
 
58
architecture DCT_BEH of DCT_BEH is
59
        type TLUT2 is array(0 to 255 ) of real;
60
        type TLUT3 is array(0 to 63 ) of real;
61
        type TLUT1 is array(0 to 255 ) of std_logic_vector(7 downto 0);
62
        constant LATENCY:integer:=3; -- 40; --51;
63
        constant c   : real := 0.7071;
64
        constant c0  : real := 0.9808;
65
        constant c1  : real := 0.8315;
66
        constant c2  : real := 0.5556;
67
        constant c3  : real := 0.1951;
68
        constant c4  : real := 0.9239;
69
        constant c5  : real := 0.3827;
70
        Constant c6  : real := 0.7071;
71
        constant c0i  : real := -0.9808;
72
        constant c1i  : real := -0.8315;
73
        constant c2i  : real := -0.5556;
74
        constant c3i  : real := -0.1951;
75
        constant c4i  : real := -0.9239;
76
        constant c5i  : real := -0.3827;
77
        Constant c6i  : real := -0.7071;
78
 
79
        Constant ROM3:Tlut3:=( (
80
        c,c,c,c,c,c,c,c,
81
        c0,c1,c2,c3,c3i,c2i,c1i,c0i,
82
        c4,c5,c5i,c4i,c4i,c5i,c5,c4,
83
        c1,c3i,c0i,c2i,c2,c0,c3,c1i,
84
        c6,c6i,c6i,c6,c6,c6i,c6i,c6,
85
        c2,c0i,c3,c1,c1i,c3i,c0,c2i,
86
        c5,c4i,c4,c5i,c5i,c4,c4i,c5,
87
        c3,c2i,c1,c0i,c0,c1i,c2,c3i
88
        ));
89
 
90
 
91
        Constant ROM4:Tlut3:=( (
92
        c,c0,c4,c1,c6,c2,c5,c3,
93
        c,c1,c5,c3i,c6i,c0i,c4i,c2i,
94
        c,c2,c5i,c0i,c6i,c3,c4,c1,
95
        c,c3,c4i,c2i,c6,c1,c5i,c0i,
96
        c,c3i,c4i,c2,c6,c1i,c5i,c0,
97
        c,c2i,c5i,c0,c6i,c3i,c4,c1i,
98
        c,c1i,c5,c3,c6i,c0,c4i,c2,
99
        c,c0i,c4,c1i,c6,c2i,c5,c3i
100
        ));
101
 
102
        signal RESET: std_logic;
103
        signal COEF : STD_LOGIC_VECTOR (6 downto 0);
104
        signal  X,X11,DATAINi:  STD_LOGIC_VECTOR (7 downto 0);
105
        signal  Y1,y2:  STD_LOGIC_VECTOR (15 downto 0);
106
        signal  Y,DATAOUTi:  STD_LOGIC_VECTOR (11 downto 0);
107
        signal K1,K2,X1,k8,couna: INTEGER;
108
        signal k3,k4,k7: real;
109
        signal ram00,ramres,ramt : tlut3;
110
        signal prov,prov1:  std_logic_vector (7 downto 0);
111
        signal inarray,inarray0,tmpar1,tmpar2,tmpar3: tlut3;
112
        signal          index: integer range 0 to 63;
113
        signal CLK64,eoutput,indataready,indataready2,  startdel,startd1,startd2,       startfix,readyi:boolean;
114
        signal delay,cycle: integer:=0;
115
begin
116
 
117
 
118
        G1:     if       SIGNED_DATA=1   generate
119
                DATAINi<=DATAIN;
120
        end generate;
121
        G0:             if       SIGNED_DATA=0   generate
122
                DATAINi<=unsigned (DATAIN) - 128;
123
        end generate;
124
 
125
 
126
 
127
        DATA_INPUT: process(CLK,RST,START)
128
                variable index: integer  range 0 to 64;
129
        begin
130
                if RST='1' or START='1' then
131
                        index:=0;          indataready<=false;
132
                        for i in 0 to 63 loop
133
                                inarray0(i)<=0.0;
134
                        end loop;
135
                elsif CLK='1' and CLK'event then
136
                        if en='1' then
137
                                inarray0(index)<=REAL(CONV_INTEGER(SIGNED(DATAINi)));
138
                                index:=(index+1) mod 64;
139
                                if index=63               then
140
                                        indataready<=true;
141
                                else
142
                                        indataready<=false;
143
                                end if;
144
                        end if;
145
                end if;
146
 
147
        end process;
148
 
149
        DATAREADY:process(CLK)
150
        begin
151
                if CLK'event and CLK='1'  then
152
                        if en='1' then
153
                                indataready2<=indataready;
154
                                if indataready2 then
155
                                        inarray<=inarray0;
156
                                end if;
157
                        end if;
158
                end if;
159
 
160
        end process;
161
 
162
 
163
        DCT:    process                           --Discrete Cosine Transform calculation
164
                variable cc0,cc1,cc2,cc3,cc4,cc5,cc6: real;
165
                variable ac0,ac1,ac2,ac3,ac4,ac5,ac6,ac7: real;
166
                variable s,i,j,k: integer;
167
        begin
168
                for s in 0 to 7 loop
169
                        for j in 0 to 7 loop
170
                                ac0:= 0.0;
171
                                for i in 0 to 7 loop
172
                                        cc0 := rom3(s*8 + i);
173
                                        cc1 := (inarray(j + i*8)); -- - 128.0);
174
                                        ac0 := ac0 +  cc0 * cc1;
175
                                end loop;
176
                                ram00(s*8 +j) <= ac0;
177
                                ramt(j*8 +s)<=ac0/2.0;
178
                                wait for 1 ps;
179
                        end loop;
180
                end loop;
181
 
182
 
183
                wait for 5 ps;
184
                for s in 0 to 7 loop
185
                        for j in 0 to 7 loop
186
                                ac0:= 0.0;
187
                                for i in 0 to 7 loop
188
                                        cc0 := ram00(s*8 + i);
189
                                        cc1 := rom3(j*8 + i);
190
                                        ac0 := ac0 + cc0 * cc1;
191
                                end loop;
192
                                ramres(s*8 +j) <= ac0/8.0;                              --results
193
                                wait for 1 ps;
194
                        end loop;
195
                end loop;
196
                wait on indataready2;
197
        end process;
198
 
199
 
200
        --      CLK64<= indataready ; 
201
 
202
        DATA_OUTPUT:process(CLK,RST,START)
203
 
204
                --      variable delay: integer;
205
        begin
206
                if       RST='1' or START='1'  then
207
                        startfix<=false;
208
                elsif  START='0' and START'event  then
209
                        startfix<=true;
210
                end if;
211
 
212
                if       RST='1' or START='1' then
213
                        eoutput<=false;
214
                        startdel<=false;
215
                        delay<=0;
216
                elsif rising_edge(CLK) and startd2 then
217
                        if en='1' then
218
                                startdel<=(delay=LATENCY);   --momemt of 1 st result ready
219
                                delay<=delay+1;
220
                                if startdel then
221
                                        eoutput<=true;
222
                                end if;
223
                        end if;
224
                end if;
225
 
226
 
227
                if       RST='1' or START='1' then
228
                        cycle<=0;
229
                        readyi<=false;
230
                elsif rising_edge(CLK) and eoutput  then
231
                        if en='1' then
232
                                cycle<=(cycle+1) mod 64;
233
                        end if;
234
                end if;
235
 
236
                readyi<= cycle = 63 or startdel;                         -- 63
237
                if readyi then READY<= '1' ; else  READY<= '0'; end if;
238
 
239
 
240
                if RST='1' or STARTDel then
241
                        index<=0;
242
                elsif CLK='1' and CLK'event and eoutput  then   --
243
                        if en='1' then
244
 
245
                                index<=(index+1) mod 64;
246
                        end if;
247
                end if;
248
 
249
 
250
 
251
        end process;
252
 
253
 
254
        process(clk,rst)
255
                begin
256
                        if RST='1' or STARTDel then
257
                                DATAOUT<= (others => '0');
258
                        elsif CLK='1' and CLK'event and eoutput  then   --      
259
                                if en='1' then
260
                                        DATAOUT<=CONV_STD_LOGIC_VECTOR(INTEGER( tmpar2(index)),12);              -- 12  
261
                                        DATAOUTi<=CONV_STD_LOGIC_VECTOR(INTEGER(        ramt((index-14) mod 64)),12);            -- 16
262
                                end if;
263
                        end if;
264
                end process;
265
 
266
 
267
 
268
        RESULT_ARRAY: process(readyi,CLK)
269
        begin
270
                if CLK='1' and CLK'event and readyi then
271
                        if en='1' then
272
                                tmpar2<=tmpar1;
273
                        end if;
274
                end if;
275
        end process     ;
276
 
277
        DELAYED:process ( indataready2,START,RESET) --delay for 128 cycles
278
        begin
279
                if START='1' or RESET='1' then
280
                        startd2<=false;
281
                        startd1<=false;
282
                elsif  indataready2 and  indataready2'event then
283
                        if en='1' then
284
                                for i in 0 to 63 loop
285
                                        tmpar1(i)<=ramres(i)*2.0;       --SCALING  !!!
286
                                end loop;
287
                                startd2<=startd1;
288
                                startd1<=STARTFIX;
289
                        end if;
290
                end if;
291
        end process;
292
 
293
 
294
 
295
end DCT_BEH;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.