Skip to content

Commit

Permalink
Grbl can now take advantage of the extra memory in the 328
Browse files Browse the repository at this point in the history
  • Loading branch information
Simen Svale Skogsrud committed Mar 14, 2010
1 parent e409f10 commit 937c70c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# is connected.
# FUSES ........ Parameters for avrdude to flash the fuses appropriately.

DEVICE = atmega168
DEVICE = atmega328p
CLOCK = 16000000
PROGRAMMER = -c avrisp2 -P usb
OBJECTS = main.o motion_control.o gcode.o spindle_control.o wiring_serial.o serial_protocol.o stepper.o \
Expand Down
5 changes: 2 additions & 3 deletions script/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@

SerialPort.open('/dev/tty.FireFly-A964-SPP-1', 115200) do |sp|
sp.write("\r\n\r\n");
sleep 5
sleep 1
ARGV.each do |file|
puts "Processing file #{file}"
prebuffer = $prebuffer ? 12 : 0
prebuffer = $prebuffer ? 20 : 0
File.readlines(file).each do |line|
next if line.strip == ''
puts line.strip
sp.write("#{line.strip}\r\n");
if prebuffer == 0
sleep 0.1
begin
result = sp.gets.strip
puts "Grbl >> #{result}" unless result == '' or result == 'ok'
Expand Down
3 changes: 2 additions & 1 deletion serial_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <math.h>
#include "nuts_bolts.h"
#include <avr/pgmspace.h>
#define LINE_BUFFER_SIZE 30
#define LINE_BUFFER_SIZE 50

char line[LINE_BUFFER_SIZE];
uint8_t char_counter;
Expand All @@ -52,6 +52,7 @@ void sp_process()
{
if((c == '\n')) { // Line is complete. Then execute!
line[char_counter] = 0;
printString(line); printPgmString(PSTR("\r\n"));
gc_execute_line(line);
char_counter = 0;
prompt();
Expand Down
15 changes: 14 additions & 1 deletion stepper.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

/* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith
and Philipp Tiefenbacher. The circle buffer implementation gleaned from the wiring_serial library
and Philipp Tiefenbacher. The ring buffer implementation gleaned from the wiring_serial library
by David A. Mellis */

#include "stepper.h"
Expand All @@ -32,7 +32,12 @@

#include "wiring_serial.h"

// Pick a suitable line-buffer size
#ifdef __AVR_ATmega328P__
#define LINE_BUFFER_SIZE 40 // Atmega 328 has one full kilobyte of extra RAM!
#else
#define LINE_BUFFER_SIZE 10
#endif

struct Line {
uint32_t steps_x, steps_y, steps_z;
Expand Down Expand Up @@ -86,7 +91,11 @@ void st_buffer_line(int32_t steps_x, int32_t steps_y, int32_t steps_z, uint32_t
// This timer interrupt is executed at the rate set with config_step_timer. It pops one instruction from
// the line_buffer, executes it. Then it starts timer2 in order to reset the motor port after
// five microseconds.
#ifdef TIMER1_COMPA_vect
SIGNAL(TIMER1_COMPA_vect)
#else
SIGNAL(SIG_OUTPUT_COMPARE1A)
#endif
{
if(busy){ return; } // The busy-flag is used to avoid reentering this interrupt

Expand Down Expand Up @@ -158,7 +167,11 @@ SIGNAL(SIG_OUTPUT_COMPARE1A)

// This interrupt is set up by SIG_OUTPUT_COMPARE1A when it sets the motor port bits. It resets
// the motor port after a short period (settings.pulse_microseconds) completing one step cycle.
#ifdef TIMER2_OVF_vect
SIGNAL(TIMER2_OVF_vect)
#else
SIGNAL(SIG_OVERFLOW2)
#endif
{
// reset stepping pins (leave the direction pins)
STEPPING_PORT = (STEPPING_PORT & ~STEP_MASK) | (settings.invert_mask & STEP_MASK);
Expand Down
30 changes: 3 additions & 27 deletions wiring_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ int rx_buffer_tail = 0;

void beginSerial(long baud)
{
#if defined(__AVR_ATmega168__)
UBRR0H = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8;
UBRR0L = ((F_CPU / 16 + baud / 2) / baud - 1);

Expand All @@ -49,34 +48,16 @@ void beginSerial(long baud)

// enable interrupt on complete reception of a byte
sbi(UCSR0B, RXCIE0);
#else
UBRRH = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8;
UBRRL = ((F_CPU / 16 + baud / 2) / baud - 1);

// enable rx and tx
sbi(UCSRB, RXEN);
sbi(UCSRB, TXEN);

// enable interrupt on complete reception of a byte
sbi(UCSRB, RXCIE);
#endif

// defaults to 8-bit, no parity, 1 stop bit
}

void serialWrite(unsigned char c)
{
#if defined(__AVR_ATmega168__)
while (!(UCSR0A & (1 << UDRE0)))
;

UDR0 = c;
#else
while (!(UCSRA & (1 << UDRE)))
;

UDR = c;
#endif
}

int serialAvailable()
Expand Down Expand Up @@ -106,18 +87,13 @@ void serialFlush()
rx_buffer_head = rx_buffer_tail;
}

#if defined(__AVR_ATmega168__)
SIGNAL(SIG_USART_RECV)
#ifdef USART_RX_vect
SIGNAL(USART_RX_vect)
#else
SIGNAL(SIG_UART_RECV)
SIGNAL(SIG_USART_RECV)
#endif
{
#if defined(__AVR_ATmega168__)
unsigned char c = UDR0;
#else
unsigned char c = UDR;
#endif

int i = (rx_buffer_head + 1) % RX_BUFFER_SIZE;

// if we should be storing the received character into the location
Expand Down

0 comments on commit 937c70c

Please sign in to comment.