Katerina

Problem using comparator

9 posts in this topic

I am using version 9.2 of Cx-programmer. I want to compare the current value of a reversible counter(CNTR)  with the value 0. I tried to create a comparator by writing

[CMP C7 0 ] and then in the next rung I connect the comparator with a coil ( which should be energised when the comparator is true). But there is an error :

ERROR: Coil is not positioned correctly at rung 155 ( 6, 0 ). 
ERROR: Function 'CMP(020)' is positioned incorrectly. at rung 155 ( 0, 0 ). 
 I have attached apicture which shoes clearly what I have done!

comparator_error.jpg

Share this post


Link to post
Share on other sites

The CMP instruction sets one of the arithmetic flags in the A memory area. You need to use a NO contact of the appropriate flag (<, <=,=,>=,>) in rung 155.

It is probably easier just to use the corresponding symbol math instruction (<, <=,=,>=,>) and forget the CMP entirely.

Edited by Mendon Systems

Share this post


Link to post
Share on other sites

Also, note that if you are trying to compare the counter value with 0, you need to put #0, which means a constant BCD (in this case, can mean Hex also) value of 0.  By just putting 0, you are comparing the value of the counter with the value in channel 0 (which may or may not be a value of 0).  Channel 0 is the first input or output channel of the PLC.

Share this post


Link to post
Share on other sites

You need CF113 in front of the compare instruction. I would just use the symbol math instructions as suggested above and then to an output.

Share this post


Link to post
Share on other sites
18 hours ago, Mendon Systems said:

The CMP instruction sets one of the arithmetic flags in the A memory area. You need to use a NO contact of the appropriate flag (<, <=,=,>=,>) in rung 155.

It is probably easier just to use the corresponding symbol math instruction (<, <=,=,>=,>) and forget the CMP entirely.

Thank you for your answer! What do you mean by saying''NO contact of the appropriate flag (<, <=,=,>=,>)'' ? Is that what you told me to do? (see the picture)

 

comparator_error.jpg

Share this post


Link to post
Share on other sites

This is the method you are attempting. NO is 'Normally Open' contact. The Symbol Math Instructions are a different method.

Compare.thumb.jpg.bb614eaf4084ced994caa9

Share this post


Link to post
Share on other sites
3 hours ago, Katerina said:

Thank you for your answer! What do you mean by saying''NO contact of the appropriate flag (<, <=,=,>=,>)'' ? Is that what you told me to do? (see the picture)

 

comparator_error.jpg

The method that you have used in your latest code sample is the simplest way to accomplish what you want. The symbol math instructions (called "input comparison" instructions in the older CJ1/CS1 manuals) will do everything in one instruction.

The CMP instruction requires you to use the processor flags as shown in IO-Rack's example. It does have the advantage of being able to check for all three conditions in one rung, but you must be careful to do the condition tests immediately after the CMP is executed so that nothing changes those flags.

Share this post


Link to post
Share on other sites

There is a mistake in this ladder code below, make sure to use the = instruction, not the =F instruction.  =F is floating point and the CNTR instruction uses BCD as the format.   An additional note:  you do not need to make a comparison to a counter value.  When the counter reaches 0, the bit C7 will turn on.  Just Use a N.O. C7 wherever you wanted to use the Bm_Free bit.  With a standard counter (CNT) instruction, using the counter done bit makes sense and will function as expected.  It would count down to from 4 to 0 and then you would have to reset it to start again.  When the counter is at 0, the done bit would turn on.  With the CNTR instruction, it is a bit different.  The top input will make C7 count up, the middle will make it count down and the bottom is a reset.  Both the count up and count down will make the counter value wrap around like this:  when counting up: 1, 2, 3, 4, 0, 1, 2, 3, ....  When counting down:  0, 4, 3, 2, 1, 0, 4, 3, 2, 1...  The done bit will be on when C7 is 0.

 

comparator_error.jpg

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