Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 461 lines (383 sloc) 12.661 kb
1e6c740 @triffid tons of changes, implementing 4D dda
authored
1 #include "dda.h"
2
3 #include <string.h>
f8eee36 @triffid Lots of minor tweaks during some test runs, most notable is that tail of...
authored
4 #include <avr/interrupt.h>
1e6c740 @triffid tons of changes, implementing 4D dda
authored
5
90ea291 @triffid time to save again, looking good so far
authored
6 #include "timer.h"
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
7 #include "serial.h"
8 #include "sermsg.h"
8cc6fa6 @triffid split up dda and its queue, moved clock tick functions from main loop so...
authored
9 #include "dda_queue.h"
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
10
11 #ifndef ABS
12 #define ABS(v) (((v) >= 0)?(v):(-(v)))
13 #endif
14
15 #ifndef ABSDELTA
16 #define ABSDELTA(a, b) (((a) >= (b))?((a) - (b)):((b) - (a)))
17 #endif
90ea291 @triffid time to save again, looking good so far
authored
18
d302329 @triffid time to save, made debug output (524 bytes) and global clock (50 bytes) ...
authored
19 #ifndef DEBUG
20 #define DEBUG 0
21 #endif
22
411ada4 @triffid this one actually compiles
authored
23 /*
4fc004c @triffid It's alive! (cue evil cackle). still has some bugs, eg small movements w...
authored
24 step timeout
25 */
26
27 uint8_t steptimeout = 0;
28
29 /*
5b1245e @triffid solved bug where speed would be seemingly random for moves beyond about ...
authored
30 position tracking
31 */
32
33 TARGET startpoint = { 0, 0, 0, 0, 0 };
34 TARGET current_position = { 0, 0, 0, 0, 0 };
35
36 /*
411ada4 @triffid this one actually compiles
authored
37 utility functions
38 */
39
90ea291 @triffid time to save again, looking good so far
authored
40 // courtesy of http://www.oroboro.com/rafael/docserv.php/index/programming/article/distance
6fb725a @triffid time to save again, DDA doesn't like negative moves at the moment
authored
41 uint32_t approx_distance( uint32_t dx, uint32_t dy )
1e6c740 @triffid tons of changes, implementing 4D dda
authored
42 {
90ea291 @triffid time to save again, looking good so far
authored
43 uint32_t min, max, approx;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
44
45 if ( dx < dy )
46 {
47 min = dx;
48 max = dy;
49 } else {
50 min = dy;
51 max = dx;
52 }
53
90ea291 @triffid time to save again, looking good so far
authored
54 approx = ( max * 1007 ) + ( min * 441 );
55 if ( max < ( min << 4 ))
56 approx -= ( max * 40 );
57
58 // add 512 for proper rounding
59 return (( approx + 512 ) >> 10 );
60 }
61
62 // courtesy of http://www.oroboro.com/rafael/docserv.php/index/programming/article/distance
6fb725a @triffid time to save again, DDA doesn't like negative moves at the moment
authored
63 uint32_t approx_distance_3( uint32_t dx, uint32_t dy, uint32_t dz )
90ea291 @triffid time to save again, looking good so far
authored
64 {
65 uint32_t min, med, max, approx;
66
67 if ( dx < dy )
68 {
69 min = dy;
70 med = dx;
71 } else {
72 min = dx;
73 med = dy;
74 }
75
6fb725a @triffid time to save again, DDA doesn't like negative moves at the moment
authored
76 if ( dz < min )
90ea291 @triffid time to save again, looking good so far
authored
77 {
78 max = med;
79 med = min;
80 min = dz;
6fb725a @triffid time to save again, DDA doesn't like negative moves at the moment
authored
81 } else if ( dz < med ) {
90ea291 @triffid time to save again, looking good so far
authored
82 max = med;
83 med = dz;
84 } else {
85 max = dz;
86 }
87
88 approx = ( max * 860 ) + ( med * 851 ) + ( min * 520 );
89 if ( max < ( med << 1 )) approx -= ( max * 294 );
90 if ( max < ( min << 2 )) approx -= ( max * 113 );
91 if ( med < ( min << 2 )) approx -= ( med * 40 );
92
93 // add 512 for proper rounding
94 return (( approx + 512 ) >> 10 );
1e6c740 @triffid tons of changes, implementing 4D dda
authored
95 }
96
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
97 uint32_t abs32(int32_t v) {
98 if (v < 0)
6fb725a @triffid time to save again, DDA doesn't like negative moves at the moment
authored
99 return (uint32_t) (-v);
100 return (uint32_t) (v);
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
101 }
102
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
103 uint32_t delta32(uint32_t v1, uint32_t v2) {
104 if (v1 >= v2)
105 return v1 - v2;
106 return v2 - v1;
107 }
108
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
109 // this is an ultra-crude pseudo-logarithm routine, such that:
110 // 2 ^ msbloc(v) >= v
111 const uint8_t msbloc (uint32_t v) {
112 uint8_t i;
113 uint32_t c;
114 for (i = 31, c = 0x80000000; i; i--) {
115 if (v & c)
116 return i;
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
117 c >>= 1;
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
118 }
119 return 0;
120 }
121
1e6c740 @triffid tons of changes, implementing 4D dda
authored
122 /*
5b1245e @triffid solved bug where speed would be seemingly random for moves beyond about ...
authored
123 CREATE a dda given current_position and a target, save to passed location so we can write directly into the queue
1e6c740 @triffid tons of changes, implementing 4D dda
authored
124 */
125
8cc6fa6 @triffid split up dda and its queue, moved clock tick functions from main loop so...
authored
126 void dda_create(DDA *dda, TARGET *target) {
496d58f @triffid time to save again, preliminary PID/PWM support for extruder barrel heat...
authored
127 uint32_t distance;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
128
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
129 // initialise DDA to a known state
130 dda->live = 0;
131 dda->total_steps = 0;
132
33ba692 @triffid time to save
authored
133 if (1)
d302329 @triffid time to save, made debug output (524 bytes) and global clock (50 bytes) ...
authored
134 serial_writestr_P(PSTR("\n{DDA_CREATE: ["));
6fb725a @triffid time to save again, DDA doesn't like negative moves at the moment
authored
135
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
136 // we end at the passed target
bde8ab7 @triffid fixed a few bugs, such as two consecutive moves to a point and back to t...
authored
137 memcpy(&(dda->endpoint), target, sizeof(TARGET));
1e6c740 @triffid tons of changes, implementing 4D dda
authored
138
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
139 dda->x_delta = abs32(target->X - startpoint.X);
140 dda->y_delta = abs32(target->Y - startpoint.Y);
141 dda->z_delta = abs32(target->Z - startpoint.Z);
142 dda->e_delta = abs32(target->E - startpoint.E);
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
143
144 dda->x_direction = (target->X >= startpoint.X)?1:0;
145 dda->y_direction = (target->Y >= startpoint.Y)?1:0;
146 dda->z_direction = (target->Z >= startpoint.Z)?1:0;
147 dda->e_direction = (target->E >= startpoint.E)?1:0;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
148
33ba692 @triffid time to save
authored
149 if (1) {
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
150 if (dda->x_direction == 0)
151 serial_writechar('-');
d302329 @triffid time to save, made debug output (524 bytes) and global clock (50 bytes) ...
authored
152 serwrite_uint32(dda->x_delta); serial_writechar(',');
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
153 if (dda->y_direction == 0)
154 serial_writechar('-');
d302329 @triffid time to save, made debug output (524 bytes) and global clock (50 bytes) ...
authored
155 serwrite_uint32(dda->y_delta); serial_writechar(',');
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
156 if (dda->z_direction == 0)
157 serial_writechar('-');
d302329 @triffid time to save, made debug output (524 bytes) and global clock (50 bytes) ...
authored
158 serwrite_uint32(dda->z_delta); serial_writechar(',');
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
159 if (dda->e_direction == 0)
160 serial_writechar('-');
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
161 serwrite_uint32(dda->e_delta);
162
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
163 serial_writestr_P(PSTR("] ["));
d302329 @triffid time to save, made debug output (524 bytes) and global clock (50 bytes) ...
authored
164 }
1e6c740 @triffid tons of changes, implementing 4D dda
authored
165
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
166 if (dda->x_delta > dda->total_steps)
167 dda->total_steps = dda->x_delta;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
168 if (dda->y_delta > dda->total_steps)
169 dda->total_steps = dda->y_delta;
90ea291 @triffid time to save again, looking good so far
authored
170 if (dda->z_delta > dda->total_steps)
171 dda->total_steps = dda->z_delta;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
172 if (dda->e_delta > dda->total_steps)
173 dda->total_steps = dda->e_delta;
174
33ba692 @triffid time to save
authored
175 if (1) {
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
176 serial_writestr_P(PSTR("ts:")); serwrite_uint32(dda->total_steps);
33ba692 @triffid time to save
authored
177 }
178
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
179 if (dda->total_steps == 0) {
1e6c740 @triffid tons of changes, implementing 4D dda
authored
180 dda->nullmove = 1;
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
181 }
182 else {
980f39a @triffid time to save, motors working nicely, XON/XOFF flow control implemented f...
authored
183 // get steppers ready to go
184 steptimeout = 0;
7b79d2e @triffid tons of small fixes, improvements etc. Clocked DDA at 25000mm/min (over ...
authored
185 power_on();
6fb725a @triffid time to save again, DDA doesn't like negative moves at the moment
authored
186
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
187 dda->x_counter = dda->y_counter = dda->z_counter = dda->e_counter =
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
188 -(dda->total_steps >> 1);
189
190 // since it's unusual to combine X, Y and Z changes in a single move on reprap, check if we can use simpler approximations before trying the full 3d approximation.
191 if (dda->z_delta == 0)
192 distance = approx_distance(dda->x_delta * UM_PER_STEP_X, dda->y_delta * UM_PER_STEP_Y);
193 else if (dda->x_delta == 0 && dda->y_delta == 0)
194 distance = dda->z_delta * UM_PER_STEP_Z;
195 else
196 distance = approx_distance_3(dda->x_delta * UM_PER_STEP_X, dda->y_delta * UM_PER_STEP_Y, dda->z_delta * UM_PER_STEP_Z);
197
198 if (distance < 2)
199 distance = dda->e_delta * UM_PER_STEP_E;
200
33ba692 @triffid time to save
authored
201 if (1) {
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
202 serial_writestr_P(PSTR(",ds:")); serwrite_uint32(distance);
5b1245e @triffid solved bug where speed would be seemingly random for moves beyond about ...
authored
203 }
204
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
205 // pre-calculate move speed in millimeter microseconds per step minute for less math in interrupt context
206 // mm (distance) * 60000000 us/min / step (total_steps) = mm.us per step.min
207 // note: um (distance) * 60000 == mm * 60000000
208 // so in the interrupt we must simply calculate
209 // mm.us per step.min / mm per min (F) = us per step
5b1245e @triffid solved bug where speed would be seemingly random for moves beyond about ...
authored
210
211 // break this calculation up a bit and lose some precision because 300,000um * 60000 is too big for a uint32
212 // calculate this with a uint64 if you need the precision, but it'll take longer so routines with lots of short moves may suffer
213 // 2^32/6000 is about 715mm which should be plenty
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
214
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
215 // changed * 10 to * (F_CPU / 100000) so we can work in cpu_ticks rather than microseconds.
216 // timer.c setTimer() routine altered for same reason
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
217
218 // changed distance * 6000 .. * F_CPU / 100000 to
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
219 // distance * 2400 .. * F_CPU / 40000 so we can move a distance of up to 1800mm without overflowing
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
220 uint32_t move_duration = ((distance * 2400) / dda->total_steps) * (F_CPU / 40000);
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
221
222 // c is initial step time in IOclk ticks
33ba692 @triffid time to save
authored
223 dda->c = (move_duration / startpoint.F) << 8;
224
225 if (1) {
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
226 serial_writestr_P(PSTR(",md:")); serwrite_uint32(move_duration);
227 serial_writestr_P(PSTR(",c:")); serwrite_uint32(dda->c >> 8);
33ba692 @triffid time to save
authored
228 }
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
229
230 if (startpoint.F != target->F) {
33ba692 @triffid time to save
authored
231 uint32_t stF = startpoint.F / 4;
232 uint32_t enF = target->F / 4;
233 // now some constant acceleration stuff, courtesy of http://www.embedded.com/columns/technicalinsights/56800129?printable=true
234 uint32_t ssq = (stF * stF);
235 uint32_t esq = (enF * enF);
236 int32_t dsq = (int32_t) (esq - ssq) / 4;
237
238 uint8_t msb_ssq = msbloc(ssq);
239 uint8_t msb_tot = msbloc(dda->total_steps);
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
240
33ba692 @triffid time to save
authored
241 dda->end_c = (move_duration / target->F) << 8;
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
242 // the raw equation WILL overflow at high step rates, but 64 bit math routines take waay too much space
243 // at 65536 mm/min (1092mm/s), ssq/esq overflows, and dsq is also close to overflowing if esq/ssq is small
244 // but if ssq-esq is small, ssq/dsq is only a few bits
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
245 // we'll have to do it a few different ways depending on the msb locations of each
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
246 if ((msb_tot + msb_ssq) <= 30) {
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
247 // we have room to do all the multiplies first
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
248 serial_writechar('A');
33ba692 @triffid time to save
authored
249 dda->n = ((int32_t) (dda->total_steps * ssq) / dsq) + 1;
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
250 }
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
251 else if (msb_tot >= msb_ssq) {
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
252 // total steps has more precision
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
253 serial_writechar('B');
33ba692 @triffid time to save
authored
254 dda->n = (((int32_t) dda->total_steps / dsq) * (int32_t) ssq) + 1;
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
255 }
256 else {
257 // otherwise
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
258 serial_writechar('C');
259 dda->n = (((int32_t) ssq / dsq) * (int32_t) dda->total_steps) + 1;
33ba692 @triffid time to save
authored
260 }
261
262 if (1) {
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
263 serial_writestr_P(PSTR("\n{DDA:CA end_c:")); serwrite_uint32(dda->end_c >> 8);
33ba692 @triffid time to save
authored
264 serial_writestr_P(PSTR(", n:")); serwrite_int32(dda->n);
265 serial_writestr_P(PSTR(", md:")); serwrite_uint32(move_duration);
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
266 serial_writestr_P(PSTR(", ssq:")); serwrite_uint32(ssq);
267 serial_writestr_P(PSTR(", esq:")); serwrite_uint32(esq);
33ba692 @triffid time to save
authored
268 serial_writestr_P(PSTR(", dsq:")); serwrite_int32(dsq);
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
269 serial_writestr_P(PSTR(", msbssq:")); serwrite_uint8(msb_ssq);
270 serial_writestr_P(PSTR(", msbtot:")); serwrite_uint8(msb_tot);
33ba692 @triffid time to save
authored
271 serial_writestr_P(PSTR("}\n"));
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
272 }
273
274 dda->accel = 1;
275 }
276 else
277 dda->accel = 0;
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
278 }
90ea291 @triffid time to save again, looking good so far
authored
279
33ba692 @triffid time to save
authored
280 if (1)
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
281 serial_writestr_P(PSTR("] }\n"));
6fb725a @triffid time to save again, DDA doesn't like negative moves at the moment
authored
282
1e6c740 @triffid tons of changes, implementing 4D dda
authored
283 // next dda starts where we finish
bde8ab7 @triffid fixed a few bugs, such as two consecutive moves to a point and back to t...
authored
284 memcpy(&startpoint, target, sizeof(TARGET));
1e6c740 @triffid tons of changes, implementing 4D dda
authored
285 }
286
287 /*
5b1245e @triffid solved bug where speed would be seemingly random for moves beyond about ...
authored
288 Start a prepared DDA
1e6c740 @triffid tons of changes, implementing 4D dda
authored
289 */
290
291 void dda_start(DDA *dda) {
90ea291 @triffid time to save again, looking good so far
authored
292 // called from interrupt context: keep it simple!
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
293 if (dda->nullmove) {
aa9b599 @triffid time to save
authored
294 // just change speed?
295 current_position.F = dda->endpoint.F;
90ea291 @triffid time to save again, looking good so far
authored
296 return;
aa9b599 @triffid time to save
authored
297 }
90ea291 @triffid time to save again, looking good so far
authored
298
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
299 // ensure steppers are ready to go
300 steptimeout = 0;
7b79d2e @triffid tons of small fixes, improvements etc. Clocked DDA at 25000mm/min (over ...
authored
301 power_on();
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
302
4fc004c @triffid It's alive! (cue evil cackle). still has some bugs, eg small movements w...
authored
303 // set direction outputs
1e6c740 @triffid tons of changes, implementing 4D dda
authored
304 x_direction(dda->x_direction);
305 y_direction(dda->y_direction);
306 z_direction(dda->z_direction);
307 e_direction(dda->e_direction);
90ea291 @triffid time to save again, looking good so far
authored
308
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
309 // ensure this dda starts
310 dda->live = 1;
411ada4 @triffid this one actually compiles
authored
311
4fc004c @triffid It's alive! (cue evil cackle). still has some bugs, eg small movements w...
authored
312 // set timeout for first step
33ba692 @triffid time to save
authored
313 setTimer(dda->c >> 8);
1e6c740 @triffid tons of changes, implementing 4D dda
authored
314 }
315
316 /*
317 CAN STEP
318 */
319
320 uint8_t can_step(uint8_t min, uint8_t max, int32_t current, int32_t target, uint8_t dir) {
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
321 if (dir) {
322 // forwards/positive
323 if (max)
324 return 0;
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
325 if (current >= target)
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
326 return 0;
327 }
328 else {
329 // backwards/negative
330 if (min)
331 return 0;
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
332 if (target >= current)
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
333 return 0;
334 }
1e6c740 @triffid tons of changes, implementing 4D dda
authored
335
336 return 255;
337 }
338
339 /*
340 STEP
341 */
342
343 void dda_step(DDA *dda) {
7326e17 @triffid misc tidying, added watchdog stuff, moved things around a bit
authored
344 // called from interrupt context! keep it as simple as possible
1e6c740 @triffid tons of changes, implementing 4D dda
authored
345 uint8_t step_option = 0;
346 #define X_CAN_STEP 1
347 #define Y_CAN_STEP 2
348 #define Z_CAN_STEP 4
349 #define E_CAN_STEP 8
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
350
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
351 // step_option |= can_step(x_min(), x_max(), current_position.X, dda->endpoint.X, dda->x_direction) & X_CAN_STEP;
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
352 step_option |= can_step(0 , 0 , current_position.X, dda->endpoint.X, dda->x_direction) & X_CAN_STEP;
7326e17 @triffid misc tidying, added watchdog stuff, moved things around a bit
authored
353 // step_option |= can_step(y_min(), y_max(), current_position.Y, dda->endpoint.Y, dda->y_direction) & Y_CAN_STEP;
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
354 step_option |= can_step(0 , 0 , current_position.Y, dda->endpoint.Y, dda->y_direction) & Y_CAN_STEP;
7326e17 @triffid misc tidying, added watchdog stuff, moved things around a bit
authored
355 // step_option |= can_step(z_min(), z_max(), current_position.Z, dda->endpoint.Z, dda->z_direction) & Z_CAN_STEP;
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
356 step_option |= can_step(0 , 0 , current_position.Z, dda->endpoint.Z, dda->z_direction) & Z_CAN_STEP;
357 step_option |= can_step(0 , 0 , current_position.E, dda->endpoint.E, dda->e_direction) & E_CAN_STEP;
33ba692 @triffid time to save
authored
358 // step_option |= can_step(0 , 0 , current_position.F, dda->endpoint.F, dda->f_direction) & F_CAN_STEP;
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
359
360 if (step_option & X_CAN_STEP) {
361 dda->x_counter -= dda->x_delta;
362 if (dda->x_counter < 0) {
363 x_step();
364 if (dda->x_direction)
365 current_position.X++;
366 else
367 current_position.X--;
368
369 dda->x_counter += dda->total_steps;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
370 }
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
371 }
1e6c740 @triffid tons of changes, implementing 4D dda
authored
372
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
373 if (step_option & Y_CAN_STEP) {
374 dda->y_counter -= dda->y_delta;
375 if (dda->y_counter < 0) {
376 y_step();
377 if (dda->y_direction)
378 current_position.Y++;
379 else
380 current_position.Y--;
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
381
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
382 dda->y_counter += dda->total_steps;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
383 }
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
384 }
1e6c740 @triffid tons of changes, implementing 4D dda
authored
385
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
386 if (step_option & Z_CAN_STEP) {
387 dda->z_counter -= dda->z_delta;
388 if (dda->z_counter < 0) {
389 z_step();
390 if (dda->z_direction)
391 current_position.Z++;
392 else
393 current_position.Z--;
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
394
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
395 dda->z_counter += dda->total_steps;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
396 }
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
397 }
1e6c740 @triffid tons of changes, implementing 4D dda
authored
398
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
399 if (step_option & E_CAN_STEP) {
400 dda->e_counter -= dda->e_delta;
401 if (dda->e_counter < 0) {
402 e_step();
403 if (dda->e_direction)
404 current_position.E++;
405 else
406 current_position.E--;
b6b2951 @triffid time to save, looks like the DDA is working! NOTE: endstops disabled in ...
authored
407
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
408 dda->e_counter += dda->total_steps;
1e6c740 @triffid tons of changes, implementing 4D dda
authored
409 }
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
410 }
411
7326e17 @triffid misc tidying, added watchdog stuff, moved things around a bit
authored
412 #if STEP_INTERRUPT_INTERRUPTIBLE
413 // since we have sent steps to all the motors that will be stepping and the rest of this function isn't so time critical,
414 // this interrupt can now be interruptible
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
415 // however we must ensure that we don't step again while computing the below, so disable *this* interrupt but allow others to fire
7326e17 @triffid misc tidying, added watchdog stuff, moved things around a bit
authored
416 disableTimerInterrupt();
417 sei();
418 #endif
419
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
420 // linear acceleration magic, courtesy of http://www.embedded.com/columns/technicalinsights/56800129?printable=true
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
421 if (dda->accel) {
422 if (
423 ((dda->n > 0) && (dda->c > dda->end_c)) ||
424 ((dda->n < 0) && (dda->c < dda->end_c))
425 ) {
33ba692 @triffid time to save
authored
426 dda->c = (int32_t) dda->c - ((int32_t) (dda->c * 2) / dda->n);
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
427 dda->n += 4;
33ba692 @triffid time to save
authored
428 setTimer(dda->c >> 8);
429
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
430 // debug
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
431 if (0) {
33ba692 @triffid time to save
authored
432 serwrite_uint32(dda->c >> 8);
8575ae3 @triffid time to save, bugfixes in linear acceleration code, fixed point delta t ...
authored
433 serial_writestr_P(PSTR("/"));
33ba692 @triffid time to save
authored
434 }
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
435 }
436 else if (dda->c != dda->end_c) {
437 dda->c = dda->end_c;
33ba692 @triffid time to save
authored
438 setTimer(dda->c >> 8);
d302329 @triffid time to save, made debug output (524 bytes) and global clock (50 bytes) ...
authored
439 }
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
440 // else we are already at target speed
4c47901 @triffid tons of commenting and tidying, fixes to heater PID loop
authored
441 }
4fc004c @triffid It's alive! (cue evil cackle). still has some bugs, eg small movements w...
authored
442
33ba692 @triffid time to save
authored
443 if (step_option)
4fc004c @triffid It's alive! (cue evil cackle). still has some bugs, eg small movements w...
authored
444 // we stepped, reset timeout
445 steptimeout = 0;
446
6002e10 @triffid time to save, acceleration seems to be temporarily broken, will have to ...
authored
447 // if we could do anything at all, we're still running
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
448 // otherwise, must have finished
33ba692 @triffid time to save
authored
449 else {
9b067d3 @triffid time to save, think I solved reducing F bug, movement is now lovely!
authored
450 dda->live = 0;
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
451 // linear acceleration code doesn't alter F during a move, so we must update it here
452 // in theory, we *could* update F, but that would require a divide in interrupt context which should be avoided if at all possible
3c7784c @triffid trying out some constant acceleration code, expect breakage
authored
453 current_position.F = dda->endpoint.F;
454 }
1bde999 @triffid seems to be working nicely, although the speeds don't seem quite right.....
authored
455
5b1245e @triffid solved bug where speed would be seemingly random for moves beyond about ...
authored
456 // turn off step outputs, hopefully they've been on long enough by now to register with the drivers
76834e6 @triffid time to save, also changed makefile to atmega328 because I fried my 168
authored
457 // if not, too bad. or insert a (very!) small delay here, or fire up a spare timer or something.
458 // we also hope that we don't step before the drivers register the low- limit maximum speed if you think this is a problem.
5b1245e @triffid solved bug where speed would be seemingly random for moves beyond about ...
authored
459 unstep();
1e6c740 @triffid tons of changes, implementing 4D dda
authored
460 }
Something went wrong with that request. Please try again.