aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@trantor.hos.anvin.org>2008-12-30 16:14:34 -0800
committerH. Peter Anvin <hpa@trantor.hos.anvin.org>2008-12-30 16:14:34 -0800
commitfa7694a568081acd2f6284ea213e0bd78502b9d9 (patch)
treec1cca6bc5ab99667c9860c4f2e67350a8968bf70
parent060c89ac28498ca76b2308970d06273c6caa1c73 (diff)
downloadabc80-fa7694a568081acd2f6284ea213e0bd78502b9d9.tar.gz
abc80-fa7694a568081acd2f6284ea213e0bd78502b9d9.tar.xz
abc80-fa7694a568081acd2f6284ea213e0bd78502b9d9.zip
Fix audio DAC programmingabc80-de1-13
Quite a few of the sound DAC register settings were just plain wrong. Fix them.
-rw-r--r--CHANGES18
-rw-r--r--i2c.v29
-rw-r--r--sound.v8
3 files changed, 40 insertions, 15 deletions
diff --git a/CHANGES b/CHANGES
index a98452c..60cd4d6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,21 @@
+Changes in release DE1-13:
+--------------------------
+* Reset the audio DAC before programming it. That way we avoid
+ potential painful sounds if another application has been using
+ it in another mode.
+* More correct DAC programming. In particular, the DAC was
+ incorrectly programmed into DSP mode, when it was expected to be
+ used in I2S mode.
+* Pad all the audio samples with zero to avoid signedness issues.
+
+
+Changes in release DE1-12:
+--------------------------
+* Fix misreading of the spec w.r.t. the HCS bit in ACMD41. Add a
+ unique error code (E8) to ACMD41 failure. Shouldn't
+ really matter much.
+
+
Changes in release DE1-11:
--------------------------
* Read the SD OCR properly - in DE1-10 all *non*-SDHC cards were broken...
diff --git a/i2c.v b/i2c.v
index 77f3f08..7f24d97 100644
--- a/i2c.v
+++ b/i2c.v
@@ -27,7 +27,7 @@ module sound_i2c (
parameter i2c_addr = 7'h1A; // DAC I2C address
- // Only need to set registers 0-9
+ // Only need to set registers 15 + 0-9
parameter i2c_rom_stop = 4'd9; // Last valid register number
reg [3:0] i2c_rom_a;
@@ -61,7 +61,8 @@ module sound_i2c (
if ( ~rst_n )
begin
// Synchronous reset
- i2c_rom_a <= 4'd0;
+ // Note: we write register 15 (RESET) first, then 0-9.
+ i2c_rom_a <= 4'd15;
i2c_bit_ctr <= 5'd0;
i2c_qtr <= 2'b00;
i2c_active <= 1'b1;
@@ -170,19 +171,21 @@ module sound_i2c_rom (
reg [8:0] q_reg;
assign q = q_reg;
-
+
+ // See the Wolfson WM8731 datasheet for the meaning of these values
always @(*)
case (a)
- 4'h0: q_reg <= 9'h01a;
- 4'h1: q_reg <= 9'h01a;
- 4'h2: q_reg <= 9'h07b;
- 4'h3: q_reg <= 9'h07b;
- 4'h4: q_reg <= 9'h0f8;
- 4'h5: q_reg <= 9'h006;
- 4'h6: q_reg <= 9'h000;
- 4'h7: q_reg <= 9'h001;
- 4'h8: q_reg <= 9'h002;
- 4'h9: q_reg <= 9'h001;
+ 4'd15: q_reg <= 9'b000000000; // Device reset
+ 4'd0: q_reg <= 9'b0_0_00_10111; // Left line in
+ 4'd1: q_reg <= 9'b0_0_00_10111; // Right line in
+ 4'd2: q_reg <= 9'b0_0_1111001; // Left headphone out
+ 4'd3: q_reg <= 9'b0_0_1111001; // Right headphone out
+ 4'd4: q_reg <= 9'b0_11_0_1_1_0_0_0; // Analogue audio path control
+ 4'd5: q_reg <= 9'b0000_0_0_11_0; // Digital audio path control
+ 4'd6: q_reg <= 9'b000000000; // Power down control
+ 4'd7: q_reg <= 9'b0_0_0_0_0_00_10; // Digital audio interface format
+ 4'd8: q_reg <= 9'b0_0_0_0111_0_0; // Sampling control
+ 4'd9: q_reg <= 9'b00000000_1; // Active control (enable)
default: q_reg <= 9'hxxx;
endcase
diff --git a/sound.v b/sound.v
index 887ff08..056d082 100644
--- a/sound.v
+++ b/sound.v
@@ -320,11 +320,15 @@ module sound_i2s(
if (stb_16us)
sample <= magnitude;
+ // We load serial_out after clock 1, which means each frame has two
+ // zero padding bits at the front. Bit 0 is required by I2S standard
+ // format, and bit 1 means our unsigned output is always in the positive
+ // half of the signed number space.
always @(posedge i2s_clk)
- if (ctr[6:0] == 7'h00)
+ if (ctr[6:0] == 7'h01)
serial_out <= sample;
else
- serial_out <= { serial_out[12:0], 1'b0 };
+ serial_out <= { serial_out[13:0], 1'b0 };
sound_generator sound_generator (
.clk (i2s_clk),