You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

Reply
 
Thread Tools Display Modes
Old January 13th, 2022, 03:01 PM   #16
GregPirch
Member
United States

GregPirch is offline
 
Join Date: Oct 2008
Location: Texas
Posts: 6
PMP23 with Negative Pressure Solution

OK, just to complete this thread I am including below my solution to properly interpolate both Positive and Negative pressure from an Endress Hauser PMP23 connected to an IFM IOLink Master Module.

The biggest hurdle is preserving the negative from a 30 Bit INT when “MOVing” it into a REAL data type. One way is to shift the entire 30 bit INT (which in the PLC is living within a DINT) so that the Negative bit (which in a 30 bit INT is at bit 29) ends up at bit 31 of the DINT (where is belongs).
Then divide the DINT by 3 (which in Binary is bits 0 and 1 set) to a REAL data type. This preserves the negative value and converts it to a REAL.

Anyway, hope this might help someone in the future …
... see code snip below …

FYI: I tuned up some of the tag descriptions to help everyone follow the bouncing ball.
Attached Images
File Type: png PMP23 Code.png (41.9 KB, 27 views)
  Reply With Quote
Old January 13th, 2022, 04:09 PM   #17
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 4,978
I am all but certain the divisor should be 4 not 3, the CLR should not be necessary with the current method, and a simpler approach would replace the

NXB CLR ... MVM ... NXB BTD ... DIV ... BND


inner branches, plus the first MUL on the next rung, with

NXB XIC Helper_DINT[10].29 OTE Helper_DINT[10].30 OTE Helper_DINT[10].30 NXB MUL Helper_DINT[10] 0.001 PT_4232.PSI BND


That said, how does multiplying -29.3334 by 0.001 yield a result of -0.022?
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good

Last edited by drbitboy; January 13th, 2022 at 04:27 PM.
  Reply With Quote
Old January 14th, 2022, 06:49 PM   #18
GregPirch
Member
United States

GregPirch is offline
 
Join Date: Oct 2008
Location: Texas
Posts: 6
Quote:
Originally Posted by drbitboy View Post
I am all but certain the divisor should be 4 not 3...
WOW!!! Good catch DrBitboy. When metrology performed a bench test of the pressure sensor it is was off by a 1.33 multiplier (for both negative and positive pressures) which (after reading your reply) now make sense ... I was dividing by 3 instead of 4 (hence 4/3 = 1.33). THANK YOU!!!


Quote:
Originally Posted by drbitboy View Post
NXB XIC Helper_DINT[10].29 OTE Helper_DINT[10].30 OTE Helper_DINT[10].30 ...
I believe I know what your getting at but please check your code. You have two "OTE Helper_DINT[10].30 OTE Helper_DINT[10].30" in a row AND I think I should be setting bit 31 instead of bit 30.
Also, wouldn't I need to OTU bit 29 using this method?
Are you just trying to move the negate bit to its proper location in the DINT?

So, I tried this (moving the negate bit to bit 31) early on and it works perfect for positive values ... but when the value (pressure) goes negative you can no longer just move the negate bit because of how signed binary stores negative numbers.

Is my thinking correct?? I would love a simpler approach if you can think of one. I actually created an AOI since I have 23 of these pressure sensors

Quote:
Originally Posted by drbitboy View Post
That said, how does multiplying -29.3334 by 0.001 yield a result of -0.022?
My bad, I actually had this rung AFIed when I took the screen shot.


Again, thank you for finding my Divide by 3 bug.
  Reply With Quote
Old January 15th, 2022, 12:28 AM   #19
drbitboy
Lifetime Supporting Member
United States

drbitboy is offline
 
drbitboy's Avatar
 
Join Date: Dec 2019
Location: Rochester, NY
Posts: 4,978
Quote:
Originally Posted by GregPirch View Post
WOW!!! Good catch DrBitboy.
Well, I am drbitboy.

Quote:
Originally Posted by GregPirch View Post
I believe I know what your getting at but please check your code. You have two "OTE Helper_DINT[10].30 OTE Helper_DINT[10].30" in a row AND I think I should be setting bit 31 instead of bit 30.
Yes, good catch on your part! However, just to be clear, you should be setting them both i.e. sign extension or zero extension; See this link.

Quote:
Originally Posted by GregPirch View Post
Also, wouldn't I need to OTU bit 29 using this method?
Are you just trying to move the negate bit to its proper location in the DINT?
I don't think so: I am doing either sign extension or zero extension.

If the high bit of the 30-bit integer, i.e. bit .29, is 1, then the number is a negative 30-bit integer, and all that is needed is to extend the sign out to both bit .30 and bit .31 to make it a twos-complement, signed 32-bit integer i.e. a DINT.

For example, say the 30-bit integer was -(2**29)
=> -536,870,912
=> 0x20000000 (hexadecimal, usual convention)
=> 20000000H (hexadecimal, A-B convention)
=> 0b10_0000_0000_0000_0000_0000_0000_0000 (binary, usual convention)
=> 10_0000_0000_0000_0000_0000_0000_0000b (binary, A-B convention but with underscores for nibbles)
See image below for representation of that value in 32-bit long (RSLogix Micro Starter Lite; RSLogix 500/5000 should be similar).

And if the 30-bit integer is positive, then bit .29 will be 0, and so, in the 32-bit integer, both bits .30 and bit .31 should also be 0.

xxx.png
__________________
i) Take care of the bits, and the bytes will take care of themselves.
ii) There is no software problem that cannot be solved with another layer of indirection.
iii) Measurement is hard.
iv) I solemnly swear that I am up to no good

Last edited by drbitboy; January 15th, 2022 at 12:33 AM.
  Reply With Quote
Old January 15th, 2022, 03:37 PM   #20
GregPirch
Member
United States

GregPirch is offline
 
Join Date: Oct 2008
Location: Texas
Posts: 6
Quote:
Originally Posted by drbitboy View Post
However, just to be clear, you should be setting them both i.e. sign extension or zero extension; See this link.
OK ... Wow!! Great info drbitboy.
After 25 years of programming PLCs (primarily ABs) I now understand how to represent the same (negative) integer value across varying lengths of bits.
A sincere thank you for walking me through this.

And ... now I KNOW how to simplify my original code.
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Pressure Transmitter ( Air pressure transmitter and Lpg pressure transmitter valu Ex) Hayat Ali LIVE PLC Questions And Answers 8 June 18th, 2020 11:50 PM
Creating a setpoint for a pressure transmitter in studio 5000. tgonz11 LIVE PLC Questions And Answers 4 April 9th, 2020 03:28 AM
Looking for a high temperature rated pressure transmitter RonJohn LIVE PLC Questions And Answers 7 December 27th, 2016 10:37 AM
Someone just had to ask. Peter Nachtwey LIVE PLC Questions And Answers 213 November 17th, 2008 07:36 PM
Pressure-Position Orn Jonsson LIVE PLC Questions And Answers 5 July 9th, 2002 04:44 PM


All times are GMT -4. The time now is 09:45 AM.


.