Midi VU meter, LM3914, Arduino, PWM

Discussion in 'The Projects Forum' started by needle, Sep 22, 2010.

  1. needle

    Thread Starter New Member

    Sep 22, 2010
    6
    0
    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:
    [​IMG]

    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:
    [​IMG]

    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.

    Code ( (Unknown Language)):
    1.  
    2. byte incomingByte;
    3. byte note;
    4. byte velocity;
    5. int vuPin=9;
    6. int statusled = 13;
    7. int val =0;
    8.  
    9. void setup()
    10. {
    11.   Serial.begin(31250);
    12.   pinMode(statusled, OUTPUT);  
    13. }
    14.  
    15. void loop ()
    16. {
    17.   if (Serial.available() > 2)
    18.   {
    19.     digitalWrite(statusled,HIGH);
    20.     incomingByte = Serial.read();
    21.    if (incomingByte == 144)
    22.     {              
    23.     note = Serial.read();
    24.      if (note == 1)
    25.     {
    26.           velocity = Serial.read();
    27.           val = map(velocity, 0, 127, 5, 80); // 5 = all leds off, 80 is all leds on
    28.           analogWrite(vuPin, val);
    29.          }  
    30.  
    31.    }
    32.   digitalWrite(statusled, LOW);
    33.   } // end of reading MIDI input
    34.  } // end of loop
    35.  
    [​IMG]
     
    Last edited: Sep 22, 2010
  2. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    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
     
  3. needle

    Thread Starter New Member

    Sep 22, 2010
    6
    0
    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
    seems i have to learn some more difficult coding...
     
    Last edited: Sep 22, 2010
  4. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    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?
     
  5. needle

    Thread Starter New Member

    Sep 22, 2010
    6
    0
    well i used this one but it seemed to work better with a 4k instead of a 4k7:

    [​IMG]

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

    Senior Member

    May 9, 2009
    2,613
    214
    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.
     
  7. needle

    Thread Starter New Member

    Sep 22, 2010
    6
    0
    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...
     
  8. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    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
     
  9. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    Try this: a 100k resistor with a 100n cap, and a 100k resistor shunted to ground.
     
  10. needle

    Thread Starter New Member

    Sep 22, 2010
    6
    0
    ok, tried it, but now it shows a dimming effect, like described here: http://forum.allaboutcircuits.com/showthread.php?t=12761

    i already used that topic, as i had that problem before, that's actually when i also found the solution of using the 4k with a 1uF cap.
     
  11. tom66

    Senior Member

    May 9, 2009
    2,613
    214
    Ok, is it possible to increase the Arduino's PWM frequency?
     
  12. needle

    Thread Starter New Member

    Sep 22, 2010
    6
    0
    Last edited: Sep 23, 2010
  13. R!f@@

    AAC Fanatic!

    Apr 2, 2009
    8,754
    760
    U need analog voltage for fast VU response.
     
Loading...