This PCB is in first place an add-on for our Raspberry Pi Audio DAC (160198-1) but it’s also usable for general use (separate symmetrical 5V supply needed then). Volume and/or an application running on the Raspberry Pi can be controlled by six buttons (a seventh button is used for storing a preferred setting of the volume level) and IR remote control. As the name points out it’s a volume control for our RPi DAC, because the IC we used (PCM1794A) doesn’t have one. Discarding bits in software is not an option. So the only option is additional hardware. The volume controller chosen is an integrated circuit from Texas Instruments, the PGA2311. We used it because of its excellent low noise and low distortion specifications and it works on a symmetrical 5 V power supply. Called ‘Digitally-Controlled Analog Volume Control’ it’s controlled by a Serial Control Interface, also has selectable zero crossing detection and a mute function. To control the PGA2311 we use a microcontroller from Atmel (ATtiny series).
When used as an add-on no additional power supply is needed. +4.74 and -4.81 V are supplied by the DAC and +3.3 V by the Raspberry Pi (expansion connector pin 1). In this case K8, C15 and C16 can be left unmounted. The +3.3 V is only needed to supply the inverters (IC4) driving the GPIO pins of the expansion connector. K7 is a special 3way long pin stack through connector so it can be soldered at some distance from the PCB on the bottom side. A normal socket isn’t long enough. K7 is connected to K6 on the DAC PCB. The power supply for the PGA2311 is filtered with common mode choke L6 and inductors L2, L3 and L4. L5 filters the digital power supply for the microcontroller (IC1) and L7 filters the 3.3 V power supply for the inverters (IC4). L1 separates the digital and analog power supply of the PGA2311. L4 avoids an RF ground loop since both power (K7) and the ground connections of K2 and K3 are already connected on the DAC.
For general use IC4, C18, C17, L7, K2, K3 and K7 can be left unmounted. Best is to replace L4 with a 0 Ω resistor.
We’re not going to discuss the internal workings of the PGA2311 (IC2) but instead refer to the datasheet. The zero crossing enable is connected to jumper JP1 and so this function can be enabled or disabled whatever the preference is. Test points are placed on the connections for the serial interface between the microcontroller and the PGA2311 (CS, SDI, SCLK and MUTE). The inputs and outputs are connected through 47 Ω resistors (R1..R8) to two different connectors. Additional 3way long pin stack through connectors (K2, K3) are used to connect the ins and outs of the DAC and Volume Control the same way as is done with the power supply. The ins and outs of IC2 are also connected to 3.5 mm jack audio sockets (K4, K5). Now the original DAC signal is also available through this type of connecter (K5), on the DAC the output signals are available through RCA phono jacks. The output signal from the volume control is available through 3.5 mm jack K4.
For general use K5 is the input of the PGA2311 and K4 the output. The 47 Ω resistors protect the outputs from capacitive loads and separate the different connectors.
To make the PGA2311 work we need a microcontroller to send the correct data to the serial control interface. Microcontroller ATtiny861A is a 20pin IC with just enough I/O’s for the serial interface, 7 push buttons, an IR receiver and a LED. LED1 is a through hole version so it can be connected through wires by placing a pin header instead. This way the led can be placed elsewhere. Even all the ISP I/O’s are used, accept for the Reset. So don’t push any buttons while programming the microcontroller. Two different firmware’s are available. 160321-11 for use with our the Raspberry Pi DAC (running Volumio 1.55) or general use and firmware 160321-12 for use with a RPi running Volumio 2. The protocol for remote control is RC5. Perhaps better protocols are out there but the fastest way to success was the use of Bascom. It has a single statement for RC5: Getrc5(Address, Command). Programming in Bascom is easy.
This firmware is developed with Volumio 2 in mind (https://volumio.org). It has a plugin for GPIO Buttons. Almost all GPIO’s can be given one the following actions: Play/Pause, Volume + Volume -, Previous, Next and Shutdown. Our DAC doesn’t have a volume control so four actions can be used to control Volumio, but for DAC’s with volume control Volume + and Volume – are also connected. The GPIO pins selected are free in a sense that they are not used for I2S or the 3.5” touchscreen LCD. The GPIO’s have pull downs by default. The version of Volumio we used (2.041, date 12-12-2016) doesn’t support the 3.5”touchscreen LCD (yet?). The following table gives a view of the functions of all Raspberry Pi expansion connector pins.
K1 Rpi (v3) 160321-12 I2S 3.5" LCD
1 3.3V 3.3V 3V3
2 5V 5V
3 GPIO2 (SDA1) NC
4 5V 5V
5 GPIO3 (SCL1) NC
6 GND GND GND GND
7 GPIO4 (GPIO_GCLK) NC
8 GPIO14 (TXD0) NC
9 GND GND GND GND
10 GPIO15 (RXD0) NC
11 GPIO17 (GPIO_GEN0) TP_IRQ
12 GPIO18 (GPIO_GEN1) BCK NC
13 GPIO27 (GPIO_GEN2) NC
14 GND GND GND GND
15 GPIO22 (GPIO_GEN3) S1/Play/pause NC
16 GPIO23 (GPIO_GEN4) NC
17 3.3V 3.3V
18 GPIO24 (GPIO_GEN5) LCD_RS
19 GPIO10 (SPI_MOSI) LCD_SI/TP_SI
20 GND GND GND GND
21 GPIO9 (SPI_MISO) TP_SO
22 GPIO25 (GPIO_GEN6) RST
23 GPIO11 (SPI_SCLK) LCD_SCK/TP_SCK
24 GPIO8 (SPI_CE0_N) LCD_CS
25 GND GND GND GND
26 GPIO7 (SPI_CE1_N) TP_CS
30 GND GND GND
32 GPIO12 S6/Shutdown
33 GPIO13 S5/Volume up
34 GND GND GND
35 GPIO19 LRCK
36 GPIO16 S4/Volume down
37 GPIO26 S2/Previous track
38 GPIO20 S3/Next track
39 GND GND GND
40 GPIO21 DATA
The following RC5 commands are used:
Play/pause RC5 command 1 (Digit entry)
Previous track RC5 command 2 (Digit entry)
Next track RC5 command 3 (Digit entry)
Shutdown RC5 command 12 (Standby)
Mute/de-mute RC5 command 13
Personal preference settings RC5 command 14
Increase sound volume RC5 command 16
Decrease sound volume RC5 command 17
Shift sound balance to the right RC5 command 26
Shift sound balance to the left RC5 command 27
The logic high level of the GPIO’s is 3.3 V. We use a Hex Schmitt Inverter of type MC74VHC14DG from ON Semiconductor that can act as a level translator. The inputs can withstand voltages of up to 7 V. So it’s perfect for the job. The corresponding I/O’s of the microcontroller must have a high level if not active. This means the two I/O’s configured as input for volume must have pull ups activated (PA0/PA1). And the I/O’s configured as output for the four actions must be set to a high level if not active (PA2/PA3/PB1/PB3). The six push buttons S1..S6 are connected to the I/O’s of the microcontroller through 470 Ω resistors. If these buttons are pushed the resistors avoid short circuiting the outputs of the microcontroller while activating the corresponding inverters by making the inputs low. The impedance of the resistors is low enough to pull the inputs of the microcontroller to a low logic level. Pushing button S7 will store the current volume setting as a personal preference. It’s not located at the edge of the PCB since it will rarely be used. Some televisions had (have?) a green button to reset the most important settings to a preference. Some replacement remote controls might still have this button. LED1 will blink four times if S7 is pushed, indicating the current volume setting is written to EEPROM. This setting is used after power up. The first time a new microcontroller is powered up a default gain of -20 dB is set. This volume level can be too loud. So be warned.
The main purpose of LED1 is to indicate a RC5 command is being received but it’s not necessarily a command used by the volume control. The IR receiver is connected to PB6 because Getrc5 uses TIMER0 and the TIMER0 interrupt. The IR receiver used is a type from Vishay suitable for RC5. When developing your own software and a different IR protocol is used be sure that the IR receiver is the right one. The footprint is a standard one. A strange thing was noticed during the development of the software. If divide clock by 8 is disabled the Getrc5 statement doesn’t work properly. So fuse ckdev8 must be checked when programming the fuses of the microcontroller. Instead of disabling this fuse we increased the frequency of the external crystal to 12 MHz (X1). The examples of Bascom show 4 MHz as the default clock frequency.
This firmware was initially developed for use with Volumio 1.55 and our Raspberry Pi Audio DAC (have a look at project ‘Audio DAC for RPi – Networked Audio Player using Volumio ). But this firmware can also be used with Volumio 2 or entirely different purposes. Other applications require a separate symmetrical 5 V power supply. To avoid ground loops when using the Volume Control for other purposes we strongly advise to use an isolated power supply and replace L4 with a 0 Ω resistor (0603) or a small piece of wire. With K4 and K5 mounted and the right cables the circuit can be connected between any analog stereo link (Vmax is 2 V). The circuit can add remote controlled volume to any amplifier. Beside the 3.5 mm phone audio connectors (K4/K5) K2 and K3 can also be used. In latter case place pin headers or solder wires directly into the PCB.
The six push buttons S1..S6 are used to change volume settings only. The functions of the six push buttons and RC5 commands to control the PGA2311 are:
S1 = personal preference RC5 command 14
S2 = balance to the left RC5 command 27
S3 = balance to the right RC5 command 26
S4 = volume down RC5 command 17
S5 = volume up RC5 command 16
S6 = mute RC5 command 13
S7 is still the button to store the current volume setting in EEPROM as personal preference.
When mute is activated either in software or hardware (pin 8) the internal buffer amplifiers in the PGA2311 are disconnected from the output pins and VOUTL and VOUTR are terminated with 10-kΩ resistors to ground. This can cause the noise from the connected amplifier to increase. Muting also initiates an internal offset calibration.
At the moment the small 3.5 “ touchscreen LCD is not supported in Volumio 2. With the plugin to support the original Raspberry Pi Display installed a standard monitor can also be connected to the HDMI connector of the Raspberry Pi. A tip concerning installing this plugin. Don’t connect a keyboard to the RPi. Also remove a dongle if it’s for a mouse/keyboard combo. Best is to start the installation from within the WebUI.
We performed measurements on our prototype for general use. A laboratory power supply set to +4.74 and -4.81 V was used. This way the measurements are more or less comparable when used with our RPi DAC. L4 is replaced by a 0 Ω resistor. Output load is 10 k for each channel.
Supply current +11 mA (LED1 off)
+12 mA (LED1 on)
Maximum output voltage 2.3 V (0 dB gain)
(1 kHz, THD = 0.1 %) 2.6 V (20 dB gain)
0.39 V (-20 dB gain, 3.9 V in)
THD+N 1 kHz, B = 22 kHz 0.0003 % (0 dB gain, 2 V out)
1 kHz, B = 80 kHz 0.00042 % (0 dB gain, 2 V out)
20 kHz, B = 80 kHz 0.0022 % (0 dB gain, 2 V out)
1 kHz, B = 22 kHz 0.0016 % (20 dB gain, 2 V out)
1 kHz, B = 80 kHz 0.0025 % (20 dB gain, 2 V out)
20 kHz, B = 80 kHz 0.0035 % (20 dB gain, 2 V out)
IMD (50 Hz : 7 kHz = 4 : 1) 0.0007 % (0 dB gain, 2 V in)
0.0038 % (20 dB gain, 200 mV in)
DIM 0.0009 % (0 dB gain, 2 V in)
(3.15 kHz square + 15 kHz sine) 0.0008 % (20 dB gain, 200 mV in)
Bandwidth (-3 dB) 1.1 MHz (0 dB gain, output is triangular shaped)
690 kHz (20 dB gain)
Crosstalk < -100 dB (1 kHz)
< -90 dB (20 kHz)
We also recorded some plot with our Audio Precision Analyzer.
Plot A shows the total harmonic distortion plus noise (THD+N) as a function of frequency for a gain of 0 dB (cyan) and 20 dB (green) at an output voltage of 2 V and a bandwidth of 80 kHz. At higher gain noise is the main cause of the higher THD+N value. THD+N at 1 kHz, 2 V out and a gain of 0 dB is 0.0003 % when measured with a bandwidth of 22 kHz. THD+N at 1 kHz, 2 V out and a gain of 20 dB is 0.0016 % when measured with a bandwidth of 22 kHz.
Plot B shows amplitude as a function of frequency at a gain of 0 dB and an output level of 2 V. The maximum frequency of the generator of the Audio Precision Analyzer is 200 kHz. The small deviation round 100 kHz is not worth mentioning (look at the scale!). The cut-off frequency is 1.1 MHz. The slew rate is the limiting factor here and the output signal is triangular shaped at this high frequency. The peak-to-peak amplitude was compared to that of the sine at 1 kHz.
Plot C shows amplitude as a function of frequency at a gain of 20 dB and an output level of 2 V. The onset of the cut-off frequency of 690 kHz is visible at 200 kHz. A little over 0.1 dB decrease in amplitude at 200 kHz is negligible.
Plot D shows crosstalk as a function of frequency. The difference between the two measurements is about 2 dB, so practically symmetrical. Green is crosstalk from right to left (< -104 dB) and cyan is crosstalk from left to right (< -106 dB). At 20 kHz the crosstalk is the same for both measurements (< -92 dB).
Plot E shows THD+N as a function of output level at a gain of 0 dB. Bandwidth is reduced to 22 kHz to have a better view when clipping sets in. At this low power supply voltage (+4.74/-4.81 V) the maximum undistorted output voltage is about 1.9 V. At this point THD increases and at 2.3 V THD is 0.1 % and at 2.6 V THD is 1 %.
Plot F shows THD+N as a function of output level at a gain of 20 dB. Bandwidth is reduced to 22 kHz to have a better view when clipping sets in. At this low power supply voltage (+4.74/-4.81 V) the maximum undistorted output voltage is surprisingly higher, 2.48 V (THD is 0.0015%). At this point clipping sets in and at 2.6 V THD is 0.1 % and at 2.7 V THD is 1 %. So apparently at lower gain clipping occurs sooner in the input stage because the input voltage is higher.
Plot G shows the FFT of a 1 kHz signal at a gain of 20 dB and 2 V output voltage. Only a 2nd and 3rd harmonic are visible. This corresponds to a THD (without noise) of 0.001 %. THD+N at a bandwidth of 22 kHz is 0.0016 % (0.0025 % at a bandwidth of 80 kHz).
Plot H shows the FFT of a 20 kHz signal at a gain of 20 dB and 2 V output voltage. Here also a 2nd and 3rd harmonic are visible. This corresponds to a THD (without noise) of 0.00086 %. THD+N at a bandwidth of 80 kHz is 0.0035 %.
Plot I shows the FFT of a 1 kHz signal at a gain of 0 dB and 2 V output voltage. Several harmonics are visible but the 2nd and 3rd mainly define THD. If we calculate THD (without noise) with only these two harmonics it amounts to 0.00016 %. THD+N at a bandwidth of 22 kHz is 0.0003 % (0.00047 % at a bandwidth of 80 kHz).
Plot J shows the FFT of a 20 kHz signal at a gain of 0 dB and 2 V output voltage. Several harmonics are visible but the 2nd and 3rd mainly define THD. If we calculate THD (without noise) with only these two harmonics it amounts to 0.0021 %. THD+N at a bandwidth of 80 kHz is 0.0022 %
Bill of materials (160321-1 v1.1, all parts)
R1,R2,R3,R4,R5,R6,R7,R8,R11 = 47 Ω, 125 mW, 1 %, SMD 0805
R9,R10 = 2.2 kΩ, 100 mW, 5%, SMD 0805
R12 = 10 kΩ, 100 mW, 5%, SMD 0805
R13,R14,R15,R16,R17,R18 = 470 Ω, 100 mW, 5%, SMD 0805
C1,C2 = 22 pF, 50 V, 5 %, C0G/NP0, SMD 0805
C3,C4,C5,C13,C14,C17,C18 = 100 nF, 50 V, 10 %X7R, SMD 0805
C6,C8 = 100 nF, 25 V, 5 %, C0G/NP0, SMD 1206
C7,C9,C10,C15,C16 = 10µF, 35V, 0.04Ω, diam. 6.3 mm max., lead spacing 2/2.5 mm
Würth Elektronik 870055673001 (WCAP-PTHR Series)
C11,C12 = 4µ7, 25 V, 20 %, X5R, SMD 0805
L1,L2,L3,L4,L5,L7 = 600 Ω @ 100 MHz, 0.15 Ω, 1.3 A, SMD 0603, Murata BLM18KG601SN1D
L6 = ACM4520-231-2P-T (TDK), 2 x 0.05 Ω, 230 Ω @ 100 MHz, 2.6 A, SMD
LED1 = LED, red, T-1, 3 mm
LED2 = Led, green, low-power, SMD 0805
IC1 = ATtiny861A-SU, SOIC-20, firmware 160321-11
IC2 = PGA2311UA., SOIC-16
IC3 = TSOP34436, 3pin epoxy package
IC4 = M74VHC14DG, SMD SOIC-14 (ON Semiconductor !!!)
K1 = 40-pin GPIO Stacking Header - 2x20 Female - Extra Tall
K2,K3,K7 = 3way pin socket, vertical, pitch 2.54 mm (on bottom side!)
3way long pin stack through connectors
K4,K5 = 3pole stereo jack socket, 3.5 mm, PCB, KLBR 4 Lumberg
K6 = 2x3 header, vertical, pitch 2.54 mm
K8 = Terminal block 5.08 mm, 3-way, 630 V
JP1 = 3way pin header, vertical, pitch 2.54 mm
LED1 = 2way pin header, vertical, pitch 2.54 mm
JP1 = Shunt jumper, 2.54 mm spacing
S1,S2,S3,S4,S5,S6 = Tactile switch, right angle, SPST, FSMRA4JH TE Connectivity
S7 = Tactile switch, SPST, FSM4JRT TE Connectivity
X1 = 12 MHz miniature crystal, 5 x 3.2 mm, SMD, Cload 18 pF
4 x 17 mm M2.5 standoff (05.12.173 Ettinger)
4 x 6 mm M2.5 machine screw, cheese head slotted
4 x M2.5 nut, hex
PCB 160321-1 v1.1
To support the LCD 4 x 14 mm M2.5 standoff (05.12.143 Ettinger)
- Audio & Video
Volume control  for Raspberry Pi Audio DAC 160198
1. Februar 2017
In Elektor | November 2017 | Find it here
- Topoverlay of Volume Control (160321-1 v1.1) for RPi Audio DAC (160198)
- Copper on top and bottom of Volume Control (160321-1 v1.1) for RPi Audio DAC (160198)
- BASCOM-AVR source code for Volume Control 160321-1 v1.1 (RPi + Volumio 1.55 or stand-alone/general use) (31.89 KB )BASCOM-AVR source code for Volume Control 160321-1 v1.1 (RPi + Volumio 1.55 or stand-alone/general use)
- BASCOM-AVR source code for Volume control 160321-1 v1.1 (RPi + Volumio 2)