Dear All,
I want to check the bit value of all bit for the 32 bit data in DeltaV which is coming through serial connection.
as in case in 16 bit register we get the values at the OUT_D of BFI block.
You must subtract or remove the first 16 bits. The result will then be sent to a bfo. You can remove the first 16 by subtracting 65536 from the value, take the absolute value, then send the value to the in_d of the bfo. Don't use the Out# of the calc block to wire the value, as this will convert the value to a float and risk precision loss.
You can also use the Rol/Ror/Shr/Shl functions to roll or shift the bits, but I've never used them.
If you can view this linkedIn group, this might help
www.linkedin.com/.../Floating-IEEE-754-algorithm-in-1270757.S.162412801
In reply to IntuitiveNeil:
Sorry I may have misunderstood the requirement, you're not trying to convert to float, just extract the individual bits from the top 16 bits of a 32 bit word. The code at that link shows the SHR function in use.
If we imagine the 32 bit integer parameter is called 32BITIN, and the input parameter connected to input of the first BFO called LOW16BITS and the input parameter connected to the second BFO called HIGH16BITS.
You'll need to perform a bitwise and mask of 0000FFFF hex against the 32 bit input number and store that in a register for input to the first 16 bit BFO. Then shift the top 16 bits into the bottom 16 bits position.
Your code would be
LOW16BITS := 32BITIN & 65535;
HIGH16BITS := SHR (32BITIN, 16)
Parameters LOW16BITS and HIGH16BIT should be unsigned integers type.
I recently had to implement this and one gotchya I came up against was that the IN1 of your calc block won't handle your 32-bit integer, so make sure your 32BITIN (per IntuitiveNeil's solution) is directly referencing the 32-bit parameter or you will lose precison and get incorrect results. Unless you tested every bit, it would be possible to think you have it working when in fact some of the 32 outputs will not be correct.
To make your FBD look nicer, you could even still connect the 32-bit input parameter to IN1 of your calc block, but in the calc block explain with a comment why IN1 is not used so as to not create confusion.
I forgot to mention the calc in# as well. We recently had to track down floating point conversion and loss of large integer sensitivity. As an additional statement, I believe we saw that performing any arithmetic function with a calc in which the other operands are floats causes the result to also be cast as a float, regardless of whether you address the assignment outside of the calc.
In reply to Youssef.El-Bahtimy:
The CALC block IN and OUT parameters are Float type. DeltaV automatically converts wired connections to Floats, and as mentioned above, 32 bit integers lose precision. A Float uses a 22 Bit mantissa (resolution of the floating point number), so it can handle 16 Bit integers. However, if you looked at the IN parameter for bit wise operation, it would not be the same as the original 16 BIT integer.
The code presented by IntuitiveNeil would not work if you used internal parameters, so the code should look like:
'^/LOW16BITS' := '^/32BITIN' & 65535;
'^/HIGH16BITS' := SHR ('^/32BITIN', 16)
Internal parameters in a CALC block will be floating points, so you need to store your intermediate integer values in declared parameters outside the CALC block, defined as the desired variable data type.
I don't think you can declare CALC variables to be a particular data type, and they are all Floating Point. If that's not the case, would be happy to see a post that explains how to declare a variable as 32 Bit integer. Otherwise, parameters need to be used of the desired data type.
Andre Dicaire
In reply to Andre Dicaire:
I agree with Andre on this. Minimize the transactions with the 32 bit integer in the calc block. I dug up my code from when I had to do this and turns out I did use SHR afterall.
'^/BFO2/IN_INT.CV' := SHR('^/INT32_SELECT.CV',16);
Where INT32_SELECT is a 32bit integer.
You have 32 bit (Boolean) and you need to writing on BFI blocks? or it's 32 bit unsigned integer and you need to writing on BFO blocks?
1- Map 32 bit (Boolean) on BFI blocks:
The result of the OUT_D of BFI block is calculated as follows:
OUT_INT = IN1 x (2)^0 + IN2 x (2)^1 + IN3 x (2)^2 + IN4 x (2)^3 + IN5 x (2)^4 + IN6 x (2)^5 + ........ + IN16 x (2)^15
For example:
if IN1 = 1 and IN2 to IN16 = 0, OUT_INT = 1 x (2)^0 = 1
if IN1 and IN2 = 1 and IN3 to IN16 = 0, OUT_INT = 1 x (2)^0 + 1 x (2)^01 = 1 + 2 = 3
You can do an equation for the 32 bits in a CALC block .
1- Map 32 bit (unsigned integer) on BFO blocks:
The link below for Application Exchange is for different conversion:
https://deltav.com/Appsnew/application.asp?subid=243
In reply to Nabil BOU:
In reply to Brent Hamilton:
In reply to stamate_mircea: