Passing an m code variable to the Plc

All things related to Centroid Oak, Allin1DC, MPU11 and Legacy products

Moderator: cnckeith

Post Reply
bakeng
Posts: 66
Joined: Wed Nov 16, 2011 5:50 pm
Allin1DC CNC Controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC11: Yes
CPU10 or CPU7: Yes

Passing an m code variable to the Plc

Post by bakeng »

How can I a pass a variable from a running g code program to the Plc? For example, if the g code program has a line "m25 ss2000"
I want to run the m25 macro and make the value of ss avalible in the Plc program.
cncsnw
Posts: 3887
Joined: Wed Mar 24, 2010 5:48 pm

Re: Passing an m code variable to the Plc

Post by cncsnw »

"m25 ss2000" would always give you an error, because "ss" is not a valid token in the G codes.

If you wrote "m25 s2000", and had a custom M25 macro, then your G code macro could retrieve the current "S" value through the G code system variable #4119. See page 11-5 of the M-Series Operator's Manual. Your custom M25 macro could then put that value somewhere where the PLC program can see it: for example, use G10 to store it in one of Machine Parameter 170-179 or 900-999. For example, "G10 P910 R#4119" would put the current S value into Machine Parameter 910.

Your PLC program could then periodically inspect the PLC system variable named "SV_MACHINE_PARAMETER_910" and take appropriate action.

If you want to send down a value specified with a G code token that, unlike "S", is not reserved for a single purpose, then you will want to use a G65 macro instead of a custom M function. Tokens like "A", "I", "J", "Q", "R", etc. mean different things in different contexts, and thus are generally not available through fixed G code system variables. But such letters, when specified in a G65 macro call, can always be found as local variables (again see page 11-5, and also see G65 on page 12-14).

Once in the G65 macro, you would still use G10 to store the local variable value into a Machine Parameter, so the PLC program can read it with the SV_MACHINE_PARAMETER_xx PLC program system variables.

If you need to also send the PLC program a flag (telling it when to act on the new value) then you can do that with an M94/M95 request: e.g. "M94/10" in the G code macro will set (turn on) the bit SV_M94_M95_10 in the PLC program. "M95/10" will reset it (turn it back off).

It is a good idea to insert a short pause (e.g. "G4 P0.1") between storing a new scalar value in a machine parameter with G10, and signalling the PLC program with M94. Updated machine parameter values are sent down to the PLC program on an asynchronous and lower-priority basis, so you need to allow some time for the new value to become available in the PLC SV_MACHINE_PARAMETER_xx variables before you tell the PLC program to go look at it.
bakeng
Posts: 66
Joined: Wed Nov 16, 2011 5:50 pm
Allin1DC CNC Controller: No
CNC Control System Serial Number: none
DC3IOB: No
CNC11: Yes
CPU10 or CPU7: Yes

Re: Passing an m code variable to the Plc

Post by bakeng »

That makes sense. What I'm trying to do is pass a speed setting from my g code program to the Plc. Then I can convert the speed setting to Bcd and output it. Externally I will then have a controller take that info and run a drive. I actuly need to do this twice. From my understanding centroid cannot directly control a sub spindle and live tooling on a lathe. This is my work around.
Post Reply