×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Converting Modbus register values to 4-20mA

## Converting Modbus register values to 4-20mA

(OP)
Hello,

Can someone provide me please with some pointers on how to convert Modbus analog input signal (Analog read from input register at specified address) to a 4-20mA value.

Modbus protocol can be RTU or TCP/IP.

If you plan an escape, you must succeed as if you fail, you will be punished for trying. Never say or write down your plan. Heart is the only place where secrecy is granted.

### RE: Converting Modbus register values to 4-20mA

(OP)
IRstuff,

Thanks for the links, what I need in fact is not hardware but the (software) methodology to do a conversion.
I just found this document which seems interesting:

https://www.emerson.com/documents/automation/manua...

Apparently this procedure is called "integer scaling".

If you plan an escape, you must succeed as if you fail, you will be punished for trying. Never say or write down your plan. Heart is the only place where secrecy is granted.

### RE: Converting Modbus register values to 4-20mA

The most likely thing is that you have an unsigned 16-bit value (range 0 - 65535), where a value of 0 corresponds to 4mA, and a value of 65,536 (2^16) would correspond to 20mA. You can linearly interpolate between these. It is possible that the numerical values actually correspond to a greater current range (e.g. 0mA - 24mA) -- this should be documented in the manual for the unit.

### RE: Converting Modbus register values to 4-20mA

(OP)
Thanks for the reference.
cswilson,

Does it make sense to work on basis 0 to 100% (or 0 to 1) instead of 4-20mA

So we could consider two ranges to configure (assuming unsigned 16-bit value):

Range#1: percentage units (data signal)
Min: 0 (corresponds to 0)
Max: 100% (corresponds to 65535)

Range#2: engineering units (e.g. Temperature in Kelvin)
Min: 290 K
Max: 300 K

So we interpolate between 0:65535 to obtain a value within the 290:300 K range.

Now back to the case you mentioned of (0mA - 24mA) range, so we have (20mA-4mA) / (24mA-0mA) = 0.667 => 66.7%

Min: 0 (corresponds to 0)
Max: 66.7% (corresponds to 43690)

So we interpolate between 0:43690 to obtain a value within the 290:300 K range.
The part between 43690 and 65535 being not utilized (or left for overflow)

If you plan an escape, you must succeed as if you fail, you will be punished for trying. Never say or write down your plan. Heart is the only place where secrecy is granted.

### RE: Converting Modbus register values to 4-20mA

It doesn't matter, you likely only have 53521 levels of resolution: https://www.ti.com/lit/ds/symlink/dac161s997.pdf?t... so you map that however you want. All you need is a precise and clear interface control document (ICD) that describes what any value of measured current between 4 to 20 mA represents, i.e., Nlo ~ 4ma, Nhi ~ 20mA , Nmid ~ ((Nmid-Nlo)/(Nhi-Nlo))*16mA + 4mA

TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

### RE: Converting Modbus register values to 4-20mA

(OP)
IRstuff,

I think the document link you have attached shows an example of a component that converts SPI data (can be for example from an instrument whose output is SPI serial communication) to inject into a 4-20mA loop. The functional block diagram shows that the loop is a 0-24mA. So if the measured parameter exceeds the low- or high limit by a small amount the 4-20 mA output will still be proportional giving one the ability to log values slightly above or slightly below. I understand that probably not all instruments offer that ability but it may be common practice.

1/- My question is, if - for some reason- I use the full span of 65535 levels of resolution, I will not be able to benefit from this ability, is this correct?

2/- However since I will likely have 53521 levels or resolution, the range from 53522 to 65535 could be anyhow leveraged to exploit the ability, is this correct? When you mention 53521 levels or resolution, is it because it is common industry practice?

I think bottom line when you say it does not matter, is that irrespective of the considerations in 1/ and 2/ I would in all cases need an ICD document that describes what any value of measured current between 4 to 20 mA represents and implement as per Nlo ~ 4ma, Nhi ~ 20mA , Nmid ~ ((Nmid-Nlo)/(Nhi-Nlo))*16mA + 4mA

Is the above correct understanding?

Thanks

If you plan an escape, you must succeed as if you fail, you will be punished for trying. Never say or write down your plan. Heart is the only place where secrecy is granted.

### RE: Converting Modbus register values to 4-20mA

You're sure the Modbus value is an A/D count and not an integer or a floating point value in engineering units? Have you checked the Modbus register table/map for the format of the value?

### RE: Converting Modbus register values to 4-20mA

The reference design uses the entire 16-bit dynamic range to cover 0 to 24 mA, but if your receiver only "sees" 4-20 mA, then 53521 levels is all you have. Figure 17 in the datasheet shows that 0-0444H and D555H-FFFFH are not usable in the reference design for the 4-20mA use-case.

Now, you could modify the reference design from the datasheet so that the entire 16-bits falls into 4-20 mA.

TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

### RE: Converting Modbus register values to 4-20mA

You guys are assuming too much.
Does the Modicon input card have 16 bits of resolution?
I doubt it until proven otherwise.
Also, if the analog card is only 12 or 14 bits is the least significant bit bit 0?
I always want the most significant bit to be bit 15 no matter how many bits there really are.
In the case of a 12 bit AtoD the lower 4 bits would be tied low.
This way I can write software and always treat the analog data as 16 bit data.

Peter Nachtwey
Delta Computer Systems
http://www.deltamotion.com
http://forum.deltamotion.com/

### RE: Converting Modbus register values to 4-20mA

(OP)
danw2,
In the modbus list specification, it says 16 bit unsigned integer and scaling 65535.
Nevertheless, I looked at float32 and integer 32 and it looks a bit complicated because of all those big-endian/little-endian with or without byte swap. I saw water burning...

PNachtwey,
The architecture is as follows: Field transmitters (analog signals) wired to machine control system (4-20mA). Machine control system is normally a PLC (Allen Bradley, Siemens, or equivalent) and it communicates analog signals to DCS/SCADA via Modbus. That is the Modbus data I am reading. By the way, I would expect any of the major PLC brand to have I/O 16 bit cards, nowadays but also up to ~2 decades back. Correct me if I am wrong?
Otherwise when it is 12 bit, I would need to change scaling accordingly (2^12) for sure, but If I understand well the problem is when reading 12 bit as 16 bit analog data, that would require a special program, is this what you mean?

If you plan an escape, you must succeed as if you fail, you will be punished for trying. Never say or write down your plan. Heart is the only place where secrecy is granted.

### RE: Converting Modbus register values to 4-20mA

Oh, I think you finally gave enough information; I thought you were trying to generate 4-20mA signals, but it now sounds like you have a Modbus device receiving 4-20mA signals. So, that should all be spelled out in your Modbus device manual, particularly for something standard like 4-20mA.

TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

### RE: Converting Modbus register values to 4-20mA

(OP)
Oh, sorry IRstuff for that confusion.

If you plan an escape, you must succeed as if you fail, you will be punished for trying. Never say or write down your plan. Heart is the only place where secrecy is granted.

### RE: Converting Modbus register values to 4-20mA

>I would expect any of the major PLC brand to have I/O 16 bit cards,

Not necessarily. The PLC market has low end, mid grade and high end AI cards; you have what was paid for.

What does the spec sheet for the AI card say its resolution is?

A Modbus register is by definition 16 bits. A 10, 12 or 14 bit value would take up as much of the 16 bits as needed, but sometimes a Modbus Holding Register is used that is populated with a scaled value in engineering units, rather than an Modbus Input Register with its raw value.

### RE: Converting Modbus register values to 4-20mA

Here's a link to A-B's ControlLogix Analog I/O manual.

See page 43-44 for a discussion of data format as related to resolution and scaling

Whatever PLC is involved should have similar documentation.

### RE: Converting Modbus register values to 4-20mA

#### Quote:

By the way, I would expect any of the major PLC brand to have I/O 16 bit cards, nowadays but also up to ~2 decades back. Correct me if I am wrong?
Don't assume anything. Schnieder sells 12 and 16 bit analog input cards even now. The OP should have specified the card number.

#### Quote:

Otherwise when it is 12 bit, I would need to change scaling accordingly (2^12) for sure, but If I understand well the problem is when reading 12 bit as 16 bit analog data, that would require a special program, is this what you mean?
It makes a difference how the 12 bits are read into a 16 bit registers and whether the analog inputs are uni-polar or bi-polar.

Peter Nachtwey
Delta Computer Systems
http://www.deltamotion.com
http://forum.deltamotion.com/

### RE: Converting Modbus register values to 4-20mA

Please note that the specification said "16 bit unsigned integer and scaling 65535". So you need to read and use this as a 16 bit value, not a 32 bit integer or a 32 bit floating point number. It is one register with a range of 0 to 65535. Don't use it as a signed integer, that has a range of -32766 to 32767. Same 16 bits but used differently and have different ranges. You might have to do a type conversion in your DCS.

### RE: Converting Modbus register values to 4-20mA

(OP)
Dear all, thanks for the valuable input.
Appreciated.

If you plan an escape, you must succeed as if you fail, you will be punished for trying. Never say or write down your plan. Heart is the only place where secrecy is granted.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

#### Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a partâ€™s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!