abdoalghareeb
Member level 5
- Joined
- Feb 5, 2010
- Messages
- 84
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 1,981
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.
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.
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.
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:
For smooth motion you should implement "look ahead" technique since interperting g-code line-by-line will give you poor performance.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?