Arduino Forum

Using Arduino => General Electronics => Topic started by: Wosche on Jul 13, 2018, 12:37 pm

Title: 4-20mA controlling
Post by: Wosche on Jul 13, 2018, 12:37 pm
Dear community,

I have a question to controlling a device with a 4-20mA current.

I have found the AD694 (http://www.analog.com/media/en/technical-documentation/data-sheets/AD694.pdf) which need a 0-10V input and gives out a 4-20mA current

Would it be possible to connect an analog output of the Arduino to an MCP4725 (https://www.sparkfun.com/datasheets/BreakoutBoards/MCP4725.pdf) for the 0-5V range, double it up with some OPVs to 0-10V and the connecting it to the AD694?

Or (and I'm pretty sure there is) is there a way better option to controll the 4-20mA with the Arduino (eventually Nano or Mega) ??

Best regards
Wosche
Title: Re: 4-20mA controlling
Post by: allanhurst on Jul 13, 2018, 01:21 pm
Just to be clear....


Do you want to make a device which takes some sort of measurement, and sinks 4-20mA  from a supply provided by an external source?


Or the inverse of this?

ie a transmitter or receiver?

Allan
Title: Re: 4-20mA controlling
Post by: Wosche on Jul 13, 2018, 01:32 pm
the Arduino is the transmitter, the other device is the receiver of the control current
Title: Re: 4-20mA controlling
Post by: hammy on Jul 13, 2018, 06:12 pm
You can take the output from the Arduino and switch a transistor connected to a 10v supply with series resistor .
The Arduino is PWM output so you then have a PWM 10v signal - if you drive a smoothing circuit with that then you should get a smooth 0-10v signal .
Title: Re: 4-20mA controlling
Post by: hammy on Jul 13, 2018, 08:11 pm
Just looked at the spec of that chip ... you can have a 0-2v fsd input , so you can use a potential divider from an Arduino o/p and a smoothing circuit .
Title: Re: 4-20mA controlling
Post by: ReverseEMF on Jul 14, 2018, 12:18 am
You can take the output from the Arduino and switch a transistor connected to a 10v supply with series resistor .
The Arduino is PWM output so you then have a PWM 10v signal - if you drive a smoothing circuit with that then you should get a smooth 0-10v signal .
But, consider that there is the issue of ripple vs responsiveness.  The more you reduce ripple, the more sluggish it will be when changing voltage. 

One way to increase this ratio is to use a higher PWM frequency.  Another is to use a buffer.  And yet another is to use an active filter.
Title: Re: 4-20mA controlling
Post by: allanhurst on Jul 14, 2018, 01:00 am
This is textbook stuff.

Circuit enclosed.

Allan
Title: Re: 4-20mA controlling
Post by: ReverseEMF on Jul 14, 2018, 07:56 am
This is textbook stuff.

Circuit enclosed.

Allan
That's good for 0-20mA.  But the OP requested 4-20mA.  But, you could get away with that by not using the full DAC range [I'm including the PWM technique under that DAC umbrella].  But, if you want the full precision available:

(http://forum.arduino.cc/index.php?action=dlattach;topic=557910.0;attach=265948)
The above is more concepuized-- basically two current sinks, one at a constant 4mA, and the other a Voltage to Current translator [0-5V to 0-16mA].  The combination creates a 4 to 20mA transmitter, with a linear voltage to current transfer.  This one is shown with a simple PWM low-pass filter.

(http://forum.arduino.cc/index.php?action=dlattach;topic=557910.0;attach=265950)
And, this one is a more practical diagram.  The Op-Amps can be any common mode to ground, single supply device that can handle whatever voltage is in use, such as the LM324 or the LM358.  I forgot to show the supply lines on the op-amps.  Tie V- to ground, and V+ to 30V or whatever voltage is the VHigh supply you choose.

The transistors can be 2N3904, or one with a higher max CE voltage, like: MPS06

Typically, a 4-20mA transmitter has a fairly large voltage range going as high as 36V, with 12 to 30V typical.  Basically, this voltage needs to be high enough to allow 20mA to flow in the loop--a level that is determined by the total expected maximum resistance in the current loop.  BUT, check to see if the device you intend to drive has a max voltage rating, and, at least, comply with that.

For greater precision and probably better response, I suggest using a serial DAC, like the following:

https://www.adafruit.com/product/935 (https://www.adafruit.com/product/935)

The same page has links to Arduino sample code.

The 10k + 10k voltage divider that follows the DAC is there to reduce the top voltage so there is a greater voltage span in the current loop.  Also, it keeps the input voltage within the input range.

And, you will need to incorporate some variable resistors in there, to calibrate the thing to exactly 4mA at 0V in and 20mA at 2.5V in.

Also wise to use stable resistors [e.g. 1% metal film].  And quality trim pots.  And, maybe some sort of protection circuitry on the 4-20mA output.

And, if this will be driving some sort of expensive or hard to replace device, then do this at your own risk!

Or, purchase something like this: https://www.ebay.com/itm/Arduino-4-20mA-Current-Loop-Transmitter-XTR116U-I2C-Interface-industry-standard/173326373205?hash=item285b0e9155%3Ag%3AL4IAAOSwwcdbALKV&_sacat=0&_nkw=arduino+shield+4-20ma+transmitter&_from=R40&rt=nc&_trksid=m570.l1313 (http://"http://www.ebay.com/itm/Arduino-4-20mA-Current-Loop-Transmitter-XTR116U-I2C-Interface-industry-standard/173326373205?hash=item285b0e9155%3Ag%3AL4IAAOSwwcdbALKV&_sacat=0&_nkw=arduino+shield+4-20ma+transmitter&_from=R40&rt=nc&_trksid=m570.l1313")

But, good luck getting it to work.

Then there's this: https://ncd.io/interfacing-isolated-4-20ma-current-loop-transmitter-arduino/ (https://ncd.io/interfacing-isolated-4-20ma-current-loop-transmitter-arduino/)
Title: Re: 4-20mA controlling
Post by: Wawa on Jul 14, 2018, 08:18 am
Why use two opamps and two drive transistors.
A third resistor between 5volt and the +input of the opamp can also add that 4mA idle current.

An LM324 is not a R2R opamp, but R2R is not needed in Allan's diagram (100ohm emitter R).
Leo..
Title: Re: 4-20mA controlling
Post by: ReverseEMF on Jul 14, 2018, 08:56 am
Why use two opamps and two drive transistors.
A third resistor between 5volt and the +input of the opamp can also add that 4mA idle current.

An LM324 is not a R2R opamp, but R2R is not needed in Allan's diagram (100ohm emitter R).
Leo..
Probably.  Analog is not my strong suit-- but I don't see any other valid offerings, so I stepped in ;)
Title: Re: 4-20mA controlling
Post by: Wawa on Jul 14, 2018, 09:37 am
Allan's circuit.
Change R1 to 37.5k, and add 150k between 5volt and opamp +input.
Leo..
Title: Re: 4-20mA controlling
Post by: allanhurst on Jul 14, 2018, 11:19 am
Or just drive it with 1-5v to get 4-20mA.
 
ie use map() to get numbers between 51 and 255  for the analogWrite value.
That'll give you a resolution of about 0.5% as against 0.4% using the full range. A bit worse, but simple.
If this isn't good enough you'll have to use a suitable external DAC.

And ( my mistake) the NPN shown should be eg a BC337 etc, NOT a BC327 which is PNP.

Allan

ps In any case the PWM resolution error is swamped by others :

unless you spend out for super accurate resistors it'll need calibrating.

With typical 1% ones you can get up to 3% error.

And if driven from the arduino's +5 that'll have an error of a couple of percent as well - much worse if using USB power.      That's the arduino error - not my circuit, which doesn't care.

Leo's mod DOES make it sensitive to the +5 error, as do ReverseEMF's suggestions.

The opamp's errors are much smaller.

So I recommend calibration . eg make the 100 ohm 75R with a 47R adjustable preset in series.

I haven't bothered with temperature coefficients here - that's another ballgame! How accurate do you need to be?

Allan

Title: Re: 4-20mA controlling
Post by: Wawa on Jul 14, 2018, 01:27 pm
Leo's mod DOES make it sensitive to the +5 error, as do ReverseEMF's suggestions.
Are you saying that 4mA offset with a fixed resistor is different from 4mA generated from PWM.
Both using the same Arduino VCC.
Please explain.
Leo..
Title: Re: 4-20mA controlling
Post by: ReverseEMF on Jul 14, 2018, 04:52 pm
Why use two opamps and two drive transistors.
A third resistor between 5volt and the +input of the opamp can also add that 4mA idle current.

An LM324 is not a R2R opamp, but R2R is not needed in Allan's diagram (100ohm emitter R).
OK, I played around with this, using 1 OpAmp and resistors as you suggested...
Have you tried the math on that?!?  Horrendous--unless I'm missing something.  And calibration is a nightmare, because adjusting one side, moves the other side.  In other words, adjust it to 4mA when the input is at 0V, then change the input to 5V and adjust for 20mA, and the current goes to 5mA when the input is at 0V, etc.  I even tried anticipatory overshoot, and it was still difficult!  I suppose if I finished the math.  I reached this, and gave up:

(http://forum.arduino.cc/index.php?action=dlattach;topic=557910.0;attach=266003)
I would call that impractical!

In fact, one of my first jobs [back in the late 80's] was at the Jensen Filtration Plant in Sylmar, CA.  And most of the sensors were 4-20mA.  Occasionally lightening would knock one or more of them out, and recalibrating them after repairing them was a b***h, for this very reason! 

My two OpAmp circuit can be easily calibrated, because there is no interaction when adjusting the extremes.
Title: Re: 4-20mA controlling
Post by: ReverseEMF on Jul 14, 2018, 05:06 pm
Are you saying that 4mA offset with a fixed resistor is different from 4mA generated from PWM.
Both using the same Arduino VCC.
Please explain.
My circuit is vulnerable to tolerance variations in the Arduino 5V regulator (in other words, each Arduino will have a slightly different "5V" actual value.  e.g. one might be 5.04V, another 4.98V, etc).  Also, like allenhurst said, resistor tolerance is also a source of error.  That's why I suggested calibration. 

The Arduino regulator is fairly stable if driven by the Raw Power input, but if more precision is needed, then use the external DAC, and run it with a precision regulator--one that can be adjusted to exactly 5.00...V [limited by error modes in the DAC] and a regulator that will hold that voltage over a temperature range expected in "the field".

Allenhurst described how to add calibration trimmers.  But, I wouldn't do that on the emitter resistor -- it will heat up, slightly, which may skew the resistance, and thus, the output current.  Also, thermal expansion and contraction could nudge the wiper on the trimmer, knocking it out of calibration.

Instead, I would place calibration trimmers on the 10k resistors that go to ground: 9k + a 2k trimmer, or something like that.
Title: Re: 4-20mA controlling
Post by: allanhurst on Jul 14, 2018, 08:45 pm
Quote
Are you saying that 4mA offset with a fixed resistor is different from 4mA generated from PWM.
Both using the same Arduino VCC.
Please explain.
Leo..
No - just saying that the simple opamp circuit does not contribute to this error.

edit - because of the high PSRR of the opamp /edit

And we still don't know what error is tolerable in the OP's application - any suggestions ,Wosche?
 

Allan
Title: Re: 4-20mA controlling
Post by: Wosche on Jul 16, 2018, 07:28 am
So sorry to the late response.

First of all, thanks to you all for the discussion and the tips :) Hoping to be able to contribute the same to others in the forum :)

I don't supply the Arduino via USB, just because i would have to adjust the output voltage to minimize the error it would make.

The idea with the simple circuit and adjusting my output to 1-5V seems to be the easiest way of getting what I want.
As far as I have seen the error would be up to 3% right? I have the opportunity to geht the restistors with quite an accurat value, although I think i would try to calibrate it
Title: Re: 4-20mA controlling
Post by: allanhurst on Jul 16, 2018, 10:25 am
Hi Wosche..

yeah -that's the way I'd go. Simple and probably good enough. Cal for better accuracy.

If you decide to calibrate you don't need to buy more accurate resistors - the cal process deals with this.



ReverseEMF:

Quote
Allenhurst described how to add calibration trimmers.  But, I wouldn't do that on the emitter resistor -- it will heat up, slightly, which may skew the resistance, and thus, the output current.  Also, thermal expansion and contraction could nudge the wiper on the trimmer, knocking it out of calibration.
Maybe. Even at 20mA, the resistor only dissipates 40mW total and the pot at 25 ohms setting 10mW  - not much. But adjusting the input divider is also perfectly viable. There's a hundred ways to skin this cat.

Allan
Title: Re: 4-20mA controlling
Post by: Wosche on Jul 16, 2018, 03:23 pm
If I do the 4-20mA conversion, I will share it here.
It would be quite a helpful thread, because I didn't find anything similar helpful here in the forum :)

Thank to all :)
Title: Re: 4-20mA controlling
Post by: allanhurst on Jul 16, 2018, 08:12 pm
You're not the first to have problems here - but it's not that hard.

The other end - the 'receiver' is a bit more complex, but not too bad.

This stuff has been around since the 70's( or before?)  and is a standard throughout many industries.

Allan
Title: Re: 4-20mA controlling
Post by: ReverseEMF on Jul 18, 2018, 05:48 pm
If you decide to calibrate you don't need to buy more accurate resistors - the cal process deals with this.
...but, be sure to use stable resistors -- for both the fixed and variable.  I.e. ones whose resistance will vary little with temperature (i.e low enough Temperature Coefficient).  Also, pay attention to Minimum and Maximum Operating Temperature, if that will make a difference in your application.
Title: Re: 4-20mA controlling
Post by: ReverseEMF on Jul 18, 2018, 05:57 pm
Maybe. Even at 20mA, the resistor only dissipates 40mW total and the pot at 25 ohms setting 10mW  - not much. But adjusting the input divider is also perfectly viable. There's a hundred ways to skin this cat.
True, it's not much power, and my concern is informed by my experience with thermistors.  Even small current through a thermistor can heat it and skew the reading.  But, maybe I'm overreacting ;) 
Still, better safe than sorry, and since the job can be done on the lower current side, doesn't that make more sense?  
Title: Re: 4-20mA controlling
Post by: allanhurst on Jul 18, 2018, 11:49 pm
Whatever.

A typical metal film resistor has a tempco of <100 ppm/C .A cermet preset a bit worse. A typical NTC thermistor has 3-4%/C. Different ballgame.

If the OP's happy with 0.5% resolution it's not significant. Either way would do.

Just don't put a thermistor in by mistake!

Allan.
Title: Re: 4-20mA controlling
Post by: andyj992000 on Nov 08, 2018, 04:17 pm
Sorry to resurrect an old post, but I have too have been using an AD694 for the 4-20mA output and an Adafruit MCP4725 DAC with a 0-5V output. The AD694 datasheet is a bit vague around using input spans other than the standard 0-2 and 0-10V. I've been scratching my head for a while but I think I can answer the OP's initial question.

Basically its as simple as treating the buffer amp as a non-inverting amp - in the 0-10V span mode pins 1 (FB) and 2 (sig-) are connected therefore the buffer amp is a simple voltage follower. If you wish to use a different input span connect a resistor between pins 1 & 2, and a resistor between pin 2 and ground. The ratio between the resistors governs the gain. A gain of 2 will enable 0-5V input to equate to 4-20mA output.

My first post on here so I hope this helps
Title: Re: 4-20mA controlling
Post by: JohnRob on Nov 08, 2018, 05:05 pm
I wouldn't worry about the resistors,  if the OP needs something more stable then they should look at the PWM output voltage.  Without going through a lot of numbers I believe it is the largest source of error in this implementation.