Omron CLC question

ceilingwalker

Lifetime Supporting Member
Join Date
Mar 2010
Location
Phoenix, AZ
Posts
1,586
Hello, I would like to know when/why one would use the Clear Carry (CLC) instruction before performing arithmetic operations for a C200HX. The reason I ask is, this logic I am trying to understand will sometimes turn off the CY bit prior to performing math and then, at other times, they didn't. The only guess I could make is that they were anticipating there would be a carry and they wanted to make sure any carry that may have been left-over doesn't show up in the math operation that is about to be executed?
omron question .jpg
 
Also, if I may add another question: it APPEARS to me as though I have some DM registers that are written to as a decimal however, other registers are reading it as a BCD, without a BCD to decimal converter. Does that sound like a common practice? What those registers are doing is telling the NT631 which screens to open.
 
Clear carry is only used after a function that has a carry - many do not have a carry. Mostly the ones I use do not and I do not have to bother. The PLC stores data not data types. Some functions expect decimal, others BCD and the like. It is the same data it is only interpretation that does this. For example 1234 in decimal is 4D2 in HEX - it is the same data. Many instructions that have been around for years still use HEX and BCD - in CX-P there are touch pads that enable you to view in HEX, signed, unsigned and the like.
 
By the way I often use a word type in my symbol table that raises a warning about incorrect word type for a function - it is only a warning. I do this because that is how I want to view it in the program when commissioning.
 
By the way I often use a word type in my symbol table that raises a warning about incorrect word type for a function - it is only a warning. I do this because that is how I want to view it in the program when commissioning.

Does this mean that if you view it as the incorrect word type in the data table, it will appear as "error" or something? Not sure I understand what you are saying.
 
Not an error - just a warning - it will not cause any issues. If a function expects an INT and you define it as a UINT there will be a warning when the program compiles - it does not matter. It is only interpretation of the data - will not change the data or how it works. Sorry if I am confusing you - I am used to it I guess.
 
I am not a C200HX user, but have worked with systems that use the carry.


Basically a math instruction ADD is really:
C := A + B + Carry
This would be useful say for adding a 64bit number with only 16bit registers:
Code:
CLC
ADD A_LL,B_LL,C_LL
//Carry the one
ADD A_LH,B_LH,C_LH
//Carry the one
ADD A_HL,B_HL,C_HL
//Carry the one
ADD A_HH,B_HH,C_HH
As a general rule, you should clear carry every time without fail. You would only not clear it if: you wanted to do something like the above, you know the preceding math instruction cannot set the CCY flag (and you know future-you is never going to add a math instruction between them which can), or you're feeling lucky.
 
[/CODE]As a general rule, you should clear carry every time without fail. You would only not clear it if: you wanted to do something like the above, you know the preceding math instruction cannot set the CCY flag (and you know future-you is never going to add a math instruction between them which can), or you're feeling lucky.

So, if I am understanding you correctly, if a math instruction (for example) carries over to other registers that extend beyond what that data normally uses, it acts almost as a buffer? In my case they are always following BCD instructions. Does this mean that instead of the usual limit of 1001 for the digit, it could actually carry over say to 1101? Or am I way off? Thanks
 
When there is a carry, does that mean an additional bit box was used?

It's a dedicated bit. In the HX, that's bit 255.04, or P_CY if you use the default symbol name. EDIT: @gtsuport beat me to it.

As AustralIan alluded to, the ADD function adds the two numbers (augend and addend) and the carry.

I was always taught that for multiword numbers, use an 'add without carry' on the first set (lowest significant word), and 'add with carry' on the rest. In your case, the CLC placement follows that, because these processors don't have a separate add function for with/without carry.
 
This is from the C200H* programming manual.
The actual address of the CY bit is 255.04.
Reference manual W303.

Yes, I read that in the book, I just don't understand exactly what it was doing. I searched for some sort of a pattern in the program I am working with to see if there was any reason for why they would use it sometimes but not all of time.
 

Similar Topics

Hi all, Currently having trouble getting a speed reference to write over modbus to an Omron M1... I can successfully write a run command and...
Replies
2
Views
23
Hi There, I have couple of Omron PLCs connected on my kepserverex and my intouch reads data from kepserverex. I have been observing that roughly...
Replies
4
Views
99
Hi dear . I have a system with cj1m cpu11 etn. previously NT 5z HMI was connected with plc. recently my old HMI got damaged. I want to replace it...
Replies
7
Views
117
Omron AD081-V1 Analog Input Card Offset & Gain Adjustment Entering Adjustment Mode 1. Set the input card in adjustment mode (Turn ON Dip SW No-1)...
Replies
0
Views
56
I am working on a project using a NB screen and NX1P2 PLC. I am having a really hard time getting a real number to properly translate through to...
Replies
3
Views
116
Back
Top Bottom