Increment subroutine?

jets

Member
Join Date
Feb 2017
Location
Winnipeg, Manitoba
Posts
47
I have a bender table that I am automating. I have added a Kinco HMI and PLC, I am also using an Omron encoder sensing the rotation of the table in degrees.
There is a double acting hydraulic cylinder controlling the table. I have everything working good controlling the position of the table (scaled in degrees).
My problem is I want to set up to eight bend angles. So, I have eight set-points and eight enable bits to turn on between one and eight bends. I have copied bend angle the logic into eight subroutines each with there own set-point and enable bits.
But for the life of me I can’t figure (I should say remember, I did this years ago) out how to increment or move to the next subroutine once the first one is done. Then when the second on is done move to the third and so on… Once I hit the eight bend, I want to return to the first.
In actuality we will probably only ever use a maximum of four bend angle so this may be reduced from eight positions to four.
When the table moves to position one, say 90 degrees it then moves back to zero degrees. Each of these positions has it own bit.

How can I increment through the eight bends?
 
If any more information is need please tell me what I can provide. I'm not sure exactly how to post ladder to the forum.



The Kinco software conforms to IEC 61131-3 standard.
 
The best way is to print it to PDF i.e. select Microsoft print to PDF as the printer, then below your message field if you scroll down there is a button "Attach Files" press this a small window pops up where you can add files then press submit reply. note: only certain types of file can be uploaded & depending on your membership there is a limit on size, however, you could split it if too large.
Why 8 subroutines you could put the positions in an array then point to the correct word in the array depending on position is next.
I have done this many years ago, so you have one subroutine, you look up the next position & pass it to the sub. I know we had a calibration sensor so everytime it passed it the position was re-calibrated this cn be important.
 
Last edited:
Here is an approach that assumes that some subset of eight subroutines will be toggled on or off from an HMI, then a count for how many times to run that subset will be assigned from the HMI, then a run button from the HMI silk start the cycle.

I don't think this is what OP is looking for because the subroutines can only be enabled or disabled but their relative order cannot be changed.

Also in a production program there should be some input validation of values from the HMI.

Anything that starts with HMI_ is an input from the HMI, and any HMI boolean input is set-and-forget ie the HMI only ever writes a 1 and the PLC overwrites that 1 with a 0 after it processes the input when it sees the 1.

It assumes each subroutine is called on every scan, and the code at the bottom of the page is for a subroutine to choose when and whether it is time to run itself. Each of the 8 subroutines has a bit, bendX_done (X =1to 8) to state when it is either complete or not selected to run, and that is used to inform the next subroutine when it is time to either run or set its bendX_done bit to pass control to the subroutine after that.

This is not exceptionally clean or compact, but I think it is clear enough to maybe give OP some ideas.

PXL_20220831_151600909.jpg
 
P. S. A few things that are implicit but perhaps should be stated explicitly:

- the top rung needs to be duplicated 7 more times, one for each subroutine

- the bottom rung is meant to be inserted at the top of each subroutine, or at the top of an intermediate (wrapper) subroutine that calls the actual subroutine.

- the subroutine calls are not shown, and subroutines should not be called if run is 0.

- Each subroutine will set its bendX_done bit, even if it has not been selected to run as part of the current cycle. This ensures all 8 bendX_done bits will become 1, and in order, during a single cycle, and allow the bend8_done bit to be the trigger to indicate when the cycle is complete, even if subroutine 8 is not selected to run.

- The specific logic to execute in each subroutine is not shown other than to note that bendX_done does somehow get set to 1 when the subroutine completes its bend, assuming it has been selected.

- OP may not have a RETURN instruction available, in which case a Normally Closed contact with the do_bendX bit as its operand should trigger (or skip) the call to the actual subroutine OP has written.
 
As a @parky notes, this application should probably be rewritten using arrays and indices, to make it much easier to handle running subsets of the available bends and in any sequence.
 
Hi,


Thanks for the replies. I am just going to clean a thing or two up and then save the files to.pdf. I will post today or tomorrow.



I like the idea of the array but no 100% ho to do that. Dr bit boy I will show you have I have done already I think it's similar to what your saying. Back shortly :)
 
This should help. "x18" and "zero" are initial value stored in memory.I use zero as the return to the zero position of the table and x18 as 2000PPR (encoder) X 18 for 36000 or 360.00 degrees on HMI.


See attached Main and Position PDF, I have reduced the number of positions from eight to four.

P1020693.jpg P1020694.jpg
 

Attachments

  • main.pdf
    82.6 KB · Views: 16
  • PostionSubroutine.pdf
    72.2 KB · Views: 20
I think you need a way to ensure that only one of Pos1 through Pos4 can be 1 (enabled?) at any time, otherwise your main routine will call multiple bend subroutines on each scan.

If a given bend routine is not to be executed, then it gets messy, because, for example, how does bend subroutine 3 know to wait for 1 to finish before starting 3, instead of waiting for 2 to finish if 2 is not enabled?
 
The bend routine will have to be enabled in order by the operator that is 1-2 (two bends) 1-2-3 (three bends). 1-4 is not valid as is 1-3 not valid or 1-4 not valid. Valid would be 1-2, 1-2-3, 1-2-3-4 after 4 back to 1-2-3-4 and so on...



Unless there is simple logic to do it in any order from low to high and then back to start (low)?
 
I'm a little confused but here is my take on it, tere are certain bends in order that can be valid i.e. 1-2, 1-2-3, 1-2-3-4, & so on. Even if it was possible i.e. reverse order them (sounds like you do not want to) or even 1-3-4 or what ever, just create a map of the legal combinations, search though them & compare with operator input then put the numbers in an array, cycle through the array as and use compares to run the sub routine.
so if there was 4 bends & 4 combinations then that is a 4 x 4 matrix,
Op_Code_1 = 1
Op_Code_2 = 2
Op_Code_3 = 3
OP_Code_4 = 4
The above operator codes correspond with MapArray_4[0-3]
MAP_Array_1[0] = 1
MAP_Array_1[1] = 2
MAP_Array_1[2] = 0
MAP_Array_1[3] = 0

MAP_Array_2[0] = 2
MAP_Array_2[1] = 3
MAP_Array_2[2] = 0
MAP_Array_2[3] = 0

MAP_Array_3[0] = 3
MAP_Array_3[1] = 4
MAP_Array_3[2] = 0
MAP_Array_3[3] = 0

MAP_Array_4[0] = 1
MAP_Array_4[1] = 2
MAP_Array_4[2] = 3
MAP_Array_4[3] = 4
I would do it in a loop but could be done by brute force
Map_Array_1[0] = Op_Code_1 AND Map_Array_1[1] = Op_Code_2 AND Map_Array_1[2] = Op_Code_3 AND Map_Array_1[3] = Op_Code_4 then it's valid
do the same for all valid codes, put the one that matches into a working array & for each operation point to the working_Array & use that in order to run the routines.
Then step through this array,
Use the values in compares to enable the subroutine
i.e. Step 1, put Work_Array[0] into the Current_Step variable
Current_Step = 0 step on
Current_Step = 1 Run step 1 routine
Current_Step = 2 Run Step 2 routine
Current_Step = 3 Run Step 3 routine
& so on.
So depending on the values in the work array it runs the bending routine required.
 
Here is a quick idea, There is an array 8 x 8 in other words 8 bends, 8 different patterns bends 1-8. not that you need all these but this is fixed data as lookups.
So the operator enters the 8 possible bends (I have done it so they do not have to be in order, just to show how flexible it could be, operator presses the check button it loops through the columns of the 8x8 stored patterns, if it is a valid pattern then stores the pattern in the work array, if not it zeros the operator data & displays a message that dissapears after 3 seconds, if ok that allows the start, the seq word is zero pressing start puts a 1 in the seq word, this calls the first bend function, in that it checks it's not zero, if so it jumps out & increments the seq word to the next one, if it's not a zero, then it would do the bend what ever that was (note: as I indicated this is capable of doing then in any order provided it matches the stored patterns). here I just have a timer to simulate it so cn see the functionallity. when it completes it's task, it increments the SEQ word, this then calls the next sequence so if any of the sequences are 0 then it skips if not it runs, not re-zeroed the seq as we are only showing 2 here but expect when SEQ word reaches 9 it is reset.
It only took me about an hour & half to code this so perhaps a bit un-documented & could be better but gives you an idea.
 
The bend routine will have to be enabled in order by the operator that is 1-2 (two bends) 1-2-3 (three bends). 1-4 is not valid as is 1-3 not valid or 1-4 not valid. Valid would be 1-2, 1-2-3, 1-2-3-4 after 4 back to 1-2-3-4 and so on...



Unless there is simple logic to do it in any order from low to high and then back to start (low)?


The code I provided in post #4 of this thread, or something similar should be able to execute those 3 valid patterns, including restarting at bend 1 after the last bend.
 
One thing I'm not clear on is it 1-2 then back to start then 1-2 again i.e. the recipe is for 2 bends so that is all it does. If a recipe for 1-2-3 then it does this repeatedly & so on.
Regardless of how many bends 4 or 8, I certainly would use a sequence word to step through. so we have steps 1-4 (or 8) or what ever, the operator enables these on the HMI by putting either a value for each bend or just a false or true. for example if only 2 bends are required i.e. 1 & 2 then bend 1 & bend
& 2 field will be true (or a number) If it's 2 & 3 then only 2 & 3 fields are true & so on.
So on starting, if conditions are good, put a 1 in the seq word
so then to conditionally call each bend subroutine first it calls Bend 1, If there is an enable for bend 1, if not then increment the seq word so it does not call that routine in the routines when they complete it increments the seq word by 1, next scan the seq word is 2 so this enables bend 2 subroutine & so on if enabled.
If this is a repeat process i.e. once started, it goes back & does it again, until stopped or an amount of pipes has been reached etc.
If a bend is not required for example 1-2-3 is but 4 (and the rest is not) then when the seq word reaches 4, before it calls sub 4 it checks if it is wanted, if not it skips to 5, same goes for any others i.e. 6-7-8 then perhaps step 9 is the routine to return back to start, if a continuous process then the return routine will move 1 into the seq word ready for the next bend.
 
The touch screen will have four (I don't think we need eight) but I have written the bits and variables up to eight.
So, if bend01 is turned on only one bend will happen. If bend01 and 02 turned on then the first bend will be preformed with a touch of the forward then backward button, then once forward is pressed again then bend02 is done...
Each with the corresponding set-point(xx). If three bends are turned on then there will be three bends (all different set-point) at the end of bend three the next bend will be the first bend. Depending on the number of bends selected on the HMI it will cycle through the selected amount of bends by turning on the bit next to the set-point on the HMI.


Edit: What you are saying above Parkey is true yes.
 
Last edited:

Similar Topics

Hi, Am I being daft (again)? I want to increment a tag (Integer) by 1 each time a button on the HMI is pressed. Before the button press, the...
Replies
22
Views
2,370
Hi, I have a stand alone inspection unit with no PLC but I can send 24v input signals to the machine PLC to show a good read and a bad read when...
Replies
9
Views
780
The attached pdf shows a CPT instruction that should calculate the value of tag Cell_Charge_Percent_Remaining[1]. I've included the relevant...
Replies
4
Views
1,529
I have a considerable amount of modbus register data tags from a plc already setup in crimson. I have them setup in alphabetical order with...
Replies
4
Views
2,095
I am using the Library Designer tool to create PLC code. One of the standard routines that our company uses for simulation has individual XICs...
Replies
0
Views
1,514
Back
Top Bottom