PWM avg. voltage drop

Hello All,
In my project I want 0 to 5 VDC output to generate 4-20 mA signal. This signal is finally triggering an Industrial thyristor unit.
I am using Arduino Mega2560(v3) (digital Pin9) to generate PWM signals. These signals are fed into an OpAmp (LM358) you can find the reference circuit at:

I have implemented the circuit and now checking with the outputs.
On 100% duty cycle I am getting around 3.8VDC output at Arduino Pin 9 and thus it carries over to rest of circuit resulting only 16.16mA signals instade of 20mA.
I checked with other duty cycles too but result is same.
(Please read colums in order of, Duty Cycle -- Actual Voltage o/p at Arduino Pin9 -- Actual Final current O/p -- Expected Arduino o/p V -- Expected Final Current O/p
10% -- 0.38VDC -- 1.60mA -- ~0.50V -- ~5.6mA
25% -- 0.95VDC -- 6.80mA -- ~1.25V -- ~8.0mA
50% -- 1.90VDC -- 9.12mA -- ~2.50V -- ~12mA

What I cant figure out is If I run the arduino without any load (or with small load of RC Filter with LED at output) I can read correct voltage on Pin9 but as I connect OpAmp circuit The allover there is a voltage drop of 36%. 24%.

Will expert please guide me?

As per my small understanding of Arduino documents It is very clear that at analogWrite(##,255) will generate a PWM signals at 100% duty cycle. That means you can measure avg. voltage +5VDC over a multi-meter. and analogWrite(##,128) will cause to effectively read avg. voltage +2.5VDC (w.r.t. ground). I think the OpAmp part of the circuit is just working fine, I am getting the exact value at output of OpAmp which I can read after the RC Filter part (the voltage follower application).

So what do you actually measure at point A with these test duty cycles? Does it change when you connect or disconnect the opamp at point A?

From the opamp datasheet, what is its maximum output current? 20mA is quite high for an opamp.

You realise you can make an opamp produce current instead of voltage? You need a voltage to current circuit. You also need more than 5V driving this thing. Most industrial controllers will be expecting up to 24v available.

There are commercial chips out there that will do this for you. I don't know any model numbers from memory but Maxim and others will have lots of options.

MorganS:
From the opamp datasheet, what is its maximum output current? 20mA is quite high for an opamp.

You realise you can make an opamp produce current instead of voltage? You need a voltage to current circuit. You also need more than 5V driving this thing. Most industrial controllers will be expecting up to 24v available.

Sorry If I have framed my question wrongly. I am not going to have 20mA from opamp but have separate professional converter for that purpose. I am just feeding 0 to 5 volt signals to the converter.

MorganS:
So what do you actually measure at point A with these test duty cycles? Does it change when you connect or disconnect the opamp at point A?

At pt. A I am just measuring the avg. value of PWM output. Yes It varies as I connect or disconnect the opamp. (It gives 5V @ 100% D.C. if no opamp connected and 3.8V @ 100% D.C. if opamp is connected)

MorganS:
There are commercial chips out there that will do this for you. I don't know any model numbers from memory but Maxim and others will have lots of options.

Hummm, MCP4921 is good option for my application, but at the moment I have my project PCB populated with current setup and cant able to change it fast. I have kept this thing as the last option If every other thing fails.

What I cant figure out is If I run the arduino without any load (or with small load of RC Filter with LED at output) I can read correct voltage on Pin9 but as I connect OpAmp circuit The allover there is a voltage drop of 36%.

I don't understand why the op amp is making the output voltage sag, but one work around, might be to isolate the pwm by running it to an optocoupler.

EDIT: If a low impedance input is dragging down the arduino pin voltage, there is something very wrong with the circuit or the parts. I think it is bad practice for me to suggest a work around rather than finding the root cause of the problem.

How do you have it wired? Do you have an RC filter on it to get an analog voltage out? Is the measured voltage what is expected?

You MUST have the unused Op Amp section connected. It is probably going into oscillations or locking up, causing the other Op Amp section to malfunction.

Do NOT just ground the inputs. That still leaves it in an unstable state. Here is an excellent page on the subject:

aadityadengle:
Yes It varies as I connect or disconnect the opamp. (It gives 5V @ 100% D.C. if no opamp connected and 3.8V @ 100% D.C. if opamp is connected)

Then something's really wrong. I don't see any decoupling for the opamp, it could easily be oscillating
madly without that. Have you a 'scope to check? Try 22uF electrolytic or similar on the opamp
supply. Or perhaps the LM358 is fried.

307059c9ef6e3b6e448ba51b733c5659b7251bcd.png

That opamp has a typical short circuit output current of 20mA, but it can be as low as 10mA.

An NPN transistor can be used at the opamp output, in emitter follower config, to boost output current (sourcing only).
Don't know what OP wants to do with this circuit.
The opamp is just a voltage buffer that creates a current in the load resistor, depending on resistor value.
As soon as you connect something else to the output, or something between load resistor and ground, current will change.

Point 'A' should have 0-5volt with PWM 0-255, as long as the opamp's supply is >5volt.
Point 'B' could have 0-5volt, if the LM358 is able to keep up with the load current, and the supply is >7.5volt.
Leo..

What I cant figure out is If I run the arduino without any load (or with small load of RC Filter with LED at output) I can read correct voltage on Pin9 but as I connect OpAmp circuit The allover there is a voltage drop of 36%.

Is this in your circuit? From the datasheet: Connect low-ESR, 0.1-μF ceramic bypass capacitors between each supply pin and ground, placed as close to the device as possible. A single bypass capacitor from V+ to ground is applicable for single supply applications.

polymorph:
You MUST have the unused Op Amp section connected. It is probably going into oscillations or locking up, causing the other Op Amp section to malfunction.

Do NOT just ground the inputs. That still leaves it in an unstable state. Here is an excellent page on the subject:

Avoiding Noise and Power Problems with Unused Op Amps | Analog Devices

Thanks polymorph for pointing out very useful document. Its my bad that I have left an unused opamp floating. Last night I tried to terminate it with ground but resulted in nothing. The document gives me proper way to terminate an unused opamp. Thank you.

I dont have chance to change the circuit (as it is on PCB by now) I have to follow other way around. I am seriously thinking to move on MCP4921 (SPI DAC). Its more easy to make a new small pcb for this application than changing the big one.

DrAzzy:
How do you have it wired? Do you have an RC filter on it to get an analog voltage out? Is the measured voltage what is expected?

@DrAzzy,
I have full circuit board for the application and no internal wire hookup.
Yes I have RC filter after PWM pin of arduino, please check short schematic in my 1st post. That will also explain you what measurements I get, and arduino PWM document will clarify what voltages should I get.

dlloyd:
Is this in your circuit? From the datasheet: Connect low-ESR, 0.1-μF ceramic bypass capacitors between each supply pin and ground, placed as close to the device as possible. A single bypass capacitor from V+ to ground is applicable for single supply applications.

The bypass capacitor from V+ to ground will only somewhat stabilize the supply current. I don't think it will make any difference on account of solution to my problem.

Wawa:
Point 'A' should have 0-5volt with PWM 0-255, as long as the opamp's supply is >5volt.
Point 'B' could have 0-5volt, if the LM358 is able to keep up with the load current, and the supply is >7.5volt.
Leo..

Yes, This is what expected from the circuit but not happening. I have 12V as LM358 supply and the load is been powered separately via 24V. The opamp output has been isolated in load device.

Hi,
You image shows you measuring point at A, that is not pin 9 of the arduino.
The voltage at point A will equal point B, because the LM358 is configured as a gain of 1.
Look up the applications for the LM358 and use the other op-amp the package to add some gain to your system.
The low pass filter of the resistor and cap is a passive design, you loose signal amplitude through it, even below the cutoff frequency.
Are you using the PWM pin with 490Hz output?

The fact that the voltage at A is low could be a crook LM358, I hope you are using IC sockets on your PCB.

Pity you didn't breadboard the project and debug it before going to PCB.

Tom..... :slight_smile:

TomGeorge:
The low pass filter of the resistor and cap is a passive design, you loose signal amplitude through it, even below the cutoff frequency.
Are you using the PWM pin with 490Hz output?

The point is of course, that this is entirely irrelevant. If you do in fact as he claims to have done, perform an analogWrite(##,255), then the rather slow and tedious compiled code that performs this, intercepts it and performs a digitalWrite instead, pulling the output consistently HIGH in which case there should be no loss in the resistor and unless measured with a dicky multimeter, should achieve 5 V. (Of coruse, he would have already checked Vcc as well. :roll_eyes: )
79bd57900189ffbe1b1bb847f58740bfb4f4c02d.png

TomGeorge:
Pity you didn't breadboard the project and debug it before going to PCB.

I note on other threads the risible lament "Oh, we can't change the PCB now" or "I don't want to have to de-solder things".

Paul__B:
The point is of course, that this is entirely irrelevant. If you do in fact as he claims to have done, perform an analogWrite(##,255), then the rather slow and tedious compiled code that performs this, intercepts it and performs a digitalWrite instead, pulling the output consistently HIGH in which case there should be no loss in the resistor and unless measured with a dicky multimeter, should achieve 5 V. (Of coruse, he would have already checked Vcc as well. :roll_eyes: )
79bd57900189ffbe1b1bb847f58740bfb4f4c02d.pngI note on other threads the risible lament "Oh, we can't change the PCB now" or "I don't want to have to de-solder things".

I am very open to change the PCB and that is not a problem at all. I agree that it is my bad that have not breadboarded full circuit, but its module by module. Just making sure that I will have the list of maximum possible changes while making next PCB. Its like same debug process.

What is this "R load" at the output of the opamp.
Is this a real resistor (value?), or the input impedance of the following circuit.
Leo..

aadityadengle:
The bypass capacitor from V+ to ground will only somewhat stabilize the supply current. I don't think it will make any difference on account of solution to my problem.

Biasing and Decoupling Op Amps in Single Supply Applications

EDIT:** Easy to fix (3 parts, 1 jumper):**