module wave_gen(address,inclk,select,freq);
output[8:0] address;
input inclk;
input[1:0] select;
input[3:0] freq;
reg[7:0] Qout;
reg[8:0] adderss;
reg[7:0] k,m;
wire [1:0] select;
parameter sina_wave=2'b00,swat_wave=2'b01,
squr_wave=2'b10,trig_wave=2'b11;
always @(posedge inclk)
begin
case(select)
sina_wave:begin
if(select==2'b01) address<=128;
if(select==2'b10) address<=256;
if(select==2'b11) address<=384;
if(freq==0||freq==1)
begin
if(address>=127) adderss<=0;
else adderss<=address+1;
end
else
begin
k<=127/freq;
m<=freq*k;
if(address>=m)
adderss<=0;
else
adderss<=address+freq;
end
end
swat_wave:begin
if(select==2'b00) address<=0;
if(select==2'b10) address<=256;
if(select==2'b11) address<=384;
if(address < 128) adderss<=128;
else
begin
if(freq==0||freq==1)
begin
if(address>=255) adderss<=128;
else adderss<=address+1;
end
else
begin
k<=127/freq;
m<=freq*k;
if(address>=(m+128))
adderss<=9'd128;
else
adderss<=address+freq;
end
end
end
squr_wave:begin
if(select==2'b00) address<=0;
if(select==2'b01) address<=128;
if(select==2'b11) address<=384;
if(address<256) address<=256;
else
begin
if(freq==0||freq==1)
begin
if(address>=383) adderss<=256;
else adderss<=address+1;
end
else
begin
k<=127/freq;
m<=freq*k;
if(address>=(m+256))
adderss<=256;
else
adderss<=address+freq;
end
end
end
trig_wave:begin
if(select==2'b00) address<=0;
if(select==2'b01) address<=128;
if(select==2'b10) address<=256;
if(address<=384) address<=384;
else
begin
if(freq==0||freq==1)
begin
if(address>=511) adderss<=384;
else adderss<=address+1;
end
else
begin
k<=127/freq;
m<=freq*k;
if(address>=(m+384))
adderss<=384;
else
adderss<=address+freq;
end
end
end
endcase
end
endmodule
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>