`timescale 1ps / 1ps
module tops(
i_clk,
i_rst,
i_sel,
i_amp_add,
i_amp_sub,
i_fre_add,
i_fre_sub,
i_fre_time,
o_signal,
o_fre,
o_amp,
o_signal_type
);
input i_clk;
input i_rst;
input[3:0] i_sel; //signal sel
//0:sin
//1:square
//2:sawtooth
//3:k*sin
//4:k*square
//5:k*sawtooth
//6:sin+square
//7:sin+sawtooth
//8:sawtooth+square
//9:sin+sawtooth+square
//10:sin+ksin
//11:sawtooth+k*sawtooth
//12:square+k*square
input i_amp_add;
input i_amp_sub;
input i_fre_add;
input i_fre_sub;
input[3:0] i_fre_time;
output[11:0]o_signal;
output[23:0]o_fre;
output[6:0] o_amp;
output[3:0] o_signal_type;
reg[23:0]o_fre;
always @(posedge i_clk or posedge i_rst)
begin
if(i_rst)
begin
o_fre <= 24'd83886;
end
else begin
//frequency adjust
//frequency adjust
if(i_fre_add == 1'b1)
o_fre <= o_fre + 24'd1;
if(i_fre_sub == 1'b1)
o_fre <= o_fre - 24'd1;
if(o_fre <= 24'd42)
o_fre <= 24'd42;
if(o_fre >= 24'd83886)
o_fre <= 24'd83886;
end
end
reg[5:0]amps;
always @(posedge i_clk or posedge i_rst)
begin
if(i_rst)
begin
amps <= 7'b0111_111;
end
else begin
//frequency adjust
//frequency adjust
if(i_amp_add == 1'b1)
amps <= amps + 7'd1;
if(i_amp_sub == 1'b1)
amps <= amps - 7'd1;
if(amps <= 7'b0000_001)
amps <= 7'b0000_001;
if(amps >= 7'b0111_111)
amps <= 7'b0111_111;
end
end
assign o_amp = amps;
assign o_signal_type = i_sel;
reg signed[18:0]tmps;
wire signed[11:0]sin1;
wire signed[11:0]cube1;
wire signed[11:0]saw1;
DDS base(
.i_clk (i_clk),
.i_rst (i_rst),
.i_k (4'd1),
.i_fre (o_fre),
.o_sin (sin1),
.o_cube (cube1),
.o_saw (saw1),
.o_fre (),
.o_test1(),
.o_test2()
);
wire signed[11:0]sink;
wire signed[11:0]cubek;
wire signed[11:0]sawk;
DDS h(
.i_clk (i_clk),
.i_rst (i_rst),
.i_k (i_fre_time),
.i_fre (o_fre),
.o_sin (sink),
.o_cube (cubek),
.o_saw (sawk),
.o_fre (),
.o_test1(),
.o_test2()
);
always @(posedge i_clk or posedge i_rst)
begin
if(i_rst)
begin
tmps <= 19'd0;
end
else begin
case(i_sel)
0:tmps <= amps*sin1;
1:tmps <= amps*cube1;
2:tmps <= amps*saw1;
3:tmps <= amps*sink;
4:tmps <= amps*cubek;
5:tmps <= amps*sawk;
6:tmps <= amps*sin1[11:1] + amps*cube1[11:1];
7:tmps <= amps*sin1[11:1] + amps*saw1[11:1];
8:tmps <= amps*saw1[11:1] + amps*cube1[11:1];
9:tmps <= amps*sin1[11:2] + amps*cube1[11:2] + amps*saw1[11:2];
10:tmps <= amps*sin1[11:1] + amps*sink[11:1];
11:tmps <= amps*cube1[11:1] + amps*cubek[11:1];
12:tmps <= amps*saw1[11:1] + amps*sawk[11:1];
default:tmps <= amps*sin1;
endcase
end
end
assign o_signal=tmps[18:7];
//0:sin
//1:square
//2:sawtooth
//3:k*sin
//4:k*square
//5:k*sawtooth
//6:sin+square
//7:sin+sawtooth
//8:sawtooth+square
//9:sin+sawtooth+square
//10:sin+ksin
//11:sawtooth+k*sawtooth
//12:square+k*square
endmodule