EvanKrall / pipad

A PCB for putting a Raspberry Pi CM4 inside a 1st-generation iPad.
53 stars 3 forks source link

test new audio codec revision #12

Open EvanKrall opened 3 years ago

EvanKrall commented 3 years ago

Refer back to my project log about testing the last codec revision.

EvanKrall commented 3 years ago

Some fun with the dtoverlay: https://www.raspberrypi.org/forums/viewtopic.php?p=1914969#p1914969

Today's task is to figure out why I'm not getting audio output. I can see i2s data being sent by the pi, and the headphone pins jump to some nonzero DC offset (which is odd... the whole point of switching to this codec was to get ground-centered headphone output.)

I think my plan here is to look at the datasheet, figure out what registers need to be set to what value to get output on HPL/HPR or LOL/LOR, and then see which settings in alsamixer affect those registers.

EvanKrall commented 3 years ago

I think I forgot to connect ring2/GND_sense to ground.

EvanKrall commented 3 years ago

I should rearrange the decoupling caps to put a 10uF near pin 39 (DVDD_CP).

EvanKrall commented 3 years ago

oh, boo, the tlv320aic32x4 driver doesn't seem to know how to configure the charge pump in the 3206.

EvanKrall commented 3 years ago

boo, it also doesn't seem to know how to configure the headset detection feature, page 0 reg 67. (2.11.1 Headset Detection in https://www.ti.com/lit/an/slaa463b/slaa463b.pdf)

EvanKrall commented 3 years ago

Various registers to check:

Experiments:

EvanKrall commented 3 years ago

I finally got audio by setting page 0 reg 0x04 to 0x01 (BCLK is CODEC_CLKIN), among some other settings.

By setting DOUT to CLKOUT, and CDIV_CLKIN to PLL_CLK, I could see that the PLL was not generating a clock.

EvanKrall commented 3 years ago

with this script, I can get a steady 4xBCLK out of the PLL:

./tlv320aic32x6_set_reg.sh 0 0x04 0x07   # D6=0 low PLL clock range (?); D3..2 = 01 BCLK pin is input to PLL; D1..0 = 11: PLL clock is CODEC_CLKIN

# Page 77 in slaa463b.pdf
# PLL_CLK = (PLL_CLKIN * R * J.D) / P

./tlv320aic32x6_set_reg.sh 0 0x05 0x91  # PLL enabled (D7), configure P (D6..4) = 1 and R (D3..0) = 1 - page 96
./tlv320aic32x6_set_reg.sh 0 0x06 0x04  # PLL parameter J = 4
./tlv320aic32x6_set_reg.sh 0 0x07 0x00; ./tlv320aic32x6_set_reg.sh 0 0x08 0x00  # PLL parameter D = 0

# DOUT is CLKOUT
./tlv320aic32x6_set_reg.sh 0 0x35 0x16
# CLKOUT is PLL
./tlv320aic32x6_set_reg.sh 0 0x19 0x03
# CLKOUT powered up, divider = 1
./tlv320aic32x6_set_reg.sh 0 0x1A 0x81

There's a lot of white noise on the output, but it does work.

EvanKrall commented 3 years ago

I think I left the headphone connector's ground pin (GND_SENSE) ungrounded. I wonder if this is why it seems to be also swinging around with the output signal, and things seem to get louder when one channel is muted.

EvanKrall commented 3 years ago

Played around with enabling the charge pump tonight:


#####################################################
# Enabling the charge pump and ground-centered mode #
#####################################################

# To turn on the charge pump circuit, program Page 1, Register 1, D1:0 to “10”. When the charge pump
# circuit is disabled, VNEG acts as a ground terminal, allowing unipolar configuration of the headphone
# amps. By default, the charge pump is disabled.
./tlv320aic32x6_set_reg.sh 1 0x01 0x02  # D1-D0 = 10: Power Up Charge Pump with Internal Oscillator Clock (nom. 8MHz) 

# The switching rate of the charge pump can be controlled
# by Page 1, Register 124, D3:0. Because the charge pump can demand significant inrush currents from the
# supply, it is important to have a capacitor connected in close proximity to the DVdd_CP and DVss_CP
# pins of the device. At 500kHz clock rate this requires approximately a 10μF capacitor. The ESR and ESL
# of the capacitor must be low to allow fast switching currents.
./tlv320aic32x6_set_reg.sh 1 0x7c 0x00  # Charge Pump Clock Divide Control = 64

# The ground-centered mode of operation is enabled by configuring Page 1, Reg 125, D4 after enabling the
# charge-pump.
./tlv320aic32x6_set_reg.sh 1 0x7d 0x13  # Enable Ground Centered Mode for Headphone Drivers; Output Power Rating is 100%; DC Offset Correction for all possible signal routings for HPL and HPR

I'm seeing significant droop on AVDD and DVDD_CP when audio levels get high; I may need to bump the size of the capacitors. In particular, slaa463b says I should have a 10uF cap on DVDD_CP, but I have 0.1uF.

Earlier in the day (when I was not using ground-centered mode), I had compared left and right channels against each other with an XY chart; this showed significant correlation between the two when playing silence. (With an interesting banding pattern which I think is due to dithering applied by the DAC.) I should do this again in ground-centered mode.

I should also try to measure the droop on the various Vcc pins.

EvanKrall commented 3 years ago

By playing some white noise and looking at the FFT with my oscilloscope, it appears that the frequency response of the output drops off significantly from about 2.4kHz to 2.7kHz. I think I need to take a look at the various user-defined filters (slaa463b, page 44 and onwards).

I'm also still getting a lot of broad-spectrum noise mixed with my output signal. I'd like to get to the bottom of that. Based on how it looks on my scope (quantized), I think it may be added by codec as dithering, to reduce quantization error.