electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
poster
 Forum index » DIY Hardware and Software » Thomas Henry designs
Crazy noob?
Post new topic   Reply to topic Moderators: Scott Stites
Page 1 of 1 [15 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Wed Mar 21, 2012 9:38 pm    Post subject: Crazy noob? Reply with quote  Mark this post and the followings unread

I have an EE degree, but have done IT for 25 years now, so it's rusty. I also have had a huge curiosity about analog synths for a long time (since first hearing Switched on Bach, actually), but was always stymied by what to do for a keyboard. So I haven't done anything about it.... until NOW.

A couple months back I got an Arduino (mintduino actually, builds it on a small breadboard rather than coming pre-made). Casting about for "what can I do with this toy", I thought perhaps I'd revisit my EE Senior project which was also related to all this--we intended to build a digital sequencer with some custom microcontrollers (I think they were using 6502's as the core, but they had their own uarts etc). As I was digging around in MIDI resources for Arduino, I found a link to Thomas Henry's MTS-100 MIDI->CV module.

And at that point the flood gates opened. I've been totally obsessed with how I could build my own analog synth since then. I have a MIDI keyboard, so the long-standing roadblock is gone.

I built a modified MTS-100 on proto board, using an Arduino chip instead of the original microcontroller, and omitting the pitch bend since I don't have a controller that can generate one. I've set up the Arduino on a separate smaller board with the MIDI cicuitry, which will let me reuse it for other MIDI purposes if I wish to (for example upgrading from the DAC0800 to something with a bit more resolution). And I've got the programming pins brought out to the edge so I can reprogram it if I need to as well.

I made a misstep and trusted Allied Electronics when they said a particular power supply was "Linear" (should have paid more attention to weight and size specs), so the supply I'm using is a Cosel switching model, but I've got it wired up in a project box with a power switch and an octopus of MTA connectors, and I figure it'll get me through until I can get some sounds and see how noisy it really is (I expect pretty bad, honestly). It shouldn't be too hard to repurpose the box once I manage to build my own linear supply, but I've been hesitant to sink so much into a transformer (I have all the other parts...).

I bought An Analog Synth for the 21st century, and I've ordered a pile of additional parts, most of which are due to arrive in the next 2-4 weeks.

I just got the (not quite) MTS-100 soldered up and working tonight and I'm pretty happy about it (only a couple of missteps, and nothing catastrophic). I'm incredibly grateful to the many people who've put their schematics and work out on the net for all to see and work from, and particularly TH.



Here's a picture of the MIDI2CV boards, wired up for testing. I still need to get mounting hardware and figure out how I want it hooked up to the front panel (for now, I painted and drilled a chunk of 1/8" MDF; I have a ton of woodworking tools and scrap, but I'm not sure about trying to work aluminum with what I have). I like the 8.75" form factor, and apparently misread the standard width as 1.5 rather than 1.75...

I didn't see any "introductions" subforum, and since most of what I'm planning on in the near term is TH designs I figured this was as good a place as any to stick my head up and say hi. Feel free to redirect me if I messed up....


MIDI-CV.jpg
 Description:
 Filesize:  108.55 KB
 Viewed:  548 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.

MIDI-CV.jpg


Back to top
View user's profile Send private message
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Wed Mar 21, 2012 10:08 pm    Post subject: Reply with quote  Mark this post and the followings unread

Awesome first project, definitely enclose it somehow so it lasts (that was my mistake for years). Wood is a great medium for enclosures, I'd say go with what you know. I am interested in getting some midi2CV capability in my lab too, but all in good time. Welcome aboard, you're gonna love these people on this here website!

Les

_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
Uncle Krunkus
Moderator


Joined: Jul 11, 2005
Posts: 4761
Location: Sydney, Australia
Audio files: 52
G2 patch files: 1

PostPosted: Thu Mar 22, 2012 1:51 am    Post subject: Reply with quote  Mark this post and the followings unread

Flying leads - PCB pin - heatshrink over both.
This will last 20 times longer and eliminate a lot of troubleshooting down the track.
That goes for you too Les! Laughing

_________________
What makes a space ours, is what we put there, and what we do there.
Back to top
View user's profile Send private message Visit poster's website
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Thu Mar 22, 2012 5:08 am    Post subject: Reply with quote  Mark this post and the followings unread

I definitely need to invest in a wider range of MTA connectors Smile
Back to top
View user's profile Send private message
inlifeindeath



Joined: Apr 02, 2010
Posts: 316
Location: Albuquerque, NM

PostPosted: Thu Mar 22, 2012 7:55 am    Post subject: Reply with quote  Mark this post and the followings unread

welcome and thanks for sharing!
i just recently ordered an Arduino board and was looking for Midi to CV and/or CV quantizer code. Any suggestions on where to get started? While I know my analog electronics, i'm new to writing code and microcontrollers.

_________________
http://www.youtube.com/user/borisandfef
Back to top
View user's profile Send private message Visit poster's website
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Thu Mar 22, 2012 8:08 am    Post subject: Reply with quote  Mark this post and the followings unread

Off the top of my head, I think the biggest thing is that you will want to use the MIDI Library. Some keyboards (such as mine) use an abbreviated MIDI protocol sometimes referred to as "running mode" and the more basic stuff you'll find about Arduino + MIDI doesn't handle it.

It was really pretty simple to code. I'm posting from work (bad Pete!) but tonight I will write up some of my notes, links, and post my code.
Back to top
View user's profile Send private message
inlifeindeath



Joined: Apr 02, 2010
Posts: 316
Location: Albuquerque, NM

PostPosted: Thu Mar 22, 2012 8:11 am    Post subject: Reply with quote  Mark this post and the followings unread

thank you, i appreciate it!
now... back to work Smile

_________________
http://www.youtube.com/user/borisandfef
Back to top
View user's profile Send private message Visit poster's website
v-un-v
Janitor
Janitor


Joined: May 16, 2005
Posts: 8933
Location: Birmingham, England, UK
Audio files: 11
G2 patch files: 1

PostPosted: Thu Mar 22, 2012 8:52 am    Post subject: Reply with quote  Mark this post and the followings unread

And welcome to electro-music.com too! Very Happy
_________________
ACHTUNG!
ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS!
DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN MIT SPITZENSPARKSEN.
IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS.
ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN.
Back to top
View user's profile Send private message Send e-mail
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Thu Mar 22, 2012 7:36 pm    Post subject: Reply with quote  Mark this post and the followings unread

Apparently I got too big, and it started mangling my reply Smile So I'm going to split this into parts.


Thanks for the welcomes Smile

So I did cheat a little bit on my project Smile. I had an old Game Port -> MIDI interface that there was no chance I would ever use, so I scavenged the parts from it. That had me using a 6N136 Optoisolator, and a pair of 2N3904's as the output buffers for MIDI OUT. I first set those two up with the Arduino so I could test that my keyboard would work for me, and that's where I learned about "running mode". My keyboard also generates a velocity 0 "note on" instead of a note off.

So from this circuit defined by the standard:

http://www.midi.org/techspecs/electrispec.php

I'm using a 270R instead of 220R on the input loop for the optoisolator, and the pull up on the output is 5.6K, all of which are from the gameport circuit. I'm not sure that these are necessary differences but I believe they are because of differences in the 6N136 versus other common optoisolators--4N25/26/28. I know when I did my senior project we had problems with the first couple of isolators we used and ended up ordering a PC900 to do the job.

I didn't hook up the through port, and you probably don't need an out port for MIDI->CV, but from the circuit there I'm using a pair of transistors as the buffers. Unfortunately, I don't know Eagle or any other package well enough yet to draw a circuit diagram, but I'll include a picture of the diagram I drew in my notebook as an attachment.

As far as it goes, I'm using a hand soldered arduino board and scavenged parts, but if you went with the "standard" R3 Arduino Duemilanove, there are lots of shield boards for expanding it, including a few different versions of a MIDI shield. if you weren't interested in wiring your own, that would be a good option to get the DIN and all the parts together in one shot.

Using MIDI with the Arduino is really as basic as hooking these circuits up to pins 0 & 1, which have a built in serial UART. As I mentioned before you'll probably want to use the MIDI Library rather than rolling your own; it handles the special cases like running mode, and has defines for all the various types of messages etc so you don't have to worry directly with byte values. The library is available at:

http://arduino.cc/playground/Main/MIDILibrary

The code is really simple, see the second post for it and the circuit diagram.

I think the main thing that needs to be explained here is pin assignments. The Arduino has 14 digital pins that can be used as input or output.

Pins 0 & 1 are already hooked up to an on-board UART, as RX and TX respectively, so for this application it was just as easy to go ahead and use them that way. You could bit-bang any other pins you like, but then you're at the mercy of your loop being fast enough--the onboard UART is interrupt driven.

Pin 13 is typically wired to an "on board" LED that is used for lots of simple demonstrations. In the default setup, the program that comes loaded just blinks this LED once a second, just so you know your board is alive. I've used it as an error indicator, although if this goes into a rack I probably won't see that ever Smile.

I've used pins 2-8 as the 7 output bits, corresponding to PA0 - PA6 in TH's original MTS-100 circuit. And I've used pins 9 & 10 as trigger and gate drivers, respectively, where the original used PB1 & PB0.

Arduino "sketch" code only really uses to main blocks of code -- setup() which is run once on reset/power on, and loop() which is run continuously. The language is basically C (really under the covers I believe it's C++, hence the MIDI class...), but there are a lot of implicit definitions already included for you (you don't see me defining "HIGH" and "LOW" anywhere, nor doing an explicit include to get their definitions).

MIDI.begin() hides the (not really very much) complexity of setting up the serial port to 31250Hz etc. Most of the rest of the code is pretty self explanatory, but I'll be happy to answer any questions about particular things.


From there most of the circuitry is just like the MTS-100. I've omitted the switches and LEDs for omni and channel switching (I just force it to omni mode for what I'm doing, since I'm not driving from anything complex, just a yamaha keyboard), and the octave shift switch (I have 5 octaves on my keyboard which is enough for my purposes for now). Part of omitting this stuff is also to conserve pins. The original 68705 had 20 bidirectional pins, and TH used almost all of them. The Arduino has an additional 6 pins but they're normally used for Analog inputs or outputs (PWM, so not really sufficient quality for directly driving CV, though some people do have circuits like that out there). I haven't researched whether they could also be used as digital outputs, since I didn't need all the other stuff I just cut it out. Also, I mentioned above, I omitted the MIDI Thru ports from TH's original.

On the analog half of the circuit, I've omitted the transistors and 4016 switching between CV and pitch bend outputs, and the op amp driving the pitch bend output. Everything else is exactly as designed. I do have an additional two pins I could pretty easily use driving those though, even without worrying about the Analog pins.

Other thoughts I've had is that the octave switch could be easily cut to a single analog pin by switching segments of a voltage divider, and using the analog voltage to determine whether you were at plus 1, zero, or minus 1 octave. The analog outputs can drive LEDs, so that could give channel and omni LED outputs, however, then the switches for those two would have to be brought in somewhere unless you were strictly using the MIDI control signals to switch around.


Some other miscellaneous Arduino notes...I had a lot of trouble figuring out the running mode stuff because I was unaware of that part of the standard, and the simple examples don't handle it. With the base Arduino model, I only had the one serial port--it acts as the programming interface when loading new code, and as the MIDI ports otherwise. That didn't leave me with any good options for output so I didn't have a very good way to monitor what I was getting in from the keyboard.

I bought an Arduino Mega pre-built which has 3 additional serial ports. I was able to use a different one of those for the MIDI I/O and then I could use the serial monitor from the IDE and simple print/write commands on the main port to watch the bytes come in, and that was where I saw the fact that hitting keys at any speed was simply omitting additional control bytes (e.g. instead of noteOn, Note, Velocity, noteOn, Note Velocity, it would send noteOn, Note, Velocity, Note, Velocity, etc... and since it uses noteOn with Velocity 0 instead of noteOff, I would just get a noteOn and then a string of notes and velocities until they sent zeros). That's the definition of "running mode"-- it remembers the last control byte, and if sending another command that would use the same byte, it just omits the control byte.

Oh, one other thing, the model I have doesn't have a dedicated usb->serial interface, so I bough a small FTDI board that hooks onto the 6 header pins on the one side. But if you have the FTDI connected to rx/tx at the same time as you have a live MIDI stream going, it interferes. So I put a switch between the two (on the rx side) so that I didn't have to keep plugging and unplugging all the time. If you're using one of the prebuilt boards, usually the FTDI or some equivalent is built in. On my Mega, it uses an older smaller Atmega microcontroller to manage the serial and usb duties. Some of the discussions I saw seemed to say if you used different resistors on the input you could avoid that problem, but I was going pretty minimalist so I didn't experiment beyond finding that the switch worked fine for my needs.

Hopefully this doesn't ramble too much and has useful information. Let me know if you have any questions. Code and picture of circuit diagram follow....
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Thu Mar 22, 2012 7:37 pm    Post subject: Reply with quote  Mark this post and the followings unread

I should add that the MIDI out is mostly for discussion; the MIDI in I'm using is just like the standard, using a 6N136 and with the minor differences I mentioned in the first post.


arg, it's mangling the code too. Trying to find a solution....


Code:


/* MIDI Types enumeration
NoteOff    
NoteOn    
AfterTouchPoly    
ControlChange    
ProgramChange    
AfterTouchChannel    Channel (monophonic) AfterTouch.
PitchBend    
SystemExclusive    
TimeCodeQuarterFrame    
SongPosition    
SongSelect    
TuneRequest    
Clock    
Start    
Continue    
Stop    
ActiveSensing    
SystemReset    
InvalidType          For notifying errors.
*/

#include <MIDI>

#define LED 13
#define GATE 10
#define TRIG 9

// trigger from MTS-100 was ~ 5ms
#define TRIG_DELAY 5

// in this case, the port numbers on the Arduino correspond to the B numbers
//    incoming on the dac0800.  It may not always be so
byte DACBITS[] = { 8, 7, 6, 5, 4, 3, 2 }; // LSB to MSB order
#define numBits (sizeof(DACBITS)/sizeof(byte))

byte note; // generic holder
byte curNote = 0xFF;
byte prevNote = 0xFF; // FF is "no note"
byte vel;
boolean gate; // is it on or off

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(GATE, OUTPUT);
  pinMode(TRIG, OUTPUT);
  // make sure these are all "off"
  digitalWrite(LED, LOW);
  digitalWrite(GATE, HIGH);
  digitalWrite(TRIG, HIGH);
  for (int i=0; i< numBits; i++) {
    pinMode(DACBITS[i], OUTPUT);
  }
  note2dac(60); // start with middle C, not zero!
  MIDI.begin(MIDI_CHANNEL_OMNI);
}

// I don't actually USE the velocity info other than to find 0x90 V0 "note off" events
void loop() {
  if (MIDI.read()) {
    switch(MIDI.getType()) {
      case NoteOn:
          //digitalWrite(LED, LOW);
          note = MIDI.getData1();
          vel = MIDI.getData2();
          if (vel == 0) { // actually noteOff
            noteOff(note);
          } else {
            noteOn(note, vel);
          }
        break;
      case NoteOff:
          note = MIDI.getData1();
          noteOff(note);
        break;
      case InvalidType:
          for (int i=0; i<5; i++) {
            digitalWrite(LED, HIGH);
            delay(5);
            digitalWrite(LED, LOW);
            delay(5);
          }
        break;
    }
  }
}
[/code]


midi-ckt.jpg
 Description:
 Filesize:  130.93 KB
 Viewed:  419 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.

midi-ckt.jpg



Last edited by elmegil on Thu Mar 22, 2012 8:04 pm; edited 3 times in total
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Thu Mar 22, 2012 7:56 pm    Post subject: Reply with quote  Mark this post and the followings unread

Babble babble babble....

One other thought I've had is that the Arduino community has a lot of open sourced and freely available designs for shields...which are made to be stackable. One idea that has occurred to me is to look into whether or not it would be practical to create a CV driver shield that could be stacked on top of a MIDI shield from someone else to make a nicely integrated solution the size of an Arduino board and 3 boards tall. That would easily fit inside a 2" x 3" x 3" cube (assuming external power plugged into the top CV board) and I presume could be of interest to use the control voltage for various things.

I could even use something like a serial -> parallel latch (I'm probably abusing terms, like I said, my EE is very rusty) and cut my pin count by 5, which would let me easily implement all the other various things I've omitted in this iteration.

Of course, that would definitely require permission from TH first to be adapting and promulgating what is basically his MIDI->CV design. At this point it's only an idle idea.
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Thu Mar 22, 2012 8:05 pm    Post subject: Reply with quote  Mark this post and the followings unread

Second part of the code

Code:


void noteOn(byte note, byte vel) {
  prevNote = curNote;
  curNote = note;
  note2dac(note);
  if (!gate) {
    gate = true;
    gateOn();
  }
  doTrigger();
}

void noteOff(byte note) {
  boolean reTrig = false; // had been 0xFF incorrectly
  if (curNote == note) {
    curNote = prevNote;
    prevNote = 0xFF;
    reTrig = true;
  } else { // can we assume that else always means prevNote == note?
    prevNote = 0xFF;
    reTrig = false;
  }
  if (curNote == 0xFF) { // no previous note
    gate = false;
    gateOff();
  } else {
    // may need a delay between note2dac & doTrigger to let v settle?
    if (reTrig && (curNote != 0xFF)) {
      note2dac(curNote);
      doTrigger();
    }
  }
}

// if this is glitchy, may need to gateOff briefly while we set up the dac
// also reordered to do MSB -> LSB to get faster switch to new voltage
void note2dac(byte note) {
  byte mask = 0x1 << (numBits - 1);
  for (int i=numBits - 1; i>=0; i--) {
    if (note & mask) {
      digitalWrite(DACBITS[i], HIGH);
    } else {
      digitalWrite(DACBITS[i], LOW);
    }
    note = note << 1;
  }
}

void gateOn() { // "on" is LOW
  digitalWrite(GATE, LOW);
}

void gateOff() {
  digitalWrite(GATE, HIGH);
}

void doTrigger() {
  digitalWrite(TRIG, LOW);
  delay(TRIG_DELAY);
  digitalWrite(TRIG, HIGH);
}


AHA, I've figured out what's going on with the code glitches...

Where I have a string like <something something something newline something else > (like an if statement before a for statement as in note2dac() ) it wants to compress that down to being an HTML tag. The solution is to disable HTML for the post (since I'm not using it anyway).

Last edited by elmegil on Fri Mar 23, 2012 8:22 pm; edited 2 times in total
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Thu Mar 22, 2012 10:19 pm    Post subject: Reply with quote  Mark this post and the followings unread

Surprisingly this looks like the only MIDI shield I've found that can be further stacked on:

http://ruggedcircuits.com/html/flexible_midi_shield.html

Of course you could design it so that the CV shield was in the middle, but given 3 - 1/4" jacks and a +/- 15V supply connection, that seems like it could be tricky.
Back to top
View user's profile Send private message
Inventor
Stream Operator


Joined: Oct 13, 2007
Posts: 6221
Location: near Austin, Tx, USA
Audio files: 267

PostPosted: Fri Mar 23, 2012 12:21 am    Post subject: Reply with quote  Mark this post and the followings unread

elmegil, TMI! No, i joke - there is no such thing as TMI when it comes to sharing project information. I'm not that into this project that I'll read it now, however it's an awesome reference for us to refer to later.

Since you seem to be really into this, I'd like to focus your attention on our tutorials subforum. Perhaps you would like to copy/paste and summarize much of this info into a nice little pdf or txt document and post it there? That would be a great way of preserving your work for posterity, and it creates a reference for yourself that will never go away (we believe). Consider it.

It's great to have someone so thorough here on our site and if I may be selfish, I would secondarily like to call your attention to my personal subforum, Les Hall's Projects Including eChucK. You might like something you see there. Also check out the rest of the DIY forums, you will find a home or homes somewhere!

Les

_________________
"Let's make noise for peace." - Kijjaz
Back to top
View user's profile Send private message Send e-mail
elmegil



Joined: Mar 20, 2012
Posts: 2177
Location: Chicago
Audio files: 16

PostPosted: Sat Mar 24, 2012 1:11 pm    Post subject: Reply with quote  Mark this post and the followings unread

WE HAVE SOUND. Very Happy Not very well TUNED sound, but the keyboard makes the oscillator change pitch.

I'm using Rene Schmitz' 4069 VCO from here http://www.uni-bonn.de/~uzs159/vco4069.html since I had all the parts already.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Scott Stites
Page 1 of 1 [15 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Thomas Henry designs
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use