Skip to content

Commit

Permalink
Needs to be tested - target coordinates.
Browse files Browse the repository at this point in the history
  • Loading branch information
timkrins committed Jun 6, 2011
1 parent cbae2b2 commit daa859c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -30,7 +30,7 @@
DEVICE = atmega644p
CLOCK = 20000000L
PROGRAMMER = -cusbtiny -P usb
OBJECTS = main.o motion_control.o gcode.o wiring_serial.o serial_protocol.o stepper.o \
OBJECTS = main.o motion_control.o gcode.o wiring_serial.o serial_protocol.o spindle_control.o stepper.o \
eeprom.o settings.o planner.o lcd.o


Expand Down
8 changes: 5 additions & 3 deletions config.h
Expand Up @@ -72,9 +72,11 @@ The Z axis:
#define ZPOS_LIMIT_BIT 4
#define ZNEG_LIMIT_BIT 5

#define SPINDLE_ENABLE_DDR DDRB
#define SPINDLE_ENABLE_PORT PORTB
#define SPINDLE_ENABLE_BIT 4
#define SPINDLE_ENABLE_DDR DDRD
#define SPINDLE_ENABLE_PORT PORTD
#define SPINDLE_ENABLE_BIT 2
#define SPINDLE_DIRECTION_PORT DDRD
#define SPINDLE_DIRECTION_BIT 1

#define LCD_DDR DDRA
#define LCD_PORT PORTA
Expand Down
5 changes: 4 additions & 1 deletion gcode.c
Expand Up @@ -26,6 +26,7 @@
#include <string.h>
#include "nuts_bolts.h"
#include <math.h>
#include <stdio.h>
#include "settings.h"
#include "motion_control.h"
#include "spindle_control.h"
Expand Down Expand Up @@ -251,7 +252,7 @@ uint8_t gc_execute_line(char *line) {
} else {
spindle_stop();
}

char print1[50];
// Perform any physical actions
switch (next_action) {
case NEXT_ACTION_GO_HOME: mc_go_home(); break;
Expand All @@ -261,10 +262,12 @@ uint8_t gc_execute_line(char *line) {
case MOTION_MODE_CANCEL: break;
case MOTION_MODE_SEEK:
mc_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], gc.seek_rate, FALSE);
sprintf(print1, "SEK X%f.3, Y%f.3, Z%f.3",(double)target[X_AXIS],(double)target[Y_AXIS],(double)target[Z_AXIS]);
break;
case MOTION_MODE_LINEAR:
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);
sprintf(print1, "LNR X%f.3, Y%f.3, Z%f.3",(double)target[X_AXIS],(double)target[Y_AXIS],(double)target[Z_AXIS]);
break;
#ifdef __AVR_ATmega328P__
case MOTION_MODE_CW_ARC: case MOTION_MODE_CCW_ARC:
Expand Down
2 changes: 1 addition & 1 deletion lcd.c
Expand Up @@ -102,7 +102,7 @@ void lcd_write_line(char *s) {
lcd_write(*s); // write it to the LCD
s++; // and go to the next character
} else {
lcd_write(" ");
lcd_write(0x20);
}
}
}
Expand Down
25 changes: 15 additions & 10 deletions lcd.h
Expand Up @@ -9,18 +9,23 @@ Questions? Ask Tim K

#include "config.h"

#define LCD_DATAMASK (1<<LCD_DATA_BIT_1)|(1<<LCD_DATA_BIT_2)|(1<<LCD_DATA_BIT_3)|(1<<LCD_DATA_BIT_4)
#define LCD_DATAMASK ((1<<LCD_DATA_BIT_1)|((1<<LCD_DATA_BIT_2)|((1<<LCD_DATA_BIT_3)|(1<<LCD_DATA_BIT_4))))
#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
#define LCD_NIBBLE ((LCD_PORT&LCD_CONTROLS)|(((NIBBLE&0b00000001)<<LCD_DATA_BIT_1)|(((NIBBLE&0b00000010)<<LCD_DATA_BIT_2)|(((NIBBLE&0b00000100)<<LCD_DATA_BIT_3)|((NIBBLE&0b00001000)<<LCD_DATA_BIT_4)))))

#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
#define LCD_CONTROLS_NIB2 ((LCD_PORT&LCD_CONTROLS)|(((NIB2&0b00000001)<<LCD_DATA_BIT_1)|(((NIB2&0b00000010)<<LCD_DATA_BIT_2)|(((NIB2&0b00000100)<<LCD_DATA_BIT_3)|((NIB2&0b00001000)<<LCD_DATA_BIT_4)))))

#define LCD_NIBBLE ((LCD_PORT&LCD_CONTROLS)|(((((NIBBLE&0b00000001)<<LCD_DATA_BIT_1)|((NIBBLE&0b00000010)<<LCD_DATA_BIT_2))|(((NIBBLE&0b00000100)<<LCD_DATA_BIT_3)|((NIBBLE&0b00001000)<<LCD_DATA_BIT_4)))))

#define LCD_CONTROLS_NIB2 ((LCD_PORT&LCD_CONTROLS)|(((NIB2&0b00000001)<<LCD_DATA_BIT_1)|((NIB2&0b00000010)<<LCD_DATA_BIT_2)|((NIB2&0b00000100)<<LCD_DATA_BIT_3)|((NIB2&0b00001000)<<LCD_DATA_BIT_4)))
void lcd_write_line(char *s);

#endif
void lcd_cnc_init(void);

void lcd_set_line(char x);

#endif
8 changes: 4 additions & 4 deletions main.c
Expand Up @@ -23,15 +23,15 @@
#include <util/delay.h>
#include "planner.h"
#include "stepper.h"
//#include "spindle_control.h"
#include "spindle_control.h"
#include "motion_control.h"
#include "gcode.h"
#include "serial_protocol.h"
#include "nuts_bolts.h"
#include "settings.h"
#include "wiring_serial.h"
#include "config.h"
#include "lcd.c"
#include "lcd.h"
#include <math.h>
#include <avr/pgmspace.h>

Expand All @@ -46,7 +46,7 @@ char print1[50];
settings_init();
plan_init();
st_init();
//spindle_init();
spindle_init();
lcd_cnc_init();
gc_init();

Expand All @@ -55,7 +55,7 @@ char print1[50];
sp_process(); // ... process the serial protocol

/* Not sure if this will work, but trying anyway */
sprintf(print1, "X%f.3, Y%f.3, Z%f.3",(double)position[X_AXIS],(double)position[Y_AXIS],(double)position[Z_AXIS]);
//sprintf(print1, "X%f.3, Y%f.3, Z%f.3",(double)target[X_AXIS],(double)target[Y_AXIS],(double)target[Z_AXIS]);
lcd_set_line(2); // sets the screen position, line 3
lcd_write_line(print1);
}
Expand Down
4 changes: 4 additions & 0 deletions planner.c
Expand Up @@ -69,6 +69,10 @@
#else
#define BLOCK_BUFFER_SIZE 5
#endif

// The current position of the tool in absolute steps
static int32_t position[3];

static block_t block_buffer[BLOCK_BUFFER_SIZE]; // A ring buffer for motion instructions
static volatile int block_buffer_head; // Index of the next block to be pushed
static volatile int block_buffer_tail; // Index of the block to process now
Expand Down
3 changes: 0 additions & 3 deletions planner.h
Expand Up @@ -51,10 +51,7 @@ typedef struct {
uint32_t decelerate_after; // The index of the step event on which to start decelerating

} block_t;


// The current position of the tool in absolute steps
static int32_t position[3];

// Initialize the motion plan subsystem
void plan_init();
Expand Down

0 comments on commit daa859c

Please sign in to comment.