The REAL logarithmic scale in vu meter

Hello,
i did linear scale vu meter on my KS0108 LCD, but it doesnt look right, because it shows linear scale, not log.

Searched net, found one project about log scale, made it, and it still doesnt look right, sometimes it looks that MCU or LCD is too slow to refresh so fast, and sometimes, im getting peak’s.

Kinda strange, i have got 17 bars on screen, and lets say it shows from 1 to 9 bars. For like 0,5 second bar goes to max scale(17 bars) although nothing happened while playing song. So, i placed “dBAudio” variable on screen, which shows calculated decibels, and when these peaks appear, it doesnt change at all.

Well, i guess its enough of writing, time to show some schematic/code which im using.

Audio signal im getting from line out(head phones and bla bla) and using LM224 opamp with this schematic:

Getting only left channel. And out goes to ADC channel. And code is here: http://pastebin.com/hgArzRpS
Or here:

float newZero = 512;
int dbPerBar = 3;
float currADC;

void setup()
{
  GLCD.Init();

  GLCD.SelectFont(Wendy3x5);
  
  //GLCD.DrawLine(0, 11, 128, 11);
  //GLCD.DrawLine(7, 12, 7, 30);
  //GLCD.DrawLine(0, 31, 128, 31);
}

void loop()
{
  GLCD.GotoXY(2, 13);
  GLCD.print("L"); 
  GLCD.GotoXY(2, 27);
  GLCD.print("R");
  
  getPPMsample();
  
  for (int bar = 0; bar < 17; bar++) 
  {
    if (abs(dBAudio) >= (bar * dbPerBar) + 0.1) 
    {
      GLCD.FillRect(vuMeterBar[bar], 14, 6, 3);   // left
      //GLCD.FillRect(vuMeterBar[bar], 28, 6, 3); // right
    } 
  }
  
  for (int i = 1; i <= 17; i ++)
  {
    if (currADC >= 60 * i)
    {
      GLCD.FillRect(vuMeterBar[i - 1], 28, 6, 3); // right
    }
  } 
 
  GLCD.GotoXY(2, 45);
  GLCD.print(dBAudio);
  GLCD.GotoXY(2, 52);
  GLCD.print(currADC);  
  
  delay(100);
  GLCD.ClearScreen();
}


void getPPMsample() 
{
  float maxAudio = 0; 
  float rawAudio;
  for (int sample = 0; sample < 48; sample++) 
  {
    rawAudio = analogRead(A1);  
    if (rawAudio > maxAudio) 
      maxAudio = rawAudio; 
  }
  currADC = maxAudio;
  dBAudio = 20 * log10 (abs(maxAudio - newZero) / newZero);
}

Array vuMeterBar is just each bar x position on screen. Getting log scale with “getPPMsample” method and showing everything in loop. By the way, left channel on screen(it is also commented on code) does log scale, and right does linear, just to see differences.

They are almost same, just log scale makes these “peaks” which uses all 17 bars…
So maybe im using wrong formula to calculate log scale? Or schematic provides only linear output?

It helps if you post your code using the </> icon or attach it. The schematic did not make it. Use the reply not the quick reply and attach it.

Hi,
Just a question, have you got the gnd of the arduino connected to the gnd of the audio circuit you are measuring.

Tom...... :slight_smile:

Grumpy_Mike:
It helps if you post your code using the </> icon or attach it. The schematic did not make it. Use the reply not the quick reply and attach it.

Well, i attached an pastebin link with code, but sure, can post in here aswell.

TomGeorge:
Hi,
Just a question, have you got the gnd of the arduino connected to the gnd of the audio circuit you are measuring.

Tom… :slight_smile:

Yes, even if its not showed in schematic.

Your circuits isn't right. It's supposed to operate in dual power supply configuration (+15/-15), but you have only single +5V.

Magician:
Your circuits isn’t right. It’s supposed to operate in dual power supply configuration (+15/-15), but you have only single +5V.

As i mentioned, using LM224 op-amp. And i can see in its datasheet:

Wide Power Supply
– Single Supply 3 V to 32 V voltage.
– or Dual Supplies ±1.5 V to ±16 V

So yeah, thats not the case.

You didn't get it, in single power supply configuration when you amplifying AC you need "virtual ground"
Look here to get the idea:
http://www.redcircuits.com/Page97.htm