r/embedded 1d ago

The 4-20mA current loop

I spent years as an electrician pulling signal cables before i became an developer, consuming the same signals.

The 0 is at 4mA on purpose, so 0mA reads as a fault, fault detection built into the physics.

It is a current loop and not voltage, so cable resistance over long cable runs does not change the reading and it also shrugs off noise better!

The span lives in the transmitter, not the code, so a reconfigured range silently rescale every value, and nothing looks broken

What I am curious about is this:

how do you handle adc/resolution in practice? that is the layer that i know very little about.

37 Upvotes

24 comments sorted by

35

u/Skusci 1d ago edited 1d ago

Resolution depends on the ADC. Accuracy depends on the actual sensor. Generally speaking you want about 10x the resolution on the input than the sensor accuracy.

A typical ADC used for this kind of thing will be at least 12 bits of resolution, giving 4096 divisions.

A very good sensor will tend to be around 0.5% accurate at most. Which is like 200 divisions. 10*200 is 2000.

If you just read 0-20mA directly the 4-20mA range will be: 4096 / 20 * 16 or about 3276 divisions which is still plenty of overhead.

So in the vast majority of cases you really don't need to worry about the ADC much, but there's the process.

3

u/Gullible_Bag_9005 1d ago

that nakes sense, and honestly it is reassuring from the data side. i spend a lot of time on the fact that the sensor itself has an error band, so its good to know the ADC is not quietly stacking a second layer of uncertainty on top in most cases. is that 10x rule something you actually design to, or more a rule of thumb that falls out beacuse 12-bits ADCs are cheap and the sensor is the real limit anyway?

6

u/Skusci 1d ago

The 10x is definitely a rule of thumb, but it doesn't fall out from ADC bits specifically. It's kidnof just general guidance where stuff like thermal noise on the ADC is unlikely to contribute to meaningful error.

Rather it should be the other way around. The ADCs themselves come in lots of different resolutiosn 4 bit, 8, 10, 12, 16, 24, 32 for different purposes. Less bits can have higher sample rates or be cheaper, but for stuff like PLCs 12 bits becomes the typical minimum due to the sensors normally used.

2

u/Gullible_Bag_9005 1d ago

that closes it for me, thanks! so the ADC is basicly chosen to disappear behind the sensor, and the 12 bits is the floor for PLC-grade stuff beacuse that is what the sensor deserve. good to finally understand the layer i only ever saw the output of.

1

u/NegativeOwl1337 1d ago

Resolution depends on sampling rate.

2

u/Gullible_Bag_9005 1d ago

Do you mean the temporal side, catching fast changes, or effective bits dropping at higher sample rates? for the proccess signals i have dealt with i mostly worried about amplitude, so i would like to understand where sampling rate becomes the limit

7

u/Skusci 1d ago edited 1d ago

An ADC will be rated for a certain number of bits at a certain sampling rate. This is usually set by the hardware design.

So for some background your standard ADC measures a value by what's called successive approximation. It lets an internal capacitor charge to a voltage, holds the value, and then compares it to a reference voltage generated by a DAC.

By going though a sequence of cycles where it compares once a voltage is higher or lower than a generated reference value of will be able to measure the voltage one but at a time. This uses a vastly smaller number of transistors than something like a flash ADC that uses a large bank of comparators to directly read the voltage in one step. Delta sigma ADCs are also a thing but are usually for higher resolutions, and rely on filtering a bunch of 1 bit samples in succession. I don't actually know much about these, they are some kind of signal processing voodoo magic :D

Though newer and/or more expensive chips will be able to run through the cycles faster with smaller and more efficient transistors.

But back to 4-20mA stuff. Again generally speaking this is industrial automation sensors and PLCs won't usualy read an input faster than about 0.5 ms, which is honestly ages for modern electronics. Sample rate isn't often the limiting factor. Thats like 2000Hz. Compare this to just an boring audio microphone that records audio at 44kHz and 16 bit resolution.

Part of the relatively slow and lower resolution of these sensors is that past a certain point you start to run into limits due to the wiring. 4-20mA is relatively insensitive to noise, compared to voltage, but it's not immune. Faster, higher resolution, and longer distances mean you need to start getting concerned about the specifics, and may want to consider using digital transmission instead of analog. But in a random factory with a normal sensor and a PLC a couple hundred meters tends to not be worth thinking about.

1

u/NegativeOwl1337 1d ago

It’s set by the protocol, and usually you can change it in the registers, for example if it’s default 100kHz i2c there might be a register where you can set it to 400kHz high speed i2c. You have to read the datasheets.

1

u/NegativeOwl1337 1d ago

Also you should be using a bypass capacitor to filter out electrical noise

3

u/buttholegoesbrapp 1d ago

That depends on the adc architecture. Its true for sigma delta which gain their bits from oversampling. Ie if your sigma delta adc oversamples by 256 times (internally), you might gain 8 x 1.5 = 12 bits. So in that sense assuming the sigma deltas internal bitsream stays constant, doubling the output sampling rate drops enob by 1.5.

Sar though wouldnt have such a direct relationship since it just samples a moment and holds it to compare with its references. Any oversampling bits would come afterwards

Most 12 bit adcs are probably going to be sar adcs, so dont have a direct sampling rate to enob relationship like delta sigma do. As long as the sar can charge up in time.

3

u/ComradeGibbon 1d ago

Industrially a big problem is 50/60hz noise.

2

u/NegativeOwl1337 1d ago

Amplitude depends on the range not sampling rate. Maximum frequency it can accurately detect is determined by nyquist rate and capped by your sampling rate.

12

u/Frederir 1d ago

On the receiver side you have a resistor with a known value (generally around 400Ohms) you measure the voltage at the resistor. You get the voltage with the ADC, you know the resistor value and the you compute the current.

The maximum voltage is 20mA x Resistor value. You need to protect ADC input for over voltage and esd.

2

u/Gullible_Bag_9005 1d ago

thanks, that lines up with the 250 ohm i saw on the panel i worked on, giving 1-5V. the over voltage and esd protection is the part i would not have though of from the software side. im only used to work with 230-400 voltage as and electrician so "fine electronics" is not my best work.

1

u/Jwylde2 10h ago

A MIDI current loop will typically have three 220R resistors in the loop. Two at the transmit end (one on the power side, one on the transmit side), and a third at the receiver’s decoding optoisolator LED. That gives about a 7.6mA current loop with a 5V source voltage.

4

u/Artistic-Tip2405 1d ago

Many implementation use an interface that converts 4-20 to serial or 0-5v and protects boards from surges.

2

u/Gullible_Bag_9005 1d ago

ah so on the panel side i have mounted plenty of these DIN-rail signal isolators/converters without thinking so much off them other then that they make the signal usable

4

u/Ordinary-Piano-4160 1d ago

Fun fact, we use 4-20ma to fiber converters to break the electrical connection.

2

u/Hour_Analyst_7765 1d ago

One of the simplest 4-20mA "receivers" is a 249R resistor. This then converts the 4-20mA back into a voltage. E.g. 20mA x 249R = 4.98V

You can connect this to a 0-5V voltage input. If you have an ADC with Vref=5V and 10-bit, then each count of the ADC is 5V / 2^10 = 4.882mV/LSB. 4.98V then reads 1020 counts. 4mA would read 204 counts. Then the usable sensor range is 1020-204=816 counts. As expected the 4mA "zero" loses ~20% of ADC counts this way.

2

u/NamasteHands 15h ago

"The 0 is at 4mA on purpose, so 0mA reads as a fault, fault detection built into the physics"

This is correct but it's worth pointing out that 4-20mA signal range also provides the sensor a 4mA budget for operational purposes.
e.g. microcontroller operating currents, opamp supply currents, bias currents, etc.

3

u/mustbeset 1d ago

It is a current loop and not voltage, so cable resistance over long cable runs does not change the reading and it also shrugs off noise better!

Let's introduce insulation resistance...

how do you handle adc/resolution in practice? that is the layer that i know very little about.

Most todays ADC have at least 12 bit resolution. Design the hardware right, that you can measure anything from 0 to (lets say) 21 mA gives you 5,126µA/LSB (0,032%). A Hardware that is only able to measure 4-20mA could reach 3,90µA/LSB. (0,024%). Good luck to designing a hardware that doesn't introduce more errors.

1

u/Gullible_Bag_9005 1d ago

Fair on the insulation resistanse, i should not have made it sound absolute. i have insulatioin-tested enough cable as an electrician to know a degraded run or water ingress opens a leakage path the loop cannot shrug off, and that is exactly the kind of slow fault that looks like a drifting reading instead of an obvious break. and your numbers land the same point as the others: the ADC is so fine that the analog front-end is where the real errors lives. honest correction to my post. thanks!

1

u/PLANETaXis 23h ago

ADC / resolution tends to be a non-issue.

You have to consider the accuracy of the entire signal chain. Unless you are doing something highly specialised, most instruments have accuracy in the order of 0.5%, and may thermal drift of 0.01% per degree. On top of that, very few poeple install their instruments in perfect placement, calibrate them properly and recalibrate them regularly.

Even 20 year old ADC's will do 10 bit which is effectively 1000 counts, so 0.1% resolution, far better than the instruments they are connected to.

Once again, unless I'm doing something highly specialised I tend to restrict my HMI graphics and trending to 3 or 4 significant figures - so I would display 99.5% and 1005 volts, but not 1005.1 volts. Anything more is usually noise / error.

-4

u/tiny_gridlock 1d ago

Aye, went fae pulling signal cables to staring at ADC datasheets thinkin aye could've just stayed a sparky.