converting my arduino midi sequencer to CV

From circuitbending to homebrew stompboxes & synths, keep the DIY spirit alive!

Moderators: Kent, luketeaford, Joe.

conscious
Wiggling with Experience
Posts: 453
Joined: Fri Sep 23, 2011 9:03 am

converting my arduino midi sequencer to CV

Post by conscious » Fri Nov 11, 2011 4:46 pm

Hi,

i did build a analog style sequencer using an arduino board and now I would
like to control my eurorack gear with it, how hard is it to get the arduino to output CV? Can i kinda just change a couple of lines to get a CV sequencer?

thnx a lot

User avatar
Mongo1
Ultra Wiggler
Posts: 766
Joined: Fri Aug 26, 2011 9:42 am
Location: Raleigh NC

Post by Mongo1 » Fri Nov 11, 2011 5:02 pm

Well, there are two ways to go about it -
If you are content with 8 bits of resolution, you can use a PWM output for the control voltage. You'll have to filter it, but it will work.

If you want better resolution, you'll need to get a DAC (12 bit) chip, and connect it. I keep looking for a nice shield with a high quality dac or two, and some buffers etc, but nobody seems to make one.

If you go over to the arduino site, I think there are some discussions about what is required to do all of this.

Gary
I'd never belong to a club that would have ME as a member. Except for Muffwiggler.com

User avatar
bendedavis
Veteran Wiggler
Posts: 727
Joined: Sat Aug 07, 2010 12:08 pm
Location: Portland, OR

Post by bendedavis » Fri Nov 11, 2011 5:07 pm

If it's just a standard sequencer design then multiplexers would probably be easier to use. check out 4067's for a 16 channel mux. Then just use the arduino to control the selects on the multiplexer

User avatar
rosch
roadkill
Posts: 814
Joined: Thu Dec 23, 2010 12:44 pm
Location: doucheland

Post by rosch » Fri Nov 11, 2011 6:02 pm

have you checked the MIDIbox CV?
http://www.ucapps.de/

there are some people around here and EM who have it in their systems.
afaik there will be a new version soon with lot more features.

User avatar
ringroad1
Common Wiggler
Posts: 163
Joined: Mon Oct 18, 2010 7:17 am
Location: Coventry, UK

Post by ringroad1 » Fri Nov 11, 2011 7:02 pm

check the MCP4922 - two channels of 12-bit-ness over SPI, available in DIP, and cheap. there's code out there for having it communicate with an arduino.

User avatar
Neutron7
Oldschool bleeper
Posts: 1974
Joined: Sun May 23, 2010 12:24 pm

Post by Neutron7 » Fri Nov 11, 2011 7:39 pm

you can get 10 bits of resolution on pins 9 and 10 by setting timer 1 to 16 bit (it wastes the other bits) then you can have your program send values from 0 - 1023 which conveniently happens to be the same as the input ADC input range.

one thing i have noticed that is sort of strange, If you are using any floating point math fuctions (not sure exactly which one) and also the fast analog read trick. you might get glitches on the PWM output. i solved it by changing the prescaler to 32 instead of 16. (still much faster than 128 which is the default)

analogread tweak. they are really slow and this will give you much tighter timing

in declarations

Code: Select all

// defines for setting and clearing register bits

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
in setup

Code: Select all


 // set prescale to 32 Makes analogreads faster (default is 128).
  //
  sbi(ADCSRA,ADPS2) ;
  cbi(ADCSRA,ADPS1) ;
  sbi(ADCSRA,ADPS0) ; //set to 32
  // cbi(ADCSRA,ADPS0) ; //use instead of previous line to set to 16 but in some cases with floating point maths.

If you want to get clever, you could add the 2 PWM together (after filter) and use the second one for a fine control for glides and whatnot. remember the 303 only has a 6 bit DAC!

User avatar
Neutron7
Oldschool bleeper
Posts: 1974
Joined: Sun May 23, 2010 12:24 pm

Post by Neutron7 » Fri Nov 11, 2011 9:11 pm

If you use an SPI DAC instead of the PWM output you will get a smoother result for sure, but there are a couple of things to watch for.

there are 2 ways the DAC can be serviced, one is by interrupt, which means you just set the variable and next time that interrupt comes around it will send it to the DAC

the other way is to have a routine that sends the variable to the DAC after it is generated by your program.

I prefer the latter because it always takes almost exactly the same amount of time so the output of the DAC changes right when it needs to be + the amount of time it takes for the serial data to be sent. If you use an interrupt, there can be jitter because the interrupt might not happen exactly after you want the new value to be output. and the interrupt has overhead, and makes the main program run slower.

One of the best things about hardware is its tightness, so i dont want to ruin that with computer like "interrupts"

conscious
Wiggling with Experience
Posts: 453
Joined: Fri Sep 23, 2011 9:03 am

Post by conscious » Sat Nov 12, 2011 12:34 am

xx

conscious
Wiggling with Experience
Posts: 453
Joined: Fri Sep 23, 2011 9:03 am

Post by conscious » Sat Nov 12, 2011 12:36 am

well im not content with the stuff you say, i guess its a step to high for me.
Im familiar with basic C and did get the sequecer running with some cool features, but i have no idea how to trigger a DAC.
Will this thing work:

http://www.watterott.com/index.php?page ... &info=1923
you can get 10 bits of resolution on pins 9 and 10 by setting timer 1 to 16 bit (it wastes the other bits) then you can have your program send values from 0 - 1023 which conveniently happens to be the same as the input ADC input range.
could you give me an examplecode?

this is my code that plays a note:

I attached a picture, so you can see my work :)
Attachments
seq1.JPG
seq1.JPG (177.16 KiB) Viewed 495 times

User avatar
Neutron7
Oldschool bleeper
Posts: 1974
Joined: Sun May 23, 2010 12:24 pm

Post by Neutron7 » Sat Nov 12, 2011 2:21 am

i did something like that, it was a synth on arduino mega.


User avatar
Yeuky
Common Wiggler
Posts: 83
Joined: Sun Jun 19, 2011 5:43 am
Location: Sydney, Australia

Post by Yeuky » Sat Nov 12, 2011 6:05 am

bendedavis wrote:If it's just a standard sequencer design then multiplexers would probably be easier to use. check out 4067's for a 16 channel mux. Then just use the arduino to control the selects on the multiplexer
This.

You wire up your pot's to the 4067's inputs and 4 digital pins to control which output is selected (Standard BCD) and your all set.

conscious
Wiggling with Experience
Posts: 453
Joined: Fri Sep 23, 2011 9:03 am

Post by conscious » Sat Nov 12, 2011 9:34 am

could you point me to an example, im to much noob to get that on the fly.

User avatar
Neutron7
Oldschool bleeper
Posts: 1974
Joined: Sun May 23, 2010 12:24 pm

Post by Neutron7 » Sat Nov 12, 2011 1:33 pm

conscious wrote:could you point me to an example, im to much noob to get that on the fly.
a shield with it already done. there is example code as well.

http://mayhewlabs.com/products/arduino-mux-shield

conscious
Wiggling with Experience
Posts: 453
Joined: Fri Sep 23, 2011 9:03 am

Post by conscious » Sat Nov 12, 2011 3:00 pm

mmh, i was thinking about outputting 1 CV for each note that is played, would I need a multiplexer for this, or did I get something wrong. sorry.
Right now the pins are enough, atm.

User avatar
Neutron7
Oldschool bleeper
Posts: 1974
Joined: Sun May 23, 2010 12:24 pm

Post by Neutron7 » Sat Nov 12, 2011 3:14 pm

if you want to output more CVs you could use an 8 channel DAC like the MIDIbox one or you could use a multiplexer and a sample and hold, which might actually be more expensive and complicated.

conscious
Wiggling with Experience
Posts: 453
Joined: Fri Sep 23, 2011 9:03 am

Post by conscious » Sat Nov 12, 2011 8:35 pm

what do I have to do to output 1 CV?
Can you point me to a guide?
I tried the official arduino forums, but i couldnt find anything there.


thnx

User avatar
xi-bot
Common Wiggler
Posts: 155
Joined: Thu Jan 13, 2011 1:52 pm

Post by xi-bot » Sat Nov 12, 2011 9:47 pm

here is a nice and easy instruction how to connect arduino with one MCP4921 12bit dac to have 1 cv (0 - 5volt)
http://mrbook.org/blog/wp-content/uploa ... 50mod4.png
http://mrbook.org/blog/wp-content/uploa ... gakken.pde
http://mrbook.org/blog/category/arduino/
you could use op-amps to buffer and optionaly scale (10volt or +/- 5volt) the output

if you want to run the MCP4921 at audio rate have a look at ladyadas waveshield code http://www.ladyada.net/make/waveshield/download.html

conscious
Wiggling with Experience
Posts: 453
Joined: Fri Sep 23, 2011 9:03 am

Post by conscious » Sat Nov 26, 2011 7:14 am

xi-bot wrote:here is a nice and easy instruction how to connect arduino with one MCP4921 12bit dac to have 1 cv (0 - 5volt)
http://mrbook.org/blog/wp-content/uploa ... 50mod4.png
http://mrbook.org/blog/wp-content/uploa ... gakken.pde
http://mrbook.org/blog/category/arduino/
you could use op-amps to buffer and optionaly scale (10volt or +/- 5volt) the output

if you want to run the MCP4921 at audio rate have a look at ladyadas waveshield code http://www.ladyada.net/make/waveshield/download.html
Do I get is right that "P2" would be my CV?

User avatar
xi-bot
Common Wiggler
Posts: 155
Joined: Thu Jan 13, 2011 1:52 pm

Post by xi-bot » Sun Nov 27, 2011 7:28 pm

yes

User avatar
a.b.o.z.
Common Wiggler
Posts: 76
Joined: Sat Nov 05, 2011 6:35 pm
Location: zgb, cro

Post by a.b.o.z. » Mon Nov 28, 2011 12:53 am

xi-bot wrote:here is a nice and easy instruction how to connect arduino with one MCP4921 12bit dac to have 1 cv (0 - 5volt)
http://mrbook.org/blog/wp-content/uploa ... 50mod4.png
http://mrbook.org/blog/wp-content/uploa ... gakken.pde
http://mrbook.org/blog/category/arduino/
you could use op-amps to buffer and optionaly scale (10volt or +/- 5volt) the output
but for this you still need a computer to run the procesing sketch right?
its not a standalone midi->arduino->cv setup!?

User avatar
xi-bot
Common Wiggler
Posts: 155
Joined: Thu Jan 13, 2011 1:52 pm

Post by xi-bot » Mon Nov 28, 2011 8:41 pm

a.b.o.z. wrote:
xi-bot wrote:here is a nice and easy instruction how to connect arduino with one MCP4921 12bit dac to have 1 cv (0 - 5volt)
http://mrbook.org/blog/wp-content/uploa ... 50mod4.png
http://mrbook.org/blog/wp-content/uploa ... gakken.pde
http://mrbook.org/blog/category/arduino/
you could use op-amps to buffer and optionaly scale (10volt or +/- 5volt) the output
but for this you still need a computer to run the procesing sketch right?
its not a standalone midi->arduino->cv setup!?
no. you can do both. with arduino you can easily build standalone applications or connect them to your computer via usb

conscious
Wiggling with Experience
Posts: 453
Joined: Fri Sep 23, 2011 9:03 am

Post by conscious » Wed Dec 07, 2011 8:23 am

i started looking at it and im nopt sure if I can convert my programm to be compatible with the sketch you posted.
Anybody willing to take a look at my code and help out.

There are 3 pins leaving the arduino, is this gakken special or the usual for CV output?

User avatar
xi-bot
Common Wiggler
Posts: 155
Joined: Thu Jan 13, 2011 1:52 pm

Post by xi-bot » Wed Dec 07, 2011 9:48 am

conscious wrote:i started looking at it and im nopt sure if I can convert my programm to be compatible with the sketch you posted.
Anybody willing to take a look at my code and help out.

There are 3 pins leaving the arduino, is this gakken special or the usual for CV output?
you have to reserve the pins 10, 11, 13 on the arduino for the dacs spi connection
the dac is also connected to 5 volt and ground
pin 8 outputs your cv signal (0-5volt)
just call the function "write_value" from this example
http://mrbook.org/blog/wp-content/uploa ... gakken.pde
with a number (integer) between 0 and 4093 to output a voltage between 0 and 5 volt

User avatar
xi-bot
Common Wiggler
Posts: 155
Joined: Thu Jan 13, 2011 1:52 pm

Post by xi-bot » Wed Dec 07, 2011 9:49 am

these are the essential parts you need to add to your code

Code: Select all

#define DATAOUT 11//MOSI
#define DATAIN 12//MISO - not used, but part of builtin SPI
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss

void setup()                    //  add this setup to your setup function
{
  // Control Voltage Section
  byte clr;
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  digitalWrite(SLAVESELECT,HIGH); //disable device
  
  SPCR = &#40;1<<SPE&#41;|&#40;1<<MSTR&#41;;
  //SPCR = B01010000;
  clr=SPSR;
  clr=SPDR;
  delay&#40;10&#41;;
&#125;

void write_value&#40;uint16_t sample&#41;  // add this function to your code
&#123;
  uint8_t dacSPI0 = 0;
  uint8_t dacSPI1 = 0;
  dacSPI0 = &#40;sample >> 8&#41; & 0x00FF;
  dacSPI0 |= 0x10;
  dacSPI1 = sample & 0x00FF;
  digitalWrite&#40;SLAVESELECT,LOW&#41;;

  SPDR = dacSPI0;                    // Start the transmission
  while &#40;!&#40;SPSR & &#40;1<<SPIF&#41;&#41;&#41;     // Wait the end of the transmission
  &#123;
  &#125;;
  
  SPDR = dacSPI1;
  while &#40;!&#40;SPSR & &#40;1<<SPIF&#41;&#41;&#41;     // Wait the end of the transmission
  &#123;
  &#125;;  
  digitalWrite&#40;SLAVESELECT,HIGH&#41;;
  //delay&#40;5&#41;;
&#125;

conscious
Wiggling with Experience
Posts: 453
Joined: Fri Sep 23, 2011 9:03 am

Post by conscious » Wed Dec 07, 2011 11:09 am

this is my function for playing the midi note,
so i just give "AnalogValue[stepnr]" to the write_valuse fcuntion?

Code: Select all

void playstep&#40;int stepnr&#41; &#123;
  
  if &#40;currentSwitchState&#91;stepnr&#93; == 1&#41; &#123;
    
    AnalogValue&#91;stepnr&#93; = analogRead&#40;stepnr&#41;;
    note&#91;stepnr&#93; = AnalogValue&#91;stepnr&#93;/8 ;
     holdState = digitalRead&#40;holdPin&#41;;
    if &#40;holdState == 1&#41; &#123;
         noteOn&#40;0xB0, 0x7B, 0x00&#41;;  // all notes off     
    &#125;  
    noteOn&#40;0x90, note&#91;stepnr&#93;, 0x7F&#41;; // play note

    for &#40;int i=0; i<=15; i++&#41; &#123;
      digitalWrite&#40;LEDpins&#91;i&#93;, i==stepnr&#41;;
    &#125;
  &#125;
&#125;
edit:

i dont get any voltage on the output:
where goes which pin on the dac?

#define DATAOUT 3//MOSI
#define DATAIN 2//MISO - not used, but part of builtin SPI
#define SPICLOCK 4//sck
#define SLAVESELECT 5//ss
Last edited by conscious on Wed Dec 07, 2011 11:41 am, edited 1 time in total.

Post Reply

Return to “Music Tech DIY”