Converting 16bit Word (INT) into REAL Decimal Number (Via SINT[2])

jake4eng

Member
Join Date
Sep 2016
Location
British Columbia
Posts
9
I am having problems expressing an ANALOG OUTPUT 16bit INT word (0-10V Proportional Valve Voltage) as a REAL decimal number.

From my understanding the word is divided into 2 (8bit) bytes...one representing the whole number value and the second the decimal value.

We're using BL20 I/O Module (german therefore LSB first).

I need to MOV/COP (read) the value, CONVERT it into a REAL number, Manipulate the REAL VALUE, then CONVERT the MANIPULATED REAL Value back into a 16bit INTEGER & WRITE the NEW Integer Value into Proportional Valve Voltage Location.



I also have a similar situation regarding our Incremental Encoder. In this scenario the pulse count is obviously a whole number (no decimals) where 4 (16bit) bytes represent the REAL Count Value..

I have read other posts on similar conversion topics and understand the general premise, but I'm having problems specifying write parameters..

- i.e. writing bits 0-7 from an INT into SINT[0] (HIGH BYTE representing the whole # value? ) and writing bits 8-15 into SINT[1] (LOW BYTE representing the decimal value) THEN CONVERTING into REAL # (Voltage fed to Proportional Valve) ...manual section... page 282&283 http://pdb2.turck.de/repo/media/_us/Anlagen/d300717.pdf

- i.e. writing bits 0-15 from INT[0] , INT[1] , INT[2] and INT[3] into a LINT (not sure if correct) THEN CONVERTING into REAL # (Encoder Count)

...manual section... page 17 (current count value) http://pdb2.turck.de/repo/media/_en/Anlagen/D301224.pdf

ANY SUGGESTIONS WOULD BE GREATLY APPRECIATED...
project file if interested.. https://sites.google.com/site/lyncedrgb/eva/untitledpost-2/StellaPLC.ACD
 
Last edited:
You can use 2 BTDs to combine 2 SINT into 1 INT value.

You can use a SCP instruction to convert an integer to a real number.
 
We're using BL20 I/O Module (german therefore LSB first).
It is not because it is from germany, but because the "endianess" is different. And the endianess is typically related to if the mircoprocessor that is used follows Intel or Motorola encoding.

Which PLC ?
For the endianess, it may be necessary to do a byte swap of the word before it is sent to the analog output module.
Most PLCs have an instruction for performing byte swaps.

From my understanding the word is divided into 2 (8bit) bytes...one representing the whole number value and the second the decimal value.
Where do you get this from ?
PLC analog inputs and outputs "normally" never use engineering values directly. They "normally" have a fixed integer value ranges.
The only exception I have ever seen is with AB PLC5 that does scaling directly in the module.

In the Turck manual it says for the 0-10V analog output module BL20-2AO-U(-10/0..+10VDC):
2 channels (1-2) with 6 bytes total (!) - bytes 0-5.
The bits 0 and 1 in the 1st byte (byte 0 for channel 1) decide the range and data format.
The analog data is in the 2nd and 3rd byte (byte 1 and 2 for channel 1).

The default data format is "15 bit + sign".
That would mean that the 0-10V signal has a -32767...+32767 representation.
It is not impossible that the manual is not exactly correct and it is actually 0-10V signal has a 0...+32767 representation. I am guessing that 0-10V = 0...+32767 is the correct one.

Which means you shall have a scaling function that scales your engineering value to 0...32767, the bytes of the scaled integer value should be swapped, and then send the value to bytes 1 and 2 for channel 1, and to bytes 4 and 5 for channel 2.

I also have a similar situation regarding our Incremental Encoder. In this scenario the pulse count is obviously a whole number (no decimals) where 4 (16bit) bytes represent the REAL Count Value..
Which encoder is that ? All encoders I have seen counts integers, not REALs.
I am guessing that you mean 4 Bytes with double integer representation.
 
From what you've wrote I would assume that you are using the BL20 as an IO expansion module for a PLC, because you mentioned MOV/COP I think it's some Allen-Bradley device, is that right? If it is, how do they communicate? Ethernet IP & a generic module in your IO?

Edit:
You are using an Allen-Bradley PLC, seeing that acd file extension...
 
Last edited:
http://pdb.turck.de/media/_cn/Anlagen/d301034.pdf#page173

I hope you did read that before but take a look at chapter 6.6.1 again.
I don't see them mentioning any byteswaps. At page 6-10 in the manual you've linked they state that byte n = lsb and byte n+1 = msb, doesn't seem to be swapped. However if you are looking at the word holding the input data and the bytes would be swapped I would expect the value to be all over the place at the slightest change in signal...

Double check that you've setup the communication parameters correctly. The Comms Format should be set to INT.
Regarding the analog input: As Jesper said a valid reading will range between -32767 & 32767. The module will give you a binary representation of the value, you have to convert it into engineering units yourself.
 
Last edited:
Thanks everyone for your input!
Jesper&Mareka... I checked the COMMS and they are set as INT!
Jesper: I need to change the value from INT to REAL in order to mathematically read & manipulate my input and outputs for a 0-10V Proportional Valve and Encoder Counts...Then convert my manipulated value back into INT form in order to be able to over write the current values..
PLC: 1756 L71 with an Ethernet Module Connecting all 8 BL20 I/O Modules
Encoder: http://pdb2.turck.de/en/contacts-139/products/0000003600024d760002003a

It is not because it is from germany, but because the "endianess" is different. And the endianess is typically related to if the mircoprocessor that is used follows Intel or Motorola encoding.

Which PLC ?
For the endianess, it may be necessary to do a byte swap of the word before it is sent to the analog output module.
Most PLCs have an instruction for performing byte swaps.

Where do you get this from ?
PLC analog inputs and outputs "normally" never use engineering values directly. They "normally" have a fixed integer value ranges.
The only exception I have ever seen is with AB PLC5 that does scaling directly in the module.

In the Turck manual it says for the 0-10V analog output module BL20-2AO-U(-10/0..+10VDC):
2 channels (1-2) with 6 bytes total (!) - bytes 0-5.
The bits 0 and 1 in the 1st byte (byte 0 for channel 1) decide the range and data format.
The analog data is in the 2nd and 3rd byte (byte 1 and 2 for channel 1).

The default data format is "15 bit + sign".
That would mean that the 0-10V signal has a -32767...+32767 representation.
It is not impossible that the manual is not exactly correct and it is actually 0-10V signal has a 0...+32767 representation. I am guessing that 0-10V = 0...+32767 is the correct one.

Which means you shall have a scaling function that scales your engineering value to 0...32767, the bytes of the scaled integer value should be swapped, and then send the value to bytes 1 and 2 for channel 1, and to bytes 4 and 5 for channel 2.

Which encoder is that ? All encoders I have seen counts integers, not REALs.
I am guessing that you mean 4 Bytes with double integer representation.
From what you've wrote I would assume that you are using the BL20 as an IO expansion module for a PLC, because you mentioned MOV/COP I think it's some Allen-Bradley device, is that right? If it is, how do they communicate? Ethernet IP & a generic module in your IO?

Edit:
You are using an Allen-Bradley PLC, seeing that acd file extension...
 
Last edited:

Similar Topics

Hello everyone, can anyone help me with covert the STL code to ladder. Iam using plc s71200. A %DB1.DBX33.7 // angel of vaccum...
Replies
2
Views
210
Hello PLCs Forum, I am in a bit of a pickle and was hoping someone could offer me some help. I have a .rss file and just need to see the ladder...
Replies
2
Views
123
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
320
Hello, did anybody know, if there exist an converting cable like the1492-CM1746-M01 (for an 1746-IB16 to an 5069-IB16), for an 1746-HSCE to an...
Replies
3
Views
391
Hello, This will be my first time converting powerflex 40's and 400's from devicenet to ethernet. I did some research, and it seems I will need...
Replies
4
Views
759
Back
Top Bottom