cv to arduino

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

Moderators: Kent, lisa, luketeaford, Joe.

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

cv to arduino

Post by matcsat » Thu Nov 15, 2018 1:07 pm

Hi,

i want to send CV to arduino in order to control servo motors.

I already tested the arduino code part (a simple knob example sketch) and i was able to sent CV via optocoupler, but i prefer a solution with voltage offset.

Is this a viable solution ?

Image[/img]

It's my first attempt to work on an active circuit and i'm navigate in a fog.
The simulation (falstad) seems to work, but checking with the comunity doesnt hurt.

Thanks in advance.

Marco.

User avatar
Sin_Phi
Common Wiggler
Posts: 116
Joined: Fri Feb 06, 2015 10:10 am
Location: L.A. (Palos Verdes)
Contact:

Post by Sin_Phi » Thu Nov 15, 2018 3:38 pm

That isn't going to scale the voltages the way you want. Check out the schematics of some mutable instruments modules and how they do it https://renbeeves.com/blog/modular/2018 ... atics.html The Elements one in particular is useful because it lists the voltage ranges.

User avatar
pichenettes
Super Deluxe Wiggler
Posts: 1361
Joined: Mon Aug 06, 2012 5:07 am
Location: Paris

Re: cv to arduino

Post by pichenettes » Thu Nov 15, 2018 3:51 pm

matcsat: one flaw in your solution is that the input impedance is 10k – which would cause a significant (10%) voltage drop if the module upstream includes a 1k protection resistor on its output. Also, you might fry the MCP6002 if the input voltage gets too high or too low.

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Thu Nov 15, 2018 4:01 pm

Hi,

tanks for the answer.

What do you mean with "That isn't going to scale the voltages the way you want", what i have to expect from my schematics ? Are the resistor value the problem or the entire concept ?

I already look at the MI schematics, but i wasn't able to understand some part, (where the AREF came from for example).
Also isn't it in an inverting amplifier configuration ? Will it be inverted again via software ?
What are the benefits ?

A voltage follower is another op amp solution that seems viable, but for some inexplicable reason i landed to the other solution. (onestly i choose the example on the datasheet).

Thanks again.

Marco.

User avatar
pichenettes
Super Deluxe Wiggler
Posts: 1361
Joined: Mon Aug 06, 2012 5:07 am
Location: Paris

Post by pichenettes » Thu Nov 15, 2018 4:04 pm

AREF comes from a voltage reference (LM4040).

It's an inverting configuration, inverted back by software.

Benefits:

viewtopic.php?p=2066709#2066709

And:
- The input impedance is 100k. Always. That's kind of an implicit standard in eurorack-land.
- If the input voltage is too high or too low, nothing bad will happen, the op-amp will just clip. For example, if your input voltage is 50V, the output of the op-amp will just be 0, and the input resistor will dissipate 50x50/100k = 25mW.
Last edited by pichenettes on Thu Nov 15, 2018 4:10 pm, edited 2 times in total.

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Re: cv to arduino

Post by matcsat » Thu Nov 15, 2018 4:06 pm

Hi,
pichenettes wrote:matcsat: one flaw in your solution is that the input impedance is 10k – which would cause a significant (10%) voltage drop if the module upstream includes a 1k protection resistor on its output. Also, you might fry the MCP6002 if the input voltage gets too high or too low.
I see your answer after my reply.

Thanks. I'll investigate further.

Marco.

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Thu Nov 15, 2018 4:08 pm

I'm a very very slow writer ! :)

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Thu Nov 15, 2018 5:02 pm

Hi,

one thing about the inverting amplifier part:

The arduino code for the internal value conversion is this:

val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)

Can i just swap the input values for invert the input signal ?

val = map(val, 1023, 0, 0, 180);


Marco.

P.s.

I just realized that the REF_-5 is obtained from the -12v pin from the modular PSU (unless i missinterpreted the branches's schematics);
I intend to build an external box powered by unipolar PSU.
How can i obtain the REF_-5 in this scenario ?

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Fri Nov 16, 2018 7:36 am

Hi,

swap the value in the code does the trick.

I'm stuck in regard of the negative voltage for the offset part.

Any suggestion appreciated.

Marco.

User avatar
StillNotWorking
Veteran Wiggler
Posts: 654
Joined: Thu Aug 22, 2013 3:29 pm
Contact:

Post by StillNotWorking » Fri Nov 16, 2018 9:22 am

OT but I found in an older version of Arduino that the map() function for some strange reason was acting rather slow. Copying the map() code to a local function gain me 1/12 speed increase when mapping ADC data.
Not sure if this still is an issue, but something to look out for if you don't get the performance you want.
long mymap(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Fri Nov 16, 2018 9:49 am

Hi,
StillNotWorking wrote:OT but I found in an older version of Arduino that the map() function for some strange reason was acting rather slow. Copying the map() code to a local function gain me 1/12 speed increase when mapping ADC data.
Not sure if this still is an issue, but something to look out for if you don't get the performance you want.
long mymap(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
i do not notice any performance troubles, (I encounter some jittering, but i think is due to the servos quality.), but to be honest i use the servos only for kicking some objects, not for reaching specific positions or other precise tasks.

On that point i wonder if the previous suggestions are to much for my needs, even so i'm very greatfull for those suggestions.

Marco.

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Fri Nov 16, 2018 2:24 pm

Hi,

i found a different approach online that saves me from the AREF problem.

Image

Again, the simulation works, i think the risk of over/under voltage is no more (the only signal that feed the +in of the op amp is 5v max).

I dont know about the impedance. (what i have to look ?)

Marco.

User avatar
Sandrine
Super Deluxe Wiggler
Posts: 2326
Joined: Tue Jun 09, 2015 10:28 pm
Location: BC Canada
Contact:

Post by Sandrine » Sat Nov 17, 2018 12:16 am

map() function uses floats so gobbles up significant CPU resources, perhaps try a simple expanding formula to stay away from floats.
I discovered this a couple years ago when mapping a flight simulator dashboard & couldn't figure out why everything was moving in hops. :sadbanana:

User avatar
Grumble
Super Deluxe Wiggler
Posts: 1799
Joined: Thu Dec 17, 2015 5:24 am
Location: U aint much if U aint Dutch
Contact:

Post by Grumble » Sat Nov 17, 2018 12:30 am

Image
Since the input inpedance of an opamp is very high, you can drop the bottom opamp.
For better result you might want to put the buffer between the wiper of the top potmeter and the top/left 100k.

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Sat Nov 17, 2018 12:58 pm

Hi,

thanks Grumble and Sandrine.

Grumble: i just tested your suggestion and it works. (No buffer for now).

Sandrine: i have to investigate further because i don't know what are you talking about ! :lol: :doh:

I'll keep working.

Marco.

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Sat Nov 17, 2018 2:37 pm

Work in progress ...

Image

Marco.

P.s.

It's a crude version that miss the capacitor in the feedback loop, the reverse protection diode at the psu, the second jack, etc.

fg
Common Wiggler
Posts: 185
Joined: Wed Dec 10, 2014 4:18 pm
Location: rennes

schema & code for 3 servo

Post by fg » Sat Nov 17, 2018 4:52 pm

hi,


Image

the code here : servopot.zip

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Sun Nov 18, 2018 7:41 am

Hi,

Thanks fg.

I looked at your code and it seems the same kind of the one i'm using. (Mine came from a joystick controlled servos sketch).

The circuits have a couple of thing not suit for my needs: the servos are powered separately from the arduino, share the control signal but not the ground, isn't better a complete isolation ? (the optocouplers worked for me).
It seems you're using the eurorack power for the op amp, in my case i power the rail to rail op amp from arduino with only the +5v. (Independent external box)

Thanks anyway for your contribution.

Marco.

fg
Common Wiggler
Posts: 185
Joined: Wed Dec 10, 2014 4:18 pm
Location: rennes

ref-5

Post by fg » Sun Nov 18, 2018 2:53 pm

Image

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Sun Nov 18, 2018 5:26 pm

Hi,

thanks again.
Saddly we are at the same previous point.

It is again necessary a negative power line that would increase the circuitation beyond my already dubious knowledge (the -12v in your schematics and like in the MI schematics).

Unless there is some huge flaw in the ones suggested by Grumble it's the one i'm currently using without problems.
Nevertheless i'm interested in understand why one thing or the other.

Marco.

User avatar
marcelds
Common Wiggler
Posts: 130
Joined: Mon Aug 05, 2013 10:30 am
Location: copenhagen

Post by marcelds » Mon Nov 19, 2018 4:19 am

It is again necessary a negative power line that would increase the circuitation beyond my already dubious knowledge (the -12v in your schematics and like in the MI schematics).
in your diagrams above, you have a bipolar signal coming in (+/-5) - if you want to work with the whole range from +5 to -5V you need to consider negative voltages as well. i could be reading your case wrong though!

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Mon Nov 19, 2018 8:35 pm

Hi,
marcelds wrote:in your diagrams above, you have a bipolar signal coming in (+/-5) - if you want to work with the whole range from +5 to -5V you need to consider negative voltages as well. i could be reading your case wrong though!
i'm able to use the negative portion of the input CV signal thanks to the voltage feed at the "+" input of the opamp.*
The signal need attenuation but the pots are there for this porpouse.
I'm not shure if the signal at the "+" input has to be seen as an offset or some sort of virtual 0v for the bipolar signal or the two description are the same.
All i know is it's working, good !, if i end to understand it, better !

At the moment i paused it waiting for a heat sink for the regulator, i think it's required for the almost 3W that need dissipation.

Marco.

*The diagram i'm using is the one posted by Grumble, a simplification of the one i previously posted.

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Thu Nov 22, 2018 11:41 am

Hi,

a little test:

[video][/video]

Marco.

adam
Super Deluxe Wiggler
Posts: 2919
Joined: Wed Dec 25, 2013 6:24 am

Post by adam » Thu Nov 22, 2018 4:33 pm

thats great, my friend has been making small items like this, mostly percussion

User avatar
matcsat
Common Wiggler
Posts: 177
Joined: Thu Sep 26, 2013 4:24 pm
Location: Italy

Post by matcsat » Sun Nov 25, 2018 11:46 am

Hi,
adam wrote:thats great, my friend has been making small items like this, mostly percussion
Thanks.

I lost track of time in the last few days, i hope to build this thing shortly.

Marco.

Post Reply

Return to “Music Tech DIY”