Is it possible to program this onto a Click PLC? If so, I need help anyway.

Quick question. I am making the program now with subroutines, I have one problem where I think things will go wrong. One of the subroutines has a counter inside it and is reset when the sequence goes back to 0. If this is inside the subprogram and later on in another subprogram the sequence flips back to 0, will this counter recognize that it flipped to zero? Or does this counter need to be in the main program to recognize it. In easier words, will this counter reset if another subprogram changes the sequence to 0?
 
Quick question. I am making the program now with subroutines, I have one problem where I think things will go wrong. One of the subroutines has a counter inside it and is reset when the sequence goes back to 0. If this is inside the subprogram and later on in another subprogram the sequence flips back to 0, will this counter recognize that it flipped to zero? Or does this counter need to be in the main program to recognize it. In easier words, will this counter reset if another subprogram changes the sequence to 0?

If you just use subroutines as a means of splitting the program up into logical sections and call them all every scan (no input conditions on the CALL rungs in the MAIN) then the execution will be exactly the same as it would be if all the rungs were in one program.

Scan order in the Click (and most other PLCs) is top to bottom, left to right. This little PLC will run all the logic in the order you tell it to, hundreds of times per second. I can analyze your concern about the order of things with your counter if you can share the ckp file (zip it first to meet forum rules for file types).
 
...In easier words, will this counter reset if another subprogram changes the sequence to 0?


As @OkiePC says, yes.

The code memory and the data memory are "separate," if you will.

The Data Registers (data memory: DS1-DS4500; C1-C2000; T1-T500, X001-Xnnn; Y001-Ynnn; etc.) are all "global," where global means that all subprograms have access to the same bits in those same memory locations via the same Address names (DS1, C1, DF2; etc.) and nicknames (Seq step, HMI_Start Button, Pressure of Water, etc.).
 
For example, in Post #88, in the first image, look at Subroutine 00 First Scan: Rung 2 writes a 0 as the value of the (bits composing the 16-bit signed) integer Address/Nickname DS1/Seq step.

Until that value is changed, that value of 0 will be used by every reference to DS1/Seq step in the Main Program as well as in every subroutine called by the Main Program.
 
So any emergency process needs to be put on the main program. If I put an emergency procedure in a sub routine the emergency features will only enable in that sub routine? Or if I putt it in the main program, at any point during any subroutine if the emergency processes are true then they will execute correct? I will send my program over soon almost done with it but I have a couple questions. Mainly about the emergency process like if there is a overpressure. How do I attach a zip file here? Do I have to pay for that, because I can only attach images and links
 
Last edited:
The code executes the main routine from top left to bottom right,
So it starts in the first rung and processes to the right when it reaches the end of that rung it starts on the next rung, if that rung calls a subroutine it does that and then goes to the next rung and so on until it gets to the last rung, it will go back and start with the first rung again.
It will do this continuously until you turn it off.

There will also be house keeping functions that will be done during the last rung before it does the first rung again.
 
Last edited:
... How do I attach a zip file here?
See here. Don't forget to upload.

I suggest that, in addition to a .ZIP with the .ckp Click program, you attach a PDF of the code; you should be able to Print the project and choose [Microsoft Print to PDF] as the printer on the Print dialog menu, and then when you press the [Print] button, Windows will prompt you for the name of the PDF file to which to print.

Do I have to pay for that
No, but you do have to be signed in to your PLCtalk.net account.
 
The code executes the main routine from top left to bottom right, ...


It will do this continuously until you turn it off.


@Aljubovic: you need to understand the scan cycle; if you do not understand what the scan cycle is and/or what @alan_505 wrote above, then stop whatever you are doing and learn about the scan cycle.

If you do understand the scan cycle, then ignore this.
 
So any emergency process needs to be put on the main program. If I put an emergency procedure in a sub routine the emergency features will only enable in that sub routine? Or if I putt it in the main program, at any point during any subroutine if the emergency processes are true then they will execute correct? I will send my program over soon almost done with it but I have a couple questions. Mainly about the emergency process like if there is a overpressure. How do I attach a zip file here? Do I have to pay for that, because I can only attach images and links




The code in the main program, along with any code in subroutines called by the main program, are executed repeatedly and continuously via the PLC scan cycle; all such code is evaluated, and re-evaluated, and re-evaluated again, at several hundred if not a thousand Hz.

So if you have a subroutine coded with emergency "features" (i.e. behavior), and at some point in the Main Program there are CALL instructions to that emergency subroutine, then that emergency-related code in that subroutine will execute and the emergency logic will be evaluated perhaps as many as one thousand times per second.

If you put that CALL instruction to the emergency subroutine at the beginning of the Main Program, then if the emergency logic changes anything that would affect the Main Program (e.g. reset Seq step value to 0), that will be detected by the Main Program in that same scan cycle.

If you put that CALL instruction to the emergency subroutine at the end of the Main Program, then if the emergency logic changes anything that would affect the Main Program (e.g. reset Seq step value to 0), that will be detected by the Main Program on that next scan cycle, which will execute in one (or a few) milliseconds later.
 
Okay I finished but it's unrevised and probably messed up doing the subroutine calls and returns because I don't know how they work. Just to remind you this is my second program ever so it will probably be full with errors.
I do understand how the scan cycle works. I was just confused about subroutines and if they would interfere with some functions.

I cannot upload the zip file because my work does not allow it and block that and I can't upload the PDF either so I have to go to a website to link it . The best I can do is send the PDF through link.
I put 2 questions I had on the rung I was interested in, check the comments on these rungs.

Rung 6 in the main program which asked is this the best place to put it. I think yes because it's one of the first things scanned and
It will execute quick if there is an overpressure.

Rung 1 in the sequence 30 subroutine asks if the sequence number is set to 0 at any point in the main program or any of the subroutines, will this counter reset.
I understand scan cycle but I don't understand sub routines that much and if they only get scanned when they get called, but now I will know.

Here is the link to the pdf:
https://online.flippingbook.com/view/872456753/

edit: I already spotted 1 error, on sequence 0 subroutine rung 2, the value is supposed to be Real PSI value, not sequence number. I changed it
 
Last edited:
FYI: the six rungs, four of which are conditional, of subroutine 0 Pre Start Check can be reduced to the five unconditional rungs below.
Untitled2.png
Now that you understand the scan cycle (and well done), you need to think about boolean logic.

This rung:
Untitled.png
States, in prose:
IF the value of Y002 is 1, then ASSIGN 0 to the value of Y001.

There are only two possibilities:

  • if Y001 has a value of 1 before this rung,
    • then the expression evaluates to True,
    • and 0 will be assigned to the value of Y001,
    • so after this rung Y001 will have a value of 0
  • if Y001 has a value of 0 before this rung,
    • then the expression evaluates to True,
    • and there will be no assignment to the value of Y001,
    • but the value of Y001 was already 0,
    • so after this rung Y001 will have a value of 0
So no matter what the value of Y001 is before this rung, the value of Y001 will always be 0 after this rung.

Which means the presence of the if expression has no effect on the final result, so the [if <expression>] can be removed from the prose version of this logic, and the NO Contact can be remove from the rung version of this logic.

The same logic holds for Y002. And since original rungs 3 and 4 will always assign values of 0 to Y001 and to Y002, original rung 2 is unnecessary as well.

And since Y001 and Y002 will always both have values of 0 after original rung 4, the conditional NO Contacts on original rung 5 will always evaluate to True, so those NO Contacts can be removed as well.
 
Last edited:
I understand. Yea I messed up there, if the system had pressure in it then the valves would open, but in the next 2 rungs the valves also would open so I see my problem there. Idk how I didn't realize putting an NO contact for a valve then right after putting a reset for the valve would cause it to go in a never ending loop. I will look at the rest of my code, but the main thing I am worried about is the layout of everything. I don't want emergency procedures and key parts of the system to not execute because of the scan cycle. I put all the emergency things at the top of the main program, some of the subroutines I am worried will glitch out if a emergency stop happens. I will keep snooping to see what I can catch in the code but help is appreciated.
 

Similar Topics

Hello. I have been trying to crack this one without success and could not find any hint after several search attempts. I wonder if any CODESYS...
Replies
4
Views
3,932
Hello, I'm pretty sure I know the answer to this, but wanted to verify with the experts. Am I able to write a program using the Micro Starter...
Replies
7
Views
3,159
First off, i am new to ladder logic. I do have some experience programming microcontrollers in C. I will try and give a short version and if more...
Replies
7
Views
2,022
This is a CompactLogix L33ERM, version 30 (31 is too unstable on my machine to work with), with a Kinetix 5500 drive. I have a program where...
Replies
2
Views
2,006
Good morning guys! I have a doubt. I uploaded a program from a S7-200xp on the field and took it to the office. Before doing any test I tried to...
Replies
7
Views
2,156
Back
Top Bottom