AndrejP Posted March 21, 2018 Report Posted March 21, 2018 Hello. How can I easely determen if for example the value in DM100 is ODD or EVEN? Thanks.
innoaloe Posted March 21, 2018 Report Posted March 21, 2018 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...
Crossbow Posted March 21, 2018 Report Posted March 21, 2018 Depending on which PLC, can't you also just look at the least significant bit? D100.0? 2
Michael Walsh Posted March 21, 2018 Report Posted March 21, 2018 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.
innoaloe Posted March 21, 2018 Report Posted March 21, 2018 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
gclshortt Posted March 22, 2018 Report Posted March 22, 2018 On the older units, use a move to a HR register first. Nice solution Crossbow. Garry
AndrejP Posted March 26, 2018 Author Report Posted March 26, 2018 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.
AndrejP Posted March 26, 2018 Author Report Posted March 26, 2018 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...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now