-5V to 5V range with Arduino PWM, an op amp and a symmetric power supply

Hi all,

I am currently trying to generate a -5V to 5V voltage to draw a characteristic current-voltage. I am using the Arduino PWM to do that.

First of all, I have a +5V external power that has the same GND as my Arduino. To get a symmetric voltage out of it, I used an old MAX232 from TI I had. This module is supposed to give V- = -8.5V and V+ = +8.5V. It works fine except I have very fluctuating values depending on the resistance of the circuit connected to V+ and V-... But I managed to keep it at more or less +7V and -5V.
Now that I have a symmetric power supply, the idea is to use to it power an op amp (TL082) so that this op amp converts my 0-5V range of PWM to a -5V ---> 5V range (of course I'll be loosing precision as there is only a fixed number of 254 values but I don't need such precision). Here's an idea of the scale I wanna reach:
0V --> -5V
2.5V --> 0V
5V --> 5V
To do that, I had the idea to use the differential circuit of the amp op. So I had to connect 2.5V to the inverting input. I created a voltage divider with two equal resistances of 2.2k connected to my 5V Vcc giving me the 2.5V I wanted. Then I had to multiply by 2 the output so I doubled the resistance I had in the voltage divider (I used 5.6k instead because I couldn't find 4.7k resistances). Theoretically, I thought all this made sense.
Here's a scheme of the circuit : (the PWM signal is filtered with a low-pass RC and my arduino code waits more than 3T so that the requested voltage value is reached before moving up to the next voltage value).

The output I get doesn't seem to be linear nor stable. When I start the PWM, I get -3V, moving quickly up to 2.5V, then staying at 2.5V for a while, before skyrocketing to 6V. My idea is that this comes from the unequal +7V and -5V of the power supply I use with my op amp but I am not sure how to fix that.

Do you guys have any ideas ? Could I directly use my 5V power supply,connect it to the inverting input and forget about the voltage divider and the R4 resistance of 5.7k ? It seems kind of off for me to connect directly my Vcc to the inverting input.

Thanks!
Rayou

First, I would not integrate the input PWM waveform, so I would not use C1. Next, there is the stage gain: R1 parallel with R2 = 1.1K, so, Gain = 1 + R4 / 1.1K = 6.09. I think you want gain = 2. It looks like R4 should be 1.1K. For least offset error, R3 should be 1.1K also.

2 Likes

I tried with the values you suggested and the output voltage was between -1 and 4V... Kinda strange because you were right in your calculations.
Why not keep the RC low pass filter though ?

I'm going to try this solution but I don't understand where the non inverting input goes ? Into the ground ?
And so this is a whole other method you're suggesting without the 2.5V I was talking about ? Because even the gain here is -R2/R1 so -1

Like this:
You need an LM358 or an MC33078 opamp.
Will NOT work with a AD549
The supply needs to be more than +/-7V, +/-5V will not work
oa

2 Likes

Sorry I forgot to mention I'm using a TL082... I don't have KiCad on my computer so I use LTSpice and the software doesn't have all the op amps. Thanks for the circuit I'm going to try it right now.
I only have an LM258 though so in terms of performances it's a little less but it should do the trick

Since my Arduino is a Due, the microcontroller doesn't use 5V but 3.3V so my PWM goes from 0 to 3.3V.
I think that explains why with your method, I get an output voltage that goes from -5 to 1.4V. I guess I would need a 3V on the inverting input instead of 5 ?

Yes but then the output will only go +/- 3.3V.
You will need another gain stage to bring it to +/-5V

I can be satisfied with a +/-3.3V for my use. The thing is, to make the 3.3V out of the 5V, my first idea is a voltage divider but this will add resistance on the inverting input and thus unbalance everything in my circuit right ?
I think it's best if I use the 3.3V of the arduino card and when I'll make the circuit on PCB I'll find another solution.

Also, there will be a whole other problem when it comes to measuring the values after with the Analog Inputs of the Arduino since it is only going to read positive voltages so my idea is to offset everything by 3.3V with an op amp (and divide by 2 my values).
But thank you very much for the solution you brought it seems much more stable and works fine!

This will give you 3.3V from 5V
REMOVE C1 from the other circuit
53

1 Like

Thank you!!!

5V to 3V leveling is what the 74HC4050 has 6 channels of for a clean leveler.

For a single line 5V to 3V,

  1. block the 5V with a diode so when that 5V pin goes low, it drains the line.
  2. put a 3.3V pullup (4700R) on the 3V side of the diode.

When the 5V source is HIGH, the 3V pin sees 3.3V. And 0V is the same for both.
Write the code so that off is HIGH (like serial) and it should waste less current.

I learned that from an Apple forum.

Essentially how logic converters work....except they have a mosfet and a pullup on both sides.

Another option would be to use the 74LVC245, 8 channels of logic leveling. :nerd_face:

1 Like

Problem is I'm using 3.3V not 3V but that could be a good idea to get a clean signal. For the moment I'll stick to using my 3.3V output on the arduino but when it will come to making the whole product on PCB I'll see if I canb uy this logic converter.

To keep everything updated for future people or I don't know : for the moment, here's the circuit I have


The last stage with the second amplifier is to transform my -3.3V / 3.3V range to a positive 0/3.3V output so that I can read it with the analog input of the arduino (that only accepts positive voltages). I didn't do the math for the resistances for the moment, nor did I solve the problem to get the information of the current (my idea was to do (AI0-AI1)/R4 but it will be impossible as there will be negative voltages...).

EDIT : the -3.3V is another question. I think I'll use a voltage regulator LM337SP connected to my -9V power. This module seems to be adjustable to -3.3V

8 is nice when doing port work!
I have only needed 3 lines, for SD cards and I paid 35 cents ea for the 4050's.

So far I haven't needed 2-way leveling. The Apple site had the mosfet thing, they cost more though I have some that ran 10 cents each (when I bought 50) that max out at 250Ma and those might be right for logic converters. The 4050 works both ways IIRC.

A diode and a resistor from a cheap assortment... in Today Money could run 10 cents?

1 Like

Remove R6
Make R5 = 10K
Make R7 = 5K
Replace R8 with a pot connected to 3.3V and adjust for 0V output when the
input is +3V

The output of the second LM258 will be inverted.
When the input is -3.3V the output will be 3.3V and when the input is 3.3V the output will be 0V

Please.

The 4050, you feed it VDD (device voltage) and VDD comes out. In the datasheet the Max V is listed and it is > 3.4V. The same applies to SD modules.

Solder leveled wires to the pads on an SD adapter for microSD and you have a DIY microSD slot of Arduino. I'm not a hardware guru but this isn't guru-level nor is breadboarding DIP AVR's!

Digital circuits are greatly simpler in general than analog circuits. There can be a half volt of slop and no problem by design. The difference between LOW trigger V and HIGH is usually VCC (or VDD) / 3 and that's how not-perfect works dependably.

1 Like