G code programming compiler

Status
Not open for further replies.

abdoalghareeb

Member level 5
Joined
Feb 5, 2010
Messages
84
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,981
I have built my homemade CNC machine
I use my design to build motor driver circuit using pic16f877 and serial communication.
I looked in internet for software ,and I found a lot of software (EMC,IMGTOGCODE for example) which generate G-CODE (at the last step).

My question is : after compile G-CODE lines what is the output data which send to my pic controller.
I need these data to know how I have to program the pic.
Is there any documents about G-CODE compiling ?
 

Hi there. I am also making a 3 axis CNC machine using a PIC uC. dsPIC33EP512MU810. I am also facing the same problem as you are.

After 4 months of searching the internet I have realised that you have to write a G CODE INTERPRETER on your own for the type of PIC uC you are using. In this program, the logic will go lyk this:

1. The uC will wait for data (G code) from the connected pc.
2. If the received data has G or M as the first received byte, then the uC will process the data, otherwise it'll ignore it.
3. It'll then compare the received G/M codes with a sort of look up table (case structure in C program) and send out the corresponding PWM signal outputs to the motor driver.

Problem is, there are some 170-180 G code alone. But fortunately, only about 40-50 codes are commonly used. So you have to write a PWM generation sub routine for each of the commonly used G codes to make your machine as versatile as possible.

This is what I am planning to do.

If you find some fault in my logic or have some found some other solution, please do share.
 




I don't understand G CODE INTERPRETER in uC. Can you help me how to write G CODE INTERPRETER in uC ?. I also need it. Can you help me? Thanks.
 

In a G CODE INTERPRETER, the uC will process one line of G CODE at a time. You have to write subroutines to generate PWM signals for the various types of G CODES in switch case structure (in C language).

Read one line of G CODE as string > process it > Generate PWM> Send a signal to pc to send next line of G CODE> Read one line of G CODE as string > ...

This is what I am planning to do. I haven't finished it yet.
 


Thanks. But how do you process interpolator?
 

If its a straight line along ONE axis, then its not much problem. For a straight line in 2D, I am using Y = mX + c. That way, I would know how many times (PWM pulses/ motor steps) I have to move the router along X axis for each PWM pulse for Y axis, or vice versa.

For an arc, you probably have to use the modified equation of a circle. Note that, when a G CODE is written for an arc, it also provides the value of the radius of the arc.

However, I am concentrating on straight lines at present as my CNC machine will route PCBs initially.
 


Thanks you! I'm doing a my project of CNC. but i don't use uC. I use PLC, and PC.
In PC, i use C# :
Step 1. C# code : to compiler G-code to code user (to understand what need we do?)
Step 2. process interpolator ; calculator pulse number ...
Step 3. Communication to PLC : I send pulse number of 3 axis and dir
In PLC, i use : Motion function to control drive motor. Because in PLC support many tool for control such as jog, velocity(v)...
Can you check and give me advice?
 

I have very limited knowledge on PLC. Just wrote a few basic codes in ladder programming for a Siemens PLC I think.

Anyway, if you are using PLC then you have to do the G CODE interpretation in pc. You just have to send pulses to the PLC. Going by your logic, it seems you are on the right path, but as I said my knowledge is limited.

I guess you'll find more help regarding PLC if you start a new thread on this topic :smile:
 


Thank you very much! But I have a wonder in the way of CNC code execution. As far as I understand, the program will perform g-code line by line. So when we perform 1 g-code line, the pulse of the drive motor and run dir to the desired coordinates. then how to program to identify the correct coordinates cnc arrived to begin calculating and implementing the next command.
 

For smooth motion you should implement "look ahead" technique since interperting g-code line-by-line will give you poor performance.

implements the "look ahead" technique - you can speak clearly about this technique? Because I began research on this field? Thanks!
 

LOOK AHEAD technique is bit more complex than line-by-line G Code execution technique. No doubt LOOK AHEAD technique increases the speed of the CNC drastically and also makes it more smoother. But as a beginner, one should start with the basics, i.e. line-by-line G Code. Thats what I think.
 

hi guys, after a couple months, when i was looking for G code compiler solution for my own 2D mill, i found this forum, unfortunately yet you haven't find any solution too!

i don't need exactly a G code compiler or interpreter, i just need some way to process same G code many times and i have an idea (not a brilliant one though). i will build a uC card and connect it to my pc's lpt port and listen and record all pulses produced by mach3 program, it gives every stepper motor's action (step and direction) so i will just replicate the recorded pulses thanks to my uC card.

it is not a solution for building a self cnc machine controlled by self program but i gives me an opportunity to run my cnc mill without pc and Mach3 program every time.
 

Most 3D printer controller on the market now actually G-Code interpreter, so just find some info on open source 3D printer controller.
 

Hi, all process you mention in posts are good but it is not complete!
You must design a real time system! LPT port, line by line interpreter, uC processing is NOT a good solution for a high precision CNC!
get a real time system!
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…