Tag Archives: gpio

Changing the output filter characteristics of the HiFiBerry Mini DAC

hifiberry-filter-jumperThe HiFiBerry Mini has a cool feature: you can switch the characteristics of the output filter by software. The DAC chip generates high output frequencies. These have to be filtered to remove all components above the audio bandwidth. There are two parts of this filtering process: a digital filter on the DAC chip itself and a first-order analog filter. You can see the analog filter between the two RCA connectors on the port.

But let’s have a look on the digital filter. It can run in IIR and in FIR mode. There are a lot of discussion, which is better. The good thing here is: you can listen to both and find out be yourself what you like more.

There is a jumper “Filter” on the board. It can be used like this:

  • no jumper – DAC runs in IIR mode (low latency)
  • jumper left – DAC runs in FIR mode (higher latency)
  • jumper right – filter can be controlled by the Raspberry Pi

But how do you control the filter settings from the Raspberry Pi? You just have to control GPIO27 of the Raspberry.

WiringPi

A nice program to control the state of the GPIO ports is theĀ WiringPi toolset.

sudo gpio export 27 out
sudo gpio readall
+----------+-Rev2-+------+--------+------+-------+
| wiringPi | GPIO | Phys | Name   | Mode | Value |
+----------+------+------+--------+------+-------+
|      0   |  17  |  11  | GPIO 0 | IN   | Low   |
|      1   |  18  |  12  | GPIO 1 | IN   | Low   |
|      2   |  27  |  13  | GPIO 2 | OUT  | Low   |
|      3   |  22  |  15  | GPIO 3 | IN   | Low   |
|      4   |  23  |  16  | GPIO 4 | IN   | Low   |
|      5   |  24  |  18  | GPIO 5 | IN   | Low   |
|      6   |  25  |  22  | GPIO 6 | IN   | Low   |
|      7   |   4  |   7  | GPIO 7 | IN   | Low   |
|      8   |   2  |   3  | SDA    | OUT  | Low   |
|      9   |   3  |   5  | SCL    | ALT0 | High  |
|     10   |   8  |  24  | CE0    | ALT0 | High  |
|     11   |   7  |  26  | CE1    | ALT0 | High  |
|     12   |  10  |  19  | MOSI   | ALT0 | Low   |
|     13   |   9  |  21  | MISO   | ALT0 | Low   |
|     14   |  11  |  23  | SCLK   | ALT0 | Low   |
|     15   |  14  |   8  | TxD    | ALT0 | High  |
|     16   |  15  |  10  | RxD    | ALT0 | High  |
|     17   |  28  |   3  | GPIO 8 | IN   | Low   |
|     18   |  29  |   4  | GPIO 9 | IN   | High  |
|     19   |  30  |   5  | GPIO10 | IN   | Low   |
|     20   |  31  |   6  | GPIO11 | IN   | Low   |
+----------+------+------+--------+------+-------+

You can now toggle the port using

sudo gpio write 2 1 # low latency IIR filter
sudo gpio write 2 0 # normal latency FIR filter

Shell script

If you don’t want to install additional software, you can also use a shell script:

sudo echo "27"  > /sys/class/gpio/export
sudo echo "out" > /sys/class/gpio/gpio27/direction 
sudo echo "1" > /sys/class/gpio/gpio27/value # low latency IIR filter
sudo echo "0" > /sys/class/gpio/gpio27/value # normal latency FIR filter