Commit Graph

208 Commits

Author SHA1 Message Date
Nico Tonnhofer f9c8652715 dda.c: correct md_candidate calculation 2017-04-03 23:07:17 +02:00
Nico Tonnhofer 104cc0b757 dda.c: c_limit calculation is only for non-temporal configs
no functional change, but saves 24 bytes when using acceleration temporal
2017-04-03 23:07:17 +02:00
Nico Tonnhofer 56c2238fef dda.c/dda_maths: add int_f_sqrt for controller with FPU
very fast sqrt in hardware
also accurate dda->c for high steps/mm without overflowing
2017-03-03 18:54:57 +01:00
Nico Tonnhofer 8a4cd52a68 DDA: Fix slow travel speed
@phord abstract this to: This happens only when !recalc_speed,
meaning we are cruising, not accelerating or decelerating. So it
pegs our dda->c at c_min if it never made it as far as c_min.

This commit will fix https://github.com/Traumflug/Teacup_Firmware/issues/69
2017-02-28 22:08:25 +01:00
Nico Tonnhofer e707c395f3 Revert "dda.c: let's save 3 divisions."
delta_um can become very small, where maximum_feedrate_P is constant.
When moving this division out of the loop, the result can be wrong.
dda->total_steps becomes also very small with delta_um. So this will fit perfectly.

This reverts commit cd66feb8d1.
2017-02-13 19:04:21 +01:00
Nico Tonnhofer 1e052a77a2 DDA: The test of total_steps against step_no was a good idea.
So let's bring this part back.

We save 35 clock cycles at 'LED on time maximum'

ATmega sizes               '168   '328(P)   '644(P)     '1280
Program:  18038 bytes      126%       59%       29%       14%
   Data:   1936 bytes      190%       95%       48%       24%
 EEPROM:     32 bytes        4%        2%        2%        1%

short-moves.gcode statistics:
LED on occurences: 888.
LED on time minimum: 217 clock cycles.
LED on time maximum: 520 clock cycles.
LED on time average: 249.626 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 22589.
LED on time minimum: 217 clock cycles.
LED on time maximum: 537 clock cycles.
LED on time average: 284.747 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 217 clock cycles.
LED on time maximum: 520 clock cycles.
LED on time average: 270.933 clock cycles.
2017-02-13 19:04:21 +01:00
Nico Tonnhofer 22489c69cb dda.c: simply resort the values and save up to 8 clocks
ATmega sizes               '168   '328(P)   '644(P)     '1280
Program:  18266 bytes      128%       60%       29%       15%
   Data:   1936 bytes      190%       95%       48%       24%
 EEPROM:     32 bytes        4%        2%        2%        1%

short-moves.gcode statistics:
LED on occurences: 888.
LED on time minimum: 243 clock cycles.
LED on time maximum: 555 clock cycles.
LED on time average: 250.375 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 22589.
LED on time minimum: 243 clock cycles.
LED on time maximum: 572 clock cycles.
LED on time average: 292.139 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 243 clock cycles.
LED on time maximum: 555 clock cycles.
LED on time average: 275.699 clock cycles.
2017-02-13 19:04:20 +01:00
Nico Tonnhofer b36aa4168a Revert "DDA: don't count individual axis steps." 2017-02-13 19:04:20 +01:00
Nico Tonnhofer c441548c37 dda.c: when we have no move on the cartesian axes, we have a move on E.
But we can also have very short moves with only 1 step, without E. So include this moves also.
2017-02-12 15:12:06 +01:00
Phil Hord 1e9cb8b8e1 dda->id is needed even when !LOOKAHEAD
In `ACCELERATION_RAMPING` code we use the dda->id field even when we do
not enable `LOOKAHEAD`. Expose the variable and its related `idcnt`
when `ACCELERATION_RAMPING` is used.

Add a regression-test to catch this in the future.
2017-02-01 10:21:48 -08:00
Wurstnase 4573a8fbbb dda.c: move code to reduce size.
No functional change. Reduces program size by 2 bytes:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  17942 bytes      126%       59%       29%       14%
     Data:   1920 bytes      188%       94%       47%       24%
   EEPROM:     32 bytes        4%        2%        2%        1%
2016-12-15 20:31:07 +01:00
Markus Hitter 84dcd089d4 DDA: get rid of dda->delta_um[].
These values were queued up just for finding out individual axis
speeds in dda_find_crossing_speed(). Let's do this calculation
with other available movement properties and save 16 bytes of RAM
per movement queue entry.

First version of this commit forgot to take care of the feedrate
sign (prevF, currF). Lack of that found by @Wurstnase. Idea of
tweaking calculation of 'dv' to achieve this also by @Wurstnase.

It was tried to set the sign immediately after calculation of the
absolute values, but that resulted in larger ( = slower) code.

Binary size down 132 bytes, among that two loops. RAM usage down
256 bytes for the standard test case:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  17944 bytes      126%       59%       29%       14%
     Data:   1920 bytes      188%       94%       47%       24%
   EEPROM:     32 bytes        4%        2%        2%        1%
2016-12-15 20:00:29 +01:00
Markus Hitter 39f66ef6b0 dda.c: pretty-format dda_start().
Formatting was messed up during all the recent changes.

Only whitespace and comment changes, no functional change.
2016-12-06 20:25:36 +01:00
Markus Hitter 7726b3179c DDA: revert recent dda_start() changes.
Neither of them brought a performance improvement, so we revert
both. Commits as well as revert kept to preserve the knowledge
gained.

This reverts commits

  "DDA, dda_start(): use mb_tail_dda directly." and
  "DDA, dda_start(): don't pass mb_tail_dda as parameter."

Performance and binary size is back to what we had before:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19270 bytes      135%       63%       31%       15%
     Data:   2179 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 218 clock cycles.
  LED on time maximum: 395 clock cycles.
  LED on time average: 249.051 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 237 clock cycles.
  LED on time maximum: 438 clock cycles.
  LED on time average: 272.216 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 237 clock cycles.
  LED on time maximum: 395 clock cycles.
  LED on time average: 262.572 clock cycles.
2016-12-06 20:24:38 +01:00
Markus Hitter e28afeca7d DDA, dda_start(): use mb_tail_dda directly.
Just avoiding to pass mb_tail_dda as parameter didn't work out,
so how about using it directly? This is what this commit does.

Result: binary size another 32 bytes bigger, slowest step another
16 clock cycles slower. No dice.

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19306 bytes      135%       63%       31%       15%
     Data:   2179 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 218 clock cycles.
  LED on time maximum: 414 clock cycles.
  LED on time average: 249.436 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 237 clock cycles.
  LED on time maximum: 457 clock cycles.
  LED on time average: 272.256 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 237 clock cycles.
  LED on time maximum: 414 clock cycles.
  LED on time average: 262.595 clock cycles.
2016-12-06 19:44:25 +01:00
Markus Hitter 480cc40618 DDA, dda_start(): don't pass mb_tail_dda as parameter.
Instead, read the global variable directly.

The idea is that reading the global variable directly removes
the effort to build up a parameter stack, making things faster.

Actually, binary size increases by 4 bytes and the slowest step
takes 3 clock cycles longer. D'oh.

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19274 bytes      135%       63%       31%       15%
     Data:   2179 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 218 clock cycles.
  LED on time maximum: 398 clock cycles.
  LED on time average: 249.111 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 237 clock cycles.
  LED on time maximum: 441 clock cycles.
  LED on time average: 272.222 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 237 clock cycles.
  LED on time maximum: 398 clock cycles.
  LED on time average: 262.576 clock cycles.
2016-12-06 19:44:23 +01:00
Markus Hitter d5eb8cd916 DDA: avoid looking up the movebuffer array.
As we have mb_tail_dda now, that's no longer necessary. Using
something like movebuffer[mb_tail] is more expensive than
dereferencing mb_tail_dda directly.

This is the first time we see a stepping performance improvement
since introducing mb_tail_dda. 13 clock cycles faster on the
slowest step, which is 9 cycles faster than before that
introduction.

Binary size also a nice 94 bytes down.

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19270 bytes      135%       63%       31%       15%
     Data:   2179 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 218 clock cycles.
  LED on time maximum: 395 clock cycles.
  LED on time average: 249.051 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 237 clock cycles.
  LED on time maximum: 438 clock cycles.
  LED on time average: 272.216 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 237 clock cycles.
  LED on time maximum: 395 clock cycles.
  LED on time average: 262.572 clock cycles.
2016-12-06 15:33:26 +01:00
Markus Hitter eec0e00f85 dda_queue.c/.h: eliminate queue_current_movement().
Again no stepping performance improvement, but another 34 bytes
off the binary size:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19364 bytes      136%       64%       31%       16%
     Data:   2179 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%
2016-12-06 15:08:50 +01:00
Markus Hitter fc70e00ca2 DDA: don't queue up heater waits.
Not queuing up waits for the heaters in the movement queue removes
some code in performance critical paths. What a luck we just
implemented an alternative M116 functionality with the previous
commit :-)

Performance of the slowest step is decreased a nice 29 clock
cycles and binary size decreased by a whoppy 472 bytes. That's
still 210 bytes less than before implementing the alternative
heater wait.

Best of all, average step time is down some 21 clock cycles, too,
so we increased general stepping performance by no less than 5%.

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19436 bytes      136%       64%       31%       16%
     Data:   2177 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 259 clock cycles.
  LED on time maximum: 429 clock cycles.
  LED on time average: 263.491 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 251 clock cycles.
  LED on time maximum: 472 clock cycles.
  LED on time average: 286.259 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 251 clock cycles.
  LED on time maximum: 429 clock cycles.
  LED on time average: 276.616 clock cycles.
2016-12-05 21:36:03 +01:00
Markus Hitter 974c4b7de8 dda.c: simplify copy of startpoint.
This reduces binary size by 26 bytes without drawback.

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19526 bytes      137%       64%       31%       16%
     Data:   2175 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%
2016-11-27 22:16:58 +01:00
Markus Hitter 6d95620f32 DDA: don't queue up nullmoves.
Nullmoves are movements which don't actually move a stepper. For
example because it's a velocity change only or the movement is
shorter than a single motor step.

Not queueing them up removes the necessity to check for them,
which reduces code in critical areas. It also removes the
necessity to run dda_start() twice to get past a nullmove.

Best of this is, it also makes lookahead perform better. Before,
a nullmove just changing speed interrupted the lookahead chain,
now it no longer does. See straight-speeds.gcode and
...-Fsep.gcode, which produced different timings before, now
results are identical.

Also update the function description for dda_create().

Performance increase is impressive: another 75 clock cycles off
the slowest step, only 36 bytes binary size increase:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19652 bytes      138%       64%       31%       16%
     Data:   2175 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 280 clock cycles.
  LED on time maximum: 458 clock cycles.
  LED on time average: 284.653 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 501 clock cycles.
  LED on time average: 307.275 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 458 clock cycles.
  LED on time average: 297.625 clock cycles.

Performance of straight-speeds{-Fsep}.gcode before:

  straight-speeds.gcode statistics:
  LED on occurences: 32000.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 586 clock cycles.
  LED on time average: 298.75 clock cycles.

  straight-speeds-Fsep.gcode statistics:
  LED on occurences: 32000.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 672 clock cycles.
  LED on time average: 298.79 clock cycles.

Now:

  straight-speeds.gcode statistics:
  LED on occurences: 32000.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 501 clock cycles.
  LED on time average: 298.703 clock cycles.

  straight-speeds-Fsep.gcode statistics:
  LED on occurences: 32000.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 501 clock cycles.
  LED on time average: 298.703 clock cycles.

There we save even 171 clock cycles :-)
2016-11-27 22:16:56 +01:00
Markus Hitter 3ba52e5906 Revert "DDA: use bitmask to track active axes [...]"
While this was an improvement of 9 clocks on AVRs, it had more
than the opposite effect on ARMs: 25 clocks slower on the slowest
step. Apparently ARMs aren't as efficient in reading and writing
single bits.

  https://github.com/Traumflug/Teacup_Firmware/issues/189#issuecomment-262837660

Performance on AVR is back to what we had before:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19610 bytes      137%       64%       31%       16%
     Data:   2175 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 280 clock cycles.
  LED on time maximum: 549 clock cycles.
  LED on time average: 286.273 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 580 clock cycles.
  LED on time average: 307.439 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 539 clock cycles.
  LED on time average: 297.732 clock cycles.
2016-11-25 20:58:25 +01:00
Phil Hord 00a28cd502 DDA: use bitmask to track active axes for faster dda_step().
In dda_step instead of checking our 32-bit-wide delta[n] value,
just check a single bit in an 8-bit field.  Should be a tad faster.
It does make the code larger, but also about 10% faster, I think.

Performance:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19696 bytes      138%       65%       32%       16%
     Data:   2191 bytes      214%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 263 clock cycles.
  LED on time maximum: 532 clock cycles.
  LED on time average: 269.273 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 255 clock cycles.
  LED on time maximum: 571 clock cycles.
  LED on time average: 297.792 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 255 clock cycles.
  LED on time maximum: 522 clock cycles.
  LED on time average: 283.861 clock cycles.
2016-11-24 11:31:46 +01:00
Markus Hitter 1326db002f DDA, dda_step(): test for individual axes again.
This time we don't test for remaining steps, but wether the axis
moves at all. A much cheaper test, because this variable has to
be loaded into registers anyways.

Performance is now even better than without this test. Slowest
step down from 604 to 580 clock cycles.

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19610 bytes      137%       64%       31%       16%
     Data:   2175 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 280 clock cycles.
  LED on time maximum: 549 clock cycles.
  LED on time average: 286.273 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 580 clock cycles.
  LED on time average: 307.439 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 272 clock cycles.
  LED on time maximum: 539 clock cycles.
  LED on time average: 297.732 clock cycles.
2016-11-23 12:47:46 +01:00
Markus Hitter 437cb08e42 dda.c: use muldiv in update_current_position().
Apparently gcc doesn't manage to sort nested calculations. Putting
all the muldiv()s into one line gives this error:

  dda.c: In function ‘update_current_position’:
  dda.c:969:1: error: unable to find a register to spill in class ‘POINTER_REGS’
   }
   ^
  dda.c:969:1: error: this is the insn:
  (insn 81 80 259 4 (set (reg:SI 82 [ D.3267 ])
          (mem:SI (post_inc:HI (reg:HI 2 r2 [orig:121 ivtmp.106 ] [121])) [4 MEM[base: _97, offset: 0B]+0 S4 A8])) dda.c:952 95 {*movsi}
       (expr_list:REG_INC (reg:HI 2 r2 [orig:121 ivtmp.106 ] [121])
          (nil)))
  dda.c:969: confused by earlier errors, bailing out

This problem was solved by doing the calculation step by step,
using intermediate variables. Glad I could help you, gcc :-)

Moving performance unchanged, M114 accuracy should have improved,
binary size 18 bytes bigger:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19582 bytes      137%       64%       31%       16%
     Data:   2175 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%
2016-11-22 19:28:12 +01:00
Markus Hitter 20a0808887 DDA: don't count individual axis steps.
Using the Bresenham algorithm it's safe to assume that if the axis
with the most steps is done, all other axes are done, too.

This way we save a lot of variable loading in dda_step(). We also
save this very expensive comparison of all axis counters against
zero. Minor drawback: update_current_position() is now even slower.

About performance. The slowest step decreased from 719 to 604
clocks, which is quite an improvement. Average step time increased
for single axis movements by 16 clocks and decreased for multi-
axis movements. At the bottom line this should improve real-world
performance quite a bit, because a printer movement speed isn't
limited by average timings, but by the time needed for the slowest
step.

Along the way, binary size dropped by nice 244 bytes, RAM usage by
also nice 16 bytes.

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19564 bytes      137%       64%       31%       16%
     Data:   2175 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%

  short-moves.gcode statistics:
  LED on occurences: 888.
  LED on time minimum: 326 clock cycles.
  LED on time maximum: 595 clock cycles.
  LED on time average: 333.62 clock cycles.

  smooth-curves.gcode statistics:
  LED on occurences: 23648.
  LED on time minimum: 318 clock cycles.
  LED on time maximum: 604 clock cycles.
  LED on time average: 333.311 clock cycles.

  triangle-odd.gcode statistics:
  LED on occurences: 1636.
  LED on time minimum: 318 clock cycles.
  LED on time maximum: 585 clock cycles.
  LED on time average: 335.233 clock cycles.
2016-11-22 19:13:41 +01:00
wurstnase cd66feb8d1 dda.c: let's save 3 divisions. 2016-11-14 21:49:44 +01:00
wurstnase 2b1f3371c7 DDA: get rid of fast_spm.
We need the fastest axis instead of its steps.

Eleminates also an overflow when ACCELERATION > 596.

We save 118 bytes program and 2 bytes data.

Reviewer Traumflug's note: I see 100 bytes program and 32 bytes
RAM saving on ATmegas here. 16 and 32 on the LPC 1114. Either way:
great stuff!
2016-11-14 21:36:00 +01:00
Wurstnase 39cababb07 dda.c: don't apply feedrate multiplier when searching endstops.
With M220 we can increase the step rate while printing. But when
using this feature it could cause unexpected behaviour while
homing.
2016-11-08 21:21:34 +01:00
Phil Hord 5f6371c53d M220: add support for feedrate override percentage.
Similar to M221 which sets a variable flow rate percentage, add
support for M220 which sets a percentage modifier for the
feedrate, F.

It seems a little disturbing that the flow rate modifies the next
G1 command and does not touch the buffered commands, but this
seems like the only reasonable thing to do since the M221 setting
could be embedded in the source gcode for some use cases.  Perhaps
an "immediate" setting using P1 could be considered later if
needed.
2016-07-09 14:18:06 +02:00
Phil Hord 6679dd6562 dda_create(): treat 'target' as const and input only.
`target` is an input to dda_create, but we don't modify it.  We
copy it into dda->endpoint and modify that instead, if needed.
Make `target` const so this treatment is explicit.

Rely on dda->endpoint to hold our "target" data so any decisions
we make leading up to using it will be correctly reflected in our
math.
2016-07-09 14:17:51 +02:00
Phil Hord 51321910bc M221: use 256 for 100% flow internally for faster math
The flow rate is given as a percentage which is kept as
100 = 100% internally. But this means we must divide by 100 for
every movement which can be expensive.  Convert the value to
256 = 100% so the compiler can optimize the division to a
byte-shift.

Also, avoid the math altogether in the normal case where the
flow rate is already 100% and no change is required.

Note: This also requires an increase in the size of e_multiplier
to 16 bits so values >= 100% can be stored.  Previously flow
rates only up to 255% (2.5x) were supported which may have
surprised some users.  Now the flow rate can be as high as
10000% (100x), at least internally.
2016-07-09 11:42:16 +02:00
wurstnase 9b010e65ee Introduce M221 aka flow-control.
Now it is possible to control the extruders flow.

  M221 S100 = 100% of the extruders steps
  M221 S90  = 90% of the extruders steps

M221 is also used in other firmwares for this. Also a lot of
hosts, like Octoprint and Pronterface using this M-Code for
this behaviour.
2016-07-09 11:42:16 +02:00
Markus Hitter 6cce9d173a DDA: extruders aren't subject to kinematics.
As such, move extruder handling out of dda_kinematics.c into
dda.c.
2016-07-09 11:42:16 +02:00
wurstnase 705e4563db DDA: X is not critical anymore.
It's prepared here:

  https://github.com/Traumflug/Teacup_Firmware/commit/294f0eda26

And gone here:

  https://github.com/Traumflug/Teacup_Firmware/commit/4f0a00c1a

Anyhow, we have a calculation with X in dda_lookahead.c

Traumflugs review note: true, at least until we get distinct
acceleration on each axis.
2016-07-02 22:07:27 +02:00
Phil Hord 803ff6e8b3 fix ACCELERATION_REPRAP build (moved/extra vars)
REPRAP style acceleration broke quite a while ago, but no one noticed.
Maybe it's not being used, and therefore also not tested. But it should
at least compile while it remains an option.

The compiler complains that dda->n is not defined and that current_id is
never used.  The first bug goes back to f0b9daeea0 in late 2013.

In the interest of supporting exploratory accelerations, fix this to
build when ACCELERATION_REPRAP is chosen.
2016-06-22 19:28:38 -04:00
Phil Hord b317ba086c corexy: Fix new_dda_startpoint for corexy
Add a function axes_um_to_steps to convert from um to steps on all axes
respecting current kinematics setting.

Extend code_stepper_axescode_axes_to_stepper_axes to convert all axes,
including E-axis for consistency.

It seems like axes_um_to_steps could be simplified to something like
"apply_kinematics_axes()" which would just do the transformation math
in-place on some axes[] to move from 'Cartesian' to 'target-kinematics'.
Then the original um_to_steps and delta_um code could remain untouched
since 2014.  But I'm not sure how this will work with scara or delta
configurations. I'm fairly certain they only work from absolute positions
anyway.

Fixes #216.
2016-05-31 15:19:50 -04:00
Phil Hord 90d519af5f dda_clock(): guard against *dda changes in interrupts
dda_clock() might be interrupted by dda_step(), and dda_step might
use or modify variables also being used in dda_clock().  It is
possible for dda to be modified when a new dda becomes live during
our dda_clock().  Check the dda->id to ensure it has not changed on
us before we actually write new calculated values into the dda.

Note by Traumflug: copied some of the explanation in the commit
message directly into the code.
2016-05-21 15:46:10 +02:00
Phil Hord 1eefb28a19 dda_clock(): modify dda->n only in atomic code
dda_clock() might be interrupted by dda_step(), and dda_step might
use or modify variables also being used in dda_clock. In particular
dda->c is modified in both functions but it is done atomically in
dda_clock() to prevent dda_step() from interrupting during the
write.  But dda->n is also modified in both places and it is not
protected in dda_clock().

Move updates to dda->n to the atomic section along with dda->c.

Note by Traumflug: good catch! It even makes the binary 14 bytes
smaller, so likely faster.
2016-05-21 15:45:49 +02:00
Markus Hitter e633222cd3 Make message/text sending aware of the sending destination.
Point of this change is to allow using these functions for
writing to the display, too, without duplicating all the code.

To reduce confusion, functions were renamed (they're no longer
'serial', after all:

  serwrite_xxx() -> write_xxx()
  sersendf_P()   -> sendf_P()

To avoid changing all the existing code, a couple of macros
with the old names are provided. They might even be handy as
convenience macros.

Nicely, this addition costs no additional RAM. Not surprising, it
costs quite some binary size, 278 bytes. Sizes now:

Program:  24058 bytes      168%       79%       38%       19%
   Data:   1525 bytes      149%       75%       38%       19%
 EEPROM:     32 bytes        4%        2%        2%        1%

Regarding USB Serial: code was adjusted without testing on
hardware.
2016-04-26 15:23:15 +02:00
Markus Hitter 82374b8e24 Rename Z_LATE_ENABLE to Z_AUTODISABLE and refine description.
Also turn it on by default for the Mendel printer.

Also add the forgotten Mendel90 printer.
2016-03-27 20:23:05 +02:00
Wurstnase 57afef9fdd Add Z late enable.
Until this commit, the Z axis is disabled after each move and
only enabled when the Z axis will move. Now you can enable this
as a feature. Some printer axes are too heavy or have a high
pitch which are not self locking. In that case simply do nothing.
It's now off by default.
2016-03-27 20:14:04 +02:00
Markus Hitter 5d8e866501 Move interrupt busy detection from dda_clock() to clock tick ISR.
The reason is, interrupts can't be re-entered on ARM, so we need
a different mechanism.
2015-08-12 14:26:37 +02:00
Markus Hitter 7be5212f06 ARM: introduce sei() and cli().
No test, because it's tricky to test, but it compiles and the
firmware still works as before.
2015-08-12 14:26:36 +02:00
Phil Hord 22b640697b Replace SIMULATOR with __AVR__ in several places.
Previously some features were excluded based on whether SIMULATOR
was defined. But in fact these should have been included when __AVR__
was defined. These used to be the same thing, but now with ARM coming
into the picture, they are not. Fix the situation so AVR includes are
truly only used when __AVR__ is defined.

The _crc16_update function appears to be specific to AVR; I've kept the
alternate implementation limited to AVR in that case in crc.c. I think
this is the right thing to do, but I am not sure. Maybe ARM has some
equivalent function in their libraries.
2015-07-29 21:05:38 +02:00
Yiannis Mandravellos fb249214f0 dda.c: fix overflow for large steps/meter values.
The trick is to use doubles earlier. As these calculations are
optimised out anyways, binary size and performance is kept.

Verified to have an identical outcome on a few common steps/mm and
acceleration cases.
2015-06-06 12:04:52 +02:00
Markus Hitter 9dd7426f9d DDA: on short schedules, repeat step routine immediately ...
... instead of trying to fire an interrupt as quickly as possible.
This affects ACCELERATION_TEMPORAL only. It almost doubles the
achievable step rate. Measured maximum step rate (X axis only,
100 mm moves) is 40'000 steps/s on a 16 MHz electronics, so
approx. 50'000 steps/s on a 20 MHz controller, which is even
a bit faster than the ACCELERATION_RAMPING algorithm.

Tests with temporary test code were run and judging by these
tests, clock interrupts are now very reliable up to the point
where processing speed is simply exhaused.

Performance with ACCELERATION_RAMPING: this costs 10 bytes
binary size and exactly 2 clock cycles per step interrupt or
0.6% performance even. We could avoid this with a lot
of #ifdefs, but considering ACCELERATION_TEMPORAL will one
day be the default acceleration, skip these #ifdefs, also
for better code readability.

$ cd testcases
$ ./run-in-simulavr.sh short-moves.gcode smooth-curves.gcode triangle-odd.gcode
    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH  : 20528 bytes         144%        67%        33%      16%
    RAM    :  2188 bytes         214%       107%        54%      27%
    EEPROM :    32 bytes           4%         2%         2%       1%

short-moves.gcode statistics:
LED on occurences: 838.
LED on time minimum: 304 clock cycles.
LED on time maximum: 715 clock cycles.
LED on time average: 310.717 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 8585.
LED on time minimum: 309 clock cycles.
LED on time maximum: 712 clock cycles.
LED on time average: 360.051 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 304 clock cycles.
LED on time maximum: 710 clock cycles.
LED on time average: 332.32 clock cycles.
2015-04-21 02:51:32 +02:00
Markus Hitter 7dda91ab56 dda.c: put code for ACCELERATION_TEMPORAL in dda_step() together.
Performance for ACCELERATION_RAMPING unchanged:

$ cd testcases
$ ./run-in-simulavr.sh short-moves.gcode smooth-curves.gcode triangle-odd.gcode
[...]
    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH  : 20518 bytes         144%        67%        33%      16%
    RAM    :  2188 bytes         214%       107%        54%      27%
    EEPROM :    32 bytes           4%         2%         2%       1%

short-moves.gcode statistics:
LED on occurences: 838.
LED on time minimum: 302 clock cycles.
LED on time maximum: 713 clock cycles.
LED on time average: 308.72 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 8585.
LED on time minimum: 307 clock cycles.
LED on time maximum: 710 clock cycles.
LED on time average: 358.051 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 302 clock cycles.
LED on time maximum: 708 clock cycles.
LED on time average: 330.322 clock cycles.
2015-04-21 02:51:32 +02:00
Markus Hitter 8b88334b06 Rename setTimer() to timer_set() for more consistency.
Pure cosmetical change.

Performance check:

$ cd testcases
$ ./run-in-simulavr.sh short-moves.gcode smooth-curves.gcode triangle-odd.gcode
[...]
    SIZES             ATmega...  '168    '328(P)    '644(P)    '1280
    FLASH  : 20518 bytes         144%        67%        33%      16%
    RAM    :  2188 bytes         214%       107%        54%      27%
    EEPROM :    32 bytes           4%         2%         2%       1%

short-moves.gcode statistics:
LED on occurences: 838.
LED on time minimum: 302 clock cycles.
LED on time maximum: 713 clock cycles.
LED on time average: 308.72 clock cycles.

smooth-curves.gcode statistics:
LED on occurences: 8585.
LED on time minimum: 307 clock cycles.
LED on time maximum: 710 clock cycles.
LED on time average: 358.051 clock cycles.

triangle-odd.gcode statistics:
LED on occurences: 1636.
LED on time minimum: 302 clock cycles.
LED on time maximum: 708 clock cycles.
LED on time average: 330.322 clock cycles.
2015-04-21 02:51:32 +02:00
Markus Hitter a6be2f9584 dda.c: add forgotten variable declaration.
Forgotten in commit 74808610c7,
"DDA: Move axis calculations into loops, part 5.".

This and the previous commit makes ACCELERATION_TEMPORAL building
(and working!) again.
2015-04-21 02:51:31 +02:00