View previous topic :: View next topic |
Author |
Message |
fatihsen
Joined: 12 Dec 2021 Posts: 1
|
How can I translate g codes to ccs code ? |
Posted: Sun Dec 12, 2021 8:07 am |
|
|
I am new to ccs programming. I need to drive 2 stepper motors according to the given g code text file for a project. But I couldn't figure out how to do it. My first problem was I couldn't figure out how to translate g codes into ccs. What code structures will I need to use? And how do I transfer the given codes to the relevant engine? My biggest problem is interpreting g codes. Can you help? |
|
|
PrinceNai
Joined: 31 Oct 2016 Posts: 480 Location: Montenegro
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sun Dec 12, 2021 4:02 pm |
|
|
Been decades since I used it but...
Generally speaking...
G code is a simple string of ASCII formatted commands.
Each line is one command.
So 1st you'll need to receive a command. After that, you'll have to 'parse' (decode' what that command is, then have the PIC execute the appropriate function).
Now the code issues are that you have to write 'functions' for the 2 motors, I assume 'x' and 'y' and that they are mechanically connected to do 'something' ?
You'll have to figure out that for the 'x' motor to turn, say 90 degrees, that the function 'turn_x_motor' will need to send the correct number and sequence of bits to the motor driver chip.
You need to tell us what hardware (PIC, stepper drivers and motors). In choosing a PIC, I suggest one with at least 1 hardware UART and lots of memory.
As for software, begin with creating the stepper driver code (CCS supplies a basic version). Test it to be sure it works, using fixed values, say turn motor 90* (degrees), 180*, 270*, 360*. Also be sure it can go in reverse.
Once that works, then make the serial receive function. This normally will be an ISR. Again CCS does have example code. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Mon Dec 13, 2021 2:09 am |
|
|
and remember the stepper driver is going to have to handle acceleration
and deceleration of the motor, as well as things like maintaining some
current through the motors when stopped for braking.
The hard part is this driver, not the G code translation.
The physical driving of the steppers also has it's own difficulties. Lots
of potential interference to the PIC. Really careful electrical design needed.
You then have to decide whether the G code translation is going to be a
'compiler' or 'interpreter' approach. The latter adds increased difficulties
with timing if the stream is not arriving fast enough. The stepper driving
will need to be interrupt based, since each motor has to be independant
of the other, and of the actual G Code translation.
At the end of the day as Jay says, you need to start at the hardware end. |
|
|
|