Skip to content
Browse files

LCD Library works correctly, and displays useful information. Impleme…

…nted command M99 to reset the axes to zero.
  • Loading branch information...
1 parent a677c06 commit 9459c9f74a5887f7ef7f1b8e3469a13ced49c4cf @timkrins committed Nov 29, 2011
Showing with 122 additions and 78 deletions.
  1. +1 −1 Makefile
  2. +56 −27 gcode.c
  3. +23 −31 lcd.c
  4. +29 −0 lcd.h
  5. +3 −1 main.c
  6. +1 −1 planner.c
  7. +3 −1 planner.h
  8. +3 −13 readme.textile
  9. +3 −3 settings.h
View
2 Makefile
@@ -31,7 +31,7 @@ DEVICE = atmega644p
CLOCK = 20000000L
PROGRAMMER = -cusbtiny -P usb
OBJECTS = main.o motion_control.o gcode.o spindle_control.o wiring_serial.o serial_protocol.o stepper.o \
- eeprom.o settings.o planner.o
+ eeprom.o settings.o planner.o lcd.o
# Tune the lines below only if you know what you are doing:
View
83 gcode.c
@@ -26,10 +26,13 @@
#include <string.h>
#include "nuts_bolts.h"
#include <math.h>
+#include <stdio.h>
#include "settings.h"
#include "motion_control.h"
#include "spindle_control.h"
#include "errno.h"
+#include "lcd.h"
+#include "planner.h"
#include "serial_protocol.h"
#define MM_PER_INCH (25.4)
@@ -59,10 +62,12 @@ typedef struct {
uint8_t status_code;
uint8_t motion_mode; /* {G0, G1, G2, G3, G80} */
+ uint8_t prev_motion;
uint8_t inverse_feed_rate_mode; /* G93, G94 */
uint8_t inches_mode; /* 0 = millimeter mode, 1 = inches mode {G20, G21} */
uint8_t absolute_mode; /* 0 = relative motion, 1 = absolute motion {G90, G91} */
uint8_t program_flow;
+ int resetaxes;
int spindle_direction;
double feed_rate, seek_rate; /* Millimeters/second */
double position[3]; /* Where the interpreter considers the tool to be at this point in the code */
@@ -82,6 +87,8 @@ int read_double(char *line, // <- string: line of RS274/NGC code
int next_statement(char *letter, double *double_ptr, char *line, int *char_counter);
+char bufferz[20];
+int n;
void select_plane(uint8_t axis_0, uint8_t axis_1, uint8_t axis_2)
{
@@ -94,6 +101,7 @@ void gc_init() {
memset(&gc, 0, sizeof(gc));
gc.feed_rate = settings.default_feed_rate/60;
gc.seek_rate = settings.default_seek_rate/60;
+ gc.prev_motion = MOTION_MODE_CANCEL;
select_plane(X_AXIS, Y_AXIS, Z_AXIS);
gc.absolute_mode = TRUE;
}
@@ -166,48 +174,51 @@ uint8_t gc_execute_line(char *line) {
int_value = trunc(value);
switch(letter) {
case 'G':
+ lcd_clear();
switch(int_value) {
- case 0: gc.motion_mode = MOTION_MODE_SEEK; break;
- case 1: gc.motion_mode = MOTION_MODE_LINEAR; break;
+ case 0: gc.motion_mode = MOTION_MODE_SEEK; lcd_write_line(0, "> FastMove"); break;
+ case 1: gc.motion_mode = MOTION_MODE_LINEAR; lcd_write_line(0, "> LinearMove"); break;
#ifdef __AVR_ATmega328P__
- case 2: gc.motion_mode = MOTION_MODE_CW_ARC; break;
- case 3: gc.motion_mode = MOTION_MODE_CCW_ARC; break;
+ case 2: gc.motion_mode = MOTION_MODE_CW_ARC; lcd_write_line(0, "> CWArc"); break;
+ case 3: gc.motion_mode = MOTION_MODE_CCW_ARC; lcd_write_line(0, "> CCWArc"); break;
#endif
- case 4: next_action = NEXT_ACTION_DWELL; break;
- case 17: select_plane(X_AXIS, Y_AXIS, Z_AXIS); break;
- case 18: select_plane(X_AXIS, Z_AXIS, Y_AXIS); break;
- case 19: select_plane(Y_AXIS, Z_AXIS, X_AXIS); break;
- case 20: gc.inches_mode = TRUE; break;
- case 21: gc.inches_mode = FALSE; break;
- case 28: case 30: next_action = NEXT_ACTION_GO_HOME; break;
- case 53: absolute_override = TRUE; break;
- case 80: gc.motion_mode = MOTION_MODE_CANCEL; break;
- case 90: gc.absolute_mode = TRUE; break;
- case 91: gc.absolute_mode = FALSE; break;
- case 93: gc.inverse_feed_rate_mode = TRUE; break;
- case 94: gc.inverse_feed_rate_mode = FALSE; break;
- default: FAIL(GCSTATUS_UNSUPPORTED_STATEMENT);
+ case 4: next_action = NEXT_ACTION_DWELL; lcd_write_line(0, "> Dwell"); break;
+ case 17: select_plane(X_AXIS, Y_AXIS, Z_AXIS); lcd_write_line(0, "> SelectPlane1"); break;
+ case 18: select_plane(X_AXIS, Z_AXIS, Y_AXIS); lcd_write_line(0, "> SelectPlane2"); break;
+ case 19: select_plane(Y_AXIS, Z_AXIS, X_AXIS); lcd_write_line(0, "> SelectPlane3"); break;
+ case 20: gc.inches_mode = TRUE; lcd_write_line(0, "> InchesMode"); break;
+ case 21: gc.inches_mode = FALSE; lcd_write_line(0, "> mmMode"); break;
+ case 28: case 30: next_action = NEXT_ACTION_GO_HOME; lcd_write_line(0, "> Home"); break;
+ case 53: absolute_override = TRUE; lcd_write_line(0, "> Absolute");break;
+ case 80: gc.motion_mode = MOTION_MODE_CANCEL; lcd_write_line(0, "> MotionMode");break;
+ case 90: gc.absolute_mode = TRUE; lcd_write_line(0, "> AbsoluteMode");break;
+ case 91: gc.absolute_mode = FALSE; lcd_write_line(0, "> RelativeMode");break;
+ case 93: gc.inverse_feed_rate_mode = TRUE; lcd_write_line(0, "> inverseFeed");break;
+ case 94: gc.inverse_feed_rate_mode = FALSE; lcd_write_line(0, "> normFeed");break;
+ default: FAIL(GCSTATUS_UNSUPPORTED_STATEMENT); lcd_write_line(0, "> Unknown Code");
}
break;
case 'M':
+ lcd_clear();
switch(int_value) {
- case 0: case 1: gc.program_flow = PROGRAM_FLOW_PAUSED; break;
- case 2: case 30: case 60: gc.program_flow = PROGRAM_FLOW_COMPLETED; break;
- case 3: gc.spindle_direction = 1; break;
- case 4: gc.spindle_direction = -1; break;
- case 5: gc.spindle_direction = 0; break;
- default: FAIL(GCSTATUS_UNSUPPORTED_STATEMENT);
+ case 0: case 1: gc.program_flow = PROGRAM_FLOW_PAUSED; lcd_write_line(0, "> Pause");break;
+ case 2: case 30: case 60: gc.program_flow = PROGRAM_FLOW_COMPLETED; lcd_write_line(0, "> Finished");break;
+ case 3: gc.spindle_direction = 1; lcd_write_line(0, "> SpindleOn"); break;
+ case 4: gc.spindle_direction = -1; lcd_write_line(0, "> SpindleRev"); break;
+ case 5: gc.spindle_direction = 0; lcd_write_line(0, "> SpindleOff"); break; // this will turn off the spindle
+ case 99: gc.resetaxes = 1; lcd_write_line(0, "> Zeroed"); break; // this will reset all axes to zero.
+ default: FAIL(GCSTATUS_UNSUPPORTED_STATEMENT); lcd_write_line(0, "> Unknown Code");
}
break;
- case 'T': gc.tool = trunc(value); break;
+ case 'T':
+ lcd_clear(); gc.tool = trunc(value); lcd_write_line(0, "> ToolChange");break;
}
if(gc.status_code) { break; }
}
// If there were any errors parsing this line, we will return right away with the bad news
if (gc.status_code) { return(gc.status_code); }
-
char_counter = 0;
clear_vector(offset);
memcpy(target, gc.position, sizeof(target)); // i.e. target = gc.position
@@ -252,17 +263,35 @@ uint8_t gc_execute_line(char *line) {
spindle_stop();
}
+ if (gc.resetaxes) {
+ gc.prev_motion = gc.motion_mode;
+ gc.motion_mode = MOTION_MODE_CANCEL;
+ gc.resetaxes = 0;
+ n = sprintf(bufferz, "Was X%d,Y%d,Z%d", (int)gc.position[X_AXIS], (int)gc.position[Y_AXIS], (int)gc.position[Z_AXIS]);
+ lcd_write_line(2, bufferz);
+ clear_vector(gc.position);//reset to zero
+ clear_vector(target);//reset to zero
+ clear_vector(position);//reset to zero
+ memcpy(position, gc.position, sizeof(gc.position)); // position[] = target[]
+ n = sprintf(bufferz, "Now X%d,Y%d,Z%d", (int)gc.position[X_AXIS], (int)gc.position[Y_AXIS], (int)gc.position[Z_AXIS]);
+ lcd_write_line(3, bufferz);
+ }
+
// Perform any physical actions
switch (next_action) {
case NEXT_ACTION_GO_HOME: mc_go_home(); break;
case NEXT_ACTION_DWELL: mc_dwell(trunc(p*1000)); break;
case NEXT_ACTION_DEFAULT:
switch (gc.motion_mode) {
- case MOTION_MODE_CANCEL: break;
+ case MOTION_MODE_CANCEL: gc.motion_mode = gc.prev_motion; break;
case MOTION_MODE_SEEK:
+ n = sprintf(bufferz, "G00 X%d,Y%d,Z%d", (int)target[X_AXIS], (int)target[Y_AXIS], (int)target[Z_AXIS]);
+ lcd_write_line(1, bufferz);
mc_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], gc.seek_rate, FALSE);
break;
case MOTION_MODE_LINEAR:
+ n = sprintf(bufferz, "G01 X%d,Y%d,Z%d", (int)target[X_AXIS], (int)target[Y_AXIS], (int)target[Z_AXIS]);
+ lcd_write_line(1, bufferz);
mc_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS],
(gc.inverse_feed_rate_mode) ? inverse_feed_rate : gc.feed_rate, gc.inverse_feed_rate_mode);
break;
View
54 lcd.c
@@ -7,23 +7,9 @@
#include <avr/io.h> // include input and output functions
#include <util/delay.h> // include functions for accurate delays
#include <stdio.h>
+#include "lcd.h"
-#define LCD_PORT PORTA // customised to our hardware. should be moved to config.h
-#define LCD_RS_BIT 0 // customised to our hardware. should be moved to config.h
-#define LCD_RW_BIT 6 // customised to our hardware. should be moved to config.h
-#define LCD_E_BIT 1 // customised to our hardware. should be moved to config.h
-#define LCD_DATAMASK 0b00111100 // customised to our hardware. should be moved to config.h
-#define LCD_CONTROLS ~LCD_DATAMASK
-
-#define RS0 LCD_PORT &= ~(1<<LCD_RS_BIT) // Register select line low, select the control register
-#define RS1 LCD_PORT |= (1<<LCD_RS_BIT) // Register select line high, select the data register
-#define RW0 LCD_PORT &= ~(1<<LCD_RW_BIT) // Write mode
-#define RW1 LCD_PORT |= (1<<LCD_RW_BIT) // Read mode
-#define E0 LCD_PORT &= ~(1<<LCD_E_BIT) // Stop data write
-#define E1 LCD_PORT |= (1<<LCD_E_BIT) // Start data write
-
-
-void lcd_set_controls_4bit(char controlvar) { // wait for LCD to be ready
+void lcd_set_controls_4bit(controlvar) { // wait for LCD to be ready
char NIB1;
char NIB2;
NIB1 = ((controlvar&0b11110000)>>4); // set the first nibble
@@ -34,12 +20,12 @@ void lcd_set_controls_4bit(char controlvar) { // wait for LCD to
E1; // write data to LCD
_delay_us(1); // delay for signal
E0; // stop data write
- _delay_ms(20); // delay for signal
+ _delay_ms(2); // delay for signal
LCD_PORT = (LCD_PORT&LCD_CONTROLS)|((NIB2<<2)&LCD_DATAMASK); // set the second nibble bits
E1; // write data to LCD
_delay_us(1); // delay for signal
E0; // stop data write
- _delay_ms(20); // delay for signal
+ _delay_ms(2); // delay for signal
RS1; // select the data register (disables control register)
}
@@ -50,7 +36,7 @@ void lcd_set_controls_8bit(char controlvar) { // wait for L
E1; // write data to LCD
_delay_us(1); // delay for signal
E0; // stop data write
- _delay_ms(20); // delay for signal
+ _delay_ms(2); // delay for signal
RS1; // select the data register (disables control register)
}
@@ -69,7 +55,7 @@ void lcd_clear_display(void) {
lcd_set_controls_4bit(0b00000110); // Increment and do not shift display.
}
-void lcd_set_line(char x) {
+void lcd_set_line(x) {
switch (x) {
case 0:
lcd_set_controls_4bit((1<<7)|0x00); // sets the position of the DDRAM input
@@ -86,7 +72,7 @@ void lcd_set_line(char x) {
}
}
-void lcd_write(char writeval) {
+void lcd_write(writeval) {
char NIB1;
char NIB2;
NIB1 = (writeval&0b11110000) >> 4;
@@ -103,26 +89,32 @@ void lcd_write(char writeval) {
_delay_ms(3);
}
-void lcd_write_line(char *s) {
+void lcd_write_line(int line, char *s) {
+ lcd_set_line(line);
char t;
- for(t = 0; t<20; t++) { // reads 14 characters from the passed string
+ for(t = 0; t<20; t++) { // reads 20 characters from the passed string
if(*s) { // if there is a character
lcd_write(*s); // write it to the LCD
s++; // and go to the next character
+ } else {
+ lcd_write(0x20);
}
}
}
+void lcd_clear(void) {
+lcd_write_line(0, "");
+lcd_write_line(1, "");
+lcd_write_line(2, "");
+lcd_write_line(3, "");
+}
+
void lcd_cnc_init(void) {
DDRA = 0xFF;
lcd_clear_display(); // clear and initialise the LCD
lcd_set_home(); // sets the lcd home
- lcd_set_line(0); // sets the screen position, line 1
- lcd_write_line("HackMelbourne CNC"); // writes this string to the LCD
- lcd_set_line(1); // sets the screen position, line 2
- lcd_write_line("GRBL loaded:"); // writes this string to the LCD
- lcd_set_line(2); // sets the screen position, line 3
- lcd_write_line("XPos, Ypos, Zpos"); // writes this string to the LCD
- lcd_set_line(3); // sets the screen position, line 4
- lcd_write_line("XNext, YNext, Znext"); // writes this string to the LCD
+ lcd_write_line(0, "HackMelbourne CNC"); // writes this string to the LCD
+ lcd_write_line(1, "GRBL loaded!"); // writes this string to the LCD
+ lcd_write_line(2, " Open serial term"); // writes this string to the LCD
+ lcd_write_line(3, " and type '$'."); // writes this string to the LCD
}
View
29 lcd.h
@@ -0,0 +1,29 @@
+#ifndef lcd_h
+#define lcd_h
+
+#define LCD_PORT PORTA // customised to our hardware. should be moved to config.h
+#define LCD_RS_BIT 0 // customised to our hardware. should be moved to config.h
+#define LCD_RW_BIT 6 // customised to our hardware. should be moved to config.h
+#define LCD_E_BIT 1 // customised to our hardware. should be moved to config.h
+#define LCD_DATAMASK 0b00111100 // customised to our hardware. should be moved to config.h
+#define LCD_CONTROLS ~LCD_DATAMASK
+
+#define RS0 LCD_PORT &= ~(1<<LCD_RS_BIT) // Register select line low, select the control register
+#define RS1 LCD_PORT |= (1<<LCD_RS_BIT) // Register select line high, select the data register
+#define RW0 LCD_PORT &= ~(1<<LCD_RW_BIT) // Write mode
+#define RW1 LCD_PORT |= (1<<LCD_RW_BIT) // Read mode
+#define E0 LCD_PORT &= ~(1<<LCD_E_BIT) // Stop data write
+#define E1 LCD_PORT |= (1<<LCD_E_BIT) // Start data write
+
+char controlvar;
+char x;
+char writeval;
+
+void lcd_set_controls_4bit();
+void lcd_set_line();
+void lcd_write();
+void lcd_write_line();
+void lcd_cnc_init();
+void lcd_clear();
+
+#endif
View
4 main.c
@@ -31,7 +31,7 @@
#include "settings.h"
#include "wiring_serial.h"
#include "config.h"
-#include "lcd.c"
+#include "lcd.h"
#include <math.h>
#include <avr/pgmspace.h>
@@ -41,6 +41,8 @@
int main(void)
{
+
+_delay_ms(500);
sp_init();
settings_init();
plan_init();
View
2 planner.c
@@ -75,7 +75,7 @@ static volatile int block_buffer_head; // Index of the next block to b
static volatile int block_buffer_tail; // Index of the block to process now
// The current position of the tool in absolute steps
-static int32_t position[3];
+//move to main... static int32_t position[3];
static uint8_t acceleration_manager_enabled; // Acceleration management active?
View
4 planner.h
@@ -51,7 +51,9 @@ typedef struct {
uint32_t decelerate_after; // The index of the step event on which to start decelerating
} block_t;
-
+
+int32_t position[3];
+
// Initialize the motion plan subsystem
void plan_init();
View
16 readme.textile
@@ -1,15 +1,5 @@
-h1. Grbl_for_CCHS - An embedded g-code interpreter and motion-controller for the ATmega644p microcontroller, adapted from Grbl.
-
-Grbl is a no-compromise, high performance, low cost alternative to parallel-port-based motion control for CNC milling. It will run on a vanilla Arduino (Duemillanove/Uno) as long as it sports an Atmega 328.
+h1. hackmelbournecnc.
-The controller is written in highly optimized C utilizing every clever feature of the AVR-chips to achieve precise timing and asynchronous operation. It is able to maintain more than 30kHz of stable, jitter free control pulses.
+hackmelbournecnc is a pre-configured version of GRBL by simen for the HackMelbourne CNC machine.
-It accepts standards-compliant G-code and has been tested with the output of several CAM tools with no problems. Arcs, circles and helical motion are fully supported - but no support for tool offsets, functions or variables as these are apocryphal and fell into disuse after humans left G-code authoring to machines some time in the 80s.
-
-Grbl includes full acceleration management with look ahead. That means the controller will look up to 20 motions into the future and plan its velocities ahead to deliver smooth acceleration and jerk-free cornering.
-
-*Important note for Atmega 168 users:* Grbl used to be compatible with both the older Ardunios running atmega 168 and the newer with 328p. This had to go, as I was unable to fit the acceleration management into the 16k code space of the 168. If you want to run Grbl on an 168 I am still maintaining Grbl 0.51 "in the branch called 'v0_51'":https://github.com/simen/grbl/tree/v0_51.
-
-*Note for users upgrading from 0.51 to 0.6:* The new version has new and improved default pin-out. If nothing works when you upgrade, that is because the pulse trains are coming from the wrong pins. This is a simple matter of editing config.h – the whole legacy pin assignment is there for you to uncomment.
-
-_The project was initially inspired by the Arduino GCode Interpreter by Mike Ellery_
+Please see the original documentation at https://github.com/simen/grbl
View
6 settings.h
@@ -56,9 +56,9 @@ void settings_store_setting(int parameter, double value);
// Default settings (used when resetting eeprom-settings)
#define MICROSTEPS 1
-#define DEFAULT_X_STEPS_PER_MM 635
-#define DEFAULT_Y_STEPS_PER_MM 635
-#define DEFAULT_Z_STEPS_PER_MM 635
+#define DEFAULT_X_STEPS_PER_MM 493
+#define DEFAULT_Y_STEPS_PER_MM 493
+#define DEFAULT_Z_STEPS_PER_MM 493
#define DEFAULT_STEP_PULSE_MICROSECONDS 15
#define DEFAULT_MM_PER_ARC_SEGMENT 0.1
#define DEFAULT_RAPID_FEEDRATE 600.0 // in millimeters per minute

0 comments on commit 9459c9f

Please sign in to comment.
Something went wrong with that request. Please try again.