Digital Stereo VU-meter

digital_vu_meter_1
digital_vu_meter_1digital_vu_meter_2digital_vu_meter_3digital_vu_meter_4
5 5 2 Product


Here we will deal with the construction of a digital sound level indicator (Voltage Unit meter). Our digital VU meter is based on a microcontroller and it is able to display a stereo bar graph on two LED bars. Although being a digital one, it does not use any digital interface in its inputs. It rather has analog inputs, and therefore can be easily embedded in any common audio device (amplifier, mixer, musical instrument, etc.).

Digital Stereo VU-meter
Photo 1. Digital Stereo VU-meter with LED - bars

The idea of using a microcontroller to display audio signals level in real time is quite simple but there are several details and limitations that we will deal with. Our VU-meter uses LED bars but the basic idea presented here could be used for building meters to use any kind of digital display. Actually, we present some fresh ideas and not just construction details.

Block diagram

We use the dsPIC30F2012 microcontroller from Microchip. This microcontroller belongs to the Microchip dsPic family and has fast digital signal processing capabilities. However, we do not use any of these capabilities in our project. We only use the CPU of the dsPIC30F2012 as in the case of being just a simple microcontroller.

The choice of dsPIC30F2012 instead of any simple microcontroller was made because: a) it has a 12bit A/D converter module unlike most common microcontrollers that have 10bit A/D converter. b) Its a relatively low cost device and has a lot of input-output (I/O) pins and c) just happened to be in stock in our lab.

The more essential reason of choosing dsPIC30F2012 is due to its 12bit analog to digital (A/D), which gives a 72db dynamic range, compared to 60db that we would theoretically have with a 10 bit A/D. Before we analyze in detail how these numbers came about, let's first look at the block diagram of our digital VU-meter:

Block diagram of a digital VU-meter
Figure 1. The general concept of a digital VU-meter with an analog input

Figure 1 presents the general concept of a digital VU-meter with an analog input. The presented block diagram is for a monaural VU-meter (there is only one audio input - one channel). For stereo or for any other polyphonic version, the above block has to be repeated.

According to figure 1, the VU-meter consists of 5 stages. The first stage is a precision rectifier. The second stage is an averaging detector circuit. The third stage is an analog to digital (A/D) converter, located inside the microcontroller. The fourth stage is the CPU of the microcontroller and the fifth stage is the display device (LED bar or screen).

The rectifier and the averaging detector could be implemented digitally within the dsPIC by utilizing the digital signal processing capabilities of the specific controller. However, mainly for simplicity, we prefer these stages to be implemented with external hardware. By implementing these stages on hardware, we save enough computing power (the microcontroller runs in reduced speed), the microcontroller needs less power and makes use of less memory but in this way, we also eliminate the need of use of an additional anti-aliasing filter.

It is a common rule that conversions from analog to digital with an ADC (Analog to Digital Converter) always require an anti-aliasing filter. This is due to the need for band limiting of the input signal at less than the half of the sampling frequency. In our case, however, the averaging circuit by itself produces a very slow varying signal which is band limited in very low frequencies (some Hz), much less than the half of the sampling frequency. Therefore we do not need to use an additional anti-aliasing filter.

The averaging stage produces an almost DC signal which is proportional to the amplitude of the input signal. The averaging circuit is actually an integrator with appropriate defined time constants for hold and release in order to ensure a proper response for the VU-meter. The response of the VU-meter is not very fast, so that the display on the LEDs is neither flickering nor too slow, so that it can easily follow the noticeably perceived changes of the sound.

The ADC converts the averaged signal to a digital sequence of 12bit digital values. With the aim of the CPU, this digital sequence is used in real time to produce a bar-graph to some LEDs or to a digital display.


Rectifying and averaging

In case of a rectifier will no loss or gain, the amplitude of the rectified signal is equal to the amplitude of the AC input signal. By using an active rectifier circuit with some gain in our project, the amplitude of the rectified signal is not equal but remains proportional to the amplitude of the input signal. Then, an almost DC signal that is proportional to the sound level is derived by smoothing out the rectifier’s output. This is the technique that is used in our digital VU-meter.

In our stereo VU-meter circuit, there are two rectifiers and two smoothing circuits, each pair for each audio channel, respectively. These circuits are presented in figure 2. We will examine in detail the topology of the Right audio channel. The corresponding circuits of the left channel are identical.

Digital VU meter - Input stages
Figure 2. The electronic circuit of the Digital VU-meter (1 of 2 - analog section)

From figure 2, you may notice that we use a precision rectifier and not just a standard diode rectifier. This is because we have to deal with low level signals, much lower than the threshold voltage of about 0.7V of conventional silicon diodes.

The majority of precision rectifiers require dual power supply (positive and negative). However, in our project we wished to make a single supply voltage rectifier. This was achieved by the use of the Microchip’s MCP6022 rail to rail operating amplifier. The low voltage output rail of the MCP6022 can be as low as zero without the need for a negative supply voltage. This characteristic makes possible the design of a single supply voltage precision rectifier.

From figure 2, you may notice that the rectifier circuit (right channel) is actually a non-inverting amplifier which uses the D4 diode, for rectification, in its feedback loop. Since there is no negative supply, even if diode D4 did not exist, the circuit would still function as a rectifier because the amplifier could not amplify the negative half-cycle of the input signal. However, we use D4 to prevent the smoothing capacitor C10 from discharging through the output resistance of the operating amplifier during the negative half-cycle of the input signal.

D3 provides an additional discharging path for the C10. This path does not have any great impact to the discharging time constant of C10, since R17 has a much greater value than R20. However, it could significantly affect the circuit, in case of modification of the value of R17 (if it becomes comparable to R20).

Digital VU-meter circuit schematic
Figure 3. The electronic circuit of the digital VU-meter (2 of 2 - digital section)

A smoothing circuit after the rectifier is used to exact the mean value of the input signal. This circuit consists of R18, C10 and R20 and also D4 has an important role in its operation. R17 and D3 also imply some minor effects. This circuit can be viewed as a smoothing circuit or as an integrator with unequal attack and release time constants.

C10 is charged via R18 at every increase of the rectifier’s output signal. It can also discharge via R20 and D3-R17 at each decrease of the rectifier’s output signal. The capacitor is charged and discharged from different paths due to D4 which allows current flowing in one way only. This means that there are different time constants for charging and discharging. Due to the very small value of R18, charging is almost instantaneous. On the contrary, the discharge is relatively slow through R20 and R17 (has a much greater time constant). Because charging is faster than discharging, capacitor C10 acts approximately as a peak holding element.

Charging and discharging time constants for C10 determine the overall response of the VU-meter. These constants have been calculated according to trial an error method, and the response of the VU-meter has been adjusted according to the designer's preferences.

This response can be adapted to different aesthetic criteria by modifying C10, R18 and R20 values. C10 can be easily modified but some care is needed for R18 and R20 due to the fact that these two resistors form a voltage divider. R18 should always be much smaller than R20; otherwise there would be some significant attenuation and some dynamic range reduction.

Dynamic range aspects

The dsPIC30F2012 has an internal 12bit ADC. This means that there are 212 = 4096 possible levels. In db, this corresponds to a dynamic range equal to 20·log(4096-1)=72db. That is, the voltage represented by level 4095 is 72db higher than level 1 (4095 times higher).

For the ADC, we have only one reference voltage value available and this specific value is equal to the supply voltage (5V). Applying a different than the supply voltage reference would be much helpful but this requires the use of external circuitry and a dedicated I/O pin. Unfortunately, there is no available I/O pin left for this purpose in our design.

Having only a 5V reference voltage available, a significant problem arises: The system could not use the entire dynamic range of the ADC due to the fact that the maximum voltage at the terminals of C10 can never reach the value of 5V (supply voltage). This is because, although the positive rail of the MCP6022 can reach as max as 5V, the averaged value of the rectified signal can never be equal to its amplitude. In practice, with a 5V supply voltage, the maximum signal level at the input of the ADC is around 3.3V (with an input signal of about 0.5Vrms). This voltage corresponds to the 2700 level of the ADC and this implies a maximum dynamic range of 20·log(2700) = 68db. In other words, we have about 4db reduction of the total dynamic range, in relation to the theoretical dynamic range of 72db, due to the fact that we use a 5V reference voltage which is larger than the 3.3V maximum signal level at ADC’s input.

We could resolve this matter either by using an external reference voltage for the ADC of 3.3V or less or by using a higher supply voltage for the MCP6022 (in order to increase the maximum signal level at ADC’s input). Both of these solutions require some additional circuitry. Thus, for reasons of simplicity, we decided to tolerate the loss of 4 db from the dynamic range and, moreover, even the 68db that can be practically achieved are not bad at all!

LED Bar-graphs

The audio level is mapped on 2 bar-graphs, of 20 LEDs each. One bar-graph displays the level of the right audio channel (R-audio channel) and the other one, displays the level of the left channel (L-audio channel). Due to the 20 LEDs in each bar, there are 20 steps and the total dynamic range of the display depends upon the choice of a step value.

For instance, if we choose each step to correspond to 2db, the total dynamic display range will be 2x20 = 40db. If we choose a step value of 3db, the total dynamic display range will be 2x30 = 60db. The above cases refer to a uniform step but there is also the possibility to choose a non-uniform step. All these can be arranged through software. However, it is worth noting that regardless of the display step we choose, the total dynamic range cannot exceed the limit of 68db (implied by hardware) as we mentioned in a previous paragraph.

Using discrete LEDs on a plugged-on board
Photo 2. The Digital VU-meter can also use discrete LEDs ( in a plugged board)

The display has 40 LEDs in total and this means that ideally we should have 40 I/O pins available in the microcontroller to drive all these LEDs in a parallel manner. In contrast, the dsPIC30F2012 has a total of 20 I/O pins and some of them are multiplexed with the 2 input channels of the ADC and also with the main clock. In practice, there are only 17 I/O pins available for the display. Thus, we use a multiplex scenario which is shown in figure 3.

The 20 LEDs of each bar are divided into two groups of 10 LEDs. The first 10 consecutive LEDs (the least important) are distributed into one group and the next 10 consecutive LEDs (the most important) are distributed to the other group. In this way, each bar is divided into two sub-bars. Thus, the BL bar of the left channel is divided into bars BG1 and BG2 and the BR bar of the right channel is divided into bars BG3 and BG4. The LEDs in each BGx bar are numbered from 0 to 9 and their anodes are connected with 10 I/O pins (ldo to ld9) of the microcontroller. In addition, their cathodes are all connected together. The common cathode is driven by a transistor. This way, the LEDs of each BGx bar are forming a common cathode display and transistors Q1, Q2, Q3 and Q4 are used to activate the BG2, BG1, BG3 and BG4 bars, respectively. These are shown in detail in the electronic schematic of Figure 3. With this multiplex scenario, only 14 IO pins are required to drive the 40 LEDs. 10 of these pins (ld0 to ld9) are directly connected to the all 10LEDs of any BGx common cathode display, and 4 of these pins (AL0, AL1, AR0, AR1) are connected to the bases of transistors Q1 to Q4.

Obviously, due to the multiplexing, the LEDs cannot be activated all together at the same time. The controller uses a sequence of 4 steps to display the bar graphs, as follow: Firstly, the microcontroller maps the signal level of the Left audio channel to the appropriate LEDs in the BG1 bar and then in the BG2 bar. Then, it maps the signal level of the Right audio channel to the appropriate LEDs in the BG3 bar and then in the BG4 bar. Then the process starts again from the beginning.

In each display cycle we have 4 steps. This means that each LED, can only be activated for a time period equal to the ¼ of the total display cycle. This reduces the brightness of each LED to a value of about ¾ of its maximum potential. To compensate for this decrease in brightness we need to increase the LED driving current. Therefore, we chose to drive the LEDs directly from their corresponting I/O pins, without the use of any series resistances. The current is only limited by the active resistances of the driving transistors (Q1 to Q4) and the internal transistors of the microcontroller. Due to the fact that each display cycle lasts a few ms, the current is also limited by the internal capacities of the diodes and the circuit. The display speed is particularly high, so that no flicker can be noticeably perceived.

Display modes

From Figure 3, you may notice that there is a set of 3 DIP switches. This is the S1 (SW DIP-3). S1 is used to provide some choices between different display modes. Due to the 3 switches, there are 23 = 8 different choices. Each choice corresponds to a different display mode from a total of 8 available display modes. These 8 display modes are as follow:

Mode 0: 2db step bar-graph
The audio level is displayed logarithmically in two bars of 20 LEDs each (one bar is for the right audio channel and the other one is for the left audio channel) with a display step of 2db.  Considering that the most important LED - in each bar corresponds to a 0db level, the next LEDs in the order, up to the least important, correspond to the levels of -2, -4, -6 ……. up to -38db, respectively. The total dynamic display range is about 40db.

Mode 1: 3db step bar-graph
The audio level is displayed logarithmically in two bars of 20 LEDs each (one bar is for the right audio channel and the other one is for the left audio channel) with a display step of 3db. Considering that the most important LED - in each bar corresponds to a 0db level, the next LEDs in the order, up to the least important, correspond to the levels of -3, -6, -9 ……. up to -57db, respectively. The total dynamic display range is about 60db.

Mode 2: 2db step bar-graph with peak hold
It corresponds to a logarithmic audio level representation in bars with a 2db step, as in mode 0, and the meter also indicates the highest output level at any instant in each bar. The peak at any instant is held for about 0.5sec.

Mode 3: 3db step bar-graph with peak hold
It corresponds to a logarithmic audio level representation in bars with a 3db step, as in mode 1, and the meter also indicates the highest output level at any instant in each bar. The peak at any instant is held for about 0.5sec.

Mode 4: 2db step dot display
It is a logarithmic audio level representation with a 2db step with only one active LED in each bar at any instant. Only the LED corresponding to the peak level at any instant lights up in each bar. The resulting representation is a “dancing” (moving) dot according to the audio level. Each LED, from the most to the least important, corresponds to a level of 0db, -2, -4, -6 ……. up to -38db, respectively. The total dynamic display range is about 40db.

Mode 5: 3db step dot display
It is a logarithmic audio level representation with a 3db step with only one active LED in each bar at any instant. Only the LED corresponding to the peak level at any instant lights up in each bar. The resulting representation is a “dancing” (moving) dot according to the audio level. Each LED, from the most to the least important, corresponds to a level of 0db, -3, -6, -9 ……. up to -57db, respectively. The total dynamic display range is about 60db.

Mode 6: 2db step dot display with peak hold
It is a logarithmic dot - audio level representation with a 2db step, as in mode 4, and uses peak hold of about 0.5sec at any instance. The meter indicates the highest output level at any instant by activated one corresponding LED in each bar. The peak at any instant is held for about 0.5sec. Each LED, from the most to the least important, corresponds to a level of 0db, -2, -4, -6 ……. up to -38db, respectively. The total dynamic display range is about 40db.

Mode 7: 3db step dot display with peak hold
It is a logarithmic dot - audio level representation with a 3db step, as in mode 5, and uses peak hold of about 0.5sec at any instance. The meter indicates the highest output level at any instant by activated one corresponding LED in each bar. The peak at any instant is held for about 0.5sec. Each LED, from the most to the least important, corresponds to a level of 0db, -3, -6, -9 ……. up to -57db, respectively. The total dynamic display range is about 60db.

You may view the above display modes in the demo video of our Stereo digital VU-meter. All these modes are easily customizable through software. By modifying the source code, you may adjust the meter for any step or hold time according to your own preferences or you may also program your own display modes.


Software parameters and details

The retention time for peak hold is defined in the software as a simple parameter (variable) while display levels are defined in two arrays of 20 elements each, for the two different display steps of 2 and 3 db, respectively. Due to the fact that the levels are defined in arrays, anyone could change not only the display step but can also define any set of values for non-uniform step also.

Retention time is stated in the software with the statement:
#define dt3 25 // loops // Peak hold time in main loops

In the above statement, the retention time is set to 25 repetition cycles of the main routine. Each cycle of main routine lasts about 20ms, so the value of 25 corresponds to a hold of about 0.5sec.

The display mapping to the LEDs for 2db step are defined in the software in an array of 20 elements as:
int level_2db [20] = {43,54,68,86,109,137,172,216,273,343,432,544,685,862,1086,1367,1721,2166,2727,3433};

Accordingly, the display mapping to the LEDs for 3db step are defined in the software in an array of 20 elements as:
int level_3db [20] = {4,6,10,14,19,27,39,54,77,109,153,217,306,432,610,862,1218,1721,2430,3433};

From the above statements, you may notice that the maximum level at which the most important LED lights up, corresponds to the value of 2700 which in turn corresponds to a voltage of about 3.3V. It does not make any sense to set a value higher than 2700 because as we explained in a previous section, the maximum audio level in the ADC’s input is 3.3V.

Let's demonstrate now the way we used to calculate the values for the level_2db array. We think you may find this example useful and you may use it as a guide to calculate your own levels for any step:

Let’s name the LEDs in each bar of 20 LEDs as LED0, LED1, LED2 to LED19, for the least to the most important LED respectively. Then, each LEDi should light up to a Vi level (V0, V1, V2 to V19). So let us choose the display step to be S = 2db. Then each level Vi, (with i from 0 to 19) should be S db less than the next, Vi + 1. Given the definition of db, we may write:

20 log (Vi+1 / Vi) = S⇒ Vi+1 / Vi = 10S/20⇒ Vi = Vi+1 · 10S/20

(1)

From equation (1) we may calculate the value of each level Vi, as long as we know the presenting Vi+1 level. This means that if we know the level V19, we can calculate V18. Then, knowing the level V18, we can calculate the level V17 and so on. Therefore, we can calculate all the levels, as long as we know the display step S, and the value of V19 (the level at which the most important LED lights up).

Let’s refer to some facts: The maximum voltage level at ADC’s input is 3.3V. We have a 12 bit ADC and a reference voltage of 5V.

This means that there are 212 = 4096 possible levels (from 0 to 4095) and 212-1 = 4095 steps. Level 1 corresponds to a voltage equal to 1/4096 of the reference voltage, ie equal to 5/212 = 5/4096 V. Any other level V, corresponds to a voltage

Uv = V · 5/212

(2)

By setting Uv = 3.3V in the above equation, which is the maximum voltage level at ADC’s input and solving with respect to V, we find that the voltage of 3.3V corresponds to the level of 2700, approximately, of the A/D converter. Therefore, the most important LED, LED19, should light up to the level of 2700, ie V19 = 2700.

Then, by setting S = 2 and V19 = 2700 in equation 1, we find that V18 = 2145. Then, from V18 and equation 1, we find that V17 = 1704, then that V16 = 1353 and so on up to V0. It is worth noting that while all calculations should be done with great accuracy, the final values to be set in the arrays should be rounded to the nearest integer.


More Circuit details

The complete electronic schematic of the stereo, digital VU-meter with analog inputs is shown in Figures 2 and 3. Figure 2 shows the analog section of the circuit, while Figure 3 shows the digital section.

The input signal (audio signal) is connected to the stereo input P2 (see figure 3) and the trimmer potentiometers R15 and R22 are used to adjust the sensitivity of the VU-meter, so that it can be adapted to any audio source.

The microcontroller is clocked from a 4MHz crystal (XT1), which is connected to pins 9 and 10 (timing oscillator pins). Although we use a 4MHz crystal, in fact, the microcontroller runs at 64MHz, because we also use an internal step up (PLL) x16. This setting is done through software, with proper initialization of dsPIC30F2012’s registers (see statement "_FOSC (CSW_FSCM_OFF & XT_PLL16);" With these settings, the microcontroller runs at 16MIPS (16 mega instructions per second). Each command is executed at about 62.5 nanoseconds.

Assembly details
Figure 4. Assembly guide for building the main circuit board

Making the Digital VU-meter

To make the stereo, digital VU-meter, you will need the appropriate printed circuit board (PCB) provided below. for educational purposes or for experimentation, you may also build the circuit on a large breadboard.

All components should be mounted and soldered to the circuit board according to the assembly guide of Figure 4. It should be noted that all the resistors used in this project are of 1/4W type and of 5% tolerance or better. All the capacitors we use in this project have a 5mm (20mils) footprint, that is, the horizontal distance between their terminals is around 5mm.

The microcontroller code is written in C language on the Microchip XC16 compiler (version 1.6). To program the microcontroller you do not necessarily need the source code. You only need the machine code which is provided freely below (hex file). But if you want to make changes to the code in order to customize the VU-meter according to your preferences or you wish to modify the code and make your own version, you need to get the source code.

The microcontroller can be programmed with any compatible programmer either off-board or even on-board. Our microcontroller was programmed on board by using Microchip's PICkit3 programmer. For programming, we had to temporally attach (solder) five cables to the board, in order to connect the dsPIC to the programmer, according to the instructions provided by Microchip. The cables were removed from the board after programming.

In the printed circuit of this project you cannot solder any common LEDs. The main board supports only LED bars of 10 or 20 LEDs in "DIP" package, like those of photo 3. These bars must not be soldered directly on the board, but rather indirectly by the use of some appropriate DIP bases.

LED bars
Photo 3. The main board supports LED-bars on DIP

If you want to use discrete LEDs rather than LED bars, you should use a second board that we have designed specifically for this purpose. This board can be plugged directly on the LED bases of the VU-meter board. This additional board is shown in Figure 5 and is essentially a "shield" type board that attaches directly to the original board.

The "shield" clearly provides a larger display screen compared to the LED bars and allows the use of LEDs of different colors. In the shield we made for the prototype, we used 13 green LEDs, 4 yellow and 3 red LEDs in each bar of 20 LEDs, as you can see in photo 2. All the LEDs we used have a rectangular cross section but you may also use any round or square LEDs. If you use LEDs of different colors, you should make sure that they all have the same brightness.

Shield board for discrete LEDs
Figure 5. Electronic circuit of the shield board

The electronic schematic of the "shield" board can be seen in Figure 5. Notice that 20 pin headers (headers 20) are used to fasten this board to the microcontroller board. The shield board is double sided like the microcontroller board, also.

On the microcontroller board, all components are placed on the same side (top of the board) while on the "shield" board, the LEDs are placed on the top of the board and the 20 pins headers on the other side.

For more details, to assemble the boards, refer to the assembly guides of Figures 4 and 6.

Assembly guide for the shield board
Figure 6. How to assemble the shield board

If you further wish to elegantly fit the VU-meter in a box or any audio device, it would be nice to make a suitable mask for the LEDs. In this mask, you may also print a logo and the display levels in db or in %. We do not provide this mask because we cannot guess of course your logo or the levels you will use in your project but we assume that you can easily make it based on the dimensions of the "shield" board or based on the main board ( if you are only going to use the main board).

About this project

A.G wrote this tutorial in Greek for his students, during some high school lectures on embedded design. Here, we provide a brief translation in English. A prototype of the Digital Stereo VU meter with analog inputs was initially built and tested in Greece on March of 2020. Since then, many electronic enthusiasts have built their own, based in our project.

If you have any new ideas, some additions, corrections or complaints feel free to provide feedback. Everyone will appreciate any further contribution.


Attachments

Firnware for the Digital Stereo VU-meter - for programming the dsPIC30F2012 (free download)

Printed Circuit Board Artwork for the Digital Stereo VU-meter (paid download)

Printed Circuit Board Artwork for the shield used in the Digital Stereo VU-meter (paid download)

Source code in C for the Digital Stereo VU-meter (paid download)

 

List of the comments:
No comments have been posted yet.
Vote:

Give your advice about this item:

Username:
E-mail: