588,204 active members*
4,078 visitors online*
Register for free
Login
Page 1 of 2 12
Results 1 to 20 of 25
  1. #1
    Join Date
    Apr 2009
    Posts
    20

    Programming M-Codes from scratch

    Hey all!

    I work in an auto parts plant, and we have a lot of NC machines with Fanuc controls on them. The ones I'm interested in right now use a Fanuc 30i controller.

    I've never had CNC experience before working here (I'm an Engineer by trade), but have managed to pick up NC coding quite quickly.

    However, there is something I don't get; I don't know how to write my own M-codes. I've been looking into it on and off for years, but now I want and need to get to know how to do it. :drowning:

    I have a need to write several M-codes, but from what I can tell, an M-code is not just a 'program' like a piece of ladder logic.

    On our machine, I believe the M-codes are called by a "DECB' block. However, I don't understand the basic structure of an M-Code!

    I want to write some new codes that will allow me to check sensor values on the fly, and to react to them accordingly.

    I can find the program in which the M-codes exist, but I can't see the 'guts', if you will of the M-code.

    How can I find out exacty how a certain M-code is costructed, and how can I write and isert my own?

    Thanks!

  2. #2
    Join Date
    Feb 2006
    Posts
    1792
    I also would like to know the answer.
    The only thing I know is that except a few M codes such as M00, M01....,M98, all M codes are defined by MTB. I do not know how.

    If you do not get any reply, send a personal message to Dan Fritz. He appears to know everything!

  3. #3
    Join Date
    Dec 2003
    Posts
    24220
    I am not that familiar with the i series, but the normal Fanuc method is for the CNC to pass MST codes over to the PMC ladder via registers where is is processed by the PMC. and the PMC uses the same method to acknowledge the same over what is called the BMI bus (basic machine Interface), the CNC block is held up until it receives a FINish signal from the PMC, i.e. when the M,S,T code has completed.
    The M.S.T codes are written and decoded in the ladder itself.
    If it is position values you need via sensor inputs, you may be able to use the skip feature input via G31, the axis values are stored in pre-assigned registers that may be read using macro's and acted on accordingly.
    Al.
    CNC, Mechatronics Integration and Custom Machine Design

    “Logic will get you from A to B. Imagination will take you everywhere.”
    Albert E.

  4. #4
    Join Date
    Nov 2006
    Posts
    175
    DEC decodes 1 M-code at his output address, DECB decode 8 sequential bits (SB-7 and later PMC can do multi-byte DECB). LLet see 1-M code at a line, so called high speed MST interface is for the next lesson.
    RD MF
    DECB
    0004 ;4-bytes of F10 will be decoded
    F0010 ;M-code
    3 ;start from 03
    R100 ;output address

    So, if MF=1, R100.0 will be 1 if M03 was commanded, R100.1=1 if M04 .... R100.7=1 if M10.
    Well, assume M03 was issued. Plc has to turn the spindle CW and only after that next block can be executed. So, FIN can be set 1 only after we are sure spindle is running. Here is the FIN part:
    RD F7.0 ;MF
    AND R100.0 ;M03
    AND G70.5 ;SFRA spindle CW command
    AND F45.3 ;SARA speed reached
    WRT G4.3 ;FIN
    After FIN is received, MF is reset to 0 and next block is decoded.

  5. #5
    Join Date
    Apr 2009
    Posts
    20
    Thanks, everyone, for the help.

    I have heard that this stuff is explained in the manual B-63943EN/01.

    Does anyone have a PDF of this manual I could get? I have B-63943EN/02 already, but it doesn't really explain how this stuff works.

    Thanks again!

  6. #6
    Join Date
    Apr 2009
    Posts
    20
    Hey f-bu, I've been reading over you example, and because I'm new to this, I guess I don't quite understand it.

    What kind of language is that code written in?

    Also, is there a way to open up the code that constitutes an M-code, so I can see how the ones in my machine are written?

    Thanks!

  7. #7
    Join Date
    Nov 2006
    Posts
    175
    language - ladder, text representation,
    There is a way, appropriate version of Fapt ladder. For i-series controls, you can see the ladder on-screen, for older ones - only after disassembling on a PC or Fanuc system P.

  8. #8
    Join Date
    Apr 2009
    Posts
    20
    Okay, so it's a text version of the ladder, then?

    I have a 30i controller, but I can't access the M-code 'code' at all.

    Is there not a way for me to open up the codes and find out what the heck is in there, so I can base my new custom M-codes on what's already there?

    If you can give me some step-by-step instructions, that would help a lot.

    Thanks!

  9. #9
    Join Date
    Nov 2006
    Posts
    175
    it is very difficult to explain it to someone without any knowledge in this field. As I am very bad teacher, I always start with "read the books first".
    Look for DEC or DECB function with parameter M number you are searching, and you will find the R adrs of this M-code. After that look for this R adrs trough the ladder - you should see what it does. Then starting with the FIN backwards, look for M-code FIN to find the condition, which says that execution of this code finished.

  10. #10
    Join Date
    Apr 2009
    Posts
    108

    How an M-code works

    This is the basic workings of an M-code.

    The CNC reads a program that contains an M-code. It then sends a signal to the PMC (ladder logic). Inside the PMC are decode function (DEC, DECB, etc.). When the CNC sends the signal all of the decode functions wake up and look to an address that contains the number for the M-code that was just sent. The function whose number matches the address says "It's me, it's me! That decode function will then turn on a specific output (usually an R address).

    Once that output turns on any number of things can happen. This is dependent upon who wrote the ladder logic. It could turn on a coolant pump or start the tool changer going through its process. The CNC, who started this whole ball of wax rolling, has stopped executing the program. It's waiting for a signal from the PMC called a FIN or finish signal. When the PMC is satisfied that the process has been completed successfully it will turn on the FIN signal. When the CNC sees this signal turn on it will say, "Good, you've done what I asked you to do." Now it will clear the end of block and continue running the program.

    In order to create your own M-codes that will look at a "real world" input such as a limit switch you have two options.

    1. Use the Fanuc Ladder software package to edit the ladder logic. This may have a long learning curve. It would be easier to contract the project out or have someone come in to train you on it.

    2. Look to see if there are any macro variable inputs and outputs already written into the ladder. You can then use a macro program to examine the status of various inputs and make decisions based upon them. The macro variable inputs will be assigned to address G54 or G55 bits 0-7. The outputs will be on address F54 and F55 bits 0-7.

  11. #11
    Join Date
    Feb 2006
    Posts
    1792
    Good information.
    For those who need to know the basics, please explain how to define a new M code, such as M100, for some specific operation?

  12. #12
    Join Date
    Apr 2009
    Posts
    20
    Shoprag, that is the best explanation I've seen yet, and it makes the general method a lot clearer. Thanks a ton!

    However, as usual, I would like to know more.

    I've got the ability to get the ladder logic written, no problem. We write ladder for the machines all the time, and have the Fanuc Ladder software to plug in, edit and download; all the good stuff!

    However, I can't seem to edit the ladder for an actual M-code. I can see the DECB blocks, but I can't open the actual M-codes.

    Can you tell me how I can insert a section of Ladder code that I can call as an M-code? I more or less get the idea of how the DEC and DECB work, at least in theory, but I'm lost a bit on the nuts-and-bolts implementation of how it all goes together.

    Just like sinha_nsit asked, is it possible to show how to define a new M-code, and, in addition, how to assign it to an address that can be decoded.

    Thanks a ton!

  13. #13
    Join Date
    Apr 2009
    Posts
    108

    Writing an M-code

    Pick out the number of the M-code you want to use. Look at the decode statements to see if it is already used. If so, determine the output address that is associated with it. If not, create a new one.

    When that M-code is read by the CNC the output address will turn on and stay on untill the FIN signal is sent to the CNC. Use the output address to make whatever it is you want to happen. In other words, turn on something or generate an alarm.

    Create a rung that is tied into the FIN signal (G4.3 or G5.0). In most applications you would have the output address and some type of completion address (X value) on the same rung.

    You may also want to have the output address activate a timer that would call up an alarm. On this same rung, use the X value completion signal to stop the timer from comleting. Once the FIN signal is issued the output address will turn off.

    Pick out a simple M-code,such as the coolant on command,and follow the logic through the ladder.

    This is a sample of the logic on my website.



    http://shoprag.com/procedures/M_code_example.pdf

  14. #14
    Join Date
    Apr 2009
    Posts
    20
    Thanks a ton, Shoprag!

    So, then, all an M-Code is is a bunch of ladder logic that only gets executed when the DECB command decodes the address, and sends the associated Rbit high? Do I have that right?

    That means that the M-Code itself is just ladder logic like the rest of the machine's programs?

    What, then, is the "G5.0" for the FIN signal coil? I know X, Y, A adn R, but I don't quite understand what "F" and "G" are.

    Thanks agan!

  15. #15
    Join Date
    Apr 2009
    Posts
    108

    F and G addresses

    You've got the idea. M-codes are just ladder logic.

    As for the F and G addresses, here's how to think of them. Consider the CNC and the PMC two seperate devices. These devices talk to each other by using F and G addresses in the ladder logic.

    G's are outputs from the PMC to the CNC. Things such as FIN, CYCLE START, FEED HOLD, etc.

    F's are signals from the CNC to the PMC. Things like M-code strobe, servo ready, reset, etc.

    The whole trick to troubleshooting a Fanuc control is understanding the F and G addresses By the way, don't confuse these with the F and G's used to program a part. They have nothing in common.

    If you're ever interested in a training class let me know. I teach this type of stuff.

  16. #16
    Join Date
    Apr 2009
    Posts
    20
    Hey all!

    I'm back.

    Armed with the knowledge that I got from here, I've started into investigating the M-codes in my GROB S8 machine. I now understand how the M-codes are getting triggered, and I can find the R-values that correspond to them.

    However, now I've hit another wall!! :devious:

    Shoprag: in your post, you said that the M-codes would just be ladder logic, and that the R-values would basically act as a trigger for a set of ladder lines, right? If so, I get it. If that's not what you meant, then I apologise, because that's how I understood it.

    The thing is, in my machine's ladder, I don't see ANYTHING using the R-values except the timeout alarm and the done signal. Thus, there doesn't appear to be any connection between what the M-code does and what the machine actually physically does.

    Is it possible that this code is somehow hidden? Is there a way, on a 30i controller, to hide the M-code ladder, so people can't see what it is that's going on? If so, how do I "unhide" it and make it so I can see what's going on. I really need to see how whatever's being done is actually BEING done.

    Here's the deal:

    I want to read a sensor while a part is turning. If the part is out of round, the contact sensor is going to go to a logical hi. If it's good, then the sensor will report a logical lo. There's already an M-code that does something similar to this in another station of the machine, and I want to see the ladder logic behind how they did it. Thus, I need to 'unhide' the actual M-code logic.

    (flame2)

    Also, in my machine, there are #xxxx addresses (? - I don't know what to call them) that I can check in my NC code. These are all related to a G yyyy.y address. I dont' know if this is a "G" as in the PMC->CNC signal or not. I think it might be a custom macro thing. How do these relate to the M-codes, or do they?

    I feel I'm getting warmer, but there's still at least one piece of the puzzle missing. Can somebody give me a hand with this??

    Thanks a lot!

  17. #17
    Join Date
    Apr 2009
    Posts
    108

    M-codes explained

    The M-code sample I showed on my website is just one way to do it. They could use a function statement and move the data witout actualy activating a coil. I would need to see the ladder in order to reverse engineer how they are doing this.

    A statement that checks a variable such as #1000 is looking at an address in the ladder logic. #1000 to #1015 would check the status of the bits on G54 and G55.

    This is some NC code I used on a tool monitor. A low level signal would indicate an alarm. #1006 looks at G54.6 while #1007 looks at G54.7 in the ladder.

    IF[#1006EQ0]GOTO1000(BLUNT INPUT FROM TECHNA-CHECK)
    IF[#1007EQ0]GOTO1001(BROKEN INPUT FROM TECHNA-CHECK)
    M99
    N1000 #3000=1(TOOL IS DULL)
    M99
    N1001 #3000=1(TOOL IS BROKEN)


    John Robbins
    www.shoprag.com

  18. #18
    Join Date
    Mar 2007
    Posts
    25
    HELLO ADAM!!!!!:boxing: See you at the Grob!

  19. #19
    Join Date
    Nov 2006
    Posts
    175
    looking at the questions and statements from Adam, I can only say: Adam, with FLadder in hands and the knowledge shown here you are very dangerous not only for your machine, but for the people around. Please, consider making your training on some simulator, not on real machine. This forum can answer many questions, but can not substitute real training courses. Sorry, but think positive and responsible.

  20. #20
    Join Date
    Apr 2009
    Posts
    108

    Fladder

    Training would be a good idea. I'm teaching a ladder class in two weeks in Indianapolis. Let me know if you're interested.

Page 1 of 2 12

Similar Threads

  1. Slant bed CNC lathe from scratch
    By Guldberg in forum Vertical Mill, Lathe Project Log
    Replies: 404
    Last Post: 06-18-2021, 05:25 PM
  2. CNC Lathe from Scratch
    By mackeym in forum Vertical Mill, Lathe Project Log
    Replies: 85
    Last Post: 06-02-2010, 12:20 AM
  3. M-codes and G-codes 4 Matsuura ES-1000V
    By maximusek in forum G-Code Programing
    Replies: 2
    Last Post: 11-27-2007, 01:41 PM
  4. Learning from scratch
    By Kitch02 in forum CNC (Mill / Lathe) Control Software (NC)
    Replies: 2
    Last Post: 03-22-2005, 01:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •