tweaks and bugfixes

This commit is contained in:
Simen Svale Skogsrud 2009-01-29 09:58:29 +01:00
parent ac2e26fda9
commit a9d41c6c64
9 changed files with 75 additions and 62 deletions

View File

@ -39,7 +39,7 @@ AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) -B 10
COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I.
# symbolic targets:
all: main.hex
all: grbl.hex
.c.o:
$(COMPILE) -c $< -o $@
@ -55,7 +55,7 @@ all: main.hex
$(COMPILE) -S $< -o $@
flash: all
$(AVRDUDE) -U flash:w:main.hex:i
$(AVRDUDE) -U flash:w:grbl.hex:i
fuse:
$(AVRDUDE) $(FUSES)
@ -65,19 +65,19 @@ install: flash fuse
# if you use a bootloader, change the command below appropriately:
load: all
bootloadHID main.hex
bootloadHID grbl.hex
clean:
rm -f main.hex main.elf $(OBJECTS)
rm -f grbl.hex main.elf $(OBJECTS)
# file targets:
main.elf: $(OBJECTS)
$(COMPILE) -o main.elf $(OBJECTS) -lm
main.hex: main.elf
rm -f main.hex
avr-objcopy -j .text -j .data -O ihex main.elf main.hex
avr-size main.hex *.o
grbl.hex: main.elf
rm -f grbl.hex
avr-objcopy -j .text -j .data -O ihex main.elf grbl.hex
avr-size grbl.hex *.o
# If you have an EEPROM section, you must also create a hex file for the
# EEPROM and add it to the "flash" target.

View File

@ -30,12 +30,12 @@
- Variables
- Multiple home locations
- Probing
- Spindle direction
- Override control
*/
/*
Omitted for the time being:
- Spindle direction
group 0 = {G10, G28, G30, G53, G92, G92.1, G92.2, G92.3} (Non modal G-codes)
group 5 = {G93, G94} feed rate mode
@ -126,7 +126,7 @@ uint8_t gc_execute_line(char *line) {
double unit_converted_value;
double inverse_feed_rate;
uint8_t absolute_mode = 0; /* 0 = relative motion, 1 = absolute motion {G90, G91} */
uint8_t absolute_mode; /* 0 = relative motion, 1 = absolute motion {G90, G91} */
uint8_t next_action = NEXT_ACTION_DEFAULT; /* One of the NEXT_ACTION_-constants */
double target[3], offset[3];

View File

@ -18,7 +18,13 @@
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
/* This code was inspired by the Arduino GCode_Interpreter by Mike Ellery. */
/* The structure of this module was inspired by the Arduino GCode_Interpreter by Mike Ellery. The arc
interpolator written from the information provided in the Wikipedia article 'Midpoint circle algorithm'
and the lecture 'Circle Drawing Algorithms' by Leonard McMillan.
http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
http://www.cs.unc.edu/~mcmillan/comp136/Lecture7/circle.html
*/
#include <avr/io.h>
#include "config.h"

View File

@ -2,7 +2,9 @@ Grbl - An embedded rs274/ngc (g-code) interpreter, CNC controller, readout and e
Inspired by the Arduino GCode Interpreter by Mike Ellery
Status:
* Linear interpolation machine control complete (No arcs yet)
* Linear interpolation machine control complete (Arc support in embryonic state)
* Buffered, non blocking, asynchronous stepping so the rest of the system is free to generate new steps and parse
g-code while the steppers are still steppin'
* GCode interpreter complete
* Basic serial protocol complete
* As of yet completely untested in a real environemnt. Still waiting for my micRo kit from Lumenlab.com
@ -18,7 +20,7 @@ Goals:
Limitations:
* Limited GCode-support. Focus on the kind of GCode produced by CAM tools. Leave human GCoders frustrated.
* No rotation axes, only x,y and z.
* No rotation axes, only x, y and z.

View File

@ -40,15 +40,14 @@ void print_result() {
int inches_mode;
uint8_t status_code;
uint32_t line_number;
int i; // loop variable
gc_get_status(position, &status_code, &inches_mode, &line_number);
printByte('[');
printInteger(trunc(position[X_AXIS]*100));
printByte(',');
printInteger(trunc(position[Y_AXIS]*100));
printByte(',');
printInteger(trunc(position[Z_AXIS]*100));
printString("[ ");
for(i=X_AXIS; i<=Z_AXIS; i++) {
printInteger(trunc(position[i]*100));
printByte(' ');
}
printByte(']');
printByte(' ');
printByte('@');
printInteger(line_number);
printByte(':');

View File

@ -18,6 +18,9 @@
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
/* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith
and Philipp Tiefenbacher. The circle buffer implementation by the wiring_serial library by David A. Mellis */
#include "stepper.h"
#include "config.h"
#include "nuts_bolts.h"
@ -30,7 +33,7 @@ volatile uint8_t step_buffer[STEP_BUFFER_SIZE]; // A buffer for step instruction
volatile int step_buffer_head = 0;
volatile int step_buffer_tail = 0;
uint8_t state = STEPPER_STATE_STOPPED;
uint8_t stepper_mode = STEPPER_MODE_STOPPED;
// This timer interrupt is executed at the pace set with set_pace. It pops one instruction from
// the step_buffer, executes it. Then it starts timer2 in order to reset the motor port after
@ -77,7 +80,7 @@ void st_init()
// Configure Timer 2
TCCR2A = 0; // Normal operation
TCCT2B = 1<<CS20; // Full speed, no prescaler
TCCR2B = 1<<CS20; // Full speed, no prescaler
TIMSK2 = 0; // All interrupts disabled
// start off with a slow pace
@ -100,7 +103,7 @@ void st_buffer_step(uint8_t motor_port_bits)
// Block until all buffered steps are executed
void st_synchronize()
{
if (state == STEPPER_MODE_RUNNING) {
if (stepper_mode == STEPPER_MODE_RUNNING) {
while(step_buffer_tail != step_buffer_head) { sleep_mode(); }
} else {
st_flush();
@ -119,7 +122,7 @@ void st_start()
// Enable timer interrupt
TIMSK1 |= (1<<OCIE1A);
STEPPERS_ENABLE_PORT |= 1<<STEPPERS_ENABLE_BIT;
state = STEPPER_STATE_RUNNING;
stepper_mode = STEPPER_MODE_RUNNING;
}
// Execute all buffered steps, then stop the stepper subsystem
@ -128,7 +131,7 @@ inline void st_stop()
st_synchronize();
TIMSK1 &= ~(1<<OCIE1A);
STEPPERS_ENABLE_PORT &= ~(1<<STEPPERS_ENABLE_BIT);
state = STEPPER_STATE_STOPPED;
stepper_mode = STEPPER_MODE_STOPPED;
}
void st_set_pace(uint32_t microseconds)
@ -181,25 +184,25 @@ int check_limit_switch(int axis)
// void perform_go_home()
// {
// int axis;
// if(state.home.phase == PHASE_HOME_RETURN) {
// if(stepper_mode.home.phase == PHASE_HOME_RETURN) {
// // We are running all axes in reverse until all limit switches are tripped
// // Check all limit switches:
// for(axis=X_AXIS; axis <= Z_AXIS; axis++) {
// state.home.away[axis] |= check_limit_switch(axis);
// stepper_mode.home.away[axis] |= check_limit_switch(axis);
// }
// // Step steppers. First retract along Z-axis. Then X and Y.
// if(state.home.away[Z_AXIS]) {
// if(stepper_mode.home.away[Z_AXIS]) {
// step_axis(Z_AXIS);
// } else {
// // Check if all axes are home
// if(!(state.home.away[X_AXIS] || state.home.away[Y_AXIS])) {
// if(!(stepper_mode.home.away[X_AXIS] || stepper_mode.home.away[Y_AXIS])) {
// // All axes are home, prepare next phase: to nudge the tool carefully out of the limit switches
// memset(state.home.direction, 1, sizeof(state.home.direction)); // direction = [1,1,1]
// set_direction_bits(state.home.direction);
// state.home.phase == PHASE_HOME_NUDGE;
// memset(stepper_mode.home.direction, 1, sizeof(stepper_mode.home.direction)); // direction = [1,1,1]
// set_direction_bits(stepper_mode.home.direction);
// stepper_mode.home.phase == PHASE_HOME_NUDGE;
// return;
// }
// step_steppers(state.home.away);
// step_steppers(stepper_mode.home.away);
// }
// } else {
// for(axis=X_AXIS; axis <= Z_AXIS; axis++) {
@ -209,8 +212,8 @@ int check_limit_switch(int axis)
// }
// }
// // When this code is reached it means all axes are free of their limit-switches. Complete the cycle and rest:
// clear_vector(state.position); // By definition this is location [0, 0, 0]
// state.mode = MODE_AT_REST;
// clear_vector(stepper_mode.position); // By definition this is location [0, 0, 0]
// stepper_mode.mode = MODE_AT_REST;
// }
// }

View File

@ -24,10 +24,10 @@
#include <avr/io.h>
#include <avr/sleep.h>
#define STEPPER_STATE_STOPPED 0
#define STEPPER_STATE_RUNNING 1
#define STEPPER_STATE_LIMIT_OVERRUN 2
#define STEPPER_STATE_HOMING 3
#define STEPPER_MODE_STOPPED 0
#define STEPPER_MODE_RUNNING 1
#define STEPPER_MODE_LIMIT_OVERRUN 2
#define STEPPER_MODE_HOMING 3
// Initialize and start the stepper motor subsystem
void st_init();

View File

@ -1,3 +1,6 @@
* Implement homing cycle in stepper.c
* Implement limit switch support in stepper.c (use port-triggered interrupts?)
* How to implement st_set_pace? Consider synchronizing when pace is changed
* Eliminate need for circle_x and circle_y in step_arc_along…
* Use timer interrupts to drive steppers
* Tool table

View File

@ -128,21 +128,21 @@ SIGNAL(SIG_UART_RECV)
}
}
void printMode(int mode)
{
// do nothing, we only support serial printing, not lcd.
}
// void printMode(int mode)
// {
// // do nothing, we only support serial printing, not lcd.
// }
void printByte(unsigned char c)
{
serialWrite(c);
}
void printNewline()
{
printByte('\n');
}
// void printNewline()
// {
// printByte('\n');
// }
//
void printString(const char *s)
{
while (*s)
@ -180,20 +180,20 @@ void printInteger(long n)
printIntegerInBase(n, 10);
}
void printHex(unsigned long n)
{
printIntegerInBase(n, 16);
}
void printOctal(unsigned long n)
{
printIntegerInBase(n, 8);
}
void printBinary(unsigned long n)
{
printIntegerInBase(n, 2);
}
// void printHex(unsigned long n)
// {
// printIntegerInBase(n, 16);
// }
//
// void printOctal(unsigned long n)
// {
// printIntegerInBase(n, 8);
// }
//
// void printBinary(unsigned long n)
// {
// printIntegerInBase(n, 2);
// }
/* Including print() adds approximately 1500 bytes to the binary size,
* so we replace it with the smaller and less-confusing printString(),