This repository has been archived by the owner on Jan 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCORDIC.v
113 lines (93 loc) · 1.97 KB
/
CORDIC.v
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
module sine_cosine( input clock, input signed [15:0] angle,input reset,input modes);
wire signed [15:0] arc_tan [0:14];
reg signed [15:0] sine;
integer count = 0;
assign arc_tan[00] = 16'b0010000000000000;
assign arc_tan[01] = 16'b0001001011100100;
assign arc_tan[02] = 16'b0000100111111011;
assign arc_tan[03] = 16'b0000010100010001;
assign arc_tan[04] = 16'b0000001010001011;
assign arc_tan[05] = 16'b0000000101000101;
assign arc_tan[06] = 16'b0000000010100010;
assign arc_tan[07] = 16'b0000000001010001;
assign arc_tan[08] = 16'b0000000000101000;
assign arc_tan[09] = 16'b0000000000010100;
assign arc_tan[10] = 16'b0000000000001010;
assign arc_tan[11] = 16'b0000000000000101;
assign arc_tan[12] = 16'b0000000000000010;
assign arc_tan[13] = 16'b0000000000000001;
assign arc_tan[14] = 16'b0000000000000000;
reg signed [15:0] x0;
reg signed [15:0] y0;
reg signed [15:0] x1;
reg signed [15:0] x2;
reg signed [15:0] y1;
reg signed [15:0] y2;
reg signed [15:0] z;
reg signed [15:0] z0;
always @(reset,angle)
begin
if(reset)
begin
x0<=16'b0100101100110001;
y0<=16'b0000000000000000;
z0<=angle;
end
else
z0<=angle;
end
always @ (posedge clock)
begin
count <= count+1;
if(count == 0)
begin
x1<=x0;
y1<=y0;
z <=z0;
end
else if(count == 1)
begin
if(z[15])
begin
x2 <= x1 + y1;
y2 <= y1 - x1;
z <= z + arc_tan[00];
end
else
begin
x2 <= x1 - y1;
y2 <= y1 + x1;
z <= z - arc_tan[00];
end
end
else if(count%2==0)
begin
x1<=x2;
y1<=y2;
end
else if(count == 31)
begin
sine <= y2;
cosine <= x2;
end
else
begin
if(z[15])
begin
x2 <= x1 + (y1>>>(count>>>1));
y2 <= y1 - (x1>>>(count>>>1));
z <= z + (arc_tan[count>>>1]);
sine <= x2;
cosine <= y2;
end
else
begin
x2 <= x1 - (y1>>>(count>>>1));
y2 <= y1 + (x1>>>(count>>>1));
z <= z - (arc_tan[count>>>1]);
sine <= y2;
cosine <= x2;
end
end
end
endmodule