AndrejP

OMRON ODD or EVEN value

8 posts in this topic

Hello.

How can I easely determen if for example the value in DM100 is ODD or EVEN?

Thanks.

Share this post


Link to post
Share on other sites

Welcome!
You can use the Divide instruction to get around your problem easily.

If you look into the Divide ("/") instruction manual, you will see that the output of that instruction are both the quotient and the remainder of the division operation.
For example if you Divide 10 with 2, you will get 5 as the quotient and 0 as the remainder. If you Divide 11 with 2, you will get 5 as the quotient and 1 as the remainder.

To check whether a number is Odd or Even, you just need to divide it by 2. If the Remainder is not zero, you can be certain that the number is Odd.

Something like the example below should do the job, I think...

Capture.thumb.JPG.3c42424c354abcc16150a6

Share this post


Link to post
Share on other sites

Depending on which PLC, can't you also just look at the least significant bit?  D100.0?

2 people like this

Share this post


Link to post
Share on other sites
46 minutes ago, Crossbow said:

Depending on which PLC, can't you also just look at the least significant bit?  D100.0?

Yep!  And older PLCs that will not let you do contacts for D bits have the TST and TSTN instruction.

Share this post


Link to post
Share on other sites
4 hours ago, Crossbow said:

Depending on which PLC, can't you also just look at the least significant bit?  D100.0?

Man... I may need to start on thinking how machines sees the world again :D

Nice input there Crossbow

Share this post


Link to post
Share on other sites

On the older units, use a move to a HR register first. 

Nice solution Crossbow.

Garry

Share this post


Link to post
Share on other sites

Thanks for answer.

I have allready figured out I can use reminder.

Problem is that I need to do this in Function Block.

I declare variable as UDINT. The program automatically assign address to this variable.

The sollution would be assigning fixed memory allocation.

But I would like to avoid using fixed memory allocation (when declaring variable). 

How can it be done this by looking at the R+1 (reminder) of declared variable?

Best regards.

Share this post


Link to post
Share on other sites

Hello.

I have figured out...

It's simple :-)

You declare UINT variable as array dimension 2.

Then you can use Var[0] as word R and Var[1] as reminder R+1.

Best regards...

 

 

Sl.png

Sl2.png

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