Friday, August 24, 2018

Synth DVM part IV: Neat Arduino Trick--good for Audio DIY--Crush that op amp!

I finished (!!) my arduino based Synth DVM, it worked last night anyway; need to do a few final software tweaks then will post.  As always I am sure someone can improve it, but it's working well.

You can see part 1 here--I try to master the art of undocumented Arduino clones and parts

Part 2 is here.  Design goals for the project, Blah blah ginger blah blah.

Part 3 is here.  Let's get the OLED meter to look "analog"

How it looked about a week ago...front panel an "alubase PCB" from PCBWay....the PCB is already bolted on. Along the way I found a cool and easy way to make an Arduino treat audio like it's running through 4066 cmos switcher. Maybe better?

It's a nifty enough trick that I thought it should have its own post.


My DVM.  FracRack panel.  It's actually done and working now.../



The hack goes like this:

If you've screwed around with Arduino for more than a few minutes you find the things don't like negative voltages w high current on their analog pinssince my SynthDVM is chock a block with negative voltages--it needs to read negative voltages relative to ground, I had to deal with this.  OK....

As long as you're careful with your design, carefully incoming limit current, we're fine, there's diode protection in the Arduino analog pins, but what if we're not fine?

Just to be safe, negative voltages at analog pins should be designed out if possible?

There are many ways: use an op amp in front and use GND for V-- and 5V for V++



But this will chop off some of the upper voltages close to 5V and voltages near Ground.  Not good for a DVM!

Or block the negative voltages/reverse bias current using a diode....



You'd still have to figure out a way to limit the upper voltage since Arduino pins don't like to see more than 5V relative to ground, maybe use a zener for that?  

But for a DVM this is a non starter--the output voltage sees a "diode drop" of .6-.7V which for a DVM application probably isn't good--we want incoming signals to be as unadulterated as we can. And diodes are temperature sensitive....

How about a rail to rail op amp?  I probably could have made this work, but I fried my last R-R op amp on the bench working on another project--oh well. There is also the consideration that many R-R op amps allow signals over that can go above the VDD, but I figure Arduino can probably roll with that.  

Thinking about this project, I should have just bought more rail to rail op amps--yep I should have dug into this idea more.  It probably would have simplified the design a lot. Something for a future post.



AC couple and then do an DC offset?  That would have limited my measurable signals to something like +/- 7V by my calculations, and from +/- 15V supply I wanted to be able to measure more like +/- 12V.

There are lots of ways other ways....

I discovered a way to do this by accident: you can use Arduino digital pins to clobber an analog signal, negative or positive, as long as it is less than say 30mA (as I read the Atmel datasheet, it's 40mA, but let's stay far away from that....)

So how about this hack:


You still have to protect things to not go over 5V--I used a voltage divider as you see here, which for me worked fine but if you're really concerned, perhaps use a zener to limit the top end to 5V.

For an inverting op amp, it's the same idea--connect the output pin to a digital pin on the arduino and suck the signal out of the op amp to ground.  I think I did this something like this, I will post the final schematic soon:



R1 limits current to D3, so that's important (!) and R3 limits current through the op amp--so be careful with these values.

Now program your arduino like this:

      pinMode(3,OUTPUT);
      digitalWrite(3,LOW); // PIN3 is now a working ground. Send a signal destined to go to A0 to ground; so we clobber analog signal to A0

(or)

      pinMode(3, INPUT) 

D3 goes high Z, op amp unaffected; signal delivered to A0 just fine.


So that means that you can use this trick to turn on and off analog signals as you would (say) a 4066 or 4016 cmos switcher. Output/Low the signal is off.  INPUT, the signal is on.  Easy!!!!

Cool! I didn't think it'd work but it did! 

Questions:
  • Do I think I made this hack up?  Nope. If there isn't documentation about this hack somewhere else already, I'd fall off my chair, but for the 2 cents it's worth I couldn't figure out a way to google it. Whatever. 
  • Can I flip/flop pinModes every x milliseconds and not screw stuff up?  Yes. It seems to me like flip-flopping pinModes very quickly--input to output--and back--doesn't phase the ardino at all. This surprised me, but for my design here, nope it wasn't an issue. I haven't totally tested this vs. say a 4066 for "what can flip faster?  What "sounds better?"  Don't know. Put it on your bench, fool with it, and let me know!
  • Does this work for clobbering audio signals that are more than say 2.5V P/P?  Yes. I could power my op amps from +/- 15V supply, run an audio signal to close to the op amp rails, and still use the above hack to clobber the signal.  Just make sure you are careful about resistors like R1 and R3 in the inverting diagram above.  We don't want to send too much current to the OUTPUT/LOW pin, or the A0 analog pin, and we don't want to heat up the op amp but not limit its output either.  But as long as you can work with that, we're good.
  • Does it work for positive or negative V relative to ground?  So will D3 in output-LOW mode source and sink current? In rapid succession? Yes.
  • Overall, does this method work better in this app than a CMOS switch (4066?) for me, yes. I could never get enough hi-Z on the 4066, still not sure why but after a couple of evenings of trying to get a 4066 to switch away the negative signals I gave up and used this clobber trick instead.
OK More on the entire DVM project soon, I am pretty much done, just need to finish the documentation. I am pretty happy with how it came out....and that I stumbled into this OUTPUT/LOW INPUT hack along the way!  OK enough until next time: don't breathe the fumes!







No comments:

Post a Comment

Synth Gates, Interrupts, and Arduinos; a million and one uses

Yes once again: more Arduino Control Voltage Fu. Continuing from last time ...how can we use an Arduino to get rid of mountains of analog ...