stepper.h

Sat, 07 Nov 2015 13:23:07 +0100

author
mbayer
date
Sat, 07 Nov 2015 13:23:07 +0100
changeset 0
2c8ba1964db7
permissions
-rw-r--r--

Initial code from reprappro Marlin repository

0
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
1 /*
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
2 stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
3 Part of Grbl
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
4
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
5 Copyright (c) 2009-2011 Simen Svale Skogsrud
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
6
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
7 Grbl is free software: you can redistribute it and/or modify
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
10 (at your option) any later version.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
11
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
12 Grbl is distributed in the hope that it will be useful,
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
15 GNU General Public License for more details.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
16
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
18 along with Grbl. If not, see <http://www.gnu.org/licenses/>.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
19 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
20
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
21 #ifndef stepper_h
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
22 #define stepper_h
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
23
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
24 #include "planner.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
25 #include "slave_comms.h"
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
26
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
27 #ifdef REPRAPPRO_MULTIMATERIALS
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
28
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
29 #define WRITE_E_STEP(v) { if(current_block->active_extruder == 2) { slaveRemoteStep(2, v); } else { if(current_block->active_extruder == 1) { slaveRemoteStep(1, v); } else { WRITE(E0_STEP_PIN, v); }}}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
30 #define NORM_E_DIR() { if(current_block->active_extruder == 2) { slaveRemoteDir(2, true); } else { if(current_block->active_extruder == 1) { slaveRemoteDir(1, true); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
31 #define REV_E_DIR() { if(current_block->active_extruder == 2) { slaveRemoteDir(2, false); } else { if(current_block->active_extruder == 1) { slaveRemoteDir(1, false); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
32
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
33
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
34 /*
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
35 inline void WRITE_E_STEP(int8_t v)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
36 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
37 if(current_block->active_extruder == 2)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
38 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
39 slaveRemoteStep(2, v); //E2_STEP_PIN, v);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
40 } else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
41 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
42 if(current_block->active_extruder == 1)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
43 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
44 slaveRemoteStep(1, v); //E1_STEP_PIN, v);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
45 } else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
46 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
47 WRITE(E0_STEP_PIN, v);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
48 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
49 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
50 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
51
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
52 inline void NORM_E_DIR()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
53 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
54 if(current_block->active_extruder == 2)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
55 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
56 slaveRemoteDir(2, true); //!E2_DIR_PIN, INVERT_E2_DIR);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
57 } else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
58 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
59 if(current_block->active_extruder == 1)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
60 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
61 slaveRemoteDir(1, true); //!E1_DIR_PIN, INVERT_E1_DIR);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
62 } else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
63 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
64 WRITE(E0_DIR_PIN, !INVERT_E0_DIR);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
65 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
66 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
67 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
68
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
69 inline void REV_E_DIR()
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
70 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
71 if(current_block->active_extruder == 2)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
72 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
73 slaveRemoteDir(2, false); //E2_DIR_PIN, INVERT_E2_DIR);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
74 } else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
75 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
76 if(current_block->active_extruder == 1)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
77 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
78 slaveRemoteDir(1, false); //E1_DIR_PIN, INVERT_E1_DIR);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
79 } else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
80 {
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
81 WRITE(E0_DIR_PIN, INVERT_E0_DIR);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
82 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
83 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
84 }
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
85 */
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
86 #else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
87
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
88 #if EXTRUDERS > 2
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
89 #define WRITE_E_STEP(v) { if(current_block->active_extruder == 2) { WRITE(E2_STEP_PIN, v); } else { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }}}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
90 #define NORM_E_DIR() { if(current_block->active_extruder == 2) { WRITE(!E2_DIR_PIN, INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(!E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
91 #define REV_E_DIR() { if(current_block->active_extruder == 2) { WRITE(E2_DIR_PIN, INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
92 #elif EXTRUDERS > 1
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
93 #define WRITE_E_STEP(v) { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
94 #define NORM_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
95 #define REV_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
96 #else
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
97 #define WRITE_E_STEP(v) WRITE(E0_STEP_PIN, v)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
98 #define NORM_E_DIR() WRITE(E0_DIR_PIN, !INVERT_E0_DIR)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
99 #define REV_E_DIR() WRITE(E0_DIR_PIN, INVERT_E0_DIR)
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
100 #endif
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
101
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
102 #endif
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
103
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
104
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
105
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
106 // Initialize and start the stepper motor subsystem
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
107 void st_init();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
108
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
109 // Block until all buffered steps are executed
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
110 void st_synchronize();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
111
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
112 // Set current position in steps
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
113 void st_set_position(const long &x, const long &y, const long &z, const long &e);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
114 void st_set_e_position(const long &e);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
115
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
116 // Get current position in steps
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
117 long st_get_position(uint8_t axis);
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
118
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
119 // The stepper subsystem goes to sleep when it runs out of things to execute. Call this
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
120 // to notify the subsystem that it is time to go to work.
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
121 void st_wake_up();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
122
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
123
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
124 void checkHitEndstops(); //call from somwhere to create an serial error message with the locations the endstops where hit, in case they were triggered
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
125 void endstops_hit_on_purpose(); //avoid creation of the message, i.e. after homeing and before a routine call of checkHitEndstops();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
126
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
127 void enable_endstops(bool check); // Enable/disable endstop checking
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
128
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
129 void checkStepperErrors(); //Print errors detected by the stepper
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
130
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
131 void finishAndDisableSteppers();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
132
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
133 extern block_t *current_block; // A pointer to the block currently being traced
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
134 extern volatile long endstops_trigsteps[];
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
135 extern volatile bool endstop_z_hit;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
136 extern bool old_z_min_endstop;
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
137
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
138 void quickStop();
2c8ba1964db7 Initial code from reprappro Marlin repository
mbayer
parents:
diff changeset
139 #endif

mercurial