PLC-based vs PC-based programming

chunkheng

Member
Join Date
Sep 2007
Location
Malaysia
Posts
9
Hi all,

I am used to writing PC-based programs, and I have been trying to pick up PLC programming skill for the past few of months.

But somehow, I always found myself in a situation where I was confused between PC-based and PLC-based programming, in the sense of their flows and structures.

As an example, I have a PLC program downloaded from a working machine, and inside the code, I see a lot of "KEEP" instructionand IR bits being used. I am wondering what is the practical purpose of this instruction.

It will be helpful if anyone can share some helpful hints in dealing with these two programming languages in real world/practically.

p/s: I am sorry if my question/request sounded a little "lost", but this is in fact my feeling now, as I don't see myself making any progress in learning up PLC programming skill.

Thanks in advanced for all the feedbacks/comments
 
I am going to guess that a KEEP instruction is like a latching bit?

One that might retain its state during a power cycle?

If I am correct, The PC analogy would be like writing status bits to the hard drive, so when the PC restarts, it remembers where it left off.

Except, in a PLC, this happens in microseconds, with no file open commands involved.

So, specify the PLC make and model number you are using and we can surely figure out how to help you see the big picture.

Paul
 
PLC and PC programming are not 'compatible'meaning ,you have to think differently.More like machine code and down to playing with bits and bytes .A PLC replaces relays and contacts , AND and OR gates.

You will have to get a manual for your type of PLC with the instruction codes.Imagine writing a program in C with any knowledge or help file.

Greetings

Eric
 
It sounds like you are using an Omron PLC (KEEP and IR register). If this is the case, the KEEP instruction is like a Set-Reset bit. It has two rungs associated with it. If the logic on the first rung is true, then the IR bit is set. If the logic on the second rung is true, then the IR bit is reset. You can go to Omron's website and download the instruction set manual.

By the way... I went the other way. I started out on PLCs and went back to school and got a BS Computer Science to learn how to program PCs. They are different, but now with PACs (Programmable Automation Controllers) that are capable of being programmed in structured text, the gap is closing.

Good Luck
 
I am using CMP1A as a start, as I think it is one of the most simplest PLC available..

I think my biggest problem is I always get caught in how to implement the conditions such as "If-Else", "While" conditions, etc. in PLC.
Or are there such implementations in PLC programming?

Thanks.
 
chunkheng said:
I think my biggest problem is I always get caught in how to implement the conditions such as "If-Else", "While" conditions, etc. in PLC.
Or are there such implementations in PLC programming?

Thanks.

See my first reply ... using a Siemens PLC

if else

:A condition // if
:jc next // if signal high then jump to label 'next'
:
: // do else part
:
JU end Always jump to label 'end'
next:
: // do if part
:

end :

while
Loop:L counter //
:L max value
:>I // compare loop counter with selected value
JC end2 // if counter bigger then quit loop
:
: // do while part
:
: Inc counter // increment counter
: ju Loop
end2:


Eric
 
chunkheng said:
I think my biggest problem is I always get caught in how to implement the conditions such as "If-Else", "While" conditions, etc. in PLC.

Or are there such implementations in PLC programming?

Yes there is pls [size=-1]google for
"IEC 61131-3
Languages Structured Text (ST)"

or see

www.oscat.de (oscat.lib 2.4 Plain Text) for how it can look



[/size]
 
Last edited:
Just get a PLC that supports Structured text (ST), then you can use your IF/ENDIF/ELSE statements.
 
Every rung in a PLC is an IF THEN instruction.

IF the bit is true, THEN do something, ELSE do nothing.

--] [-----------( )--


or

IF bit1 is true AND bit2 is false, do something

--] [---]/[-------( )--
 
Yes, the CPM1A is one of Omron's most basic processors, but you can do a lot with it. I agree with the previous post that every logical rung of the ladder logic program is either an AND or an OR function which equates to an If-Then-Else statement:

1.
 --]X[--]Y[--------(Z)-- 


(If X and Y are True then energize Z, Else do not energize Z)

2.
 --]X[--]Y[----------(Z)--
--]A[--]B[--|



(If X and Y are True OR A and B are True then energize Z, Else do not energize Z)

You can do many other functions with the CPM1A such as bit manipulation, word manipulation, data movement, simple math, etc. Download the manual and start from there.

Also, what software are you using? LSS or CX-Programmer? The windows programming software can make a huge difference in the learning curve. CX-Programmer is really nice software that has lots of help features.

Regards
 
Last edited:
A step further up the line - use CX-Programmer for sure. I would also suggest getting away from the CPM1A - it is quite old and not all that functional. It has basically been replaced by the CP1L.

This new PLC is cheaper than the old CPM1A and has the same instruction set as the CJ1/CS1 processors - the present and future - not the past. The CP1L can be programmed with the latest version of CX-Programmer in ladder, FB, SFC etc etc. You can also use ST inside function blocks, although I do not unless complex maths are involved. The PLC has over 400 functions available to you - you do not even have to use ST if you do not want to as the function set is huge and covers virtually everything.

I find that unless there is a repetative task - such as HVAC controls - FB is an absolute pain in the 'A'. It looks nice and that is about all as far as I am concerned for my work. There are 4 or 5 other SI's doing the same type of work as me - we all talk - and they all agree with me about FB's in our area of work, no matter what brand of PLC we use.

IF WHILE and ELSE are also available if you wish to use them.

With the CP1L, for programming the USB connection is very fast and simple. Serial ports are very inexpensive and the PLC has Modbus Slave set up built in that only involves clicking on the serial port when online and setting a few bits of info - it really is so easy. The PLC also has Easy Modbus Master which is setup up the same way and there is only 1 instruction required in the program to get it to work. A plug in serial port (RS232 or RS422/485) is less than $100 AU at full trade price - that has to be a first for a PLC.
 
It hasn't been mentioned yet so I'll throw it out there. One thing which trips up many coming from a PC background is the repeating scan nature of a PLC. Excluding JUMPs, CALLs, and other such fanciness, a PLC program is executed in sequence its entirety on each and every program scan. What this means is that in a 25-rung program or a 2500-rung program, every rung gets a shot at controlling its output(s) on each scan.

So, if rung 23 sets its output and that output is used in rung 24 the new status will have effect immediately upon rung 23 ending and rung 24 executing. It also means that that same output examined in rung 6 will have effect on the very next scan. Not after a time delay. Not next week. The next scan. The effect may be nullified by other conditions in the rung in question but, the status is there to be used if desired.

This behavior can cause all sorts of bizarre, hard-to-find, weird, and generally unwanted action.

Applied with knowledge it can also be used to put together ladder structures to create functions not necessarily available in the processor you're using - search one-shots and flip-flops on this forum.

As far as your specific question about the usefulness of "KEEP" bits (AKA 'latch/unlatch', 'set/reset'), these are used to retain (remember) the state of a rung after the conditions which caused the rung to go true no longer exist.

An example is a pushbutton application. An operator presses a button to start a conveyor. Since the button is most likely a momentary contact type and we don't want the operator to have to press on the button the whole time to keep the conveyor running, logic is written which can hold the output on after the switch is released.

It may help to think of each rung as a little task all by itself. While a rung is executing, it is the sole focus of the processor. All other rungs are essentially asleep.

Hope this helps
 
Doug-P beat me to it.

But right on this site is some very valuable information. Just click the LEARN PLCS link at the top of this page.

Another thing to be aware of is the watchdog timer. I'm not sure about omron but most PLCs have them. If the flow of the program doesn't reach the end of the last program call before the watchdog timer times out ther processor will usually fault.

This is why you can't normally hang around in a While loop waiting for something to happen, you have to keep checking for your condition on every scan. If you've ever written a multithreaded program its like that. You can't wait in one procedure or the other one(s) never get serviced.
 

Similar Topics

I am trying to use tag based alarms in Studio 5000. It seems really great at making alarms automatic. I have a few alarms that require...
Replies
0
Views
1,059
I got a problem concerning the change of coins from a vending machine plc based, i use the rs logic starter lite with Rs emulate 500 along with...
Replies
5
Views
2,077
Dear Members, I am new to S5 series PLC, In one of my application, I need to communicate S5 6ES5942-7UA12/ or S5 6ES5941-7UA12 PLC with HMI(PC...
Replies
6
Views
2,181
How can I get a rough estimate of how much memory I will need for a controller if the code is not written yet, but I know how much I/O it will be...
Replies
10
Views
3,364
Greeting, I am doing some investigations on which driver(s) support tag based addressing (eg. Pump001_Running) rather than DB or Modbus based...
Replies
4
Views
3,743
Back
Top Bottom