Browse Source

Cleanup TMC Stepper a bit.

domonoky 10 years ago
parent
commit
5727cb3ed4
4 changed files with 151 additions and 127 deletions
  1. 1
    77
      Marlin/stepper.cpp
  2. 0
    40
      Marlin/stepper.h
  3. 106
    0
      Marlin/stepper_indirection.cpp
  4. 44
    10
      Marlin/stepper_indirection.h

+ 1
- 77
Marlin/stepper.cpp View File

87
 volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
87
 volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
88
 volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
88
 volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
89
 
89
 
90
-// Stepper objects of TMC steppers are used
91
-#ifdef X_IS_TMC
92
-	TMC26XStepper stepperX(200,X_ENABLE_PIN,X_STEP_PIN,X_DIR_PIN,X_MAX_CURRENT,X_SENSE_RESISTOR);
93
-#endif
94
-#ifdef X2_IS_TMC
95
-	TMC26XStepper stepperX2(200,X2_ENABLE_PIN,X2_STEP_PIN,X2_DIR_PIN,X2_MAX_CURRENT,X2_SENSE_RESISTOR);
96
-#endif
97
-#ifdef Y_IS_TMC
98
-	TMC26XStepper stepperY(200,Y_ENABLE_PIN,Y_STEP_PIN,Y_DIR_PIN,Y_MAX_CURRENT,Y_SENSE_RESISTOR);
99
-#endif
100
-#ifdef Y2_IS_TMC
101
-	TMC26XStepper stepperY2(200,Y2_ENABLE_PIN,Y2_STEP_PIN,Y2_DIR_PIN,Y2_MAX_CURRENT,Y2_SENSE_RESISTOR);
102
-#endif
103
-#ifdef Z_IS_TMC
104
-	TMC26XStepper stepperZ(200,Z_ENABLE_PIN,Z_STEP_PIN,Z_DIR_PIN,Z_MAX_CURRENT,Z_SENSE_RESISTOR);
105
-#endif
106
-#ifdef Z2_IS_TMC
107
-	TMC26XStepper stepperZ2(200,Z2_ENABLE_PIN,Z2_STEP_PIN,Z2_DIR_PIN,Z2_MAX_CURRENT,Z2_SENSE_RESISTOR);
108
-#endif
109
-#ifdef E0_IS_TMC
110
-	TMC26XStepper stepperE0(200,E0_ENABLE_PIN,E0_STEP_PIN,E0_DIR_PIN,E0_MAX_CURRENT,E0_SENSE_RESISTOR);
111
-#endif
112
-#ifdef E1_IS_TMC
113
-	TMC26XStepper stepperE1(200,E1_ENABLE_PIN,E1_STEP_PIN,E1_DIR_PIN,E1_MAX_CURRENT,E1_SENSE_RESISTOR);
114
-#endif
115
-#ifdef E2_IS_TMC
116
-	TMC26XStepper stepperE2(200,E2_ENABLE_PIN,E2_STEP_PIN,E2_DIR_PIN,E2_MAX_CURRENT,E2_SENSE_RESISTOR);
117
-#endif
118
-#ifdef E3_IS_TMC
119
-	TMC26XStepper stepperE3(200,E3_ENABLE_PIN,E3_STEP_PIN,E3_DIR_PIN,E3_MAX_CURRENT,E3_SENSE_RESISTOR);
120
-#endif	
90
+
121
 //===========================================================================
91
 //===========================================================================
122
 //=============================functions         ============================
92
 //=============================functions         ============================
123
 //===========================================================================
93
 //===========================================================================
1420
       SERIAL_PROTOCOLLN( digitalRead(E1_MS2_PIN));
1390
       SERIAL_PROTOCOLLN( digitalRead(E1_MS2_PIN));
1421
       #endif
1391
       #endif
1422
 }
1392
 }
1423
-
1424
-#ifdef HAVE_TMCDRIVER
1425
-void tmc_init()
1426
-{
1427
-#ifdef X_IS_TMC
1428
-	stepperX.setMicrosteps(X_MICROSTEPS);
1429
-	stepperX.start();
1430
-#endif
1431
-#ifdef X2_IS_TMC
1432
-	stepperX2.setMicrosteps(X2_MICROSTEPS);
1433
-	stepperX2.start();
1434
-#endif
1435
-#ifdef Y_IS_TMC
1436
-	stepperY.setMicrosteps(Y_MICROSTEPS);
1437
-	stepperY.start();
1438
-#endif
1439
-#ifdef Y2_IS_TMC
1440
-	stepperY2.setMicrosteps(Y2_MICROSTEPS);
1441
-	stepperY2.start();
1442
-#endif
1443
-#ifdef Z_IS_TMC
1444
-	stepperZ.setMicrosteps(Z_MICROSTEPS);
1445
-	stepperZ.start();
1446
-#endif
1447
-#ifdef Z2_IS_TMC
1448
-	stepperZ2.setMicrosteps(Z2_MICROSTEPS);
1449
-	stepperZ2.start();
1450
-#endif
1451
-#ifdef E0_IS_TMC
1452
-	stepperE0.setMicrosteps(E0_MICROSTEPS);
1453
-	stepperE0.start();
1454
-#endif
1455
-#ifdef E1_IS_TMC
1456
-	stepperE1.setMicrosteps(E1_MICROSTEPS);
1457
-	stepperE1.start();
1458
-#endif
1459
-#ifdef E2_IS_TMC
1460
-	stepperE2.setMicrosteps(E2_MICROSTEPS);
1461
-	stepperE2.start();
1462
-#endif
1463
-#ifdef E3_IS_TMC
1464
-	stepperE3.setMicrosteps(E3_MICROSTEPS);
1465
-	stepperE3.start();
1466
-#endif
1467
-}
1468
-#endif

+ 0
- 40
Marlin/stepper.h View File

24
 #include "planner.h"
24
 #include "planner.h"
25
 #include "stepper_indirection.h"
25
 #include "stepper_indirection.h"
26
 
26
 
27
-#ifdef HAVE_TMCDRIVER
28
-#include <SPI.h>
29
-#include <TMC26XStepper.h>
30
-#endif
31
-
32
 #if EXTRUDERS > 3
27
 #if EXTRUDERS > 3
33
   #define WRITE_E_STEP(v) { if(current_block->active_extruder == 3) { E3_STEP_WRITE(v); } else { if(current_block->active_extruder == 2) { E2_STEP_WRITE(v); } else { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}}}
28
   #define WRITE_E_STEP(v) { if(current_block->active_extruder == 3) { E3_STEP_WRITE(v); } else { if(current_block->active_extruder == 2) { E2_STEP_WRITE(v); } else { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}}}
34
   #define NORM_E_DIR() { if(current_block->active_extruder == 3) { E3_DIR_WRITE( !INVERT_E3_DIR); } else { if(current_block->active_extruder == 2) { E2_DIR_WRITE(!INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}}}
29
   #define NORM_E_DIR() { if(current_block->active_extruder == 3) { E3_DIR_WRITE( !INVERT_E3_DIR); } else { if(current_block->active_extruder == 2) { E2_DIR_WRITE(!INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}}}
106
   void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
101
   void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
107
 #endif
102
 #endif
108
      
103
      
109
-#ifdef HAVE_TMCDRIVER
110
-void tmc_init();
111
-	 
112
-#ifdef X_IS_TMC
113
-	extern TMC26XStepper stepperX;
114
-#endif
115
-#ifdef X2_IS_TMC
116
-	extern TMC26XStepper stepperX2;
117
-#endif
118
-#ifdef Y_IS_TMC
119
-	extern TMC26XStepper stepperY;
120
-#endif
121
-#ifdef Y2_IS_TMC
122
-	extern TMC26XStepper stepperY2;
123
-#endif
124
-#ifdef Z_IS_TMC
125
-	extern TMC26XStepper stepperZ;
126
-#endif
127
-#ifdef Z2_IS_TMC
128
-	extern TMC26XStepper stepperZ2;
129
-#endif
130
-#ifdef E0_IS_TMC
131
-	extern TMC26XStepper stepperE0;
132
-#endif
133
-#ifdef E1_IS_TMC
134
-	extern TMC26XStepper stepperE1;
135
-#endif
136
-#ifdef E2_IS_TMC
137
-	extern TMC26XStepper stepperE2;
138
-#endif
139
-#ifdef E3_IS_TMC
140
-	extern TMC26XStepper stepperE3;
141
-#endif	
142
-#endif
143
-
144
 #endif
104
 #endif

+ 106
- 0
Marlin/stepper_indirection.cpp View File

1
+/*
2
+  stepper_indirection.c - stepper motor driver indirection 
3
+  to allow some stepper functions to be done via SPI/I2c instead of direct pin manipulation
4
+  Part of Marlin
5
+
6
+  Copyright (c) 2015 Dominik Wenger
7
+
8
+  Marlin is free software: you can redistribute it and/or modify
9
+  it under the terms of the GNU General Public License as published by
10
+  the Free Software Foundation, either version 3 of the License, or
11
+  (at your option) any later version.
12
+
13
+  Marlin is distributed in the hope that it will be useful,
14
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+  GNU General Public License for more details.
17
+
18
+  You should have received a copy of the GNU General Public License
19
+  along with Marlin.  If not, see <http://www.gnu.org/licenses/>.
20
+*/
21
+
22
+#include "stepper_indirection.h"
23
+#include "Configuration.h"
24
+
25
+#ifdef HAVE_TMCDRIVER
26
+#include <SPI.h>
27
+#include <TMC26XStepper.h>
28
+#endif
29
+
30
+// Stepper objects of TMC steppers used
31
+#ifdef X_IS_TMC
32
+	TMC26XStepper stepperX(200,X_ENABLE_PIN,X_STEP_PIN,X_DIR_PIN,X_MAX_CURRENT,X_SENSE_RESISTOR);
33
+#endif
34
+#ifdef X2_IS_TMC
35
+	TMC26XStepper stepperX2(200,X2_ENABLE_PIN,X2_STEP_PIN,X2_DIR_PIN,X2_MAX_CURRENT,X2_SENSE_RESISTOR);
36
+#endif
37
+#ifdef Y_IS_TMC
38
+	TMC26XStepper stepperY(200,Y_ENABLE_PIN,Y_STEP_PIN,Y_DIR_PIN,Y_MAX_CURRENT,Y_SENSE_RESISTOR);
39
+#endif
40
+#ifdef Y2_IS_TMC
41
+	TMC26XStepper stepperY2(200,Y2_ENABLE_PIN,Y2_STEP_PIN,Y2_DIR_PIN,Y2_MAX_CURRENT,Y2_SENSE_RESISTOR);
42
+#endif
43
+#ifdef Z_IS_TMC
44
+	TMC26XStepper stepperZ(200,Z_ENABLE_PIN,Z_STEP_PIN,Z_DIR_PIN,Z_MAX_CURRENT,Z_SENSE_RESISTOR);
45
+#endif
46
+#ifdef Z2_IS_TMC
47
+	TMC26XStepper stepperZ2(200,Z2_ENABLE_PIN,Z2_STEP_PIN,Z2_DIR_PIN,Z2_MAX_CURRENT,Z2_SENSE_RESISTOR);
48
+#endif
49
+#ifdef E0_IS_TMC
50
+	TMC26XStepper stepperE0(200,E0_ENABLE_PIN,E0_STEP_PIN,E0_DIR_PIN,E0_MAX_CURRENT,E0_SENSE_RESISTOR);
51
+#endif
52
+#ifdef E1_IS_TMC
53
+	TMC26XStepper stepperE1(200,E1_ENABLE_PIN,E1_STEP_PIN,E1_DIR_PIN,E1_MAX_CURRENT,E1_SENSE_RESISTOR);
54
+#endif
55
+#ifdef E2_IS_TMC
56
+	TMC26XStepper stepperE2(200,E2_ENABLE_PIN,E2_STEP_PIN,E2_DIR_PIN,E2_MAX_CURRENT,E2_SENSE_RESISTOR);
57
+#endif
58
+#ifdef E3_IS_TMC
59
+	TMC26XStepper stepperE3(200,E3_ENABLE_PIN,E3_STEP_PIN,E3_DIR_PIN,E3_MAX_CURRENT,E3_SENSE_RESISTOR);
60
+#endif	
61
+
62
+#ifdef HAVE_TMCDRIVER
63
+void tmc_init()
64
+{
65
+#ifdef X_IS_TMC
66
+	stepperX.setMicrosteps(X_MICROSTEPS);
67
+	stepperX.start();
68
+#endif
69
+#ifdef X2_IS_TMC
70
+	stepperX2.setMicrosteps(X2_MICROSTEPS);
71
+	stepperX2.start();
72
+#endif
73
+#ifdef Y_IS_TMC
74
+	stepperY.setMicrosteps(Y_MICROSTEPS);
75
+	stepperY.start();
76
+#endif
77
+#ifdef Y2_IS_TMC
78
+	stepperY2.setMicrosteps(Y2_MICROSTEPS);
79
+	stepperY2.start();
80
+#endif
81
+#ifdef Z_IS_TMC
82
+	stepperZ.setMicrosteps(Z_MICROSTEPS);
83
+	stepperZ.start();
84
+#endif
85
+#ifdef Z2_IS_TMC
86
+	stepperZ2.setMicrosteps(Z2_MICROSTEPS);
87
+	stepperZ2.start();
88
+#endif
89
+#ifdef E0_IS_TMC
90
+	stepperE0.setMicrosteps(E0_MICROSTEPS);
91
+	stepperE0.start();
92
+#endif
93
+#ifdef E1_IS_TMC
94
+	stepperE1.setMicrosteps(E1_MICROSTEPS);
95
+	stepperE1.start();
96
+#endif
97
+#ifdef E2_IS_TMC
98
+	stepperE2.setMicrosteps(E2_MICROSTEPS);
99
+	stepperE2.start();
100
+#endif
101
+#ifdef E3_IS_TMC
102
+	stepperE3.setMicrosteps(E3_MICROSTEPS);
103
+	stepperE3.start();
104
+#endif
105
+}
106
+#endif

+ 44
- 10
Marlin/stepper_indirection.h View File

157
 // TMC26X drivers have step and dir on normal pins, but everything else via SPI
157
 // TMC26X drivers have step and dir on normal pins, but everything else via SPI
158
 //////////////////////////////////
158
 //////////////////////////////////
159
 #ifdef HAVE_TMCDRIVER
159
 #ifdef HAVE_TMCDRIVER
160
+#include <SPI.h>
161
+#include <TMC26XStepper.h>
162
+
163
+#ifdef X_IS_TMC
164
+	extern TMC26XStepper stepperX;
165
+#endif
166
+#ifdef X2_IS_TMC
167
+	extern TMC26XStepper stepperX2;
168
+#endif
169
+#ifdef Y_IS_TMC
170
+	extern TMC26XStepper stepperY;
171
+#endif
172
+#ifdef Y2_IS_TMC
173
+	extern TMC26XStepper stepperY2;
174
+#endif
175
+#ifdef Z_IS_TMC
176
+	extern TMC26XStepper stepperZ;
177
+#endif
178
+#ifdef Z2_IS_TMC
179
+	extern TMC26XStepper stepperZ2;
180
+#endif
181
+#ifdef E0_IS_TMC
182
+	extern TMC26XStepper stepperE0;
183
+#endif
184
+#ifdef E1_IS_TMC
185
+	extern TMC26XStepper stepperE1;
186
+#endif
187
+#ifdef E2_IS_TMC
188
+	extern TMC26XStepper stepperE2;
189
+#endif
190
+#ifdef E3_IS_TMC
191
+	extern TMC26XStepper stepperE3;
192
+#endif	
193
+  void tmc_init();
160
 #ifdef X_IS_TMC
194
 #ifdef X_IS_TMC
161
    #undef X_ENABLE_INIT 
195
    #undef X_ENABLE_INIT 
162
-   #define X_ENABLE_INIT 
196
+   #define X_ENABLE_INIT ((void)0)
163
    
197
    
164
    #undef X_ENABLE_WRITE
198
    #undef X_ENABLE_WRITE
165
    #define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE)
199
    #define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE)
169
 #endif
203
 #endif
170
 #ifdef X2_IS_TMC
204
 #ifdef X2_IS_TMC
171
    #undef X2_ENABLE_INIT
205
    #undef X2_ENABLE_INIT
172
-   #define X2_ENABLE_INIT
206
+   #define X2_ENABLE_INIT ((void)0)
173
    
207
    
174
    #undef X2_ENABLE_WRITE
208
    #undef X2_ENABLE_WRITE
175
    #define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE)
209
    #define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE)
179
 #endif
213
 #endif
180
 #ifdef Y_IS_TMC
214
 #ifdef Y_IS_TMC
181
    #undef Y_ENABLE_INIT
215
    #undef Y_ENABLE_INIT
182
-   #define Y_ENABLE_INIT
216
+   #define Y_ENABLE_INIT ((void)0)
183
    
217
    
184
    #undef Y_ENABLE_WRITE
218
    #undef Y_ENABLE_WRITE
185
    #define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE)
219
    #define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE)
189
 #endif
223
 #endif
190
 #ifdef Y2_IS_TMC
224
 #ifdef Y2_IS_TMC
191
    #undef Y2_ENABLE_INIT
225
    #undef Y2_ENABLE_INIT
192
-   #define Y2_ENABLE_INIT
226
+   #define Y2_ENABLE_INIT ((void)0)
193
    
227
    
194
    #undef Y2_ENABLE_WRITE
228
    #undef Y2_ENABLE_WRITE
195
    #define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE)
229
    #define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE)
199
 #endif
233
 #endif
200
 #ifdef Z_IS_TMC
234
 #ifdef Z_IS_TMC
201
    #undef Z_ENABLE_INIT
235
    #undef Z_ENABLE_INIT
202
-   #define Z_ENABLE_INIT
236
+   #define Z_ENABLE_INIT ((void)0)
203
    
237
    
204
    #undef Z_ENABLE_WRITE
238
    #undef Z_ENABLE_WRITE
205
    #define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE)
239
    #define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE)
209
 #endif
243
 #endif
210
 #ifdef Z2_IS_TMC
244
 #ifdef Z2_IS_TMC
211
    #undef Z2_ENABLE_INIT
245
    #undef Z2_ENABLE_INIT
212
-   #define Z2_ENABLE_INIT
246
+   #define Z2_ENABLE_INIT ((void)0)
213
    
247
    
214
    #undef Z2_ENABLE_WRITE
248
    #undef Z2_ENABLE_WRITE
215
    #define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE)
249
    #define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE)
219
 #endif
253
 #endif
220
 #ifdef E0_IS_TMC
254
 #ifdef E0_IS_TMC
221
    #undef E0_ENABLE_INIT
255
    #undef E0_ENABLE_INIT
222
-   #define E0_ENABLE_INIT
256
+   #define E0_ENABLE_INIT ((void)0)
223
    
257
    
224
    #undef E0_ENABLE_WRITE
258
    #undef E0_ENABLE_WRITE
225
    #define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE)
259
    #define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE)
229
 #endif
263
 #endif
230
 #ifdef E1_IS_TMC
264
 #ifdef E1_IS_TMC
231
    #undef E1_ENABLE_INIT
265
    #undef E1_ENABLE_INIT
232
-   #define E1_ENABLE_INIT
266
+   #define E1_ENABLE_INIT ((void)0)
233
    
267
    
234
    #undef E1_ENABLE_WRITE
268
    #undef E1_ENABLE_WRITE
235
    #define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE)
269
    #define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE)
239
 #endif
273
 #endif
240
 #ifdef E2_IS_TMC
274
 #ifdef E2_IS_TMC
241
    #undef E2_ENABLE_INIT
275
    #undef E2_ENABLE_INIT
242
-   #define E2_ENABLE_INIT
276
+   #define E2_ENABLE_INIT ((void)0)
243
    
277
    
244
    #undef E2_ENABLE_WRITE
278
    #undef E2_ENABLE_WRITE
245
    #define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE)
279
    #define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE)
249
 #endif
283
 #endif
250
 #ifdef E3_IS_TMC
284
 #ifdef E3_IS_TMC
251
    #undef E3_ENABLE_INIT
285
    #undef E3_ENABLE_INIT
252
-   #define E3_ENABLE_INIT
286
+   #define E3_ENABLE_INIT ((void)0)
253
    
287
    
254
    #undef E3_ENABLE_WRITE
288
    #undef E3_ENABLE_WRITE
255
    #define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)
289
    #define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)

Loading…
Cancel
Save