Stian Wex

How to convert values

14 posts in this topic

Hi, anyone who can help me white my issue in sysmac? Pleas Lock at the Picture file for my question.

Regards Stian

 

How to convert numbers.JPG

Share this post


Link to post
Share on other sites

search forum for "flip-flop"

Share this post


Link to post
Share on other sites

I'm not familiar with this processor, but if the value is a signed integer, toggling the most significant bit in the word will switch from a positive to a negative number, you could use an AND mask to do this when the sequence bit is active.

 

Steve

Share this post


Link to post
Share on other sites
7 hours ago, nehpets said:

I'm not familiar with this processor, but if the value is a signed integer, toggling the most significant bit in the word will switch from a positive to a negative number, you could use an AND mask to do this when the sequence bit is active.

 

Steve

That's not true.  The positive and negative values will not match if all you do is flop the MSB.  

Think about this....

0111 1111 1111 1111 is 32,767

1111 1111 1111 1111 is -1

The MSB has a value of -32768.  All other bits are positive.

If it's >0 it's positive.  If you want it negative subtract that value from zero.

If it's <0 then it's negative.  Use the ABS instruction to make it positive.

Share this post


Link to post
Share on other sites

Crossbow

Yeah you're right, I have aboslutely no idea what I was thinking - my brain must be somewhat addled after four 16hr shifts, please disregard my post.

 

Steve

Share this post


Link to post
Share on other sites

Don't worry about it, buddy.  I pulled the same stunt about three years ago.  Took me three days to figure out it wasn't as simple as it seems.:shrug:

Share this post


Link to post
Share on other sites

A more rudimentary method is to do Two's Complement Math. It is performed by inverting all the bits then adding 1.

Omron's C Series PLCs have a Two's Complement instruction. Sysmac Studio has a Neg instruction to do this for you.

Share this post


Link to post
Share on other sites

Hi Stian,

Maybe you can use function Mul (*):  P300 Length*(-1).

Good luck!

Qing

 

Share this post


Link to post
Share on other sites

it takes two steps - first you need flip-flop to toggle bit. then depending of this bit is set or not make result positive or negative.

Share this post


Link to post
Share on other sites

Some of the solutions above are a bit more complicated than necessary.  I agree with Qing, just multiply by -1 with a leading edge one shot on the bit, like this:

h9fvZRNzqTi8AAAAABJRU5ErkJggg==

Share this post


Link to post
Share on other sites

I would subtract the value from zero.

An old habit from classic PLCs, where this executes times faster than multiplication, and also prevents unnecessary change of the data format.

Share this post


Link to post
Share on other sites
On ‎8‎/‎27‎/‎2016 at 9:49 AM, Sergei Troizky said:

I would subtract the value from zero.

An old habit from classic PLCs, where this executes times faster than multiplication, and also prevents unnecessary change of the data format.

That would certainly work, but in the NJ, the * function does not necessarily require a data format change.  For instance, you can multiply two integers (INT) and still use an integer variable (also INT) for the answer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now