PLC and Keyence sensor Ladder logic

hurricaneapa

Member
Join Date
Jun 2021
Location
Meadville
Posts
7
Disclaimer, I do not know much about PLC’s, and am completely stuck on how to proceed, so any help is appreciated!

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.
 
Put the sensor in RUN mode from IV2-Navigator.

For trigger just use a tag that when high fires a ONS to the trigger output that is sealed in with the trigger output until you get the trigger ACK back from the IV2. I use the trigger ready input as a pre condition before I fire the trigger as well. Use a 100ms pulse after your internal bit so you keep firing the trigger every 100ms. My IV2 processes in 62ms so 100 works for me just fine.

I am using SIEMENS so I get a word back of the score for tool 1. If you are using multiple tools then you need to look at them all.

Let your trigger keep firing until your score is >=80 then turn off your internal bit you are using for trigger.

For SIEMENS to change program number on the IV2 you move a value into the output word for program number then you fire the change program output bit until you get the change program ACK input back to go high then you stop firing the bit.

You will then just need to write a small sequence to do this. If you are new to PLCs then just keep it simple. IF sequence step is =0 then start sequence. Move a 1 into sequence step. At step 1 fire your trigger and wait until you get your score. Once you get your score >=8 then move a 2 into your sequence. Keep on going from there. For me it's easiest to write out my sequence I want then put it in the logic. Don't try any FOR loops or using a indexing value for any indirect addresses to try and be fancy.

If you need more help send me your program and I will help any way I can.
 
N.B. those are my PLCtalk.net signature; they are appended to every post I make. They are not as funny as others'.


what does indirection mean?
E.g. cam tables and multiplying by unity.
what do you mean by take care of the bits?
It's a play of words on the old saw: "Take care of the pennies, and the pounds will take care of themselves."

Bytes comprise bits, so if we (or our code) know where and what the bits are, and can be, then we don't need to worry about the bytes.
 
Last edited:
I'm not sure what ACK is, or what the AB equivalent is. I also can't figure out pulses either. I will look into sequence now though, but I do not think that worked before due to the format of the text
 
Per KEYENCE your tags(IV2 tagfile) are labeled as follows:

Trigger response
Master registration response
Program switching response
Warning clear response
Statistics reset response
Buffer clear response
SD Card Saving Stop
Threshold changing response
 
Disclaimer, I do not know much about PLC’s,
...
the following steps:
1. ...
...
6. ...

A PLC, when in any RUN mode, RUNs the same program (i.e. statements or ladder rungs, comprising instructions connected by logic), left to right and top to bottom, again and again, typically anywhere from 10 to 1000 times per second depending on program complexity. Each single pass over the program is called a scan.

At some points in time, while running the program, it reads inputs and writes outputs.

Each statement or rung in the program will typically examine the current state of one or more of the inputs, as well as examine the state of internal tags (neither inputs or outputs), and assign various values to one or more outputs and/or to one or more internal tags.

The important thing to understand is that ALL of the statements or rungs in the main program are processed on EVERY scan. The behavior of each may change from scan to scan as the values inputs, outputs, and internal tags change, but, again all are processed on every scan.

The result of this is that the program that performs the process steps the OP describes must have at least one statement or rung dedicated to each process step. Each may be arranged so that the logic for step N does nothing when the process is at step M. But all will be processed on each scan.

I highly recommend watching @Ron Beaufort's basic youtube series here; it takes less than 2h to watch and is well worth the time. Another excellent resource is Patterns of Ladder Logic Programming here; ladder programmers use those patterns over and over in various forms.
 
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

  1. I assume the IV2 is set up for an external trigger
  2. It makes sense to read the IV2 Ethernet/IP UDT as INTegers, not DINTs, see below:
xxx.png
 
Last edited:
[/LIST]

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]

...


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]

Thank you for the response, as it is very detailed. I think you are on the same page as me, for as how the ladder logic is intended to be written. I guess I should add that I have very little understanding on how to execute that all in ladder logic. I have knowledge in writing code, but not ladder logic.
If you would be able to assist with that actual part that would be great.

In regards to DINT vs INT, we were provided tags from Keyence, as excel files. I think I worded myself backwards, I believe they told us we would be using DINT, but INT was the correct file. We had to set up as INT because that file provided all of the controller tags we needed, unlike the DINT file. Also when we had set up as DINT, I could not get the PLC and sensor to function correctly through changing the tags from 0 to 1, like I can while set as INT.
 
Last edited:
...
I have knowledge in writing code, but not ladder logic.
If you would be able to assist with that actual part that would be great. ...

If you have ever programmed in GAWK, you can think of a PLC program as a GAWK script, where a token-ized ($0, $1, ..., $NF) input line is one of a never-ending stream representing the PLC's inputs' states for one scan, and based on those inputs, plus the outputs and any internal variables from after the previous input line (scan) was processed, the GAWK script updates the values of those outputs and internal variables.

Here is an example of how the Allen-Bradley shorthand can be used to create rungs of logic from the mnemonics in my previous post*. Basically every instruction is a function with a fixed argument list, and each instruction mnemonic or argument is a token with no spaces, so each rung can be represented as a sequence of space-separated tokens.

* N.B. I used EQ instead of EQU, so that will need to be adjusted.


xxx.png

Defining the tags (variables; INTs, BOOLEANs, IV2 structure, etc.) is left as an exercise for the user; I expect there are plenty of youtubes giving examples.
 
Last edited:
If you have ever programmed in GAWK, you can think of a PLC program as a GAWK script, where a token-ized ($0, $1, ..., $NF) input line is one of a never-ending stream representing the PLC's inputs' states for one scan, and based on those inputs, plus the outputs and any internal variables from after the previous input line (scan) was processed, the GAWK script updates the values of those outputs and internal variables.

Here is an example of how the Allen-Bradley shorthand can be used to create rungs of logic from the mnemonics in my previous post*. Basically every instruction is a function with a fixed argument list, and each instruction mnemonic or argument is a token with no spaces, so each rung can be represented as a sequence of space-separated tokens.

* N.B. I used EQ instead of EQU, so that will need to be adjusted.


View attachment 58638

Defining the tags (variables; INTs, BOOLEANs, IV2 structure, etc.) is left as an exercise for the user; I expect there are plenty of youtubes giving examples.

I think from what you had posted in your previous post and here, was all super helpful! I went into my ladder logic and was able to recreate. First, I still need a way to pull my trigger so it captures the image. Should I put that in the first rung? should it be an XIC or ONS or something else, and why? Next question is what is the meaning behind the name prognum? Because I have controller tags that mean "program number" and "program change" - when I subbed in those tags for the prognum, nothing really happened. Then, my very basic question is, how do I get my program to run without changing the tags from 0 to 1 or toggling bits?
 
I think from what you had posted in your previous post and here, was all super helpful! I went into my ladder logic and was able to recreate.
Wow, glad to help.
First, I still need a way to pull my trigger so it captures the image. Should I put that in the first rung? should it be an XIC or ONS or something else, and why?
The step labeled TRIGGER should be pulling the trigger: it puts a 1 in bit IV2:O.DATA[0].0 when the Keyence trigger should be active (when STEP is 3 or 4), and puts a 0 in that bit otherwise.

However, I assumed the program is using that IV2: structure/data block/UDT/whatever-I-don't-know-the-jargon. Are you saying you are using a physical PLC output connected to a physical IV2 input to execute the trigger?

Next question is what is the meaning behind the name prognum? Because I have controller tags that mean "program number" and "program change" - when I subbed in those tags for the prognum, nothing really happened.
The original post mentioned a "program number" that needed to be incremented after each image that results in a score of 80 or more; the PLC-local storage for "program number" is the INTeger tag PROGNUM.

I assumed that was a reference to a program number in the Keyence (p000, p001, ..., p031), e.g. see [Overview of the program functions] on page 7-3 of the [IV2 Series User's Manual (Control Panel)].

After a score of 80 or more with p000, the next image should used p001, etc.
Then, my very basic question is, how do I get my program to run without changing the tags from 0 to 1 or toggling bits?
If the PLC is in RUN mode (i.e. the "GAWK" program is running), then, after the INTeger tag STEP first becomes 1, the rungs I proposed will, I hope, automatically cause the Keyence to start taking images, and advancing the program number on scores of 80 or more.

If assigning a 1 to STEP does not start that process, then I misunderstood the Keyence documentation and the youtube example, and you are on your own, because I have neither a clue nor a device to test. Your best bets at that point would be to ignore me from now on and to adapt the program shown in the youtube video linked earlier. You could also dump the program into a PDF and post it here and maybe someone can figure out what is needed to make it work.

How the tag STEP first becomes 1 is up to you: there could be either an HMI interface, or a physical pushbutton connected to a PLC input that triggers a rung, to assign a 1 to that STEP tag.

As a test without any HMI or pushbutton, you could use Studio 5000 to

  1. put the PLC into RUN mode,
  2. put Studio 5000 into its Online mode with the PLC,
  3. and then write a 1 to the tag STEP,
At a minimum STEP should immediately change to 2 to wait for the BUSY bit (IV2:I.DATA[1].2) to become 0.
 
Last edited:

Similar Topics

Has anybody worked with these IX sensors? I'm trying to use one with a 1769-L32E processor (running version 20) but the PLC won't recognize it...
Replies
4
Views
1,953
I ma trying to measure a 0.4 difference back to the PLC. I can read the data but my scan speed of the PLC does not pick up the spikes I can see...
Replies
0
Views
2,459
Hey guys, has anyone worked with any type of Keyence PLC and could share their experience with it? Vendor showed me camera footage reply of a work...
Replies
7
Views
1,170
I have a project I am designing a quote for an upgrade on. Per the schematic, the PLC I saw and an upload I took, it is run by an AB MicroLogic...
Replies
6
Views
2,678
I have been hung out to dry by Keyence. If I had to do it all over again, I would NOT choose Keyence. They have done nothing but lead me in the...
Replies
0
Views
956
Back
Top Bottom