stepper.h

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

mercurial