View Single Post
Old August 4th, 2022, 04:51 PM   #5
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 1,821
Quote:
Originally Posted by drbitboy View Post
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
  Reply With Quote