Midi VU meter, LM3914, Arduino, PWM

Thread Starter

needle

Joined Sep 22, 2010
6
Hello everybody,

I've been working on a midi controller for some time now, Midi OUT hasn't been a problem, but for Midi IN i had to take some more time.

i've used this circuit for midi input but i've used a 4n25:


original thread @ http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1187962258/

it works great!

but for my project i need VU meters, i thought this wouldn't be a problem, because i could easily say to my arduino: if note = 1 and velocity = 80 then turn on LED A,B and C.

But i could'nt get this to work. while this easily could be a coding problem, i didn't want to waste 10 pins per VU meter, so i searched some more and found a LM3914.

i thought to myself i could easily make this work through a single PWM pin, so this would save me about 36 pins. in total i need 4 (mono) VU meters, so i would have to use 4 pwm pins.

so i bought the LM3914 and then other problems turned up. luckily i found this forum! :) especialy Sgt Wookie answers on the LM3914, were very helpfull.

so i constructed this schematic:


this works :)

now i made a RC-circuit in between the Arduino and the LM3914. with a 4Kohm resistor and 1uF cap.

also this seems to work fine, for example i can output a value of 80 from the pwm pin and this will light up all leds, or i can output a value of 41 and this will light up 5 leds.

i also tried connecting the circuit to the line out of my computer, as expected the leds do not correspond with the actual db's, but it light's up at the same time as the VU meter of my mixer does, so i know it is fast enough to keep up.

and here is the problem, when this circuit is connected to the PWM pin of the arduino, it's always one beat behind, it kinda looks like a bad stop motion movie...

so i guess the problem could be in the coding, but just as good in the circuit.

hope this is enough information and i really hope anybody here can help me out, i've been trying to make this work for over three weeks now...asked at different forums, but haven't found an answer so far.

here is the schematic and code i use now:

btw i'm reading the left master output channel, through midi with a single note, with a velocity range between 0 and 127.

Rich (BB code):
byte incomingByte;
byte note;
byte velocity;
int vuPin=9;
int statusled = 13;
int val =0;
  
void setup()
{
  Serial.begin(31250);
  pinMode(statusled, OUTPUT);  
}

void loop ()
{
  if (Serial.available() > 2)
  {
    digitalWrite(statusled,HIGH);
    incomingByte = Serial.read();
   if (incomingByte == 144)
    {			    
    note = Serial.read();
     if (note == 1)
	{
          velocity = Serial.read();
          val = map(velocity, 0, 127, 5, 80); // 5 = all leds off, 80 is all leds on
          analogWrite(vuPin, val); 
         }  
  
   }
  digitalWrite(statusled, LOW);
  } // end of reading MIDI input
 } // end of loop
 
Last edited:

R!f@@

Joined Apr 2, 2009
9,918
What if u use a DAC port instead of PWM.
I think the PWM is creating a delay via the RC input components to the LM3914.
The LM3914 will respond faster to DC voltage
 

Thread Starter

needle

Joined Sep 22, 2010
6
What if u use a DAC port instead of PWM.
I think the PWM is creating a delay via the RC input components to the LM3914.
The LM3914 will respond faster to DC voltage
ok, i'm not sure what that means, but i've found this:
http://blog.makezine.com/archive/2008/05/makeit_protodac_shield_fo.html

i'll read this and report back. thanx for responding.

*edit*
also found this
You can implement any manner of DAC outside the Arduino, but as you said, there is no DAC in the Arduino itself and PWM is not the same thing.

You can bang multiple bits at a time to the I/O registers directly. It makes your code much faster, but also much less portable to other microcontrollers. Yes, if you want to bang more than 8 bits, you will have to do it in stages, but those separate stages can now be very close together, time-wise. See the "port manipulation" page, http://www.arduino.cc/en/Reference/PortManipulation for more details.
seems i have to learn some more difficult coding...
 
Last edited:

tom66

Joined May 9, 2009
2,595
I assume since you're just a hobbyist then you won't have an oscilloscope, which would be very useful here.

The configuration of the RC filter is confusing. Shouldn't there be a shunt resistor to ground, to "bleed off" the capacitor when the PWM is low?
 

Thread Starter

needle

Joined Sep 22, 2010
6
I assume since you're just a hobbyist then you won't have an oscilloscope, which would be very useful here.

The configuration of the RC filter is confusing. Shouldn't there be a shunt resistor to ground, to "bleed off" the capacitor when the PWM is low?
well i used this one but it seemed to work better with a 4k instead of a 4k7:



and yes i'm a hobbyist and indeed i don't have a oscilloscope, which would be very helpful in this case...
 

tom66

Joined May 9, 2009
2,595
Hmm, does it take longer to go down in volume than up? I'm thinking that the cap is discharging only slowly through the Arduino, but charging fast.
 

Thread Starter

needle

Joined Sep 22, 2010
6
Hmm, does it take longer to go down in volume than up? I'm thinking that the cap is discharging only slowly through the Arduino, but charging fast.
it definitely takes longer to go down in volume than up. i thought of this before, but couldn't find a solution, or better said, didn't know what to search for...
 

R!f@@

Joined Apr 2, 2009
9,918
Use a 100n cap. The Cap is taking too long to discharge.
Another idea...swap the RC and see what happens.
Isolating the DC component will introduce spikes at the Bar graph input.
You might need a full wave rectifier with opamps
 

tom66

Joined May 9, 2009
2,595
it definitely takes longer to go down in volume than up. i thought of this before, but couldn't find a solution, or better said, didn't know what to search for...
Try this: a 100k resistor with a 100n cap, and a 100k resistor shunted to ground.
 
Top