用quartus2软件Verilog HDL语言怎么实现三角波形的产生

来源:百度知道 编辑:UC知道 时间:2024/05/30 07:47:50

加减计数器

用DDS
基本思想就是ROM查表。或者用NCO都=也可以会比DDS难一些

用生成ROM
计算出数值 填进去
一个周期加一 加一

module trigle(
input wire clk,
input wire rst_n,
output wire [15:0] out)
parameter period=300, //设定三角波周期=2*period*Tclk
reg state;
always @(posedge clk)
begin
if(!rst_n) begin
out<=0;
state<=0;
end
else begin
case (state)
'b0: begin
out<=out+1;
if(out==period) begin
state<=1;
end
end
'b1: begin
out<=out-1;
if(out==0) begin
state<=0;
end
end
endcase
end
end
endmodule