586,508 active members*
3,146 visitors online*
Register for free
Login
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2008
    Posts
    4

    C code for CNC machine controll

    Hi all.

    I built a small desktop CNC machine. I am making the controller for it now. I have a Nanocore12MAX microcontroller that I want to run it. I have the FETs on separate chips. I have run the motor it both directions using the microcontroller to make sure I can run the motor using it. I can get it to run the motor in one direct when I want it to but I need to control it with the computer. I am using CodeWarrior to program the chip in C code. I have 9 outputs from the computer. 3 for each motor 1 enable, 1 cw/ccw and 1 step. Those nine outputs make 512 states that the micro controller must know what to do when each state is given and feed the correct instructions to the machine. I can set the output by sending the correct binary number to the outputs to make the motor move.

    I have spent several hours looking around on CNCZone and the internet and not found any C code that could be used for what I need.

    I see no reason to reinvent the wheel or in this case C code. If someone has C code that would work I would use that if the owner did not mind. This would be the best solution if someone was generous enough to share code with me.

    I see 2 ways to do it. Have 512 if then statements and have the micro controller go through all of them and step as the motor as output of the computer is read. In other words brute force it. I can do it but it would not be the best solution.

    The second I was told about but have not idea how to do it have the micro controller pole the inputs and when it get an instruction it will shift a binary byte left or right to step the motor the desired directions. Then there is the worry about the carry bit. I have not idea how to do this but it would be a better solution than the above one.

    Unless someone has better advice I am going to brute force it.

    Thanks for your help.

    Stan

  2. #2
    Join Date
    Apr 2005
    Posts
    1778
    Or then you could create an array of pointers to functions and use the state value to index into the array. Then execute the function pointed to by the state value.

    However, if you are going to microstep your would have even more states by your calculations. It seems to me that you really need to define the states for a motor and then parameterize a function as to which motor to drive in that state. Then build up a composite output function based on the combined states. Does this make any sense?

    Alan

  3. #3
    Join Date
    Oct 2008
    Posts
    1
    hello !

  4. #4
    Join Date
    Oct 2008
    Posts
    4

    Not sure I understand

    Quote Originally Posted by acondit View Post
    Then build up a composite output function based on the combined states. Does this make any sense?
    Alan
    Had to go backand read this a few times and think about it for a couple of days.

    It kind of makes sense but then is that not just a bunch of if then statements?

    When the output of the computer is this then do this for each output of the computer.

    Are you suggesting that I come up with either a matrix or algorithm to direct the output based on the input? I think an algorithm would be huge and I would not know where to begin with a matrix. A matrix may be a good idea if I can figure it out.

    I could be missing what you’re suggesting.

    Stan

    PS Thanks for the Hello ndcn

Similar Threads

  1. drill post to c6 controll
    By idealtool in forum Milltronics
    Replies: 8
    Last Post: 11-06-2008, 10:08 PM
  2. Post for Mitsubishi Controll
    By Maguillacutty in forum Surfcam
    Replies: 4
    Last Post: 08-02-2008, 03:18 PM
  3. G Code Variances from machine to machine?
    By Miguel Gonzalez in forum G-Code Programing
    Replies: 16
    Last Post: 03-28-2007, 09:31 AM
  4. GN10T-F symbolic controll
    By Craig F in forum Fanuc
    Replies: 2
    Last Post: 05-25-2006, 06:32 PM
  5. Bridgeport BOSS6 SMD controll
    By Phooey in forum Bridgeport / Hardinge Mills
    Replies: 4
    Last Post: 06-17-2005, 02:21 AM

Posting Permissions

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