electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
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 
 Forum index » DIY Hardware and Software » Arduino
CV2MIDI
Post new topic   Reply to topic
Page 1 of 1 [5 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: 1488
Location: Chicago
Audio files: 14

PostPosted: Thu Jul 17, 2014 5:59 am    Post subject: CV2MIDI
Subject description: turn it around...
Reply with quote  Mark this post and the followings unread

spuddo is interested in CV2MIDI rather than MIDI2CV, has an arduino, and would like to learn how to use it. This seemed like an interesting and relevant topic to discuss on this sub-board.

Off the top of my head, the simplest way to approach this seems to be to take two inputs -- digitize the CV and capture the gate -- then quantize the CV and spit out MIDI note information instead of a quantized voltage. If more continuous output is desired, I could imagine that could be doable with pitchbend messages, but I'm not as familiar with that part of the MIDI spec.

So the hardware blocks that would be needed would be:

power
input protection (diodes and what have you)
arduino
output generation (also with possible protection)

The code would be something like

set up so that the gate input interrupts the processor on both edges (if possible) or else the main loop would be a poll on the gate input
on interrupt, or gate edge detection, read the CV digital value
quantize/convert the CV to a MIDI note value
output the MIDI on or off note

Conceivably if Arduino only interrupts on rising edge (though I don't THINK so) you could use an inverter and another input to get both edges as interrupts even so. Unfortunately the last work I did with interrupts was all PIC based, and that's washed away what I knew about Arduino interrupts...



open questions:

what input voltage range?
what range is practical?
do we allow for "offset" -- commonly CV keyboards are "rooted" at C, that is 0V is the lowest C on the keyboard, but there are exceptions. The Moog Rogue for example is "rooted" at F, so to use a Rogue with other differently rooted equipment requires an offset interval of a fourth.

This is all off the top of my head, so I'm probably missing some other considerations. part of the reason for making it a forum post is to get the experience of others and fill in gaps Smile
Back to top
View user's profile Send private message
m.o



Joined: Jul 05, 2014
Posts: 24
Location: Sweden

PostPosted: Thu Jul 17, 2014 9:04 am    Post subject: Reply with quote  Mark this post and the followings unread

The note value/number in the midi protocol is represented by a 7-bit value, so it can have value 0-127 which is 10 octaves + 8 notes - so if you want max range you should be able to accept 10.8 volts range I guess.

Practically, maybe 5-8 volts range (not many keyboards with > 8 octaves) but then again the CV may not come directly from a keyboard.

For output circuit I think in the simplest case you could possibly just let the arduino +5V drive the current (through the standard 220 Ohm resistor), and have something like a 7404 inverter (with 220 Ohm outside) connected to the Arduino Tx pin.

http://www.midi.org/techspecs/electrispec.php
Back to top
View user's profile Send private message
elmegil



Joined: Mar 20, 2012
Posts: 1488
Location: Chicago
Audio files: 14

PostPosted: Thu Jul 17, 2014 9:20 am    Post subject: Reply with quote  Mark this post and the followings unread

I've actually commonly seen it done by sinking the current directly to the tx pin, so +5V -> 220R -> pin 4 (I think) and then pin 5-> 220R -> Tx pin.

that gives a little bit of output protection and doesn't make the uC source a lot of current (I think the 5mA current loop is well within the Arduino spec, but even so...).

running it to an inverter would work as a buffer too, of course.
Back to top
View user's profile Send private message
capicoso



Joined: Nov 19, 2012
Posts: 127
Location: Argentina

PostPosted: Thu Jul 17, 2014 11:06 am    Post subject: Reply with quote  Mark this post and the followings unread

I think 5v-8v is pretty high. At least for me... Generally I use 0v as C2, like the yusynth vcos.

Handling interrupts with arduino is pretty easy, check :
http://arduino.cc/en/Reference/attachInterrupt

It has modes for rising, fall, change, etc. 2 pins can be used as interrupts with atmega328, 2 and 3.
Although I think the interrupts are not necessary for this case.


Well, the input voltage range should be 0-5v. The best way to protect the inputs imo is with two diodes, one to protect from negative voltage, and another for voltage higher than 5v, and a cap for spikes.

You could add a rotary switch to select the lowest note. When you convert the analog input to midi notes, you're mapping the lowest value to a desired midi note. So, you can declare a variable which would be the offset. If it's let's say 36, then that'll be 0v. You could use the rotary switch to select 12, 24, 36, or F and so on
Back to top
View user's profile Send private message
capicoso



Joined: Nov 19, 2012
Posts: 127
Location: Argentina

PostPosted: Thu Jul 17, 2014 11:13 am    Post subject: Reply with quote  Mark this post and the followings unread

I would get rid of interrupts.
And do it like this:

if(gateInput){
//send noteon
}
else if(!gateInput){
//send noteoff
}

and declare some flags so it doesn't send constant noteon and offs, something like this:

if(gateInput == HIGH && flag == LOW){
//send noteon
flag = HIGH;
}
if(gateInput == LOW && flag == HIGH){
//send noteoff
flag = LOW;
}
If you really want to use interrupts, you can use only one interrupt in CHANGE mode. And emulate a flip flop. The first time it triggers, it sends noteon, the second time it sends noteoff. That can be made with a counter incrementing each time the interrupt is triggered. And reset it after the second trigger.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1 [5 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 » Arduino
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
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


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