|
@@ -18,10 +18,12 @@
|
18
|
18
|
|
19
|
19
|
/*
|
20
|
20
|
This firmware is a mashup between Sprinter and grbl.
|
|
21
|
+ (https://github.com/kliment/Sprinter)
|
|
22
|
+ (https://github.com/simen/grbl/tree)
|
|
23
|
+
|
21
|
24
|
It has preliminary support for Matthew Roberts advance algorithm
|
22
|
25
|
http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
|
23
|
|
- (https://github.com/kliment/Sprinter)
|
24
|
|
- (https://github.com/simen/grbl/tree)
|
|
26
|
+
|
25
|
27
|
This firmware is optimized for gen6 electronics.
|
26
|
28
|
*/
|
27
|
29
|
|
|
@@ -35,12 +37,12 @@ char version_string[] = "0.9.0";
|
35
|
37
|
|
36
|
38
|
#ifdef SDSUPPORT
|
37
|
39
|
#include "SdFat.h"
|
38
|
|
-#endif
|
|
40
|
+#endif //SDSUPPORT
|
39
|
41
|
|
40
|
42
|
#ifndef CRITICAL_SECTION_START
|
41
|
43
|
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli()
|
42
|
44
|
#define CRITICAL_SECTION_END SREG = _sreg
|
43
|
|
-#endif
|
|
45
|
+#endif //CRITICAL_SECTION_START
|
44
|
46
|
|
45
|
47
|
// look here for descriptions of gcodes: http://linuxcnc.org/handbook/gcode/g-code.html
|
46
|
48
|
// http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes
|
|
@@ -138,18 +140,18 @@ unsigned char temp_meas_ready = false;
|
138
|
140
|
double pid_input;
|
139
|
141
|
double pid_output;
|
140
|
142
|
bool pid_reset;
|
141
|
|
-#endif
|
|
143
|
+#endif //PIDTEMP
|
142
|
144
|
|
143
|
145
|
#ifdef WATCHPERIOD
|
144
|
146
|
int watch_raw = -1000;
|
145
|
147
|
unsigned long watchmillis = 0;
|
146
|
|
-#endif
|
|
148
|
+#endif //WATCHPERIOD
|
147
|
149
|
#ifdef MINTEMP
|
148
|
150
|
int minttemp = temp2analogh(MINTEMP);
|
149
|
|
-#endif
|
|
151
|
+#endif //MINTEMP
|
150
|
152
|
#ifdef MAXTEMP
|
151
|
153
|
int maxttemp = temp2analogh(MAXTEMP);
|
152
|
|
-#endif
|
|
154
|
+#endif //MAXTEMP
|
153
|
155
|
|
154
|
156
|
//Inactivity shutdown variables
|
155
|
157
|
unsigned long previous_millis_cmd = 0;
|
|
@@ -183,7 +185,7 @@ void initsd(){
|
183
|
185
|
Serial.println("openRoot failed");
|
184
|
186
|
else
|
185
|
187
|
sdactive = true;
|
186
|
|
-#endif
|
|
188
|
+#endif //SDSS
|
187
|
189
|
}
|
188
|
190
|
|
189
|
191
|
inline void write_command(char *buf){
|
|
@@ -205,7 +207,7 @@ inline void write_command(char *buf){
|
205
|
207
|
Serial.println("error writing to file");
|
206
|
208
|
}
|
207
|
209
|
}
|
208
|
|
-#endif
|
|
210
|
+#endif //SDSUPPORT
|
209
|
211
|
|
210
|
212
|
|
211
|
213
|
void setup()
|
|
@@ -278,7 +280,7 @@ void setup()
|
278
|
280
|
SET_INPUT(Z_MAX_PIN);
|
279
|
281
|
WRITE(Z_MAX_PIN,HIGH);
|
280
|
282
|
#endif
|
281
|
|
-#else
|
|
283
|
+#else //ENDSTOPPULLUPS
|
282
|
284
|
#if X_MIN_PIN > -1
|
283
|
285
|
SET_INPUT(X_MIN_PIN);
|
284
|
286
|
#endif
|
|
@@ -297,7 +299,7 @@ void setup()
|
297
|
299
|
#if Z_MAX_PIN > -1
|
298
|
300
|
SET_INPUT(Z_MAX_PIN);
|
299
|
301
|
#endif
|
300
|
|
-#endif
|
|
302
|
+#endif //ENDSTOPPULLUPS
|
301
|
303
|
|
302
|
304
|
#if (HEATER_0_PIN > -1)
|
303
|
305
|
SET_OUTPUT(HEATER_0_PIN);
|
|
@@ -333,10 +335,10 @@ void setup()
|
333
|
335
|
#if SDPOWER > -1
|
334
|
336
|
SET_OUTPUT(SDPOWER);
|
335
|
337
|
WRITE(SDPOWER,HIGH);
|
336
|
|
-#endif
|
|
338
|
+#endif //SDPOWER
|
337
|
339
|
initsd();
|
338
|
340
|
|
339
|
|
-#endif
|
|
341
|
+#endif //SDSUPPORT
|
340
|
342
|
plan_init(); // Initialize planner;
|
341
|
343
|
st_init(); // Initialize stepper;
|
342
|
344
|
tp_init(); // Initialize temperature loop
|
|
@@ -367,7 +369,7 @@ void loop()
|
367
|
369
|
}
|
368
|
370
|
#else
|
369
|
371
|
process_commands();
|
370
|
|
-#endif
|
|
372
|
+#endif //SDSUPPORT
|
371
|
373
|
buflen = (buflen-1);
|
372
|
374
|
bufindr = (bufindr + 1)%BUFSIZE;
|
373
|
375
|
}
|
|
@@ -446,7 +448,7 @@ inline void get_command()
|
446
|
448
|
#ifdef SDSUPPORT
|
447
|
449
|
if(savetosd)
|
448
|
450
|
break;
|
449
|
|
-#endif
|
|
451
|
+#endif //SDSUPPORT
|
450
|
452
|
Serial.println("ok");
|
451
|
453
|
break;
|
452
|
454
|
default:
|
|
@@ -497,7 +499,7 @@ inline void get_command()
|
497
|
499
|
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
|
498
|
500
|
}
|
499
|
501
|
}
|
500
|
|
-#endif
|
|
502
|
+#endif //SDSUPPORT
|
501
|
503
|
|
502
|
504
|
}
|
503
|
505
|
|
|
@@ -751,7 +753,7 @@ inline void process_commands()
|
751
|
753
|
//processed in write to file routine above
|
752
|
754
|
//savetosd = false;
|
753
|
755
|
break;
|
754
|
|
-#endif
|
|
756
|
+#endif //SDSUPPORT
|
755
|
757
|
case 104: // M104
|
756
|
758
|
#ifdef PID_OPENLOOP
|
757
|
759
|
if (code_seen('S')) PidTemp_Output = code_value() * (PID_MAX/100.0);
|
|
@@ -790,7 +792,7 @@ inline void process_commands()
|
790
|
792
|
else{
|
791
|
793
|
watchmillis = 0;
|
792
|
794
|
}
|
793
|
|
-#endif
|
|
795
|
+#endif //WATCHERPERIOD
|
794
|
796
|
codenum = millis();
|
795
|
797
|
while(current_raw < target_raw) {
|
796
|
798
|
if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
|
|
@@ -922,7 +924,7 @@ void ClearToSend()
|
922
|
924
|
#ifdef SDSUPPORT
|
923
|
925
|
if(fromsd[bufindr])
|
924
|
926
|
return;
|
925
|
|
-#endif
|
|
927
|
+#endif //SDSUPPORT
|
926
|
928
|
Serial.println("ok");
|
927
|
929
|
}
|
928
|
930
|
|
|
@@ -958,7 +960,7 @@ CRITICAL_SECTION_START;
|
958
|
960
|
CRITICAL_SECTION_END;
|
959
|
961
|
|
960
|
962
|
#ifdef PIDTEMP
|
961
|
|
- pid_input = analog2temp(current_raw);//ACT
|
|
963
|
+ pid_input = analog2temp(current_raw);
|
962
|
964
|
|
963
|
965
|
#ifndef PID_OPENLOOP
|
964
|
966
|
pid_error = pid_setpoint - pid_input;
|
|
@@ -1000,7 +1002,7 @@ CRITICAL_SECTION_END;
|
1000
|
1002
|
Serial.println();
|
1001
|
1003
|
#endif //PID_DEBUG
|
1002
|
1004
|
OCR2B = pid_output;
|
1003
|
|
-#endif
|
|
1005
|
+#endif //PIDTEMP
|
1004
|
1006
|
}
|
1005
|
1007
|
|
1006
|
1008
|
|
|
@@ -1051,7 +1053,7 @@ inline void kill()
|
1051
|
1053
|
target_raw=0;
|
1052
|
1054
|
#ifdef PIDTEMP
|
1053
|
1055
|
pid_setpoint = 0.0;
|
1054
|
|
-#endif PIDTEMP
|
|
1056
|
+#endif //PIDTEMP
|
1055
|
1057
|
OCR2B = 0;
|
1056
|
1058
|
WRITE(HEATER_0_PIN,LOW);
|
1057
|
1059
|
|
|
@@ -1465,7 +1467,7 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) {
|
1465
|
1467
|
float speed_factor = 1;
|
1466
|
1468
|
float tmp_speed_factor;
|
1467
|
1469
|
if(abs(block->speed_x) > max_feedrate[X_AXIS]) {
|
1468
|
|
- speed_factor = max_feedrate[Y_AXIS] / abs(block->speed_x);
|
|
1470
|
+ speed_factor = max_feedrate[X_AXIS] / abs(block->speed_x);
|
1469
|
1471
|
}
|
1470
|
1472
|
if(abs(block->speed_y) > max_feedrate[Y_AXIS]){
|
1471
|
1473
|
tmp_speed_factor = max_feedrate[Y_AXIS] / abs(block->speed_y);
|
|
@@ -1473,11 +1475,11 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) {
|
1473
|
1475
|
}
|
1474
|
1476
|
if(abs(block->speed_z) > max_feedrate[Z_AXIS]){
|
1475
|
1477
|
tmp_speed_factor = max_feedrate[Z_AXIS] / abs(block->speed_z);
|
1476
|
|
- if(tmp_speed_factor < speed_factor) speed_factor = tmp_speed_factor;
|
|
1478
|
+ if(speed_factor > tmp_speed_factor) speed_factor = tmp_speed_factor;
|
1477
|
1479
|
}
|
1478
|
1480
|
if(abs(block->speed_e) > max_feedrate[E_AXIS]){
|
1479
|
1481
|
tmp_speed_factor = max_feedrate[E_AXIS] / abs(block->speed_e);
|
1480
|
|
- if(tmp_speed_factor < speed_factor) speed_factor = tmp_speed_factor;
|
|
1482
|
+ if(speed_factor > tmp_speed_factor) speed_factor = tmp_speed_factor;
|
1481
|
1483
|
}
|
1482
|
1484
|
multiplier = multiplier * speed_factor;
|
1483
|
1485
|
block->speed_z = delta_z_mm * multiplier;
|
|
@@ -1910,8 +1912,6 @@ ISR(TIMER0_COMPA_vect)
|
1910
|
1912
|
// Critical section needed because Timer 1 interrupt has higher priority.
|
1911
|
1913
|
// The pin set functions are placed on trategic position to comply with the stepper driver timing.
|
1912
|
1914
|
WRITE(E_STEP_PIN, LOW);
|
1913
|
|
- // e_steps is changed in timer 1 interrupt
|
1914
|
|
- CRITICAL_SECTION_START;
|
1915
|
1915
|
// Set E direction (Depends on E direction + advance)
|
1916
|
1916
|
if (e_steps < 0) {
|
1917
|
1917
|
WRITE(E_DIR_PIN,INVERT_E_DIR);
|
|
@@ -1923,7 +1923,6 @@ ISR(TIMER0_COMPA_vect)
|
1923
|
1923
|
e_steps--;
|
1924
|
1924
|
WRITE(E_STEP_PIN, HIGH);
|
1925
|
1925
|
}
|
1926
|
|
- CRITICAL_SECTION_END;
|
1927
|
1926
|
old_OCR0A += 25; // 10kHz interrupt
|
1928
|
1927
|
OCR0A = old_OCR0A;
|
1929
|
1928
|
}
|
|
@@ -1974,7 +1973,7 @@ void tp_init()
|
1974
|
1973
|
TCCR2A = 0x23; //OC2A disable; FastPWM noninverting; FastPWM mode 7
|
1975
|
1974
|
#else
|
1976
|
1975
|
TCCR2A = 0x03; //OC2A disable; FastPWM noninverting; FastPWM mode 7
|
1977
|
|
-#endif
|
|
1976
|
+#endif //PIDTEMP
|
1978
|
1977
|
OCR2A = 156; //Period is ~10ms
|
1979
|
1978
|
OCR2B = 0; //Duty Cycle for heater pin is 0 (startup)
|
1980
|
1979
|
TIMSK2 = 0x01; //Enable overflow interrupt
|
|
@@ -2009,9 +2008,9 @@ ISR(TIMER2_OVF_vect)
|
2009
|
2008
|
OCR2B = 0;
|
2010
|
2009
|
#else
|
2011
|
2010
|
WRITE(HEATER_0_PIN,LOW);
|
2012
|
|
-#endif
|
|
2011
|
+#endif //PIDTEMP
|
2013
|
2012
|
}
|
2014
|
|
-#endif
|
|
2013
|
+#endif //MAXTEMP
|
2015
|
2014
|
#ifdef MINTEMP
|
2016
|
2015
|
if(current_raw <= minttemp) {
|
2017
|
2016
|
target_raw = 0;
|
|
@@ -2019,9 +2018,9 @@ ISR(TIMER2_OVF_vect)
|
2019
|
2018
|
OCR2B = 0;
|
2020
|
2019
|
#else
|
2021
|
2020
|
WRITE(HEATER_0_PIN,LOW);
|
2022
|
|
-#endif
|
|
2021
|
+#endif //PIDTEMP
|
2023
|
2022
|
}
|
2024
|
|
-#endif
|
|
2023
|
+#endif //MAXTEMP
|
2025
|
2024
|
#ifndef PIDTEMP
|
2026
|
2025
|
if(current_raw >= target_raw)
|
2027
|
2026
|
{
|
|
@@ -2031,7 +2030,7 @@ ISR(TIMER2_OVF_vect)
|
2031
|
2030
|
{
|
2032
|
2031
|
WRITE(HEATER_0_PIN,HIGH);
|
2033
|
2032
|
}
|
2034
|
|
-#endif
|
|
2033
|
+#endif //PIDTEMP
|
2035
|
2034
|
}
|
2036
|
2035
|
}
|
2037
|
2036
|
|