Sunday, November 21, 2021

Simple Buffer/Clamp for Analog to Digital Conversion

Hello Again.  

Let's get back to the analog to digital side of things; specifically, a buffer circuit to prepare a signal for an analog to digital converter, or ADC. 

 A genuine Arduino Uno R3 costs about $20USD, has built in ADC's, and you can blow up its ADC circuitry from overvoltage, so you want to treat that with care....

Dedicated ADC chips have voltage limits as wekk--check out the datasheet for the popular MCP3008 (here); where max voltage at input is 7VDC, and ADC inputs can only be .6V over that. This chip costs approximately $3.75USD as of the writing of this post, so you want to avoid blowing up that IC as well.

Design goals for the ADC buffer: 

Must haves:

  • a simple clamp to make sure the voltages presented to the ADC protect the circuitry.  
  • Some way to attenuate the incoming signal.
  • A way to buffer the incoming signal.

Also nice to have:

  • A simple means to set a bias offset for the incoming signal--otherwise an LFO's sine wave (for instance) could get clipped
  • A way to control the output impedence flowing to the ADC IC or MPU's ADC
  • The ability to bring in the signal via 3.5" jack (for Euro modular synth
  • A reference signal to send to the ADC if needed
  • Thru hole design. Easier for bench experiments.
  • Easy to find parts--resistors, caps, PDIP op amps; junk box stuff.

From the dirty digital LFO project (post here), I've hit on something I like that perhaps meets all these goals. 

I whipped up a small board in Eagle and sent it out to this humble blogger's sponsor, PCBWAY, for fab. 

It's back!

Here it is:


Fair warning: for this initial layout I made mistakes; consequently, there were "bodges" or "kludge wires" needed to make the PCB work--in other words, I had to cut traces and solder in small wires to get the PCB to work. 




I will have another set of boards made with these fixes included....again with the help of  PCBWAY who are always enthusiastic and happy to assist (shameless sponsor plug).

Once Rev 2 is in and tests OK, I will upload all of this, but I am pretty confident that REV2 of this design and layout will be good to go.

Designing the buffer: Here's the back of the napkin drawing that preceded the PCB:



It's basically a dual op amp summing mixer with a single input and a zener clamp at output. For a true mixer, you'd add more resistors parallel to R1.....you can find this basic and ubiquitous circuit fragment explained here
 
The offset at 1B + provides the bias offset while "level" port attenuates the signal.  These can be trimmers, more resistors, or whatever, but I had a lot of cheap 9mm PCB pots lying around, so that footprint made it to this design.

Fluffing the Buffer: This post's PCB follows the napkin layout pretty closely, but Rev 1 got into trouble when normalling reference voltages to the two input jacks.

Here's the corrected schematic after cutting traces and soldering in kludge wires:




In Ref'rence: The voltage at INREF, which feeds resistor R1 and the inverting input of IC3A, is formed by R4, R5, and the LEVEL pot (it could be a trimmer).  All 3 values at 100K 1% produce very close to 5VDC relative to ground if you use + and - 15V to power this PCB.  

Again with +/- 15V DC power, for 3.3Vmax output, R5 should be 40K while the pot and R4 are 100K and of course you want to use a 3.3V zener at output, or close.  

You can use an analog circuit simulator to try out resistors values for the circuit reference voltage here; do your math to keep your MCU safe; also please check your max voltage at the OUT pad to make sure the zener is working as a clamp before hooking the buffer into an expensive IC.


   

The only surviving and fully useless bench photo of a finished REV1 board:




Posting in the buff: With wire fixes in place and errant traces cut, the REV1 board works when viewing its output with a scope, but as far as protecting an MCU, I needed to dive deeper. 

I gave it a try with an Arduino clone:



I didn't use the reference out to AREF in of the Arduino--so there were minor scaling errors, but adding a voltage reference could be added in future designs.

Specifically, The Arduino of choice for this proof of concept was a Pro Micro clone.  

It has a 32u4 Atmel MCU, a great chip for DiWhy because it has built-in USB capabilities; no need for an expensive FTDI chip or clone; all the USB capability is built into the MCU itself. More about USB to Serial conversion in the posts starting here; more about USB and the 32u4 coded with C is here.  

Furthermore, there are "maker" libraries, ready to go, that expose the 32u4's USB capabilities with simple methods--for example, you can use this same USB-ready MCU to emulate an HID USB Windows keyboard--more in the post here.  

This time I am using the very capable  MIDIUSB library from the Arduino folks, to test the buffer. 

The simple Sketch language code below allows the user to control MIDI continous controller 72 on channel 1, and assumes the ADC buffer output is wired to the Arduino's A0 input.

#include "MIDIUSB.h"


int x = 0;      

int y = 0;

 void controlChange(byte channel, byte control, byte value)

    {

    midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};

    MidiUSB.sendMIDI(event);

    }

void setup() 

{

//Serial.begin(9600)

pinMode(A0, INPUT); 

}

void loop() 

{

   x = analogRead(A0);

  y = map(x,0,1024,0,127);

 //Serial.println(y);

 controlChange(1,72,y);

/*next line debug "Arduino-style" */

//Serial.println(y)

 MidiUSB.flush();

}

It works with this Arturia Solina Plugin; the frequency sweep was generated by the output of an LFO Prime module. I could amplify its signal to 20V P/P--in other words, way above the maximum 5.6V DC--but the zener clamped this errant voltage to about 5V and the MCU was fine.



Cool!

I might flesh out this idea and post to github finished code and PCBs for a dedicated Control Voltage to Continuous Controller ("CV to CC") module in a future post.

And yes, there are other ways to do this--for instance, there are software CV to CC plug-ins out there--but this soimple hardware and code so this is how I did it.  

Code-ah: No need to power the Arduino externally--USB does that, but I had to tie the ground from the buffer board to one of the GND pins on the Arduino. The buffer during the test was powered the from a simple Frac power supply (post here on how to this linear supply).

As far as improving/modding the buffer circuit, a voltage reference board or dedicated IC could be used instead of the R4/R5/pot network; you could use jumpers to select the reference voltage from a series of resistors; and the PCB could be made a lot smaller using SMT parts for inclusion into a project, but this board is more for bench experiments and designed for simplicity. Good enough.

Best of all, for this board, with all the parts laid out on the bench, it should only take a few minutes to build. 

I'll get more of these made, possibly improve on the CV to CC proof of concept, or to incorporate into a larger project, and post the whole thing, down the road.  

Until then, don't buffer the fumes!

 



No comments:

Post a Comment

JTAG to SWD Converter

Readers: If you'd like to build the project featured in today's post, please go to PCBWAY's Community pages--gerber file, KiCAD ...