Twitter   Patreon WIGGLING 'LITE' IN GUEST MODE

Author Arduino nano Voltage Adder- Good Enough Resolution??
djthopa
av500
 assuming your DAC is connected to 5V (or 3.3V) and GND, it cannot output negative voltages. if you e.g. want to be able to add or subtract 2.5V, then you need to always subtract 2.5V from the 0V to 5V DAC range: V_out = V_DAC - 2.5V. so with V_DAC at 2.5V you add nothing, with V_DAC at 5V you add 2.5 and with V_DAC at 0V you add -2.5V if the range needs to be larger, you need to also scale the V_DAC with an opamp.
Synthiq
 If you need +/-5V out from a 5V DAC, you need a gain of 2 in the opamp as av500 pointed out. With an inverting amplifier you can achieve this output range if the positive opamp input is biased at 1/3 of the DAC reference voltage. Since the amplifier is inverting, code 0x000 will result in +5V, 0x800 is 0V and 0xFFF is -5V. Before sending the result to the DAC, negative values must be set to 0 and values above 4095 set to 4095 to prevent the DAC from generating a completely wrong output voltage.
djthopa
 av500 wrote: assuming your DAC is connected to 5V (or 3.3V) and GND, it cannot output negative voltages. if you e.g. want to be able to add or subtract 2.5V, then you need to always subtract 2.5V from the 0V to 5V DAC range: V_out = V_DAC - 2.5V. so with V_DAC at 2.5V you add nothing, with V_DAC at 5V you add 2.5 and with V_DAC at 0V you add -2.5V if the range needs to be larger, you need to also scale the V_DAC with an opamp.

Yes my MCP4725 is connected to the Arduino nano 5volt rail. I have checked the specs and max supply voltage is 6.5v. Was thinking of powering from the +12v im already powering the other TL072.

Ok i think im starting to understand. The problem i see (sorry for my lack of knowledge) is that if i have a cv input say of 1volt, then it would automatically get scaled down to -1.5v volts, which is somehow not the equal cv in.

What i want to achieve (and i dont know if its possible with my setup) is to have voltage go trough unaffected, and depending on the Octave pot, add or subtract octaves to that cv in.

As i mentioned before i can add but not subtract.

So if i add a inverting amplifier after the dac, setup with a gain of -2.5v i could achieve this?

Thanks for the clarification on the DAC values Synthiq. I thought i was doing something wrong.

So basically all the negative offset and scaling has to be done outside of arduino with an opamp.

I get lost with the code you mentioned : code 0x000 will result in +5V, 0x800 is 0V and 0xFFF is -5V, im used to decimal values and not hexadecimal values, need to get into it properly.

Thanks for the clarification on scaling the values before being sent to the dac, though i was going mental there!

Many many thanks for your supervaluable info!

Here is the code on the arduino:

#include <Wire.h>

const int voltRead = A0;
const int octRead = A1;
const int toneRead = A2;

void setup() {

Serial.begin(9600);

dac.begin(0x60);

}

void loop() {

/////////////////////////////////////////////////////

///////////////////////////////////////////

//Map Reading to 5 values, -2- -1, 0, 1, 2 (octaves)

//int octReadValMap = map (octReadVal, 0, 1023, -2, 2); // Doesnt work

int octReadValMap = map (octReadVal, 0, 1023, 0, 4);

/////////////////////////////////////////////

int toneReadValMap = map (toneReadVal, 0, 1023, 0, 12);

///////////////////////////////////////////////////////

case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;

}

////////////////////////////////////

case 0:

break;

case 1:

break;

case 2:

break;

case 3:

break;

case 4:

break;

case 5:

break;

case 6:

break;

case 7:

break;

case 8:

break;

case 9:

break;

case 10:

break;

case 11:

break;

case 12:

break;

}

//Need to create an offset for octReadVal ??

dac.setVoltage(sumvoltReadTone * 4, false); // convert from 10 bit reading to 12 bit writting *4

}
Synthiq
djthopa

Wow!

I was doing 12 bit dac mapped to 5v output range, assuming that would be the range since i was limiting the arduino inputs to 5v.

Back to the computer to get this one rolling, thanks for looking into the code and sending me the correct scaling and values!

Synthiq!
Synthiq
 djthopa wrote: I was doing 12 bit dac mapped to 5v output range, assuming that would be the range since i was limiting the arduino inputs to 5v.

My assumptions was that the 5V DAC voltage is mapped to +/-5V at the output as the thread title suggests. In practice the output voltage can only be -2V to +5V with 0-5V CV range and +/-2 octaves shift. It would be possible to change the dc shift in the output buffer so it can output -2V to +8V instead so there would be no clipping with 5V CV input and max octave and semitone shift but it would also require some small changes to the software.
djthopa
 So, i got the code change, and realised i was using a non inverting amplifier after the dac. I have changed it to an inverting amplifier; When 0 volts come from the dac the opamp outputs -5v. When i output 5 volts from the dac the opamp outputs 0V. So that would make a voltage range of 10 volts. If i wanted to make the voltage range down to 5 volts, Would i change: int sumvoltReadTone = 2048 - (2 * voltReadVal + octReadValFinal + toneReadValFinal); to int sumvoltReadTone = 2048 - (4 * voltReadVal + octReadValFinal + toneReadValFinal); And multiply the toneReadValFinal and octReadValFinal case values *2 also? How would the scalling of the values inside arduino work out? Many thanks!
Synthiq
 djthopa wrote: So, i got the code change, and realised i was using a non inverting amplifier after the dac. I have changed it to an inverting amplifier; When 0 volts come from the dac the opamp outputs -5v. When i output 5 volts from the dac the opamp outputs 0V. So that would make a voltage range of 10 volts.

It still looks like an non-inverting amplifier with a gain of 1 but with a -5V offset so the voltage range is still 5V.
Synthiq
 djthopa wrote: If i wanted to make the voltage range down to 5 volts, Would i change: int sumvoltReadTone = 2048 - (2 * voltReadVal + octReadValFinal + toneReadValFinal); to int sumvoltReadTone = 2048 - (4 * voltReadVal + octReadValFinal + toneReadValFinal); And multiply the toneReadValFinal and octReadValFinal case values *2 also? How would the scalling of the values inside arduino work out?

That sounds reasonable. With an inverting amplifier, the gain should be 1 and the noninverting input should be biased at Vdd/2 so 0V from the DAC results in 5V at the amplifier output and 5V generates 0V at the output. Limiting the output range to 0-5V will limit how much shift to the CV voltage you can apply to the input when it is close to 0V or 5V so I'm not sure it is a good idea.
djthopa
Synthiq wrote:
 djthopa wrote: So, i got the code change, and realised i was using a non inverting amplifier after the dac. I have changed it to an inverting amplifier; When 0 volts come from the dac the opamp outputs -5v. When i output 5 volts from the dac the opamp outputs 0V. So that would make a voltage range of 10 volts.

It still looks like an non-inverting amplifier with a gain of 1 but with a -5V offset so the voltage range is still 5V.

Im feeding the dac out trough a 10k resistor and into to the negative input of the opamp, and feeding a 20k trimmer resistor from the -input of the opamp into the opamps out. Also grounding the positive input of the opamp trough a 4.7k resistor. Thats an inverting amplifier with a gain of -2 right?

With these values and the ones you provided for the arduino code, im getting perfect 12 semitones and -2 octaves, 0 and +2octaves, so no octave change if the oct potentiometer is in the middle position.

But yes, when i feed 0 volts into the op amp, it outputs -5v

Is this an offset or a negative gain?

The matter that mostly concerns me is that if i have 0 volts on the dac input, the final out is 5 octaves lower, so im trying to have this possibility of adding / substracting octaves without having to zero down to -5v.

Many thanks for your help
Synthiq
 djthopa wrote: Im feeding the dac out trough a 10k resistor and into to the negative input of the opamp, and feeding a 20k trimmer resistor from the -input of the opamp into the opamps out. Also grounding the positive input of the opamp trough a 4.7k resistor. Thats an inverting amplifier with a gain of -2 right? hmmm.....

Yes, but the gain is also given by (Vout2 - Vout1)/(Vin2 - Vin1) so we have (0V - -5V)/(5V - 0V) = +1.

 Quote: But yes, when i feed 0 volts into the op amp, it outputs -5v

With the non-inverting input at ground and 0V to the input resistor, no current should flow in the input, or feedback, resistor so the output should also be at ground. If the output is at -5V, there must be another signal to the inverting input that supplies a 250uA current.
djthopa
Synthiq wrote:
 djthopa wrote: Im feeding the dac out trough a 10k resistor and into to the negative input of the opamp, and feeding a 20k trimmer resistor from the -input of the opamp into the opamps out. Also grounding the positive input of the opamp trough a 4.7k resistor. Thats an inverting amplifier with a gain of -2 right? hmmm.....

Yes, but the gain is also given by (Vout2 - Vout1)/(Vin2 - Vin1) so we have (0V - -5V)/(5V - 0V) = +1.

Ah ok, got it.

 Quote: But yes, when i feed 0 volts into the op amp, it outputs -5v

With the non-inverting input at ground and 0V to the input resistor, no current should flow in the input, or feedback, resistor so the output should also be at ground. If the output is at -5V, there must be another signal to the inverting input that supplies a 250uA current.

This is happening with inverting op amp configuration, with the non inverting configuration i was getting 0v in 0 out.

Thanks Synthiq. Considering now the pros /cons of using the inverting or the non inverting configuration.
av500
djthopa wrote:
 av500 wrote: assuming your DAC is connected to 5V (or 3.3V) and GND, it cannot output negative voltages. if you e.g. want to be able to add or subtract 2.5V, then you need to always subtract 2.5V from the 0V to 5V DAC range: V_out = V_DAC - 2.5V. so with V_DAC at 2.5V you add nothing, with V_DAC at 5V you add 2.5 and with V_DAC at 0V you add -2.5V if the range needs to be larger, you need to also scale the V_DAC with an opamp.

Yes my MCP4725 is connected to the Arduino nano 5volt rail. I have checked the specs and max supply voltage is 6.5v. Was thinking of powering from the +12v im already powering the other TL072.

Ok i think im starting to understand. The problem i see (sorry for my lack of knowledge) is that if i have a cv input say of 1volt, then it would automatically get scaled down to -1.5v volts, which is somehow not the equal cv in.

What i want to achieve (and i dont know if its possible with my setup) is to have voltage go trough unaffected, and depending on the Octave pot, add or subtract octaves to that cv in.

As i mentioned before i can add but not subtract.

So if i add a inverting amplifier after the dac, setup with a gain of -2.5v i could achieve this?

yes, 1V would get scaled down to -1.5,V but your "zero/middle" value from the DAC is 2.5V, so it's back to 1V:

V_out = V_in + V_DAC + V_ofs = 1V + 2.5V - 2.5V = 1V

you cannot power the DAC from 6.5V or 12V, 5V is correct and you scale the DAC output with an opamp...
djthopa
av500 wrote:
djthopa wrote:
 av500 wrote: assuming your DAC is connected to 5V (or 3.3V) and GND, it cannot output negative voltages. if you e.g. want to be able to add or subtract 2.5V, then you need to always subtract 2.5V from the 0V to 5V DAC range: V_out = V_DAC - 2.5V. so with V_DAC at 2.5V you add nothing, with V_DAC at 5V you add 2.5 and with V_DAC at 0V you add -2.5V if the range needs to be larger, you need to also scale the V_DAC with an opamp.

Yes my MCP4725 is connected to the Arduino nano 5volt rail. I have checked the specs and max supply voltage is 6.5v. Was thinking of powering from the +12v im already powering the other TL072.

Ok i think im starting to understand. The problem i see (sorry for my lack of knowledge) is that if i have a cv input say of 1volt, then it would automatically get scaled down to -1.5v volts, which is somehow not the equal cv in.

What i want to achieve (and i dont know if its possible with my setup) is to have voltage go trough unaffected, and depending on the Octave pot, add or subtract octaves to that cv in.

As i mentioned before i can add but not subtract.

So if i add a inverting amplifier after the dac, setup with a gain of -2.5v i could achieve this?

yes, 1V would get scaled down to -1.5,V but your "zero/middle" value from the DAC is 2.5V, so it's back to 1V:

V_out = V_in + V_DAC + V_ofs = 1V + 2.5V - 2.5V = 1V

you cannot power the DAC from 6.5V or 12V, 5V is correct and you scale the DAC output with an opamp...

Ok! had not thought about that, yes of course the DAC is @ 2.5v in the middle (2048)!!!

Thanks av500!!
Sandrine
 The offset can be from a 2.048V reference or a 4.096V reference that is built into some DACs so the "center" voltage at 2048 is still 0 volts but the op amp gain must be compensated to produce gain to 5V again. I use those voltages (i.e. the LM4040 shunt regulator which is really just a precision zener diode)rather than the 5V for offset as the 5V regs can vary quite a bit with temperature and lot. In any case it's surprisingly accurate (I hate using trimmers) when combined with 0.1% resistors
djthopa
 Sandrine wrote: The offset can be from a 2.048V reference or a 4.096V reference that is built into some DACs so the "center" voltage at 2048 is still 0 volts but the op amp gain must be compensated to produce gain to 5V again. I use those voltages (i.e. the LM4040 shunt regulator which is really just a precision zener diode)rather than the 5V for offset as the 5V regs can vary quite a bit with temperature and lot. In any case it's surprisingly accurate (I hate using trimmers) when combined with 0.1% resistors

Hi! Thanks for the info.

Yes, unfortunately i have found a small drift on the tuning of the dac since yesterday. Its colder now that when i was testing it yesterday.

Also powering the arduino from usb or my eurorack case made some small differences too.

Im going to try with a mcp4822 that has an internal reference.

Will see how it goes!

Thanks for the help!
djthopa
djthopa
Grumble
 If you are brave enough you could go foor an Analog Devices AD5754 which is a 16 bit 4 channel Digital to Analog Converter, with the following output voltages (software selectable): Output Range (V) Gain Value +5 +10 +10.8 ±5 ±10 ±10.8[/list][/list] The 10.8 volt range is very handy for midi.
djthopa
 Grumble wrote: If you are brave enough you could go foor an Analog Devices AD5754 which is a 16 bit 4 channel Digital to Analog Converter, with the following output voltages (software selectable): Output Range (V) Gain Value +5 +10 +10.8 ±5 ±10 ±10.8[/list][/list] The 10.8 volt range is very handy for midi, since midi is 10 octave + 8 keys.

Hey Grumble,

Thanks for your feedback as always!

Im starting to learn about DAC and ADC so maybe going for 16 bit resolution might be a little bit too much for me at the moment?

I will defo look into it!!!

Many thanks!
Grumble
 My guess is that 16 bits are just as easy as the 10 bits from the Arduino ADC, maybe just the interfacing is more problematic since some more hardware is involved and some more programming.
djthopa
 Grumble wrote: My guess is that 16 bits are just as easy as the 10 bits from the Arduino ADC, maybe just the interfacing is more problematic since some more hardware is involved and some more programming.

Hi again,

I have been looking at the DAC you suggested, and it seems to be only available as smd and the price is

Ill keep in on my watchlist!

Thanks!
Grumble
 yes it is pricey but smd does not have to be a concern, since there are nice and cheap converter boards for sale like these: https://nl.aliexpress.com/item/35-stks-7value-5-stks-PCB-Board-Kit-SMD -Turn-DIP-SOP-MSOP-SSOP-TSSOP-SOT23/32842167258.html
djthopa
 Grumble wrote: yes it is pricey but smd does not have to be a concern, since there are nice and cheap converter boards for sale like these: https://nl.aliexpress.com/item/35-stks-7value-5-stks-PCB-Board-Kit-SMD -Turn-DIP-SOP-MSOP-SSOP-TSSOP-SOT23/32842167258.html

Yes it is expensive!

I am eventually going to get into SMD pretty soon. I have all the modules, tools and boms ready in pile, just need to finish my thru hole backlog

Gracias
 Page 1 of 1