Author |
Message |
elmegil
Joined: Mar 20, 2012 Posts: 2177 Location: Chicago
Audio files: 16
|
Posted: Thu Jul 17, 2014 5:59 am Post subject:
CV2MIDI Subject description: turn it around... |
|
|
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 |
|
Back to top
|
|
|
m.o
Joined: Jul 05, 2014 Posts: 44 Location: Sweden
|
Posted: Thu Jul 17, 2014 9:04 am Post subject:
|
|
|
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
|
|
|
elmegil
Joined: Mar 20, 2012 Posts: 2177 Location: Chicago
Audio files: 16
|
Posted: Thu Jul 17, 2014 9:20 am Post subject:
|
|
|
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
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Thu Jul 17, 2014 11:06 am Post subject:
|
|
|
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
|
|
|
capicoso
Joined: Nov 19, 2012 Posts: 128 Location: Argentina
|
Posted: Thu Jul 17, 2014 11:13 am Post subject:
|
|
|
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
|
|
|
cappy2112
Joined: Dec 24, 2004 Posts: 2465 Location: San Jose, California
Audio files: 2
G2 patch files: 1
|
Posted: Mon Nov 17, 2014 8:17 pm Post subject:
|
|
|
[quote="capicoso"]
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.
/quote]
Yes- but unfortunately on the Uno you only have 2 external interrupt pins.
Most (if not all) ATMegas also support Pin Change interrupts, so you can use any external pin other than power & ground as an external interrupt source. There is a little downside to this- if you use this Arduino library to determine which pin generated the interrupt,
http://playground.arduino.cc/Main/PinChangeInt
your ISR response time isn't as fast as one would hope. _________________ Free Tibet. Release the Panchen Lama from prison. Let the Dalai Lama return to his home. |
|
Back to top
|
|
|
davebr
Joined: Jun 09, 2007 Posts: 198 Location: portland, or
|
Posted: Fri Dec 26, 2014 8:15 pm Post subject:
CV2MIDI |
|
|
This is a somewhat late response as I don't peruse this particular forum very often. I did CV to MIDI on my ComputerVoltageSource 10 years ago. The micro in that controller is a BasicMicro BASIC stamp. It has 8 analog inputs, 8 analog outputs, and a few digital IOs. I wrote quite a few programs using CV to MIDI where I would let LFOs drive the note, velocity, octave, and instrument. I got quite a few interesting sounds and use it quite a bit. You can drive a MIDI synth with a CV keyboard and portamento gives you very nice glissandos.
All my programs are public but of course they are written in BASIC. I did interface an Arduino as the core but there wasn't enough advantage to adapt it. The programming interface on the PC is quite easy and BASIC is easy to remember a decade later when you need modifications.
Information on my ComputerVoltageSource is at http://modularsynthesis.com/cvs/cvs.htm
A brief summary of my Arduino-based ComputerVoltageSource is at http://modularsynthesis.com/arduino/arduino-cvs/arduino-cvs.htm
My programs are at http://modularsynthesis.com/programs/programs.htm
Sound samples are at http://modularsynthesis.com/samples/samples.htm
Many samples use CV2MIDI and it is in the description. Listen especially to Circus. It is the same note with the instrument changed by CV.
Dave |
|
Back to top
|
|
|
freshnelly
Joined: Feb 25, 2015 Posts: 8 Location: Vancouver BC
|
Posted: Sun Sep 06, 2015 7:16 pm Post subject:
|
|
|
Hi, I've been designing a modular component that has a CV-->MIDI in it for universal CV input (euro -5V to +5V) that runs continuously, not just at gate.
The voltage issue is easily solved with an op-amp before the ADC (bi-polar) with the gain set to take the voltage down to the ADC min/max, which would be 0V to 5V.
My issue has been more the "sample rate" is limited by the MIDI sentence rate (just under 1mS for non-running status) so is for all intent and purposes a 1KHz CV sampler.
This would be to a MIDI CC, not notes, at this point.
The rate is capable of handling a lot of CV change but overloads a MIDI input so nothing else gets in.
My solution is to detect a change rate beyond a certain frequency, then use that data to average the signal to say 1/8th of the rate. Slower CV changes get through fine. IMHO This can be justified as there's very few things you can do with a CC that changes at those high rates anyway!
With the CV/Gate combination, the gate can be used to switch the Arduino to a quantizer and feed the ADC's 8.53/note (1V/Oct) to MIDI notes.
Has anyone thought of adding a velocity CV? Could come from an ADSR to control the note's level. |
|
Back to top
|
|
|
|