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

Subversion Repositories trigonometric_functions_in_double_fpu

[/] [trigonometric_functions_in_double_fpu/] [trunk/] [verilog/] [top.v] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 draunzer
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////                                                          ////
4
////  Trigonometric functions using double precision Floating Point Unit        ////
5
////                                                             ////
6
////  Author: Muni Aditya                                        ////
7
////          muni_aditya@yahoo.com                                ////
8
////                                                             ////
9
/////////////////////////////////////////////////////////////////////
10
////                                                             ////
11
//// Copyright (C) 2013 Muni Aditya                           ////
12
////                  muni_aditya@yahoo.com                        ////
13
////                                                             ////
14
//// This source file may be used and distributed without        ////
15
//// restriction provided that this copyright statement is not   ////
16
//// removed from the file and that any derivative work contains ////
17
//// the original copyright notice and the associated disclaimer.////
18
////                                                             ////
19
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
20
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
21
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
22
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
23
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
24
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
25
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
26
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
27
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
28
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
29
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
30
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
31
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
32
////                                                             ////
33
/////////////////////////////////////////////////////////////////////
34
 
35
`timescale 1ns / 100ps
36
 
37
`define INPUT_WIDTH 32
38
 
39
module top( enable, degrees, data1, rst, actv, clk) ;
40
 
41
 
42
input enable;
43
input [`INPUT_WIDTH-1:0] degrees ;
44
input rst;
45
input [2:0] actv;
46
input clk;
47
 
48
//////////////inputs/////////////////
49
 
50
output reg [63:0] data1;
51
 
52
//////////////output/////////////////
53
 
54
 
55
reg [63:0] data;
56
reg [`INPUT_WIDTH-1:0] half_wave;
57
reg [`INPUT_WIDTH-1:0] full_wave;
58
reg [63:0] data_tmp;
59
reg [`INPUT_WIDTH-1:0] degrees_tmp1;
60
reg [`INPUT_WIDTH-1:0] degrees_tmp2;
61
reg [1:0] quad;
62
reg sin_enable, cos_enable, tan_enable, csc_enable, sec_enable, cot_enable;
63
 
64
//////////////registers/////////////////
65
 
66
wire [63:0] data_sin, data_cos, data_tan, data_csc, data_sec, data_cot;
67
wire [`INPUT_WIDTH-1:0] divider_out;
68
 
69
//////////////wires/////////////////
70
 
71
 
72
sine_lut      a1 (.quad(quad), .enable(sin_enable) , .degrees(degrees_tmp2) , .data(data_sin), .rst(rst), .clk(clk));
73
 
74
cosine_lut    a2 (.quad(quad), .enable(cos_enable) , .degrees(degrees_tmp2) , .data(data_cos), .rst(rst), .clk(clk));
75
 
76
tangent_lut   a3 (.quad(quad), .enable(tan_enable) , .degrees(degrees_tmp2) , .data(data_tan), .rst(rst), .clk(clk));
77
 
78
cosecant_lut  a4 (.quad(quad), .enable(csc_enable) , .degrees(degrees_tmp2) , .data(data_csc), .rst(rst), .clk(clk));
79
 
80
secant_lut    a5 (.quad(quad), .enable(sec_enable) , .degrees(degrees_tmp2) , .data(data_sec), .rst(rst), .clk(clk));
81
 
82
cotangent_lut a6 (.quad(quad), .enable(cot_enable) , .degrees(degrees_tmp2) , .data(data_cot), .rst(rst), .clk(clk));
83
 
84
dividor a7 (.clk(clk), .inp(degrees), .rst(rst), .out(divider_out));
85
 
86
 
87
 
88
 
89
 
90
always@(posedge clk)
91
 
92
begin
93
 
94
        if (rst)
95
        begin
96
 
97
        sin_enable      <= 0;
98
        cos_enable      <= 0;
99
        tan_enable      <= 0;
100
        csc_enable      <= 0;
101
        sec_enable      <= 0;
102
        cot_enable      <= 0;
103
 
104
        end
105
 
106
        else
107
        begin
108
        sin_enable <= (actv == 3'b000) ? enable : 1'b0 ;
109
        cos_enable <= (actv == 3'b001) ? enable : 1'b0 ;
110
        tan_enable <= (actv == 3'b010) ? enable : 1'b0 ;
111
        csc_enable <= (actv == 3'b011) ? enable : 1'b0 ;
112
        sec_enable <= (actv == 3'b100) ? enable : 1'b0 ;
113
        cot_enable <= (actv == 3'b101) ? enable : 1'b0 ;
114
        end
115
end
116
 
117
 
118
 
119
 /////////// degress calculation////////////
120
 
121
 always@(posedge clk)
122
  begin
123
    if( degrees > `INPUT_WIDTH'd360)
124
        begin
125
 
126
//////////////// If input value greater than 360 ///////////////
127
 
128
  if (divider_out > `INPUT_WIDTH'd270)
129
        begin
130
        quad <= 2'b11;
131
        degrees_tmp2 <= divider_out - `INPUT_WIDTH'd270;
132
        end
133
   else
134
 
135
        if (divider_out > `INPUT_WIDTH'd180 && (divider_out < `INPUT_WIDTH'd270 || divider_out == `INPUT_WIDTH'd270))
136
        begin
137
        quad <= 2'b10;
138
        degrees_tmp2 <= divider_out - `INPUT_WIDTH'd180;
139
        end
140
        else
141
 
142
        if (divider_out > `INPUT_WIDTH'd90 && (divider_out < `INPUT_WIDTH'd180 || divider_out == `INPUT_WIDTH'd180))
143
                begin
144
                degrees_tmp2 <= `INPUT_WIDTH'd180 - divider_out;
145
                quad <= 2'b01;
146
                end
147
        else
148
                begin
149
                degrees_tmp2 <= divider_out;
150
                quad <= 2'b00;
151
                end
152
        end  // >360
153
        ////////////////////////end of divider///////////////////
154
   else
155
 
156
 
157
 
158
////////////// If input value is between 181 and 360//////////
159
 
160
   if (degrees > `INPUT_WIDTH'd180 && (degrees < `INPUT_WIDTH'd360 || degrees == `INPUT_WIDTH'd360))
161
        begin
162
        degrees_tmp1 <= degrees - `INPUT_WIDTH'd180;
163
 
164
        begin
165
          if(degrees_tmp1 >`INPUT_WIDTH'd90)
166
            begin
167
              quad <= 2'b11;
168
              degrees_tmp2 <= `INPUT_WIDTH'd180 - degrees_tmp1;
169
              end
170
 
171
              else
172
                begin
173
                  quad <= 2'b10;
174
                degrees_tmp2 <= degrees_tmp1;
175
                 end
176
 
177
                 end
178
 
179
        end
180
   else
181
 
182
//////////// If input value is between 91 and 180//////////////
183
 
184
   if (degrees > `INPUT_WIDTH'd90 && (degrees < `INPUT_WIDTH'd180 || degrees == `INPUT_WIDTH'd180))
185
        begin
186
        quad <= 2'b01;
187
        degrees_tmp2 <= `INPUT_WIDTH'd180 - degrees;
188
        end
189
   else
190
 
191
        begin
192
        quad <= 2'b00;
193
        degrees_tmp2 <= degrees;
194
        end
195
 
196
end
197
 
198
 always@(posedge clk)
199
 
200
  begin
201
    case (actv)
202
3'b000:         data1 <= data_sin;
203
3'b001:         data1 <= data_cos;
204
3'b010:         data1 <= data_tan;
205
3'b011:         data1 <= data_csc;
206
3'b100:         data1 <= data_sec;
207
3'b101:         data1 <= data_cot;
208
default:        data1 <= 0;
209
endcase
210
 
211
 
212
end
213
 
214
 
215
endmodule

powered by: WebSVN 2.1.0

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