How controlling the volume ?

This page explains how to control the MAS9116 / WM8816 gains, and fixing a simple symetrical power supply. The MAS9116 has 2 audio channels (stereo audio = L / R) What I will do here is sending gain(s)-data to the MAS9116. If you take a look at page 4 of the datasheet you will see the registers descriptions (here part of that page):

The registers descriptions of the MAS9116


The yellow line shows how to control both channel gains simultainiously. What now must be done is sending 16 bits of data each time for changing the gain(s) (L and R) 0.5 dB, up or down. Notice that the Address Byte stay the same all the time, and will be: X1001WXX , if you read below the yellow line, it says, the X's must be 1 (high), and the W must be 0 (low), so the Address Byte will be: 0b11001011 = 0xCB. The Data Byte will change by the rotary-encoder (or whatever way you want to control it, e.g. use DEC and INC), and that will have an 8-bit resolution (0 - 255) If you want to hear audio you should initialize at 0 dB, look at the datasheet and look at CR1 and CR2, both identical, so init will be 0b11100000 = 0xE0 (or 224th position of the wiper) Send in the Address Byte (first 8 bits) and right after that the Data Byte (last 8 bits). Don't forget that XMUTE must be hi (1) at init! Now look at page 8, what you see is the timing of the serial data, you can see very clearly the 16 databits (DATA IN) Now take a close look at the timing diagram:

The timing diagram of the MAS9116


What you see are the three wires: CCLK, XCS and DATA. So it takes 4 i/o ports of a microcontroller, or when you only use one MAS9116 in your circuit, don't use XCS, just tide it to ground, and you can pull-up XMUTE with a 10k resistor, then only 2 wires (DATA + CCLK) are left. XCS (Chip Select) will only be used for multiple MAS9116 chips in one circuit (like e.g. an audio-mixer or DJ mixer or studio-mixer). Operation: everytime CCLK goes hi the data must follow (data can be 0 (lo) or 1 (hi), you need to write a serial protocol. Do this: first make XCS low and XMUTE hi, than set the most significant bit (msb) of the Address Data ready, then make CCLK hi, now this bit will be transmitted to the MAS9116, do this 8 times (the Address information byte), then read the Data Byte from which ever source (pushbuttons, rotary-encoders, up/down) you wanna use, transmit this byte aswell, when all 16 bits (2 bytes) are in, make XCS hi (1), now the new volume level (depends on the value 0-255 of the Data byte) is set. You can also make volume or balance presets, with a few select buttons, like: mute, max. volume or 0 dB, R, L or center, etc.


Next, how to make a low-cost symetrical power-supply for it.

For audio you need a pretty good power supply, next a diagram of a symmetrical power-supply for your homemade audio projects (for this project you also can take the 7824 and 7924, but no adjustable voltage):

Symetrical Power Supply for MAS9116 / WM8816


The voltages need to be clean, so a lot of capacitors, to get rid of the noise and humm. Place the transformer away from the audio (not directly next to it) PCB (printed circuit board), and shield the audio always good (metall case/cover) The rectifiers (1N4002's) are for protecting the regulators. When R2's are turned to ground, the output voltage will be 1.25 Volt, when at max. resistance (50k + 1k5), you will get the input voltage minus the voltage drop accross the regulator, so these two voltages are the limits. I will take two digital pots (X9C503's) instead, then I will have a voltage stepsize of: Uout(max) - 1.25 / 100 (or take 50k digital pots with 1024 steps, 16bit accuracy) This way I can use voltage presets, and also can control the audio volume, DAC of the MAS9116 or WM8816, etc. with a single AVR. I took a 1k5 resistor, because the wiper current of a digipot needs to be lower than 1 mA, thus 1.25 Volt / 1500 ohm = 0.83 mA, and the range still is from 1.25 to the maximum (theoretical) output voltage: Uout = 1.25 (1 + 50000 / 1500) = 42.9 Volt, but this voltage can't be reached ofcourse, because the maximum input voltage can't exceed 40 Volt (max. Uout = 37 Volt) Also put heatsinks on the regulators, if your projects eats a lot of current. Here an example of how to fix one:


A homemade symetrical power supply, adjusted at -20V 0 +20V


Next... How detecting a peak level ?

On page 4 of the datasheet of the MAS9116, you find the register descriptions. This part of the page:

The Peak Level Detector and Reference


Register CR4 is the register where the data of the Peak Detector is stored, are four values:

0x00 = No Peak Level overload
0x01 = Right Channel Peak overload
0x02 = Left Channel Peak overload
0x03 = Both Channels Peak overload

The Peak Detector works as follows: A value is written in the Peak Detector Reference Register CR3, the DAC will set a corresponding voltage on an internal analog comparator. Can be calculated with the next formula:

Vref = k / 256 * 18V (256 means 8-bit DAC)

I.e. when you take the value k = 30, you will have a reference voltage of: 30 / 256 * 18 = 2.1 Volt (varies between 0 - 18V, this is the audio signal voltage, simply play around with some values, and you will find out which value(s) works best for your project(s)) When the audio level reaches the same or higher audio level, the Peak Detector bit(s) will toggle (works the same as an AVR analog comparator), for each audio channel one bit. After reading the status of the Peak Detector bits, they will be reset again. So first set the Peak Detector Reference value, then poll the Peak Detector Status and wait for overload.

Good luck!



[back to top]