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

Subversion Repositories ofdm

[/] [ofdm/] [branches/] [avendor/] [p2r_CordicPipe.vhd] - Blame information for rev 13

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 tmsiqueira
--
2
-- file: p2r_CordicPipe.vhd
3
-- author: Richard Herveille
4
-- rev. 1.0 initial release
5
--
6
 
7
--
8
-- This file is come from WWW.OPENCORES.ORG
9
 
10
---------------------------------------------------------------------------------------------------
11
--
12
-- Title       : p2r_CordicPipe
13
-- Design      : cfft
14
--
15
---------------------------------------------------------------------------------------------------
16
--
17
-- File        : p2r_CordicPipe.vhd
18
--
19
---------------------------------------------------------------------------------------------------
20
--
21
-- Description : Cordic arith pilepline 
22
--
23
---------------------------------------------------------------------------------------------------
24
--
25
-- Revisions       :    0
26
-- Revision Number :    1
27
-- Version         :    1
28
-- Date            :    Oct 17 2002
29
-- Modifier        :    ZHAO Ming <sradio@opencores.org>
30
-- Desccription    :    Data width configurable 
31
--
32
---------------------------------------------------------------------------------------------------
33
 
34
 
35
library ieee;
36
use ieee.std_logic_1164.all;
37
use ieee.std_logic_arith.all;
38
 
39
entity p2r_CordicPipe is
40
        generic(
41
                WIDTH   : natural := 16;
42
                PIPEID  : natural := 1
43
        );
44
        port(
45
                clk             : in std_logic;
46
                ena             : in std_logic;
47
 
48
                Xi              : in signed(WIDTH -1 downto 0);
49
                Yi              : in signed(WIDTH -1 downto 0);
50
                Zi              : in signed(19 downto 0);
51
 
52
                Xo              : out signed(WIDTH -1 downto 0);
53
                Yo              : out signed(WIDTH -1 downto 0);
54
                Zo              : out signed(19 downto 0)
55
        );
56
end entity p2r_CordicPipe;
57
 
58
architecture dataflow of p2r_CordicPipe is
59
 
60
        --
61
        -- functions
62
        --
63
 
64
        -- Function CATAN (constante arc-tangent).
65
        -- This is a lookup table containing pre-calculated arc-tangents.
66
        -- 'n' is the number of the pipe, returned is a 20bit arc-tangent value.
67
        -- The numbers are calculated as follows: Z(n) = atan(1/2^n)
68
        -- examples:
69
        -- 20bit values => 2^20 = 2pi(rad)
70
        --                 1(rad) = 2^20/2pi = 166886.053....
71
        -- n:0, atan(1/1) = 0.7853...(rad)
72
        --      0.7853... * 166886.053... = 131072(dec) = 20000(hex)
73
        -- n:1, atan(1/2) = 0.4636...(rad)
74
        --      0.4636... * 166886.053... = 77376.32(dec) = 12E40(hex)
75
        -- n:2, atan(1/4) = 0.2449...(rad)
76
        --      0.2449... * 166886.053... = 40883.52(dec) = 9FB3(hex)
77
        -- n:3, atan(1/8) = 0.1243...(rad)
78
        --      0.1243... * 166886.053... = 20753.11(dec) = 5111(hex)
79
        --
80
        function CATAN(n :natural) return integer is
81
        variable result :integer;
82
        begin
83
                case n is
84
                        when 0 => result := 16#020000#;
85
                        when 1 => result := 16#012E40#;
86
                        when 2 => result := 16#09FB4#;
87
                        when 3 => result := 16#05111#;
88
                        when 4 => result := 16#028B1#;
89
                        when 5 => result := 16#0145D#;
90
                        when 6 => result := 16#0A2F#;
91
                        when 7 => result := 16#0518#;
92
                        when 8 => result := 16#028C#;
93
                        when 9 => result := 16#0146#;
94
                        when 10 => result := 16#0A3#;
95
                        when 11 => result := 16#051#;
96
                        when 12 => result := 16#029#;
97
                        when 13 => result := 16#014#;
98
                        when 14 => result := 16#0A#;
99
                        when 15 => result := 16#05#;
100
                        when 16 => result := 16#03#;
101
                        when 17 => result := 16#01#;
102
                        when others => result := 16#0#;
103
                end case;
104
                return result;
105
        end CATAN;
106
 
107
        -- function Delta is actually an arithmatic shift right
108
        -- This strange construction is needed for compatibility with Xilinx WebPack
109
        function Delta(Arg : signed; Cnt : natural) return signed is
110
                variable tmp : signed(Arg'range);
111
                constant lo : integer := Arg'high -cnt +1;
112
        begin
113
                for n in Arg'high downto lo loop
114
                        tmp(n) := Arg(Arg'high);
115
                end loop;
116
                for n in Arg'high -cnt downto 0 loop
117
                        tmp(n) := Arg(n +cnt);
118
                end loop;
119
                return tmp;
120
        end function Delta;
121
 
122
        function AddSub(dataa, datab : in signed; add_sub : in std_logic) return signed is
123
        begin
124
                if (add_sub = '1') then
125
                        return dataa + datab;
126
                else
127
                        return dataa - datab;
128
                end if;
129
        end;
130
 
131
        --
132
        --      ARCHITECTURE BODY
133
        --
134
        signal dX, Xresult      : signed(WIDTH -1 downto 0);
135
        signal dY, Yresult      : signed(WIDTH -1 downto 0);
136
        signal atan, Zresult    : signed(19 downto 0);
137
 
138
        signal Zneg, Zpos       : std_logic;
139
 
140
begin
141
 
142
        dX <= Delta(Xi, PIPEID);
143
        dY <= Delta(Yi, PIPEID);
144
        atan <= conv_signed( catan(PIPEID), 20);
145
 
146
        -- generate adder structures
147
        Zneg <= Zi(19);
148
        Zpos <= not Zi(19);
149
 
150
        -- xadd
151
  Xresult <= AddSub(Xi, dY, Zneg);
152
 
153
        -- yadd 
154
        Yresult <= AddSub(Yi, dX, Zpos);
155
 
156
        -- zadd
157
        Zresult <= AddSub(Zi, atan, Zneg);
158
 
159
        gen_regs: process(clk)
160
        begin
161
                if(clk'event and clk='1') then
162
                        if (ena = '1') then
163
                                Xo <= Xresult;
164
                                Yo <= Yresult;
165
                                Zo <= Zresult;
166
                        end if;
167
                end if;
168
        end process;
169
 
170
end architecture dataflow;

powered by: WebSVN 2.1.0

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