Shift register help, Siemens s71200

Not sure what you mean, there is only one shift register, so can only have one divert, if a box has a "6" in it then it can only go down one cross lane (Lane6).
 
I don't have TIA14 loaded on my laptop so I put it on TIA13SP2, man was that primitive compared to 16.
I imported a tested code but I couldn't test the simulation blocks on TIA13 because PLCSIM crapped out for some reason.


So instead of just checking for duplicates I decide to test for count values that are too close based on a settable value.
The justification for that is that depending on how fast things are moving and encoder resolution I may a get two values that are too for the scan time. LINK
 
I had some time on my hands, just done some experiments (Mitsubishi Q series), used the block move for 500 registers just made the destination +1 from the source, no other program and the scan time was 0.6ms, Tried with shift register, & the scan time went up to 2.4ms. Then tried a for next loop & same result 2.4ms, so as for scan time it only makes just less than 2ms above the scan time of the block move, in reality this is not going to cause a major difference unless the pulses are less than the scan time. but block move in this case was certainly the fastest, I tried adding the block move to a reasonable sized program & the scan time only increased by 0.4ms.
Not been able to try this on any other platform so cannot verify what functions will increase the scan time more, It appears on Mitsubishi the block move compiled code is the most efficient, however, it appears that the shift function must be producing similar code to the for next loop which is in ladder.
 
Here is my suggestion, I have based it on what I understand, basically the code is no more than 50 lines I did in a bit of ST for the shift (although on my Mitsi simulator could have done it in all ladder or FBD & it could have been smaller as it has word and bit shift that's easy to use.
Not going to post the code as it is only a test but here is what I consider a one lane to 6 take off conveyors, the operator decides where the pack is going to be diverted to and presses one of the six buttons, this loads the shift register with the lane number, when it reaches that lane the register at that position is compared with the lane number an diverts the pack down that lane, not bothered to delete the value in the shift register as it falls off the end of the shift eventually.
As I said this is only a test and is limited to 28 shifts on the screen for demonstration but the shift register is currently 1000 words.
Here is a screen shot taken during the running & a couple of diverts working shown by a lamp being green.

This is exactly the way I have been looking to implement the control, did you do this in a similar way to @drbitboy’s code?
 
No I wrote it before he did, but never posted it, and I never bothered to save the code,
Here is a homemade shift register using pointers
SET(Trigger,Pulse); (*Set the bit to run the logic *)
IF Pulse
THEN
Index:= 63;
FOR Loop_Count:= 0TO 63 DO;
Last_Index:= Index-1; (* need to point to the array - 1 as well as the array pointer *)
My_Array[Index ] := My_Array[Last_Index];
Index:= Index -1; (*Decrement the index pointer *)
END_FOR;
Pulse:= FALSE; (* Reset the trigger & pulse flags *)
Trigger := FALSE;

END_IF;
Also,
Here is a quickie I did in FBD that shows a simple (only two diverts shown).
 
Here is another way of doing it using block copy, only thing is you have to zero the first word in the array or every shift would put the same number in.
By copying the block from word zero to word one shifts the data by one all down the line, not sure if this works on all platforms as will depend on how it copies it but in theory it does it in reverse order you would need to try it on S7.

Shift using a block copy.png
 
This is exactly the way I have been looking to implement the control, did you do this in a similar way to @drbitboy’s code?


It looks like @parky is shifting integer valuess through the position in an integer shift register, which values may be a code for a lane number. Each code will trigger a divert when it is in only one constant position (index) of the shift register.



My implementation was based on bits; bits in integers to be sure, but bits nonetheless. Because my non-shifting register is static and the code is incrementing ("moving") the index, my code


  • assigned 1-bits at an offset from the index
    • @parky's code always writes the code at Register[0] at a certain time
  • triggered divert(s) when 1-bit(s) were found in the integer at the varying index
    • @parky's code triggers a divert when the value at a non-zero index (position, offset in the shift register) matches the code for a divert, and that index for each diverter is constant for each diverter
  • had to clear any bits after they triggered a divert, or else those bits would still be 1 the next time the index rolled around
    • @parky's code did not have to clear the non-zero codes as they were ignored at all indices other than the index for the divert for which they were intended, and would eventually drop off the end (be overwritten, actually).
  • had to use one bit per divert line, not (bar) codes, because multiple diverts could be stored in each integer
    • @parky's code could use multi-1-bit codes
Other than that, they are basically the same.
 
DR: not bits words so the operator enters the lane number on the HMI (for convenience I have put 7 buttons so each button will put 1-7 in the array at position 0, when the shift is triggered this shifts the data down the array If you think about the conveyor just being a load of words in the array i.e. one foot of the conveyor = one location in the array so if the diverts were spaced every 20 feet then divert 1 = array[20]. divert 2 = array[40] & so on. so by comparing say array[20] with 1 if true then run divert code & the same goes for the other 6 diverts.
I have done a number of ways to create a "WORD" shift register, i.e. Use in-built (but I don't think S7 1200 has one), the other is to use a loop in ST.

SET(Trigger,Pulse); (*Set the bit to run the logic *)
IF Pulse
THEN
Index:= 63;
FOR Loop_Count:= 0TO 63 DO;
Last_Index:= Index-1; (* need to point to the array - 1 as well as the array pointer *)
My_Array[Index ] := My_Array[Last_Index];
Index:= Index -1; (*Decrement the index pointer *)
END_FOR;
Pulse:= FALSE; (* Reset the trigger & pulse flags *)
Trigger := FALSE;

END_IF;
;

The other is to use MOVE_BLK this could copy say 500 words of array to the same array but shifted by one location
i.e.

MOVE_BLK
IN = Source address (Array[0])
IN = Count (500_
OUT = Dest (Array[1])
So many ways to achieve the same thing
 

Similar Topics

Hi I am fairly new to codesys 3 but I'm currently trying to make a little project using 4 cameras, a sensor and a conveyor belt each camera take...
Replies
7
Views
3,681
Posted previously but had the wrong info, hoping to get new advice. Being a mechanical engineer, I'm not very experienced with PLCs, and what...
Replies
7
Views
2,449
I'd like to start by saying that my background in engineering is mostly mechanical, and I have a tiny bit of experience with AB and RSLogix (to...
Replies
10
Views
2,648
Hello dear experts! just started learning STL and tried writing a program that writes the status of a particular bit M0.1 on 80 bits of...
Replies
2
Views
1,752
hello people, im totally NEW in plc. i'v read reference of ladder diagram (OMRON PLC CPM1A-20CDR). why do people use 253.14 as data input of...
Replies
6
Views
4,561
Back
Top Bottom