tdraudio: correctly generate silence, clear DAC accumulator

This commit is contained in:
slederer 2025-09-30 00:50:33 +02:00
parent 4d4cc0c535
commit e690d3eb2b
2 changed files with 25 additions and 15 deletions

View file

@ -1,7 +1,8 @@
`timescale 1ns / 1ps
// waveform generator module (only pulse wave for now)
module wavegen #(DATA_WIDTH=32, CLOCK_DIV_WIDTH=22, AMP_WIDTH=16) (
// waveform generator module (pulse wave or noise)
module wavegen #(DATA_WIDTH=32, CLOCK_DIV_WIDTH=22,
AMP_WIDTH=16, AMP_BIAS=32768) (
input wire clk,
input wire reset,
input wire [1:0] reg_sel,
@ -18,11 +19,6 @@ module wavegen #(DATA_WIDTH=32, CLOCK_DIV_WIDTH=22, AMP_WIDTH=16) (
localparam TDRAU_REG_CLK = 1; /* clock divider register */
localparam TDRAU_REG_AMP = 2; /* amplitude (volume) register */
// localparam LFSR_WIDTH = 15;
// localparam LFSR_TAP_IDX_1 = 3;
// localparam LFSR_TAP_IDX_2 = 0;
// localparam LFSR_INIT = 'h7672;
// localparam LFSR_WIDTH = 18;
// localparam LFSR_TAP_IDX_1 = 17;
// localparam LFSR_TAP_IDX_2 = 10;
@ -138,7 +134,7 @@ module wavegen #(DATA_WIDTH=32, CLOCK_DIV_WIDTH=22, AMP_WIDTH=16) (
begin
if (reset)
begin
amp_out <= 0;
amp_out <= AMP_BIAS;
amp_phase <= 1;
end
else
@ -153,7 +149,7 @@ module wavegen #(DATA_WIDTH=32, CLOCK_DIV_WIDTH=22, AMP_WIDTH=16) (
end
end
else
amp_out <= 0;
amp_out <= AMP_BIAS;
// reset phase bit when enabling the channel
if (ctl_reg_write && wr_data[0])
@ -214,6 +210,8 @@ module tdraudio #(DATA_WIDTH=32) (
wire running = chan0_running || chan1_running || chan2_running || chan3_running;
reg was_running;
assign rd_data = chan0_sel ? chan0_rd_data :
chan1_sel ? chan1_rd_data :
chan2_sel ? chan2_rd_data :
@ -247,6 +245,15 @@ module tdraudio #(DATA_WIDTH=32) (
assign shutdown_n = running;
/* detect shutdown */
always @(posedge clk)
begin
if (reset)
was_running <= 0;
else
was_running <= running;
end
/* delta-sigma DAC */
always @(posedge clk)
begin
@ -255,6 +262,9 @@ module tdraudio #(DATA_WIDTH=32) (
else
if (running)
deltasigma_acc <= deltasigma_acc[DAC_WIDTH-1:0] + amp_sum;
else
if (!running && was_running) // clear accumulator on shutdown
deltasigma_acc <= 0;
end
/* 1-bit audio output */