March 22, 2019, 10:37:29 AM

Output an integer > 255

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

0 Members and 1 Guest are viewing this topic.

January 29, 2018, 04:29:17 PM

benxi

Output an integer > 255
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!

Today at 10:37:29 AM

Guest
Re:  Output an integer > 255

January 29, 2018, 05:52:04 PM

rAviteja_g

Re: Output an integer > 255
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

benxi

Re: Output an integer > 255
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

rAviteja_g

Re: Output an integer > 255
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
'--------------------------------
'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

notverycreeative

Re: Output an integer > 255
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 »

July 16, 2018, 02:05:17 PM

asgary64

Re: Output an integer > 255
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

zdravо

Re: Output an integer > 255
You can use bin-dec coding .831236 you can separate   BOO1 = 83, BOO2=12, B003=36  and integrate    83 * 1000 + 12* 100 + 36.

Today at 10:37:29 AM

Guest

Similar Topics

Convert Unsigned Integer to Signed Integer

Started by TrevorBlevins on Kawasaki Robot Support Forum

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

Started by jleblanc on Fanuc Robot Forum

4 Replies
872 Views
February 27, 2018, 06:47:30 PM
by jleblanc
integer from PLC to Robot

Started by gio_926 on Fanuc Robot Forum

2 Replies
273 Views
December 19, 2018, 01:27:11 PM
by stare284
Signed integer 16 bit

Started by Plc_User on Fanuc Robot Forum

6 Replies
2575 Views
January 25, 2017, 03:00:30 AM
by ESIELI