# Thread: Transferring a Counter Value

1. ## Transferring a Counter Value

Hey all!

Well, I've got another interesting question for you.

How can I transfer a value from a ladder logic counter to my NC? I would like to use a custom M-code to count the holes in a part, and then return this to the NC. I will be making some decision logic on further machining depending on the numbe rof holes I find.

I can transfer individual bits, I know, by setting the G1054.0 -> G1055.7 bits to change the state of #1000-#1015. However, those are only 1's and 0's, right?

I want to transfer a number like, say, "9", to one of the custom macro variable values, say, #134.

I need this, because my NC code would say something like:

IF[#134LT12]GOTO 45
...

The number in #134 would come from my counter.

Please, if you can help me out, I'd appreciate it!

Thanks!

2. I am not a ladder guy so I can't answer how to transfer numbers from the ladder to a variable. Is there a reason why you can't count the holes that you are doing by using the variables? I write a lot of macros and just have a variable counter every time that a hole has been completed. This will continue to count until it has reached the number of holes set to be machined, then end.

#134=#134+1
IF[#134LT12]GOTO45

There are so many ways to do this with just NC programming. By the looks of it you want to do 12 holes equally spaced 30deg apart. I would take it a few steps further and just have a variable that specifies how many holes you want to do and let the program calculate and figure out the spacing and when to stop. You can also set it up to start on any hole that you want and it will finish the proper amount of holes.

Stevo

3. You say that you're trying to "find" the number of holes in a part using the PC ladder ?? How do you plan to do this, with a touch-probe? A vision system?

If you want to transfer an integer value to a macro variable, you can use the PC ladder logic to set the 16 macro inputs UI0 thru UI15 as a binary number, then read macro variable #1032 in your macro. #1032 will return the binary value of those 16-bits.

0 = Ui0 to Ui15 all zeros
1 = Ui0 set to "1" all others "0"
2 = Ui1 set to "1" all others "0"
3 = Ui0 and Ui1 set to "1" all others "0"
4 = Ui2 set to "1" all others "0"
5 = Ui2 and Ui0 set to "1" all others "0"
6 = Ui2 and Ui1 set to "1" all others "0"
7 = Ui2 and Ui1 and Ui0 set to "0" all others "0"
8 = Ui3 set to "1" all others "0"
(etc.)

The maximum number is Ui0 thru Ui15 all "1"s, or 1111111111111111, which is 65536

4. Hey, Dan!

Yes, more or less with a vision system. I have a laser sensor that I use to check for holes. If it sees a reflection, then it's a solid area of the part, if it doesn't, then it's a hole.

I need to write an M-code (which I can now do, thanks to Shoprag) that will allow me to inspect the value of the sensor output (a 1 or 0) during a 360 degree rotation. If possible, I'd like to count the number of holes, and then I can make a decistion to repunch any missing holes. This is for a rework routine.

So, Dan, what are UI0-UI15? I've not heard of a U variable before. I know F, G, X, Y, R and A, but not U. How do I access them? Do you have any way to explain what the ladder would look like for this? Or is there some function that will take a counter value and dump it automatically to the U variables you list?

I get the idea, and it's cool that #1032 will do the translation from binary to decimal for the NC (or that's what I understood at least), but how does the initial setup look. I'm still a bit lost on the implementational details.

Thanks.

The Ui0 through Ui15 inputs are in the ladder somewhere as inputs to the CNC (G inputs). I'm not sure of the exact addresses in your ladder, but those are the signal names that Fanuc gives them. Also, you didn't mention what model Fanuc control you have. On the Fanuc 16/18/21 models, I believe that they are the 16 bits in G054 and G055. I would have to look in a PC ladder function manual to get the exact location of the 16 bits.

Once you know the exact addresses of the Macro inputs, try adding a rung to the ladder that sets one of the inputs to "1". Then, run a short macro program that takes the value of #1032 and puts it in a visible location (like variable #501, which you should be able to see on the MACRO VAL page. You would then see the decimal value of the binary input you just gave it.

On very old CNCs like the system 6, they didn't label the inputs as "G" or "X" or "Y" addresses, so that would take a bit of cross-referencing from an address table.

6. It's a 30i controller. I was really hoping there would be a way to increment a counter in the ladder logic and then take this number and put it into a register that could take more than 1's and 0's, like say #130.

I use #115-#130 in my NC code to handle counter variables and as status flags. However, I don't know if there's any link between them and the ladder logic.

I would prefer to not have to do any binary-decimal conversions in the NC. Is there any kind of direct transfer?

Thanks!