always @(posedge inclock)
begin
case(state)
0:begin //产生正弦波形
if(control==1) address<=9'd128;
if(control==2) address<=9'd256;
if(control==3) address<=9'd384;
if(i==0||i==1) begin
address<=address+1'b1;
if(address>=9'd127) address<=9'd0;
end
else begin
k<=127/i;m<=i*k;
address<=address+i;
if(address>=m) address<=9'd0;
end
end
1:begin //产生锯齿波形
if(control==0) address<=9'd0;
if(control==2) address<=9'd256;
if(control==3) address<=9'd384;
if(address<128) address<=9'd128;
else begin
if(i==0||i==1)begin
address<=address+1'b1;
if(address==9'd255) address<=9'd128;
end
else begin
k<=127/i;m<=i*k;
address<=address+i;
if(address>=m+9'd128) address<=9'd128;
end
end
end
2:begin //产生方波形
if(control==0) address<=9'd0;
if(control==1) address<=9'd128;
if(control==3) address<=9'd384;
if(address<9'd256) address<=9'd256;
else begin
if(i==0||i==1)begin
address<=address+1'b1;
if(address==9'd383) address<=9'd256;
end
else begin
k<=127/i;m<=i*k;
address<=address+i;
if(address>=m+256) address<=9'd256;
end
end
end
3:begin //产生三角波形
if(control==1) address<=9'd128;
if(control==2) address<=9'd256;
if(control==3) address<=9'd384;
if(address<384) address<=9'd384;
else begin
if(i==0||i==1) begin
address<=address+1'b1;
if(address==9'd511) address<=9'd384;
end
else begin
k<=127/i;m<=i*k;
address<=address+i;
if(address>=m+384) address<=9'd384;
end
end
end
endcase
end
endmodule
测试文件:
`timescale 1 ps/ 1 ps
module signal_gene_vlg_tst();