I have an Allen Bradley control logix PLC connected to a Keyence IV2 sensor. The ladder logic should automate the following steps:
1. Tell the sensor to run
2. pull the trigger to take the image.
3. If the overall position of the image is equal to or greater than 80
a. Continue or
b. Send a fail message or retake the image if less than 80
4. Once the image is => 80, the sensor should stop running.
5. the program number (what number of image we are on) should increase by one
6. Now that we are on the next image, the same steps should be taken.
These steps should be able to repeat about 15 times. It did not seem that the ladder logic needs to be that complex, but I guess I was wrong. The only way I can get the steps to execute is when I use the controller tags and change the value of the corresponding tags from 0 to 1. I also cannot figure out how to increase the program number by one each time, since they are all DINTs.
That description needs to be expanded from a general description to specific single steps. To wit,
1. "tell the sensor to run"
2. "pull the trigger to take the image."
3. "If the overall position of the image ..."
Hol' on there Baba Louie: that is more than three steps...
Caveats
- The approach below is intended for illustration only
- The approach below uses PLC INTeger tag STEP to hold sequence step numbers
- The sequence step numbers should increment by 10, not by 1, so additional steps could be added to make the program more robust e.g. for error handling
- The approach below uses the [EQ STEP n ...] notation; in an actual ladder program all logic for each step would probably be on one rung with branches
- A cleaner approach using booleans was recently posted here (https://www.plctalk.net/qanda/showthread.php?p=887257#post887257).
- It is cleaner because it isolates the step transition logic, which uses the same pattern for each step, from the logic to be executed at each step.
i. RUN_SENSOR - it is not clear what "tell the sensor to run" means, but I will guess it means:
i.a. Put the current program number, PLC INTeger tag PROGNUM, either
i.a.1. into IV2:O.DATA[2] (INTs),
[EQ STEP 1 MOV PROGNUM IV2:O.DATA[2]], OR
i.a.2. into the low 16 bits of IV2:O.DATA[1] (DINTs)
i.b. Set current step to step ii.
[EQ STEP 1 MOV 2 STEP]
ii. WAIT_FOR_NOT_BUSY - When the IV2-BUSY bit (which may be IV2:I.DATA[1].2 for INTs or IV2:I.DATA[0]18 for DINTs) is 0,
ii.a. Switch to step iii.
[EQ STEP 2 XIO IV2:I.DATA[1].2 MOV 3 STEP]
ii.a.1. N.B. This prevents a trigger error
ii.a.2. N.B. This Step ii is the target for a failed image i.e. result score less than 80
iii. TRIGGER - The IV2-BUSY bit is 0 at this point and an image should be taken and scored, so
iii.a. Change the PLC trigger output (IV:O.DATA[0].0?) from 0 to 1,
[LIM STEP 3 4 OTE IV2:O.DATA[0].0]
iii.b. Set current step to step iv.
[EQ STEP 3 MOV 4 STEP]
iv. DETECT_BUSY - When the IV2-BUSY bit (which may be IV2:I.DATA[1].2 for INTs or IV2:I.DATA[0].18 for DINTs) becomes 1,
iv.a. Change the PLC trigger output from 1 to 0 (this will be taken care of by the
[LIM STEP 3 4 ...] in step iii above)
iv.b. Set current step to step v.
[EQ STEP 5 XIC IV:I.DATA[1].2 MOV 5 STEP]
v. DETECT_NOT_BUSY - When the IV2-BUSY bit (which may be IV2:I.DATA[1].2 for INTs or IV2:I.DATA[0].18 for DINTs) is 0,
v.a. Read the IV2 score into PLC tag SCORE from either
v.a.1. IV2:I.DATA[36] (INTs),
[EQ STEP 5 XIO IV:I.DATA[1].2 MOV IV2:i.DATA[16] SCORE], OR
v.a.2. The low 16 bits of IV2:I.DATA[18] (DINTs)
v.b. Set current step to step vi.
[EQ STEP 5 XIO IV:I.DATA[1].2 MOV 6 STEP]
Now that the current image score is available in PLC INTeger tag SCORE, the remaining logic is straightforward:
vi. CHECK_SCORE - Check the value of PLC tag SCORE, and
vi.a. If the SCORE is >= 80, set current step to step vii.
[EQ STEP 6 GEQ SCORE 80 MOV 7 STEP]
vi.b. If the SCORE is < 80, set current step to step ii, to re-take and re-score the image
[EQ STEP 6 LES SCORE 80 MOV 2 STEP]
vii. INCREMENT_PROGNUM - The score was >= 80, so
vii.a. Add 1 to PROGNUM.
[EQ STEP 7 ADD PROGNUM 1 PROGNUM]
vii.c. Reset prognum after some number of programs have run e.g. 7
[GRT PROGNUM 7 MOV 0 PROGNUM]
vii.b. Set current step to step i.
[EQ STEP 7 MOV 1 STEP]
Notes
- I assume the IV2 is set up for an external trigger
- It makes sense to read the IV2 Ethernet/IP UDT as INTegers, not DINTs, see below: