count_in<=11'd0;
w_cycle<=1'b1;
state1<=4'b1001;
end
else
if(count_in==11'd1022) begin
sink_eop<=1'b1;//计满1024后拉高
state1<=4'b0010;//开始下一个1024变换
end
else begin
count_in<=count_in+11'd1;
sink_sop<=1'b0;
end
end
4'b1001:begin
//fftpts_in<=11'd0;
sink_valid<=1'b0;
sink_eop<=1'b0;
sink_sop<=1'b0;
enable<=1'b0;
if(enable==1'b1) begin
if(recycle==5'd16) begin //计满16周期后转入下一状态开始16点FFT
state1<=4'b0100;
end
else begin
enable<=1'b0;
recycle<=recycle+1'b1; //enable为1时拉高,计满16周期,及进行16次1024变换
state1<=4'b0001;
end
end
end
4'b0100: begin
recycle=5'd0;
enable<=1'b0;
fftpts_in<=11'd16;//
sink_eop<=1'b0;
w_cycle<=1'b0;
count_in<=11'd0;
if(start_16==1'b1) begin//16点FFT开始
state1<=4'b0101;
end
else begin
state1<=4'b0100;
end
end
4'b0101: begin
sink_valid<=1'b1;
sink_sop<=1'b1;
sink_eop<=1'b0;
state1<=4'b0110;
end
4'b0110: begin
if(fft16_over==1'b1) begin//16点变换结束标志,开始转入1024点FFT;
sink_valid<=1'b0;
sink_sop<=1'b0;
sink_eop<=1'b0;
state1<=4'b0000;
end
else if(count_in==11'd14) begin
sink_eop<=1'b1;
count_in<=11'd0;
state1<=4'b0111;
end
else begin
count_in<=count_in+11'd1;
flag<=1'b1;
sink_sop<=1'b0;
end
end
4'b0111: begin
sink_eop<=1'b0;
sink_sop<=1'b1;
state1<=4'b0110;
flag<=1'b1;
end
default: state1<=4'b0000;
endcase
end
FFT控制代码
module fft_control(clk,rst,rst_fifo,w_cycle,fftpts_in,sink_eop,sink_sop,sink_valid,start_16,fft16_over,switch,re_im,out_reim,count_in,recycle,re1,re2,enable)/*synthesis noprune*/;
input clk,rst;
input start_16,fft16_over;
input re1,re2;
input [47:0] re_im;
output reg [4:0] recycle;
output [10:0] fftpts_in;
output sink_eop,sink_sop,sink_valid;
output rst_fifo;
output w_cycle,switch;
output [10:0] count_in;
output [47:0] out_reim;
output enable;
wire [47:0] out_reim;
reg enable;
reg w_cycle;
reg rst_fifo;
reg [3:0] state1;
reg [10:0] fftpts_in;
reg [10:0] count_in;
reg sink_eop,sink_sop;
reg sink_valid;
reg flag;
reg switch;
assign out_reim=flag? re_im:48'd0;
always @(posedge clk)
if(!rst) begin
state1<=4'b0000;
rst_fifo<=1'b1;
w_cycle<=1'b0;
fftpts_in<=11'd1024;
sink_eop<=1'b0;
sink_sop<=1'b0;
sink_valid<=1'b0;
count_in<=11'd0;
flag<=1'b1;
fftpts_in<=11'd0;
enable<=1'b0;
end
else begin
case(state1)
4'b0000: begin
rst_fifo<=1'b0;
flag<=1'b1;
count_in<=11'd0;
fftpts_in<=11'd1024;
w_cycle<=1'b0;
recycle<=5'd0;
sink_eop<=1'b0;
sink_sop<=1'b0;
sink_valid<=1'b0;
fftpts_in<=11'd1024;//一次FFT变换长度
state1<=4'b0001;
enable<=1'b0;
end
4'b0001:begin
sink_eop<=1'b0;
if(re1||re2) begin
sink_valid<=1'b1; //fifo读取使能拉高,数据开始输出,此时sink_valid拉高,数据开始输入
sink_sop<=1'b1;//数据开始标志
sink_eop<=1'b0;//数据结束标志
state1<=4'b0011;
end
else begin
state1<=4'b0001;
end
end
4'b0010: begin
sink_valid<=1'b1;
sink_sop<=1'b1;
sink_eop<=1'b0;
state1<=4'b0011;
w_cycle<=1'b0;
enable<=1'b0;
count_in<=count_in+11'd1;
end
4'b0011: begin
if(count_in==11'd2045) begin
enable<=1'b1;//周期计数使能
sink_eop<=1'b1;
count_in<=11'd0;
w_cycle<=1'b1;
state1<=4'b1001;
end
else
if(count_in==11'd1022) begin
sink_eop<=1'b1;//计满1024后拉高
state1<=4'b0010;//开始下一个1024变换
end
else begin
count_in<=count_in+11'd1;
sink_sop<=1'b0;
end
end
4'b1001:begin
//fftpts_in<=11'd0;
sink_valid<=1'b0;
sink_eop<=1'b0;
sink_sop<=1'b0;
enable<=1'b0;
if(enable==1'b1) begin
if(recycle==5'd16) begin //计满16周期后转入下一状态开始16点FFT
state1<=4'b0100;
end
else begin
enable<=1'b0;
recycle<=recycle+1'b1; //enable为1时拉高,计满16周期,及进行16次1024变换
state1<=4'b0001;
end
end
end
4'b0100: begin
recycle=5'd0;
enable<=1'b0;
fftpts_in<=11'd16;//
sink_eop<=1'b0;
w_cycle<=1'b0;
count_in<=11'd0;
if(start_16==1'b1) begin//16点FFT开始
state1<=4'b0101;
end
else begin
state1<=4'b0100;
end
end
4'b0101: begin
sink_valid<=1'b1;
sink_sop<=1'b1;
sink_eop<=1'b0;
state1<=4'b0110;
end
4'b0110: begin
if(fft16_over==1'b1) begin//16点变换结束标志,开始转入1024点FFT;
sink_valid<=1'b0;
sink_sop<=1'b0;
sink_eop<=1'b0;
state1<=4'b0000;
end
else if(count_in==11'd14) begin
sink_eop<=1'b1;
count_in<=11'd0;
state1<=4'b0111;
end
else begin
count_in<=count_in+11'd1;
flag<=1'b1;
sink_sop<=1'b0;
end
end
4'b0111: begin
sink_eop<=1'b0;
sink_sop<=1'b1;
state1<=4'b0110;
flag<=1'b1;
end
default: state1<=4'b0000;
endcase
end
always @(posedge clk)
if(!rst)
switch<=1'b1;
else
case(fftpts_in)
11'b10000000000: switch<=1'b1;
11'b00000010000: switch<=1'b0;
default: switch<=switch;
endcase
endmodule
FFT核例化
core_fft b2v_inst5(
.clk(clk),
.reset_n(rst),
.fftpts_in(fftpts_in),
.inverse(SYNTHESIZED_WIRE_1),
.sink_valid(sink_valid),
.sink_sop(sink_sop),
.sink_eop(sink_eop),
.sink_real(SYNTHESIZED_WIRE_5),
.sink_imag(SYNTHESIZED_WIRE_4),
.sink_error(SYNTHESIZED_WIRE_3),
.source_ready(SYNTHESIZED_WIRE_2),
.source_valid(source_valid),
.fftpts_out(),
.source_error(),
.sink_ready(),
.source_sop(),
.source_eop(),
.source_imag(source_imag[36:0]),
.source_real(source_real[36:0]));
问题解决了,是复位的问题,复位要循环,就是当一次FFT结束后要再次复位然后开始下一次变换
一周热门 更多>