PLCS.net - Interactive Q & A

PLCS.net - Interactive Q & A (http://www.plctalk.net/qanda/index.php)
-   LIVE PLC Questions And Answers (http://www.plctalk.net/qanda/forumdisplay.php?f=2)
-   -   Gray Code encoder to Ethernet help!!! (http://www.plctalk.net/qanda/showthread.php?t=133684)

Ugsomania August 4th, 2022 12:33 PM

Gray Code encoder to Ethernet help!!!
 
Hey guys,

Although I've poured through this forum for help in the past this is my first post.

I am looking at replacing obsolete Baumer IVO Parallel encoders. It is a PLC 5 platform currently. I have installed a logix chassis for a previous upgrade and have a 1756-RIO card in that chassis as an adapter to get data back and forth between logix and PLC5. I'm going to be using an 842E-M encoder from AB for this upgrade. My plan is to RIO the encoder data from Logix to the PLC 5. Currently the encoder data is brought into the PLC in gray code via a 16 bit flex io input card. My plan is to set up more RIO racks and just change the current PLC logic to accept the data from my ethernet encoder rather than the flex IO input.

I have two questions.

1)My encoder data on the logix side is stored in a DINT. PLC5 works in 16bit words (INTs). But my encoders are all scaled where they don't exceed a maximum 16 bit value of 65536. Am I able to move this data to the PLC5 without any further manipulation?

2)With a 1756-RIO card in Adapter mode, am I able to move across data or am I limited to strictly inputs and outputs on the PLC5 side? I realize its ALL data technically on the logix side, but I'm under the impression I have no choice here but to land my data FROM Logix into the input data table on the PLC side. Am I correct here? So that being said I'll have to move my raw encoder position on the logix side into a DINT I would have set up to be my RIO rack and that will land in the corresponding input table in PLC5? Is there a way to move data into an integer file for example?

Thanks in advance for the assist on this.:smas:

Ugsomania August 4th, 2022 03:12 PM

Just a little update I'm currently benchtesting this...

I have my encoder position coming into a dint. I'm scaled to 0-65536 and have successfully moved this into an INT output tag that is set up to RIO to the PLC5. I have data coming into my PLC5 input word I:010.

On the logix side I have my encoder counting properly up to 65536 and then rolling over. However on the plc5 side once I get to 32767 the next value goes to -32767.

Is there a way to use the entire positive range of the 16 bit input word in the plc5?

drbitboy August 4th, 2022 03:18 PM

Quote:

Originally Posted by Ugsomania (Post 920994)
Just a little update I'm currently benchtesting this...

I have my encoder position coming into a dint. I'm scaled to 0-65536 and have successfully moved this into an INT output tag that is set up to RIO to the PLC5. I have data coming into my PLC5 input word I:010.

On the logix side I have my encoder counting properly up to 65536 and then rolling over. However on the plc5 side once I get to 32767 the next value goes to -32767.

Is there a way to use the entire positive range of the 16 bit input word in the plc5?


Yes.


Actually the next value is -32768, not -32767.


I assume you are MOVing the INT tag to the DINT tag, after that, AND the DINT with 65535 (0000ffffh), and values of -32768 to -1 in the INT will will be 32768 to to 65535 in the DINT.

drbitboy August 4th, 2022 03:39 PM

Oh wait, I think I misunderstood the query: the problem may be whether the PLC-5 has unsigned INTs or 32-bit DINTs.

PLC-5 does have floats, so you could MOVe the INT value (e.g. I3.5 or N7:0) to an element of a float file (e.g. F8:0), and then add 65536 to it if the INT value is negative:
Code:

MOV N7:0 F8:0
XIC N7:0/15    ADD F8:0 65536.0 F8:0

Alternate, probably clearer:
Code:

MOV N7:0 F8:0
LES N7:0 0    ADD F8:0 65536.0 F8:0

Floats have 23 bits of mantissa, so there will be no loss of data.

Lare August 4th, 2022 04:51 PM

Quote:

Originally Posted by drbitboy (Post 921002)
Oh wait, I think I misunderstood the query: the problem may be whether the PLC-5 has unsigned INTs or 32-bit DINTs.

PLC-5 does have floats, so you could MOVe the INT value (e.g. I3.5 or N7:0) to an element of a float file (e.g. F8:0), and then add 65536 to it if the INT value is negative:
Code:

MOV N7:0 F8:0
XIC N7:0/15    ADD F8:0 65536.0 F8:0

Alternate, probably clearer:
Code:

MOV N7:0 F8:0
LES N7:0 0    ADD F8:0 65536.0 F8:0

Floats have 23 bits of mantissa, so there will be no loss of data.




Thinking that four compares or rungs should also work for setpoint comparing but code isn't so clear.


If encoder setpoint is positive number (setpoint is less than 32768) and encoder value is positive -> bigger or equal compare



If encoder setpoint is positive number (setpoint is less than 32768) and encoder value is negative -> less compare



If encoder setpoint is negative number (bigger than 32767) and encoder value is positive -> less compare



If encoder setpoint is negative number (bigger than 32767) and encoder value is negative -> bigger or equal compare

drbitboy August 4th, 2022 05:54 PM

Quote:

Originally Posted by Lare (Post 921007)
Thinking that four compares or rungs should also work for setpoint comparing but code isn't so clear. ...


If all one wants is the direction and offset from current encoder value to the setpoint (or vice versa), then it's even simpler than that.

But this raises a question: why does it matter to OP whether the encoder is either in the range [0:65536) or in the range [-32768:+32768)? Both ranges are continuous, except at the rollover, if this is a rotary encoder.

Ugsomania August 5th, 2022 09:00 AM

Thanks for the responses. After digging a little further I've found that for the application rolling over to the negative value has no consequence. I'm fairly new to the design and commissioning side of this game. Learning everyday.

Thanks again!!


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

.