-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFFT1024_synth_test.v
138 lines (120 loc) · 2.73 KB
/
FFT1024_synth_test.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
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
// State machine for EE 201L Veritune final project.
// By Chris Li, Grayson Smith, and Carey Zhang.
`timescale 1ns / 1ps
module veritune_sm(Clk, Reset, Rec, Stop, Play, Freq, Audio_In, q_I, q_Rec, q_Stop, q_Play, Audio_Out);
// inputs
input Clk, Reset, Rec, Stop, Play;
input [7:0] Freq;
input [15:0] Audio_In;
// outputs
output reg [15:0] Audio_Out;
// store current state
output q_I, q_Rec, q_Stop, q_Play;
reg [3:0] state;
assign {q_Play, q_Stop, q_Rec, q_I} = state;
// local
localparam I = 4'b0001, REC = 4'b0010, STOP = 4'b0100, PLAY = 4'b1000, UNK = 4'bXXXX;
localparam LENGTH = 131070; // 2^17-2, max number of samples -2
reg [15:0] audio_data[16:0]; // unpacked array of N-bits
reg [16:0] index;
reg [16:0] length; // actually length recorded -1
reg signed [31:0] X_Re [1023:0];
reg signed [31:0] X_Im [1023:0];
wire write_en;
assign write_en = 1;
// Internal
wire signed [31:0] y_top_re;
wire signed [31:0] y_top_im;
wire signed [31:0] y_bot_re;
wire signed [31:0] y_bot_im;
wire [9:0] i_top, i_bot;
assign x_top_re = X_Re[i_top];
assign x_top_im = X_Im[i_top];
assign x_bot_re = X_Re[i_bot];
assign x_bot_im = X_Im[i_bot];
always @(posedge Clk)
begin
if(state == REC)
begin
if(write_en == 1)
begin
X_Re[i_top] <= y_top_re;
X_Im[i_top] <= y_top_im;
X_Re[i_bot] <= y_bot_re;
X_Im[i_bot] <= y_bot_im;
end
end
end
FFT1024 ButterflyUnit1 (
.Clk(Clk),
.Reset(Reset),
.Start(1),
.Ack(0),
.x_top_re(x_top_re),
.x_top_im(x_top_im),
.x_bot_re(x_bot_re),
.x_bot_im(x_bot_im),
.i_top(i_top),
.i_bot(i_bot),
.state(),
.Done(),
.y_top_re(y_top_re),
.y_top_im(y_top_im),
.y_bot_re(y_bot_re),
.y_bot_im(y_bot_im)
);
// NSL and SM
always @ (posedge Clk, posedge Reset)
begin : NSL_AND_SM
if (Reset)
begin : RESET
state <= I;
index <= 0;
end
else
case (state)
I:
begin
// state transition logic
if (Rec)
state <= REC;
index <= 0;
end
REC:
begin
// state transition logic
if (Stop || (index==LENGTH))
begin
length <= index;
state <= STOP;
end
// clear data first?
//X_Re[i_top] <= y_top_re;
//X_Im[i_top] <= y_top_im;
//X_Re[i_bot] <= y_bot_re;
//X_Im[i_bot] <= y_bot_im;
// store data from audio input
audio_data[index] <= Audio_In;
index <= index+1;
end
STOP:
begin
// state transition logic
if (Play)
state <= PLAY;
// just wait? or do frequency shift here?
index <= 0;
end
PLAY:
begin
// state transition logic
if (Stop || index==length)
state <= STOP;
// do frequency shift?
// drive audio output
end
default:
state <= UNK;
endcase
end
endmodule