Arduino: Preamp

I finished wiring up the analog audio side of things a few days ago. Now a Burr Brown OPA2134 opamp at unity-gain buffers the incoming audio signal and a PGA2311 provides volume control. I added a Mean Well +/- 5V PSU to power it all and provide the negative rail for the audio chips.

I had a huge breakthrough in reliability when I realized that I need to run separate MOSI lines for each chip’s SPI bus. Often you’ll see a data sheet talk about daisy chaining chips and sharing MOSI lines, but this is only for the same kind of chip. The capacitive sensor reports perfect values now.

I rewrote the code from scratch to troubleshoot when the sensor was being unreliable and learned some more about how the chips are actually communicating. Wrapping my head around the LEDControl library was a big help. I found a neat function called fscale that is similar to map, but it accepts floating point variables and can curve the result. I used it to manipulate the volume level to be more linear and predictable as the value of the sensor changes.

I adapted the volume control code from linux-works on the Arduino forums to use shiftOut instead of the custom function he had written:

void PGA_set_volume(byte value)
  byte shifted_val = (value << 1);
  digitalWrite(PGA_CS_PIN, LOW);     // assert CS
  shiftOut(PGA_SDI_PIN, PGA_SCLK_PIN, MSBFIRST, shifted_val); // right value
  shiftOut(PGA_SDI_PIN, PGA_SCLK_PIN, MSBFIRST, shifted_val); // left value
  digitalWrite(PGA_CS_PIN, HIGH);    // deassert CS

A cadmium sulphide LDR now provides ambient light values to adjust the brightness of the LEDs dynamically in software.

The next step is to tie in the 12V PSU with a relay to power an amplifier stage, and I’m considering just purchasing a Tripath-based board. I’ve backed myself into a bit of a corner by purchasing a 12V supply instead of something higher, and I don’t want to try building and soldering a board based on the complex Tripath chips when they’re so inexpensive to purchase pre-assembled.

The really hard part that’s coming up will be building the enclosure to meet the expectations I’ve set for it.