Friday, June 22, 2018

Arduino based Random Gate generator--done-works


I have been working on a PCB for my various Arduino projects including the Random Gate Generator...part I is discussed in this post.



ABOUT THE BUILD: I have fab'd up a prototype of a Arduino PCB that tries to be flexible and audio oriented, with accommodations for 6 op amps, and places to jam D/A, jellybean logic and so on. I used it as a home for the random generator.

The idea is to not have to fab up a new board for every Arduino project; most seem to be just Arduinos, DACs, and buffer op amps?

Anyway here's what I came up with:





The breadboard prototype is seen on top with working random gate.

I am starting to copy all the parts to the PCB.  Power supply (PAIA!) (+/- 15V) is in the bottom left.....

An hour or so later: Good news!  It all works!!!!  I have been having fun with this module, might build some more.

Arduino code can be downloaded at GitHub.

https://github.com/cslammy/arduino-random-gate

Schematic--note that after drawing this I added a reset switch that you'll see in the code.  this is so if you change your mind about waiting 5 minutes or whatever for the next on or off you can reset all variables to zero and start again.  To get that done, it's the standard 5V switch HIGH 10K resistor to ground LOW.



Finished and working/populated PCB looks like this--last thing to do is create a front panel and wire in 3.5mm jacks but that's really easy:



I have put on my website the  "nanofactory" PCB you see here yet--sorry to say, there are a few mistakes in the PCB--fixable, but if you take the trouble to get the gerber and have a board made, make sure to read up on the fixes.  I have started to clean it the PCB design, and have already had a new set fab'd, but they are not tested; so I kludged around the issues for what you see here. Update: new fab is still not tested; I used the first nanofactory PCB, with fixed mistakes, for the Synth DVM that's now finished.

The best thing about this: if I want to change what the pots do, add features, change how slowly it can fire a gate etc. no need to rewire or add new parts--just go in and change the code.  Also, there is plenty of I/O left over on the board, so if I want to add things (no idea what but I always think of something?) down the road that's pretty easy as well.

The most remarkable thing about all of this is how easy Arduino CV projects are to think up and do.  Comparators--envelopes--LFOs--displays--and so on--super super easy.  And inexpensive! I may never use a 555 timer again!

Last thing to do is make a front panel for this, which I will fab using PCBWAY in China. That's now done as well.  The lazertran decal process didn't come out 100% clean, don't know why, but it's time to rack this puppy and move on.

Wednesday, June 20, 2018

9mm POTS--Creating a New Device in an Eagle Library

(Advanced warning: If you don't use Eagle for schematic/PCB/gerber creation, this post will mean zilch....You have been warned....)

 I bought some dual concentric pots from Small Bear and needed it in the PCB for a few projects.  I couldn't believe I couldn't find an existing library (Alps?  Bourns? Adafruit?  Anyone?) that already had this part--this is super simple, just an array of 100 mil traces with proper spacing and some kind of tName silkscreening that works….but I couldn't.  Time to roll my own....

To summarize the very basics: Eagle libraries have all different components and variations that all have to be created and linked properly to work in a useful library that you can use in your designs.

Screw it up?  The part won't work, or worse yet, when you get your PCB back it will be butt because your custom part is butt.

So you have to know all of this.

First some Eagle terms--they could have called all of these things anything, but this is what they chose to call them:

Library: a set of devices.
Device: the entire component--the IC, header, swtich, whatever; a joining of a Footprint and Symbol 
Footprint: what goes on your PCB.  Pads/drills etc. must be right or your part won't lay onto the PCB correctly after you fab.
3D package: So you can make sure your part "fits" in your case or whatever.  I am not going to talk about 3D packages at all here.
Symbol: the image of the component that goes on your schematic.

There are many pages about creating Eagle libraries; I won't go into it all of it here. Here is a good webpage link; here is a good vid.

But I figure it might be worthwhile to mention what I got stuck on, what I seemed to be able to do (and not) maybe it will help you, or maybe it will help me in 4 months when I forget all of this.

OK let's start with the basics: editing any damn thing at all.....

Why can't I edit a @$%^ library?  And I do mean @$%(#@$!!!

The libraries that come with Eagle are "read only".  You knew that right?  I didn't.  \

Assuming you're modifying library content that came with Eagle--it's often easier to modify something vs. starting from scratch--you have to make a copy of the source lbr file and copy it somewhere else. Then point your Eagle prefs to the new library location.

It's described here and here--yes, you have to do all this. 

Note: I got somewhat confused when I read instructions that you "import" libraries--what web tutorials really seem to mean is just copy the damn library somewhere else--then you can edit it.

OK fine, but, Where are the %#@&$^ libraries that come with Eagle?

For windows 10 they are here:

C:\Users\[username]\AppData\Roaming\Eagle\lbr. You may have to enable hidden files and folders in Windows to see this at all. Search for the library you want in there and create the copy somewhere else. Now you can edit the latter.

You knew that right?

For other OS's?  No idea. Sorry.  I am pretty good with Linux and Mac as well, but have never gotten round to using Eagle in either. If you have that information (I am too lazy to look it up) please add a comment.


What order do I need to do to make this work?

There are lots of ways to make this work, since there are lots of things you can do surrounding libraries:

  • You can duplicate an existing device, symbol, or package, then edit it to change it.
  • You can create alternate footprints for a single device (so you can, for instance, choose between a SMD version of an IC or a DIP version)
  • You can add new devices to an existing library.
  • You can create a new library from scratch and add new devices that you create from scratch
  • You can create managed libraries that allow other users to edit whatever devices you are using.

The most common thing I find myself doing is to edit an existing library to change a device, footprint, and/or symbol. That's what I will cover here. I might cover some of the others in other posts.

OK, first, you open libraries in Eagle same as you'd open anything else--from the "Eagle Control panel"--the small window you see when you first open the program--File > open > Library

Choose the Library you want to edit.  can't edit?  See above. You can't edit the default Eagle libraries that live in their default locations.  But you already knew that.

For v. 9.5.1 and earlier (hopefully later as well, but Eagle has been known to move around the furniture) you see a screen with 4 sections: Device, Footprint, 3Dpackage, and symbol:



First thing I always do is duplicate whatever I want to work on.

So right click on the device (if that's what you want to edit) and say "Duplicate". Call the new device something unique, say

"1X4--newpads"

You can edit the symbol (using the add symbol icon from the left column or the command below), in the same manner, same thing with a footprint: Duplicate, then right click on the new item and left click on EDIT.

Good news: editing footprints and symbols is the same as editing schematics and boards--it's all the same tools. So if you know how to edit those, you are a long way to creating custom parts already.

And--of course--make sure to always save your work after editing.  A library is saved the same as any other object in Eagle. If you forget to save, well, you feel stupid and angry.

DEVICE MANIA: Devices editing in libraries is done using a UI you've not seen before--editing a device is not like editing a schematic ("footprint") or a symbol ("board"); it's its own strange thing. This drove me crazy at first.





The FOOTPRINT is in the top left, it's this thingy:




 The SYMBOL is to the right of it that, looks like this:




achtung! The device screen is important. This is the screen where you tell the system what pin in the Footprint maps to what pad on the Symbol. 

The device edit UI is a bit painful, but i always get stuck on the same thing: I have edited a devices and a footprint, but the new device doesn't recognize a given new footprint.

How do I make the device recognize the new footprint?

here's how:


  • Click on group, left click and lasso the FOOTPRINT you want to get rid of, click on DELETE (garbage can icon) then delete the group.  Poof!  The old footprint is gone!
  • Now go to Edit > add and  Add the new footprint  When you edit > add in this context the UI shows you any footprints you have for the device including new/duplicated ones. You knew that too, right?


ANOTHER GOTCHA: Where is "ground zero" for your symbol or footprint? If you look at the editor for these, on the blank canvas, you will find a plus sign.  Move your creation so it's close by the + symbol.  That's where you grab your part to move it around.  Took me too long to figure that one out!

OK once all of that is sorted, you need to make sure things are CONNECTED correctly.  Click the CONNECT button in the device UI:



The process of connecting symbols to footprints is pretty straightforward although obviously you can make mistakes. Always test your component before using it in production--for instance, for a resistor array create a new Schem and board, wire it up, and see if it makes sense.

USING THE COMMAND LINE FOR THIS VS. THE UI.

You can also use commands for this:

Create your new device and then issue this command:

ADD [packagename] and the package pops into the device, ready to connect.

and/or

ADD [symbolname]

CONNECT and then make sure you connections look OK.

AND A WORD OF WARNING:
After having used Eagle for a few years I have learned the hard way: NEVER TRUST A NEW DEVICE.  Especially ones you download from some unknown source.

I have seen devices and LBRs I have downloaded that have all sorts of stupid mistakes: unwired pins, footprints that don't match the part at all, footprints that don't have enough pins, symbols that are upside down, etc.

I usually print out the PCB and make sure the new part is at least close, the drills are big enough, and so on.


I'M HUNGRY, ARE WE AT MCDONALDS YET?

….with all of the blah blah ginger blah blah in hand it's time to do a Proof of concept board. 

Again I am created a new device for a dual 9mm concentric pot. I followed all the instructions above,
I did a quick layout for 3 concentric pots spaced 850mils apart. 

You can find the files for this  PCB on my website. The result--yep it worked. I can see a lot of uses for this going forward.

Now what?

You can get the clone pot library from my GITHUB page.  I will try to keep expanding this library as I need more components. As always if you find mistakes, have problems, etc. please let me know and I'll fix it.


OK that's it for today.  If an Eagle flies over, don't look up, because them turds are big ones.  Have fun!



Friday, June 15, 2018

Synth DVM part III--VU blues

This is the third entry about building a so called "Synth DVM".  If you are interested in the last 2 posts about this, here are links to part two and part one.

OK I have a working prototype on my bench, and I am having 5 boards made up for the op amps and Nano, from EasyEDA, they should be here next week.  Assuming that works I'll get a front panel made....

In the meantime I'm trying to finish up the TFT display programming for the project.  I am using the Adafruit GFX library, discussed in part two...

For the most part once I found decent code examples the TFT coding has been pretty easy, so I made it harder on myself--I decided that in addition to a simple voltage readout I want an analog looking "VU style meter" for the DVM, that shows a needle that points to -10V, 0V, 10V and all in between.
I can see reusing this for all sorts of audioDIY since the whole voltmeter thing with Arduino seems super easy--RMS conversion for displaying AC audio levels?  Arduino driven compressors with a VU to display level reduction?  A needle to show current values when paired with an INA219 current sensor?  A thousand and one uses....

That's the problem with software--you're never done!

The code basics for getting an old school looking meter going isn't that hard, the first thing I had to work on was having the meter needle turn itself off before it changed to a new position with a minimum of flickering but I think I solved that.

You can get the prototype code off of my GitHub repos, but the salient code to get this working is this:


void loop()

{
 //[…. code for numeric readout....not part of VU]


//get vu meter going
   meterx = (sensorValue * .1) + 13;
   if (meterx != lastState)
   {
      tft.drawLine(lastState,64,64,125,0x000);
      tft.drawLine(meterx,64,64,125,0xFFF);
   }
   lastState = meterx;


   delay(1);
}


meterx is a float that senses what is being read from an analogPin. I am saving the value during each loop, and then comparing it the next iteration.  If meterx changes--blank and redraw, otherwise, leave it alone.

It works--the VU moves in concert with the read voltage, and it appears to be accurate and linear and the flicker isn't too bad (extra credit: lastState is long, not float, which improved flicker--strange, I thought that wouldn't work at all?)

The "13" pixel x offset centers the meter correctly on the x axis (128 Pixels, pixel 64 is center, we read 1023 gradiations divided by 10--do the math....) of the TFT.

Here is the problem:The needle for the meter is not a constant length as it sweeps across the TFT and it should be.

Since Y is a constant in my code above, the needle "gets longer" as it approaches the far left or right side of its trajectory.  That doesn't look analog--at all!

I sat up at 3AM trying to figure out a way around this--at each refresh, put a bitmap of a semi circle over the needle, but wouldn't that flicker (and take up a ton of memory)?

some sort of sine/cosine kungfu?

A lookup table that reduces Y value depending on "meterx" value?

All of these feel like a kludge to me.

I can't figure out an elegant way to do this--there is a "drawFastVLine" function in the GFX library, but it can only draw vertical lines of a consistent length, not one that moves on a central axis.

I have no idea about the best way to solve this. I might post it to some forums and it's time for more research.  I guess it'd be best if I could expand the C++ library for Adafruit GFX to add a method "CreateMovingLine()" or "createVisibleRadius()" or something.

How deep do I want to get into this?

Here is a quick diagram of what I am up against. Any ideas anyone?  


(UPDATE electro music forum user says "use an array".  Doh.  Did this and it worked.  I was not thinking about this issue simply! I'll post the results one of these days.)

Thursday, June 7, 2018

Arduino based "Synth DVM" Part II

You can see part I of this post, where I try to get the TFT screen going, as well as discuss this DVM synth project in general here:


To review:
  • I am working on a simple DVM so I can easily see control voltages without having to crack out my Fluke DVM or Siglent Scope.  
  • This Arduino based DVM that can read positive and negative voltages relative to ground without having to flip switches or whatever.
  • Works with a +/- 15V linear power supply
  • Input is buffered so nothing "upstream" can detect it's being detected.
  • Able to read from -10V to +10V DC--with as small an error factor as possible--within say 100mV tops--less is preferred.
  • Have the readout be on a TFT display that's mounted on a 2 or 3u FracRack panel so I can put that into a rack.
  • Extra credit: be able to get P/P AC read as RMS voltage.  
  • But for phase I, stick to DC.
Since that last post I've spent time researching this (to paraphrase the immortal Don Lancaster: you can save hours at the bench by spending minutes on line....).

The first takeaway from the research: lots of folks are building various voltmeters out of Arduinos, but right away you start to see that their accuracy of most basic designs isn't going to be that good.

One problem: by default the Arduino uses 5V derived from USB to suss out the voltages present at the analog pins, which can be dodgy; when I used USB,  my internal ADC readings were inaccurate to over 500mV either way--unacceptable.

Another problem: We need to read negative voltages relative to ground, and the Arduino's analog pins will to clamp unwanted current flow through a diode to flush 'em down the electron toilet, but if you put too much current going the wrong way into the diode, you blow up the Arduino.  So we have to protect against that.

Question: there are "shields" and add on board doodads whose sole purpose is to read currents, and can display voltages and power to boot (an aside: how frigging cool is that??? Remember when this stuff was really hard to do?).

Can I just use one of those?

One of the cool little boards is based on TI's INA219, here's a Great Scott Vid about that add-on--I really like Great Scott. love that accent!  But INA219 based ADC's don't seem to deal with negative voltages very well (e.g., Great Scott's vid is positive V read only, right?) and doesn't seem to have any sort of built in clamping circuitry.  So as cool as the INA219 idea is, I didn't think it'd work here.

OK next I was looking at setting a DC offset at input to 7.5V above ground so everything coming in is positive, then use an INA219, and then code around that....but then we start coming up against rail to rail voltage limitations on the op amp and my +/- 15V power supply.....Remember I am trying to get +/- 10V to be read here....and we only have a 15V positive swing, so even if I put the incoming voltages at a 7.5V offset, we are outside the design parameters, and would only be able to read about +/- 7V DC.

So what I think may work is something like this:


The idea: 
  • The input goes through 2 buffers wired in parallel; one inverts; the other doesn't.
  • The incoming gain is divided by 3, so this could theoretically read inputs as high as +/-12V with an accuracy of about +/- 12mV's.  Remember that we are using 4.096 as external ref, and the ADC has an accuracy of 0-1023, so ADC=0 means 0-4mV, ADC=1 means approv 4.1mv-8mV, etc., up to 1023, or close to 4.096V.  That's how I am doing the math anyway....
  • The sketch will look for data > than 0V at 2 analog pins during each 1ms loop.  If it finds this on the -1 op amp, throw a minus sign in front of the output TFT numeral on display. Otherwise, leave the number as is (Easy right? Why wouldn't that work?)
  • How to keep the Arduino from blowing up?  The Arduino analog inputs want to see high impedance sources, but not too high.  So I figure I can just hook the op amp buffer output right to the analog input....but the solution is easy in any event....Each Analog input could have a  resistor in series to current limit the input of the Arduino analog pins.  It might be 22K, or less?  I figure it won't make a difference?

So step one is getting a positive 0-4.096V input signal accurately, well, read.

Turns out that was super easy--took about 10 minutes from going from the setup last time to a very accurate 0-4V or so DVM.  Here's what I did.

On Amazon I bought this cute little Adafruit LM4040 module and wired it up:





5V from Arduino > VIN on LM4040
GND from Arduino > GND on LM4040
AREF input on Arduino > 4.096 pin on LM4040

  • Modified my code in the [setup] function to include analog Reference so I wouldn't blow up the Arduino--Again here is a good link explaining how this all works.



analogReference(EXTERNAL);

  • Changed my code so that the voltage read at the analog pin was multiplied by .04.


Finally with everything wired up I tested my TFT display of voltages between 0 and 4V by comparing the Arduino voltages read to my trusty Fluke DVM.  It was "dead nuts on", as my EE brother says:


OK onward and upward.  This part turned out to be so much easier than I thought that I almost laughed. The Arduino platform is stupid easy to use! 

To finish this I need to create a PCB for the electronics and 5V power conversion and a 2U front panel for Fracrak, but that's another post.  See ya....


CEM VCO Part II: Maximus Troubleshooting, and the DOH! Count

From a couple of posts ago : My ASMVCO 's are getting old and drifting in pitch.  Might be time to ditch 'em. how about three new VC...