# Help needed with PWM and Op-Amp (for Arduino)

Feb 8, 2012
16
0
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
http://henrys,bench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/arduino-lm358-op-amp-pwm-to-voltage-converter/
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%.

2. ### #12 Expert

Nov 30, 2010
16,705
7,355
First, it is impossible to measure a PWM signal as a DC voltage with a meter. You are better off trying to measure at the op-amp because your RC has integrated the PWM signal.
Second, you can add gain to the op-amp by adding a voltage divider in the negative feedback line.
Third, your load is not shown and you might be asking too much from the op-amp. The LM358 isn't guaranteed to get any closer to the supply voltage than Vcc-2V with a 20 ma load.
If the load isn't the problem, you can put a 4.7K resistor in the negative feedback line and add a resistor to ground from the inverting input pin of size 14388 ohms (use 15K).
I think the load vs power supply voltage is the problem.

• ###### LM358.PDF
File size:
282 KB
Views:
7

Feb 8, 2012
16
0
I am completely agree with you and have not doubts at all. But if you look towards the functionality of the circuit you will understand it just converts the PWM signals to variable dc voltage. 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 +5VDC over a multi-meter. and analogWrite(##,128) will cause to effectively read +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).
I don't want to have gained signals as my load ( a 0-5V to 4-20 mA converter) will not allow that.

My Vcc at LM538 is 12VDC and I am expecting 5VDC output against 5VDC input which are will in limits of LM358, nothing extra.

• ###### Voltage_Follower.png
File size:
14.5 KB
Views:
10
Last edited: Mar 25, 2016

Feb 8, 2012
16
0
Board cutshot attached

File size:
14.5 KB
Views:
11
5. ### #12 Expert

Nov 30, 2010
16,705
7,355
Well...I'm stumped.
Apparently I am focusing on the wrong part of the problem.
I have a dead car to fix today.

6. ### dannyf Well-Known Member

Sep 13, 2015
2,196
417
With that, it is hard to understand what problem you are trying to solve.

Feb 8, 2012
16
0
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

My problem is there is always a voltage drop of 1.2V at any duty cycle.

Last edited: Mar 25, 2016
8. ### dannyf Well-Known Member

Sep 13, 2015
2,196
417
Why is that a problem?

It seems perfectly consistent with the rest of your measurements.

Feb 8, 2012
16
0
I think this all related to max current o/p of arduino pin (40mA max)
will try to put one more OpAmp before RC Filter

Feb 8, 2012
16
0

In my very first post I have already mentioned about the usage of OpAmp output. I need 0 to 5V output to generate 4-20mA signal.

11. ### dannyf Well-Known Member

Sep 13, 2015
2,196
417
then amplify it.

Feb 8, 2012
16
0
@dannyf
With due respect to your experience, I will ignore all your posts as it seems you only have interest in increasing your message count.

13. ### BR-549 Well-Known Member

Sep 22, 2013
2,184
421
"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."

The zero reference for a 4-20 ma signal is 4 ma., if that helps.

So your current span is 16 ma. From 4-20 ma.

14. ### eetech00 Active Member

Jun 8, 2013
685
118
It sounds like the Adruino output is not 5vdc.

Disconnect R1 from the Adruino and apply +5vdc to the disconnected end of R1.
Measure the output of the opamp and see if the output is at 5vdc.

Also, what is the output frequency of the Adruino? It might be that C1 doesn't have enough time to charge to 5vdc. With the R1/C1 combination your using, the cap will need at least 235mS to charge to 5v.

Last edited: Mar 25, 2016
15. ### ronv AAC Fanatic!

Nov 12, 2008
3,404
1,486
Do you have 12 volts to power the op amp like in the schematic?

BR-549 likes this.

Feb 8, 2012
16
0
Tested that way, and the result is 5V out put as expected. That is what I said earlier, there is no problem at voltage follower circuit but Arduino.
As mentioned in my earlier post I made some changes (i.e. have introduced one more opamp before RC filter) but it resulted nothing positive.

Feb 8, 2012
16
0
Yep, I have

18. ### ronv AAC Fanatic!

Nov 12, 2008
3,404
1,486
It almost sounds like a bad 358, but...
You might try grounding the unused input on the 358. Then set the duty to 100% and measure every pin on the 358.
Next option to try is 4.7 k from +5 to pin 3 of the 358 with nothing else connected to it.

19. ### eetech00 Active Member

Jun 8, 2013
685
118
Check this sim. The Adruino output pulse width needs to be longer than 235mS.