Browse Source

Removed interrupt nesting in the stepper ISR.

Add serial checkRx in stepper ISR.
Copied HardwareSerial to MarlinSerial (Needed for checkRx).
Erik van der Zalm 13 years ago
parent
commit
f75f426dfa

+ 1
- 1
Marlin/Configuration.h View File

232
 
232
 
233
 // minimum time in microseconds that a movement needs to take if the buffer is emptied.   Increase this number if you see blobs while printing high speed & high detail.  It will slowdown on the detailed stuff.
233
 // minimum time in microseconds that a movement needs to take if the buffer is emptied.   Increase this number if you see blobs while printing high speed & high detail.  It will slowdown on the detailed stuff.
234
 #define DEFAULT_MINSEGMENTTIME        20000   // Obsolete delete this
234
 #define DEFAULT_MINSEGMENTTIME        20000   // Obsolete delete this
235
-#define DEFAULT_XYJERK                30.0    // (mm/sec)
235
+#define DEFAULT_XYJERK                20.0    // (mm/sec)
236
 #define DEFAULT_ZJERK                 0.4     // (mm/sec)
236
 #define DEFAULT_ZJERK                 0.4     // (mm/sec)
237
 
237
 
238
 
238
 

+ 1
- 0
Marlin/EEPROMwrite.h View File

4
 #include "Marlin.h"
4
 #include "Marlin.h"
5
 #include "planner.h"
5
 #include "planner.h"
6
 #include "temperature.h"
6
 #include "temperature.h"
7
+
7
 #include <EEPROM.h>
8
 #include <EEPROM.h>
8
 
9
 
9
 template <class T> int EEPROM_writeAnything(int &ee, const T& value)
10
 template <class T> int EEPROM_writeAnything(int &ee, const T& value)

+ 6
- 4
Marlin/Marlin.h View File

3
 
3
 
4
 // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
4
 // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
5
 // Licence: GPL
5
 // Licence: GPL
6
+#define  HardwareSerial_h // trick to disable the standard HWserial
6
 #include <WProgram.h>
7
 #include <WProgram.h>
7
 #include "fastio.h"
8
 #include "fastio.h"
8
 #include <avr/pgmspace.h>
9
 #include <avr/pgmspace.h>
9
 #include "Configuration.h"
10
 #include "Configuration.h"
11
+#include "MarlinSerial.h"
10
 
12
 
11
 //#define SERIAL_ECHO(x) Serial << "echo: " << x;
13
 //#define SERIAL_ECHO(x) Serial << "echo: " << x;
12
 //#define SERIAL_ECHOLN(x) Serial << "echo: "<<x<<endl;
14
 //#define SERIAL_ECHOLN(x) Serial << "echo: "<<x<<endl;
17
 
19
 
18
 
20
 
19
 
21
 
20
-#define SERIAL_PROTOCOL(x) Serial.print(x);
22
+#define SERIAL_PROTOCOL(x) MSerial.print(x);
21
 #define SERIAL_PROTOCOLPGM(x) serialprintPGM(PSTR(x));
23
 #define SERIAL_PROTOCOLPGM(x) serialprintPGM(PSTR(x));
22
-#define SERIAL_PROTOCOLLN(x) {Serial.print(x);Serial.write('\n');}
23
-#define SERIAL_PROTOCOLLNPGM(x) {serialprintPGM(PSTR(x));Serial.write('\n');}
24
+#define SERIAL_PROTOCOLLN(x) {MSerial.print(x);MSerial.write('\n');}
25
+#define SERIAL_PROTOCOLLNPGM(x) {serialprintPGM(PSTR(x));MSerial.write('\n');}
24
 
26
 
25
 const char errormagic[] PROGMEM ="Error:";
27
 const char errormagic[] PROGMEM ="Error:";
26
 const char echomagic[] PROGMEM ="echo:";
28
 const char echomagic[] PROGMEM ="echo:";
46
   char ch=pgm_read_byte(str);
48
   char ch=pgm_read_byte(str);
47
   while(ch)
49
   while(ch)
48
   {
50
   {
49
-    Serial.write(ch);
51
+    MSerial.write(ch);
50
     ch=pgm_read_byte(++str);
52
     ch=pgm_read_byte(++str);
51
   }
53
   }
52
 }
54
 }

+ 7
- 18
Marlin/Marlin.pde View File

176
 
176
 
177
 static uint8_t tmp_extruder;
177
 static uint8_t tmp_extruder;
178
 
178
 
179
+
179
 //===========================================================================
180
 //===========================================================================
180
 //=============================ROUTINES=============================
181
 //=============================ROUTINES=============================
181
 //===========================================================================
182
 //===========================================================================
199
   }
200
   }
200
 }
201
 }
201
 
202
 
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
 //adds an command to the main command buffer
203
 //adds an command to the main command buffer
210
 //thats really done in a non-safe way.
204
 //thats really done in a non-safe way.
211
 //needs overworking someday
205
 //needs overworking someday
226
 
220
 
227
 void setup()
221
 void setup()
228
 { 
222
 { 
229
-  Serial.begin(BAUDRATE);
223
+  MSerial.begin(BAUDRATE);
230
   SERIAL_ECHO_START;
224
   SERIAL_ECHO_START;
231
   SERIAL_ECHOLNPGM(VERSION_STRING);
225
   SERIAL_ECHOLNPGM(VERSION_STRING);
232
   SERIAL_PROTOCOLLNPGM("start");
226
   SERIAL_PROTOCOLLNPGM("start");
289
   manage_heater();
283
   manage_heater();
290
   manage_inactivity(1);
284
   manage_inactivity(1);
291
   checkHitEndstops();
285
   checkHitEndstops();
292
-  checkStepperErrors();
293
   LCD_STATUS;
286
   LCD_STATUS;
294
 }
287
 }
295
 
288
 
296
 
289
 
297
 inline void get_command() 
290
 inline void get_command() 
298
 { 
291
 { 
299
-  while( Serial.available() > 0  && buflen < BUFSIZE) {
300
-    serial_char = Serial.read();
292
+  while( MSerial.available() > 0  && buflen < BUFSIZE) {
293
+    serial_char = MSerial.read();
301
     if(serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1) ) 
294
     if(serial_char == '\n' || serial_char == '\r' || serial_char == ':' || serial_count >= (MAX_CMD_SIZE - 1) ) 
302
     {
295
     {
303
       if(!serial_count) return; //if empty line
296
       if(!serial_count) return; //if empty line
1039
 void FlushSerialRequestResend()
1032
 void FlushSerialRequestResend()
1040
 {
1033
 {
1041
   //char cmdbuffer[bufindr][100]="Resend:";
1034
   //char cmdbuffer[bufindr][100]="Resend:";
1042
-  Serial.flush();
1035
+  MSerial.flush();
1043
   SERIAL_PROTOCOLPGM("Resend:");
1036
   SERIAL_PROTOCOLPGM("Resend:");
1044
   SERIAL_PROTOCOLLN(gcode_LastN + 1);
1037
   SERIAL_PROTOCOLLN(gcode_LastN + 1);
1045
   ClearToSend();
1038
   ClearToSend();
1088
     if (destination[Z_AXIS] > Z_MAX_LENGTH) destination[Z_AXIS] = Z_MAX_LENGTH;
1081
     if (destination[Z_AXIS] > Z_MAX_LENGTH) destination[Z_AXIS] = Z_MAX_LENGTH;
1089
   }
1082
   }
1090
 
1083
 
1091
-  plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0);
1084
+  plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate*feedmultiply/60/100.0, active_extruder);
1092
   for(int8_t i=0; i < NUM_AXIS; i++) {
1085
   for(int8_t i=0; i < NUM_AXIS; i++) {
1093
     current_position[i] = destination[i];
1086
     current_position[i] = destination[i];
1094
   }
1087
   }
1098
   float r = hypot(offset[X_AXIS], offset[Y_AXIS]); // Compute arc radius for mc_arc
1091
   float r = hypot(offset[X_AXIS], offset[Y_AXIS]); // Compute arc radius for mc_arc
1099
 
1092
 
1100
   // Trace the arc
1093
   // Trace the arc
1101
-  mc_arc(current_position, destination, offset, X_AXIS, Y_AXIS, Z_AXIS, feedrate*feedmultiply/60/100.0, r, isclockwise);
1094
+  mc_arc(current_position, destination, offset, X_AXIS, Y_AXIS, Z_AXIS, feedrate*feedmultiply/60/100.0, r, isclockwise, active_extruder);
1102
   
1095
   
1103
   // As far as the parser is concerned, the position is now == target. In reality the
1096
   // As far as the parser is concerned, the position is now == target. In reality the
1104
   // motion control system might still be processing the action and the real tool position
1097
   // motion control system might still be processing the action and the real tool position
1108
   }
1101
   }
1109
 }
1102
 }
1110
 
1103
 
1111
-
1112
-
1113
-
1114
-
1115
 void manage_inactivity(byte debug) 
1104
 void manage_inactivity(byte debug) 
1116
 { 
1105
 { 
1117
   if( (millis()-previous_millis_cmd) >  max_inactive_time ) 
1106
   if( (millis()-previous_millis_cmd) >  max_inactive_time ) 

+ 213
- 0
Marlin/MarlinSerial.cpp View File

1
+/*
2
+  HardwareSerial.cpp - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.
4
+
5
+  This library is free software; you can redistribute it and/or
6
+  modify it under the terms of the GNU Lesser General Public
7
+  License as published by the Free Software Foundation; either
8
+  version 2.1 of the License, or (at your option) any later version.
9
+
10
+  This library is distributed in the hope that it will be useful,
11
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+  Lesser General Public License for more details.
14
+
15
+  You should have received a copy of the GNU Lesser General Public
16
+  License along with this library; if not, write to the Free Software
17
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
+  
19
+  Modified 23 November 2006 by David A. Mellis
20
+  Modified 28 September 2010 by Mark Sproul
21
+*/
22
+
23
+#include <stdlib.h>
24
+#include <stdio.h>
25
+#include <string.h>
26
+#include <inttypes.h>
27
+#include "wiring.h"
28
+#include "wiring_private.h"
29
+
30
+// this next line disables the entire HardwareSerial.cpp, 
31
+// this is so I can support Attiny series and any other chip without a uart
32
+#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
33
+
34
+#include "MarlinSerial.h"
35
+
36
+// Define constants and variables for buffering incoming serial data.  We're
37
+// using a ring buffer (I think), in which rx_buffer_head is the index of the
38
+// location to which to write the next incoming character and rx_buffer_tail
39
+// is the index of the location from which to read.
40
+#define RX_BUFFER_SIZE 128
41
+
42
+struct ring_buffer
43
+{
44
+  unsigned char buffer[RX_BUFFER_SIZE];
45
+  int head;
46
+  int tail;
47
+};
48
+
49
+#if defined(UBRRH) || defined(UBRR0H)
50
+  ring_buffer rx_buffer  =  { { 0 }, 0, 0 };
51
+#endif
52
+
53
+
54
+inline void store_char(unsigned char c, ring_buffer *rx_buffer)
55
+{
56
+  int i = (unsigned int)(rx_buffer->head + 1) % RX_BUFFER_SIZE;
57
+
58
+  // if we should be storing the received character into the location
59
+  // just before the tail (meaning that the head would advance to the
60
+  // current location of the tail), we're about to overflow the buffer
61
+  // and so we don't write the character or advance the head.
62
+  if (i != rx_buffer->tail) {
63
+    rx_buffer->buffer[rx_buffer->head] = c;
64
+    rx_buffer->head = i;
65
+  }
66
+}
67
+
68
+
69
+//#elif defined(SIG_USART_RECV)
70
+#if defined(USART0_RX_vect)
71
+  // fixed by Mark Sproul this is on the 644/644p
72
+  //SIGNAL(SIG_USART_RECV)
73
+  SIGNAL(USART0_RX_vect)
74
+  {
75
+  #if defined(UDR0)
76
+    unsigned char c  =  UDR0;
77
+  #elif defined(UDR)
78
+    unsigned char c  =  UDR;  //  atmega8, atmega32
79
+  #else
80
+    #error UDR not defined
81
+  #endif
82
+    store_char(c, &rx_buffer);
83
+  }
84
+#endif
85
+
86
+// Constructors ////////////////////////////////////////////////////////////////
87
+
88
+MarlinSerial::MarlinSerial(ring_buffer *rx_buffer,
89
+  volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
90
+  volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
91
+  volatile uint8_t *udr,
92
+  uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
93
+{
94
+  _rx_buffer = rx_buffer;
95
+  _ubrrh = ubrrh;
96
+  _ubrrl = ubrrl;
97
+  _ucsra = ucsra;
98
+  _ucsrb = ucsrb;
99
+  _udr = udr;
100
+  _rxen = rxen;
101
+  _txen = txen;
102
+  _rxcie = rxcie;
103
+  _udre = udre;
104
+  _u2x = u2x;
105
+}
106
+
107
+// Public Methods //////////////////////////////////////////////////////////////
108
+
109
+void MarlinSerial::begin(long baud)
110
+{
111
+  uint16_t baud_setting;
112
+  bool use_u2x = true;
113
+
114
+#if F_CPU == 16000000UL
115
+  // hardcoded exception for compatibility with the bootloader shipped
116
+  // with the Duemilanove and previous boards and the firmware on the 8U2
117
+  // on the Uno and Mega 2560.
118
+  if (baud == 57600) {
119
+    use_u2x = false;
120
+  }
121
+#endif
122
+  
123
+  if (use_u2x) {
124
+    *_ucsra = 1 << _u2x;
125
+    baud_setting = (F_CPU / 4 / baud - 1) / 2;
126
+  } else {
127
+    *_ucsra = 0;
128
+    baud_setting = (F_CPU / 8 / baud - 1) / 2;
129
+  }
130
+
131
+  // assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
132
+  *_ubrrh = baud_setting >> 8;
133
+  *_ubrrl = baud_setting;
134
+
135
+  sbi(*_ucsrb, _rxen);
136
+  sbi(*_ucsrb, _txen);
137
+  sbi(*_ucsrb, _rxcie);
138
+}
139
+
140
+void MarlinSerial::end()
141
+{
142
+  cbi(*_ucsrb, _rxen);
143
+  cbi(*_ucsrb, _txen);
144
+  cbi(*_ucsrb, _rxcie);  
145
+}
146
+
147
+int MarlinSerial::available(void)
148
+{
149
+  return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
150
+}
151
+
152
+int MarlinSerial::peek(void)
153
+{
154
+  if (_rx_buffer->head == _rx_buffer->tail) {
155
+    return -1;
156
+  } else {
157
+    return _rx_buffer->buffer[_rx_buffer->tail];
158
+  }
159
+}
160
+
161
+int MarlinSerial::read(void)
162
+{
163
+  // if the head isn't ahead of the tail, we don't have any characters
164
+  if (_rx_buffer->head == _rx_buffer->tail) {
165
+    return -1;
166
+  } else {
167
+    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
168
+    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
169
+    return c;
170
+  }
171
+}
172
+
173
+void MarlinSerial::flush()
174
+{
175
+  // don't reverse this or there may be problems if the RX interrupt
176
+  // occurs after reading the value of rx_buffer_head but before writing
177
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
178
+  // may be written to rx_buffer_tail, making it appear as if the buffer
179
+  // don't reverse this or there may be problems if the RX interrupt
180
+  // occurs after reading the value of rx_buffer_head but before writing
181
+  // the value to rx_buffer_tail; the previous value of rx_buffer_head
182
+  // may be written to rx_buffer_tail, making it appear as if the buffer
183
+  // were full, not empty.
184
+  _rx_buffer->head = _rx_buffer->tail;
185
+}
186
+
187
+void MarlinSerial::write(uint8_t c)
188
+{
189
+  while (!((*_ucsra) & (1 << _udre)))
190
+    ;
191
+
192
+  *_udr = c;
193
+}
194
+
195
+void MarlinSerial::checkRx()
196
+{
197
+  if((UCSR0A & (1<<RXC0)) != 0) {
198
+    unsigned char c  =  UDR0;
199
+    store_char(c, &rx_buffer);
200
+  }
201
+}
202
+
203
+// Preinstantiate Objects //////////////////////////////////////////////////////
204
+
205
+#if defined(UBRR0H) && defined(UBRR0L)
206
+  MarlinSerial MSerial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
207
+#else
208
+  #error no serial port defined  (port 0)
209
+#endif
210
+
211
+
212
+#endif // whole file
213
+

+ 66
- 0
Marlin/MarlinSerial.h View File

1
+/*
2
+  HardwareSerial.h - Hardware serial library for Wiring
3
+  Copyright (c) 2006 Nicholas Zambetti.  All right reserved.
4
+
5
+  This library is free software; you can redistribute it and/or
6
+  modify it under the terms of the GNU Lesser General Public
7
+  License as published by the Free Software Foundation; either
8
+  version 2.1 of the License, or (at your option) any later version.
9
+
10
+  This library is distributed in the hope that it will be useful,
11
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+  Lesser General Public License for more details.
14
+
15
+  You should have received a copy of the GNU Lesser General Public
16
+  License along with this library; if not, write to the Free Software
17
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
+
19
+  Modified 28 September 2010 by Mark Sproul
20
+*/
21
+
22
+#ifndef MarlinSerial_h
23
+#define MarlinSerial_h
24
+
25
+#include <inttypes.h>
26
+
27
+#include "Stream.h"
28
+
29
+struct ring_buffer;
30
+
31
+class MarlinSerial : public Stream
32
+{
33
+  private:
34
+    ring_buffer *_rx_buffer;
35
+    volatile uint8_t *_ubrrh;
36
+    volatile uint8_t *_ubrrl;
37
+    volatile uint8_t *_ucsra;
38
+    volatile uint8_t *_ucsrb;
39
+    volatile uint8_t *_udr;
40
+    uint8_t _rxen;
41
+    uint8_t _txen;
42
+    uint8_t _rxcie;
43
+    uint8_t _udre;
44
+    uint8_t _u2x;
45
+  public:
46
+    MarlinSerial(ring_buffer *rx_buffer,
47
+      volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
48
+      volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
49
+      volatile uint8_t *udr,
50
+      uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
51
+    void begin(long);
52
+    void end();
53
+    virtual int available(void);
54
+    virtual int peek(void);
55
+    virtual int read(void);
56
+    virtual void flush(void);
57
+    virtual void write(uint8_t);
58
+    virtual void checkRx(void);
59
+    using Print::write; // pull in write(str) and write(buf, size) from Print
60
+};
61
+
62
+#if defined(UBRRH) || defined(UBRR0H)
63
+  extern MarlinSerial MSerial;
64
+#endif
65
+
66
+#endif

+ 642
- 641
Marlin/Sd2Card.cpp
File diff suppressed because it is too large
View File


+ 5
- 5
Marlin/SdBaseFile.cpp View File

306
  * LS_R - Recursive list of subdirectories.
306
  * LS_R - Recursive list of subdirectories.
307
  */
307
  */
308
 void SdBaseFile::ls(uint8_t flags) {
308
 void SdBaseFile::ls(uint8_t flags) {
309
-  ls(&Serial, flags, 0);
309
+  ls(&MSerial, flags, 0);
310
 }
310
 }
311
 //------------------------------------------------------------------------------
311
 //------------------------------------------------------------------------------
312
 /** List directory contents.
312
 /** List directory contents.
949
  */
949
  */
950
 void SdBaseFile::printDirName(const dir_t& dir,
950
 void SdBaseFile::printDirName(const dir_t& dir,
951
   uint8_t width, bool printSlash) {
951
   uint8_t width, bool printSlash) {
952
-  printDirName(&Serial, dir, width, printSlash);
952
+  printDirName(&MSerial, dir, width, printSlash);
953
 }
953
 }
954
 //------------------------------------------------------------------------------
954
 //------------------------------------------------------------------------------
955
 /** %Print the name field of a directory entry in 8.3 format.
955
 /** %Print the name field of a directory entry in 8.3 format.
993
  * \param[in] fatDate The date field from a directory entry.
993
  * \param[in] fatDate The date field from a directory entry.
994
  */
994
  */
995
 void SdBaseFile::printFatDate(uint16_t fatDate) {
995
 void SdBaseFile::printFatDate(uint16_t fatDate) {
996
-  printFatDate(&Serial, fatDate);
996
+  printFatDate(&MSerial, fatDate);
997
 }
997
 }
998
 //------------------------------------------------------------------------------
998
 //------------------------------------------------------------------------------
999
 /** %Print a directory date field.
999
 /** %Print a directory date field.
1018
  * \param[in] fatTime The time field from a directory entry.
1018
  * \param[in] fatTime The time field from a directory entry.
1019
  */
1019
  */
1020
 void SdBaseFile::printFatTime(uint16_t fatTime) {
1020
 void SdBaseFile::printFatTime(uint16_t fatTime) {
1021
-  printFatTime(&Serial, fatTime);
1021
+  printFatTime(&MSerial, fatTime);
1022
 }
1022
 }
1023
 //------------------------------------------------------------------------------
1023
 //------------------------------------------------------------------------------
1024
 /** %Print a directory time field.
1024
 /** %Print a directory time field.
1044
 bool SdBaseFile::printName() {
1044
 bool SdBaseFile::printName() {
1045
   char name[13];
1045
   char name[13];
1046
   if (!getFilename(name)) return false;
1046
   if (!getFilename(name)) return false;
1047
-  Serial.print(name);
1047
+  MSerial.print(name);
1048
   return true;
1048
   return true;
1049
 }
1049
 }
1050
 //------------------------------------------------------------------------------
1050
 //------------------------------------------------------------------------------

+ 2
- 0
Marlin/SdBaseFile.h View File

25
  */
25
  */
26
 #include <avr/pgmspace.h>
26
 #include <avr/pgmspace.h>
27
 #if ARDUINO < 100
27
 #if ARDUINO < 100
28
+#define  HardwareSerial_h // trick to disable the standard HWserial
28
 #include <WProgram.h>
29
 #include <WProgram.h>
30
+#include "MarlinSerial.h"
29
 #else  // ARDUINO
31
 #else  // ARDUINO
30
 #include <Arduino.h>
32
 #include <Arduino.h>
31
 #endif  // ARDUINO
33
 #endif  // ARDUINO

+ 2
- 2
Marlin/SdFatUtil.cpp View File

62
  * \param[in] str Pointer to string stored in flash memory.
62
  * \param[in] str Pointer to string stored in flash memory.
63
  */
63
  */
64
 void SdFatUtil::SerialPrint_P(PGM_P str) {
64
 void SdFatUtil::SerialPrint_P(PGM_P str) {
65
-  print_P(&Serial, str);
65
+  print_P(&MSerial, str);
66
 }
66
 }
67
 //------------------------------------------------------------------------------
67
 //------------------------------------------------------------------------------
68
 /** %Print a string in flash memory to Serial followed by a CR/LF.
68
 /** %Print a string in flash memory to Serial followed by a CR/LF.
70
  * \param[in] str Pointer to string stored in flash memory.
70
  * \param[in] str Pointer to string stored in flash memory.
71
  */
71
  */
72
 void SdFatUtil::SerialPrintln_P(PGM_P str) {
72
 void SdFatUtil::SerialPrintln_P(PGM_P str) {
73
-  println_P(&Serial, str);
73
+  println_P(&MSerial, str);
74
 }
74
 }

+ 47
- 45
Marlin/SdFatUtil.h View File

1
-/* Arduino SdFat Library
2
- * Copyright (C) 2008 by William Greiman
3
- *
4
- * This file is part of the Arduino SdFat Library
5
- *
6
- * This Library is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This Library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
-
16
- * You should have received a copy of the GNU General Public License
17
- * along with the Arduino SdFat Library.  If not, see
18
- * <http://www.gnu.org/licenses/>.
19
- */
20
-#ifndef SdFatUtil_h
21
-#define SdFatUtil_h
22
-/**
23
- * \file
24
- * \brief Useful utility functions.
25
- */
26
-#include <avr/pgmspace.h>
27
-#if ARDUINO < 100
28
-#include <WProgram.h>
29
-#else  // ARDUINO
30
-#include <Arduino.h>
31
-#endif  // ARDUINO
32
-/** Store and print a string in flash memory.*/
33
-#define PgmPrint(x) SerialPrint_P(PSTR(x))
34
-/** Store and print a string in flash memory followed by a CR/LF.*/
35
-#define PgmPrintln(x) SerialPrintln_P(PSTR(x))
36
-
37
-namespace SdFatUtil {
38
-  int FreeRam();
39
-  void print_P(Print* pr, PGM_P str);
40
-  void println_P(Print* pr, PGM_P str);
41
-  void SerialPrint_P(PGM_P str);
42
-  void SerialPrintln_P(PGM_P str);
43
-}
44
-
45
-using namespace SdFatUtil;  // NOLINT
1
+/* Arduino SdFat Library
2
+ * Copyright (C) 2008 by William Greiman
3
+ *
4
+ * This file is part of the Arduino SdFat Library
5
+ *
6
+ * This Library is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This Library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with the Arduino SdFat Library.  If not, see
18
+ * <http://www.gnu.org/licenses/>.
19
+ */
20
+#ifndef SdFatUtil_h
21
+#define SdFatUtil_h
22
+/**
23
+ * \file
24
+ * \brief Useful utility functions.
25
+ */
26
+#include <avr/pgmspace.h>
27
+#if ARDUINO < 100
28
+#define  HardwareSerial_h // trick to disable the standard HWserial
29
+#include <WProgram.h>
30
+#include "MarlinSerial.h"
31
+#else  // ARDUINO
32
+#include <Arduino.h>
33
+#endif  // ARDUINO
34
+/** Store and print a string in flash memory.*/
35
+#define PgmPrint(x) SerialPrint_P(PSTR(x))
36
+/** Store and print a string in flash memory followed by a CR/LF.*/
37
+#define PgmPrintln(x) SerialPrintln_P(PSTR(x))
38
+
39
+namespace SdFatUtil {
40
+  int FreeRam();
41
+  void print_P(Print* pr, PGM_P str);
42
+  void println_P(Print* pr, PGM_P str);
43
+  void SerialPrint_P(PGM_P str);
44
+  void SerialPrintln_P(PGM_P str);
45
+}
46
+
47
+using namespace SdFatUtil;  // NOLINT
46
 #endif  // #define SdFatUtil_h
48
 #endif  // #define SdFatUtil_h

+ 3
- 3
Marlin/motion_control.cpp View File

27
 // The arc is approximated by generating a huge number of tiny, linear segments. The length of each 
27
 // The arc is approximated by generating a huge number of tiny, linear segments. The length of each 
28
 // segment is configured in settings.mm_per_arc_segment.  
28
 // segment is configured in settings.mm_per_arc_segment.  
29
 void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8_t axis_1, 
29
 void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8_t axis_1, 
30
-  uint8_t axis_linear, float feed_rate, float radius, uint8_t isclockwise)
30
+  uint8_t axis_linear, float feed_rate, float radius, uint8_t isclockwise, uint8_t extruder)
31
 {      
31
 {      
32
   //   int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled();
32
   //   int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled();
33
   //   plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc
33
   //   plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc
123
     arc_target[axis_1] = center_axis1 + r_axis1;
123
     arc_target[axis_1] = center_axis1 + r_axis1;
124
     arc_target[axis_linear] += linear_per_segment;
124
     arc_target[axis_linear] += linear_per_segment;
125
     arc_target[E_AXIS] += extruder_per_segment;
125
     arc_target[E_AXIS] += extruder_per_segment;
126
-    plan_buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], arc_target[E_AXIS], feed_rate);
126
+    plan_buffer_line(arc_target[X_AXIS], arc_target[Y_AXIS], arc_target[Z_AXIS], arc_target[E_AXIS], feed_rate, extruder);
127
     
127
     
128
   }
128
   }
129
   // Ensure last segment arrives at target location.
129
   // Ensure last segment arrives at target location.
130
-  plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feed_rate);
130
+  plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feed_rate, extruder);
131
 
131
 
132
   //   plan_set_acceleration_manager_enabled(acceleration_manager_was_enabled);
132
   //   plan_set_acceleration_manager_enabled(acceleration_manager_was_enabled);
133
 }
133
 }

+ 1
- 1
Marlin/motion_control.h View File

27
 // the direction of helical travel, radius == circle radius, isclockwise boolean. Used
27
 // the direction of helical travel, radius == circle radius, isclockwise boolean. Used
28
 // for vector transformation direction.
28
 // for vector transformation direction.
29
 void mc_arc(float *position, float *target, float *offset, unsigned char axis_0, unsigned char axis_1,
29
 void mc_arc(float *position, float *target, float *offset, unsigned char axis_0, unsigned char axis_1,
30
-  unsigned char axis_linear, float feed_rate, float radius, unsigned char isclockwise);
30
+  unsigned char axis_linear, float feed_rate, float radius, unsigned char isclockwise, uint8_t extruder);
31
   
31
   
32
 #endif
32
 #endif

+ 3
- 3
Marlin/planner.cpp View File

451
 // Add a new linear movement to the buffer. steps_x, _y and _z is the absolute position in 
451
 // Add a new linear movement to the buffer. steps_x, _y and _z is the absolute position in 
452
 // mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
452
 // mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
453
 // calculation the caller must also provide the physical length of the line in millimeters.
453
 // calculation the caller must also provide the physical length of the line in millimeters.
454
-void plan_buffer_line(const float &x, const float &y, const float &z, const float &e,  float feed_rate)
454
+void plan_buffer_line(const float &x, const float &y, const float &z, const float &e,  float feed_rate, const uint8_t &extruder)
455
 {
455
 {
456
   // Calculate the buffer head after we push this byte
456
   // Calculate the buffer head after we push this byte
457
   int next_buffer_head = next_block_index(block_buffer_head);
457
   int next_buffer_head = next_block_index(block_buffer_head);
527
   else {
527
   else {
528
     	if(feed_rate<minimumfeedrate) feed_rate=minimumfeedrate;
528
     	if(feed_rate<minimumfeedrate) feed_rate=minimumfeedrate;
529
   } 
529
   } 
530
-  
530
+
531
 #ifdef SLOWDOWN
531
 #ifdef SLOWDOWN
532
   // slow down when de buffer starts to empty, rather than wait at the corner for a buffer refill
532
   // slow down when de buffer starts to empty, rather than wait at the corner for a buffer refill
533
   int moves_queued=(block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
533
   int moves_queued=(block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1);
534
   
534
   
535
-  if(moves_queued < (BLOCK_BUFFER_SIZE * 0.5)) feed_rate = feed_rate*moves_queued / (BLOCK_BUFFER_SIZE * 0.5); 
535
+  if(moves_queued < (BLOCK_BUFFER_SIZE * 0.5) && moves_queued > 1) feed_rate = feed_rate*moves_queued / (BLOCK_BUFFER_SIZE * 0.5); 
536
 #endif
536
 #endif
537
 
537
 
538
 /*
538
 /*

+ 1
- 1
Marlin/planner.h View File

66
 
66
 
67
 // Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in 
67
 // Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in 
68
 // millimaters. Feed rate specifies the speed of the motion.
68
 // millimaters. Feed rate specifies the speed of the motion.
69
-void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate);
69
+void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate, const uint8_t &extruder);
70
 
70
 
71
 // Set position. Used for G92 instructions.
71
 // Set position. Used for G92 instructions.
72
 void plan_set_position(const float &x, const float &y, const float &z, const float &e);
72
 void plan_set_position(const float &x, const float &y, const float &z, const float &e);

+ 7
- 30
Marlin/stepper.cpp View File

52
             counter_y, 
52
             counter_y, 
53
             counter_z,       
53
             counter_z,       
54
             counter_e;
54
             counter_e;
55
-static unsigned long step_events_completed; // The number of step events executed in the current block
55
+volatile static unsigned long step_events_completed; // The number of step events executed in the current block
56
 #ifdef ADVANCE
56
 #ifdef ADVANCE
57
   static long advance_rate, advance, final_advance = 0;
57
   static long advance_rate, advance, final_advance = 0;
58
   static short old_advance = 0;
58
   static short old_advance = 0;
63
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
63
 //static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
64
 static unsigned short acc_step_rate; // needed for deccelaration start point
64
 static unsigned short acc_step_rate; // needed for deccelaration start point
65
 static char step_loops;
65
 static char step_loops;
66
+static unsigned short OCR1A_nominal;
66
 
67
 
67
 volatile long endstops_trigsteps[3]={0,0,0};
68
 volatile long endstops_trigsteps[3]={0,0,0};
68
 volatile long endstops_stepsTotal,endstops_stepsDone;
69
 volatile long endstops_stepsTotal,endstops_stepsDone;
77
 static bool old_z_min_endstop=false;
78
 static bool old_z_min_endstop=false;
78
 static bool old_z_max_endstop=false;
79
 static bool old_z_max_endstop=false;
79
 
80
 
80
-static bool busy_error=false;
81
-unsigned short OCR1A_error=12345;
82
-unsigned short OCR1A_nominal;
83
-
84
 volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
81
 volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
85
 volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
82
 volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
86
 
83
 
164
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  TIMSK1 |= (1<<OCIE1A)
161
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  TIMSK1 |= (1<<OCIE1A)
165
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
162
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
166
 
163
 
167
-void checkStepperErrors()
168
-{
169
-  if(busy_error) {
170
-    SERIAL_ERROR_START
171
-    SERIAL_ERROR(OCR1A_error);
172
-    SERIAL_ERRORLNPGM(" ISR overtaking itself.");
173
-    busy_error = false;
174
-  }
175
-}
176
 
164
 
177
 void checkHitEndstops()
165
 void checkHitEndstops()
178
 {
166
 {
255
     timer = (unsigned short)pgm_read_word_near(table_address);
243
     timer = (unsigned short)pgm_read_word_near(table_address);
256
     timer -= (((unsigned short)pgm_read_word_near(table_address+2) * (unsigned char)(step_rate & 0x0007))>>3);
244
     timer -= (((unsigned short)pgm_read_word_near(table_address+2) * (unsigned char)(step_rate & 0x0007))>>3);
257
   }
245
   }
258
-  if(timer < 100) { timer = 100; Serial.print("Steprate to high : "); Serial.println(step_rate); }//(20kHz this should never happen)
246
+  if(timer < 100) { timer = 100; MSerial.print("Steprate to high : "); MSerial.println(step_rate); }//(20kHz this should never happen)
259
   return timer;
247
   return timer;
260
 }
248
 }
261
 
249
 
277
 // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.  
265
 // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.  
278
 // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately. 
266
 // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately. 
279
 ISR(TIMER1_COMPA_vect)
267
 ISR(TIMER1_COMPA_vect)
280
-{        
281
-  if(busy){ 
282
-    OCR1A_error = OCR1A;
283
-    busy_error = true;
284
-    OCR1A = 30000;
285
-    return; 
286
-  } // The busy-flag is used to avoid reentering this interrupt
287
-
288
-  busy = true;
289
-  sei(); // Re enable interrupts (normally disabled while inside an interrupt handler)
290
-
268
+{    
291
   // If there is no current block, attempt to pop one from the buffer
269
   // If there is no current block, attempt to pop one from the buffer
292
   if (current_block == NULL) {
270
   if (current_block == NULL) {
293
     // Anything in the buffer?
271
     // Anything in the buffer?
304
 //      #endif
282
 //      #endif
305
     } 
283
     } 
306
     else {
284
     else {
307
-//      DISABLE_STEPPER_DRIVER_INTERRUPT();
285
+        OCR1A=2000; // 1kHz.
308
     }    
286
     }    
309
   } 
287
   } 
310
 
288
 
404
         count_direction[E_AXIS]=-1;
382
         count_direction[E_AXIS]=-1;
405
       }
383
       }
406
     #endif //!ADVANCE
384
     #endif //!ADVANCE
407
-
408
     for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves) 
385
     for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves) 
386
+    MSerial.checkRx();
409
     /*
387
     /*
410
       counter_e += current_block->steps_e;
388
       counter_e += current_block->steps_e;
411
       if (counter_e > 0) {
389
       if (counter_e > 0) {
470
     unsigned short timer;
448
     unsigned short timer;
471
     unsigned short step_rate;
449
     unsigned short step_rate;
472
     if (step_events_completed <= current_block->accelerate_until) {
450
     if (step_events_completed <= current_block->accelerate_until) {
451
+      
473
       MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
452
       MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
474
       acc_step_rate += current_block->initial_rate;
453
       acc_step_rate += current_block->initial_rate;
475
       
454
       
519
       plan_discard_current_block();
498
       plan_discard_current_block();
520
     }   
499
     }   
521
   } 
500
   } 
522
-  cli(); // disable interrupts
523
-  busy=false;
524
 }
501
 }
525
 
502
 
526
 #ifdef ADVANCE
503
 #ifdef ADVANCE

Loading…
Cancel
Save