我想从我的FPGA生成一个小信号 . 我想通过我的主板上的立体声输出它 . 后者将作为一个简单的DAC . 以下是一个简单的Verilog程序,它应该发出一声嘟嘟声但不会发出哔哔声 .
module music(clk, speaker);
input clk;
output speaker;
// Binary counter, 16-bits wide
reg [15:0] counter;
initial
begin
counter = 0;
end
always @(posedge clk) counter <= counter+1;
// Use the most significant bit (MSB) of the counter to drive the speaker
assign speaker = counter[15];
endmodule
最后,我想通过立体声输出一个非常低频的正弦波 . 有没有关于如何做到这一点的示例代码...任何想法?我正在使用DE2i-150板 . 谢谢!
1 回答
我会使用异步重置来初始化计数器:
测试平台edaplayground .
你可以使用时钟频率和计数器的上限来获得你想要的频率,即,而不是使用最重要的位,只需写:
if (counter == UPPER_LIMIT) begin speaker = ~speaker; counter <=0; end
这只会产生方波 . 为了生成正弦波,一种简单的方法是创建一个查找表 . See this .