December 16, 2018, 01:07:12 PM
Robotforum | Industrial Robots Community

 Output an integer > 255


Author Topic:  Output an integer > 255  (Read 1163 times)

0 Members and 1 Guest are viewing this topic.

January 29, 2018, 04:29:17 PM
Read 1163 times
Offline

benxi


Hello,

I want to send a Z value "measured" by the robot via a search instruction. This value is now saved into a Double variable D020.

This Z value can be bigger than 255mm so I need to send D020 to the PLC via 2 group outputs, OG68 & OG69.

What is the best way to "break down" a double variable (or an integer one) into two bytes variables? Does somebody have a standard code for it?

I wanted to create a loop and divide by 2 till I reach 0 and then assign each bit; but for this I need a modulo instruction which is not available...

If possible I want to avoid using the ladder (only a system job).

Many thanks!

Linkback: https://www.robot-forum.com/robotforum/index.php?topic=25707.0

Today at 01:07:12 PM
Reply #1

Advertisement

Guest

January 29, 2018, 05:52:04 PM
Reply #1
Offline

rAviteja_g


SET D020 Z-Value

SET D027 D020

DIV D027 256

SET B002 D027

SET D027 256

MUL D020 B002

SUB D020 D027

SET B003 D020

DOUT OG(68) = B003

DOUT OG(69) = B002
« Last Edit: January 29, 2018, 05:53:46 PM by rAviteja_g »

January 30, 2018, 08:28:38 AM
Reply #2
Offline

benxi


Dear rAviteja_g,

If I use as an example Z-value of 1247mm => I got byte values B003 > 255?
Is this code tested?

Also an other question : with doubles, what happens when you divide and you get decimal number?

eg 1247/256 = 4.87... ==> is the result 4 or 5?

Many thanks!

January 30, 2018, 11:54:20 AM
Reply #3
Offline

rAviteja_g


I have typed error:  the actual program is below- change the variables how you want. I tested- it is working fine. PLC side you group the two bytes as word, U see the value what you want to sent.


NOP
'--------------------------------
'PLEASE ENTER THE REQUIRED
'ROTATION VALUE IN VARIABLE D020
'Z Value in D20
 
'--------------------------------
SET D020 1247
'________________________________
'COPY D001
SET D001 D020
'DIVIDE BY 256
DIV D001 256
'SAVING IN BYTE2
SET B002 D001
'------------
SET D001 256
MUL D001 B002
SUB D020 D001
SET B003 D000
'------------
'SENDING DATA TO PLC
DOUT OG#(67) B003
DOUT OG#(66) B002
'---------------
'COMPLETE TRANSFER
'--------------------
END





when you get DIV 1247 256  --- U'll get 4 the fractional part we dont get.


Thanks.

February 02, 2018, 04:47:13 AM
Reply #4
Offline

notverycreeative


I don't have a pendant in front of me, but I would think you should be able to do something like this. So you'll be giving the value to the PLC through the groups, and they should be able to BTD it into a tag and do the addition to get the final number


If your values are going to be larger than 512, then you should be able to create separate if statements that will cover you for when the D value is higher. You would need more than two groups though.

// If the value is less/equal to 255 only write to one OG
If D20  <= 256 then
Set OG68 D00020
Set OG69 0
Endif

//If the value is larger than 256, but less than 512, set first group to 255
// then we subtract 256 from the D variable and set
//the remainder into the second OG
Elseif D00020 > 256 AND < 512
Set OG68 256
Sub D0020 256
Set OG69 D0020
Endif
//If the data is larger than 512, but less than 1024,
//We do the same thing, but subtract 512 once we have
//populated the first two groups with that value
Elseif D0020 >512 AND < 1024
Set OG68 256
Set OG69 256
Sub D0020 512
Set OG 70 DO20
Endif
//or even larger than 1024
Elseif D0020 >1024 AND <2048
Set OG68 256
Set OG69 256
Set OG70 256
Sub D0020 1024
Set OG 71 D0020
Endif

I don't have a pendant in front of me, so I can't test this for you right now... but I think that should work?
« Last Edit: February 02, 2018, 05:13:15 AM by notverycreeative »

Today at 01:07:12 PM
Reply #5

Advertisement

Guest

July 16, 2018, 02:05:17 PM
Reply #5
Offline

asgary64


hello
can we help me?

if value was more how can break down it? for example i have 831236. how can i break down and send it on the outputs for PLC?

July 17, 2018, 12:52:44 PM
Reply #6
Offline

zdravо


You can use bin-dec coding .831236 you can separate   BOO1 = 83, BOO2=12, B003=36  and integrate    83 * 1000 + 12* 100 + 36.


Share via facebook Share via linkedin Share via pinterest Share via reddit Share via twitter

xx
Convert Unsigned Integer to Signed Integer

Started by TrevorBlevins on Kawasaki Robots

2 Replies
316 Views
Last post August 16, 2018, 12:32:20 AM
by TrevorBlevins
xx
Conversion of two 16bits Signed Integer in a 32bits Signed Integer

Started by jleblanc on Fanuc Robot Forum

4 Replies
728 Views
Last post February 27, 2018, 06:47:30 PM
by jleblanc
xx
Signed integer 16 bit

Started by Plc_User on Fanuc Robot Forum

6 Replies
2268 Views
Last post January 25, 2017, 03:00:30 AM
by ESIELI
xx
Popup with string and integer

Started by Perkerssens on Universal Robots

1 Replies
2943 Views
Last post December 12, 2014, 08:32:01 PM
by gtrobot