Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations pierreick on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Modbus register values to 4-20mA

Status
Not open for further replies.

rotw

Mechanical
May 25, 2013
1,143
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.

Thanks in advance

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.
 
Replies continue below

Recommended for you

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:


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.
 
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.
 
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.
 
It doesn't matter, you likely only have 53521 levels of resolution: 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! faq731-376 forum1529 Entire Forum list
 
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.
 
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?
 
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! faq731-376 forum1529 Entire Forum list
 
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
 
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.
 
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! faq731-376 forum1529 Entire Forum list
 
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.
 
>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.

 
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

Link

Whatever PLC is involved should have similar documentation.
 
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.

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
 
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.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor