diff --git a/Makefile b/Makefile index d2ac8a0..90742cc 100644 --- a/Makefile +++ b/Makefile @@ -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 \ diff --git a/script/stream.rb b/script/stream.rb index 65e3531..778ac03 100644 --- a/script/stream.rb +++ b/script/stream.rb @@ -26,16 +26,15 @@ end 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' diff --git a/serial_protocol.c b/serial_protocol.c index a32813f..3e246f1 100644 --- a/serial_protocol.c +++ b/serial_protocol.c @@ -26,7 +26,7 @@ #include #include "nuts_bolts.h" #include -#define LINE_BUFFER_SIZE 30 +#define LINE_BUFFER_SIZE 50 char line[LINE_BUFFER_SIZE]; uint8_t char_counter; @@ -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(); diff --git a/stepper.c b/stepper.c index d84b92c..d939c73 100644 --- a/stepper.c +++ b/stepper.c @@ -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" @@ -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; @@ -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 @@ -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); diff --git a/wiring_serial.c b/wiring_serial.c index 641aad1..fdec46f 100644 --- a/wiring_serial.c +++ b/wiring_serial.c @@ -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); @@ -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() @@ -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