Commit Graph

809 Commits

Author SHA1 Message Date
Phil Hord 452e2e5cd9 Restore simulation build target.
This code was accidentally removed long ago in a botched merge. This
patch recovers it and makes it build again. I've done minimal testing
and some necessary cleanup. It compiles and runs, but it probably still
has a few dust bunnies here and there.

I added registers and pin definitions to simulator.h and
simulator/simulator.c which I needed to match my Gen7-based config.
Other configs or non-AVR ports will need to define more or different
registers. Some registers are 16-bits, some are 8-bit, and some are just
constant values (enums). A more clever solution would read in the
chip-specific header and produce saner definitions which covered all
GPIOs. But this commit just takes the quick and easy path to support my
own hardware.

Most of this code originated in these commits:

	commit cbf41dd4ad
	Author: Stephan Walter <stephan@walter.name>
	Date:   Mon Oct 18 20:28:08 2010 +0200

	    document simulation

	commit 3028b297f3
	Author: Stephan Walter <stephan@walter.name>
	Date:   Mon Oct 18 20:15:59 2010 +0200

	    Add simulation code: use "make sim"

Additional tweaks:

Revert va_args processing for AVR, but keep 'int' generalization
for simulation. gcc wasn't lying. The sim really aborts without this.

Remove delay(us) from simulator (obsolete).

Improve the README.sim to demonstrate working pronterface connection
to sim. Also fix the build instructions.

Appease all stock configs.

Stub out intercom and shush usb_serial when building simulator.

Pretend to be all chip-types for config appeasement.

Replace sim_timer with AVR-simulator timer:

The original sim_timer and sim_clock provided direct replacements
for timer/clock.c in the main code. But when the main code changed,
simcode did not. The main clock.c was dropped and merged into timer.c.
Also, the timer.c now has movement calculation code in it in some
cases (ACCELERATION_TEMPORAL) and it would be wrong to teach the
simulator to do the same thing. Instead, teach the simulator to
emulate the AVR Timer1 functionality, reacting to values written to
OCR1A and OCR1B timer comparison registers.

Whenever OCR1A/B are changed, the sim_setTimer function needs to be
called. It is called automatically after a timer event, so changes
within the timer ISRs do not need to bother with this.

A C++ class could make this requirement go away by noticing the
assignment. On the other hand, a chip-agnostic timer.c would help
make the main code more portable. The latter cleanup is probably
better for us in the long run.
2013-12-06 19:24:58 +01:00
Markus Hitter 2f81386a7a dda.c: simplify start conditions calculation. 2013-12-06 19:24:58 +01:00
Markus Hitter da77b678e3 look-ahead: take F_end into account on acceleration calculations. 2013-12-06 19:24:58 +01:00
Markus Hitter 83433cb071 look-ahead: take F_start into account on acceleration calculations. 2013-12-06 19:24:58 +01:00
Markus Hitter c1a6c244b3 dda.c: re-gain look-ahead compatibility.
We're here! Incredible high step rates as well as smooth
movements due to look-ahead.
2013-12-06 19:24:58 +01:00
Markus Hitter f0b9daeea0 dda.c/.h: move n and c back into the dda structure.
This is a preparation for starting a move from non-zero speeds,
which is needed for look-ahead. Keeping both variables in
move_state and doing the calculations in dda_start() is possible
in principle, but might not fit the tight time budget we have when
going from one movement to the next at high step rates.

To deal with this, we have to pre-calculate n and c, so we have
to move it back into the DDA structure. It was there a year ago
already, but moved into move_state to save RAM (move_state exists
only once, dda as often as there are movement queue entries).
2013-12-06 19:24:58 +01:00
Markus Hitter 4190d6ffb9 Fix endstop stop condition for clock-based acceleration.
This required a strategy change, since move_state.n is no longer
decreasing in steps of 1.
2013-12-06 19:24:58 +01:00
Markus Hitter 3988e47467 Implement Roland Brochards' new acceleration maths clock-based.
His implementation was done on every step and as it turns out,
the very same maths works just fine in the clock interrupt.
Reason for the clock interrupt is: it allows about 3 times
higher step rates.

This strategy is not only substantially faster, but also
a bit smaller.

One funny anecdote: the acceleration initialisation value, C0,
was taken from elsewhere in the code as-is. Still it had to be
adjusted by a factor of sqrt(2) to now(!) match the physics
formulas and to get ramps reasonably matching the prediction
(and my pocket calculator). Apparently the code before
accumulated enough rounding errors to compensate for the
wrong formula.
2013-12-06 19:24:58 +01:00
Markus Hitter 921348c474 config.ramps-v1.3.h: enable extruder axis.
Spotted by @itscipher:

http://forums.reprap.org/read.php?147,272712,273344

Thank you for the contribution!
2013-11-29 11:14:24 +01:00
Markus Hitter ff9fdafa3c Add another testcase, triangle-odd.gcode.
This was found to expose a bug, see Github issue #67.
2013-11-28 23:43:10 +01:00
Markus Hitter 0eecdf895b Temperature tables: add missing const qualifiers.
Spotted and fixed by wrtlprnft, thanks for the contribution.
2013-11-16 17:31:28 +01:00
Markus Hitter d0bea9b51a Add another look-ahead testcase. 2013-11-11 19:03:52 +01:00
Phil Hord c695f1e4f7 Remove stale reference to endstops_stop
This was accidentally left out of the change at 13ec2d75.
2013-11-11 19:03:36 +01:00
Phil Hord 498779d7ab gcode-process.c: fix HEATER_EXTRUDER reference.
A rare combination of factors makes this code assume HEATER_EXTRUDER
always exists, when that is not necessarily so.  Add the normal
guard around it.
2013-11-11 19:02:52 +01:00
Markus Hitter 89c85181f7 Add a testcase for look-ahead (smooth curves). 2013-11-11 19:00:31 +01:00
Markus Hitter 59e461104b Add a testcase with excessive digits left to the decimal.
Currently, Teacup can't handle this.
2013-11-11 12:25:17 +01:00
Markus Hitter 00af5bd266 dda_queue.c: fix no longer true comment. 2013-11-08 21:38:04 +01:00
Markus Hitter 1ab42ee8eb Move the branch accel_clock into the attic.
This was a very interesting approach, but for the forseeable
future it's unlikely the code will replace the current one.

However, many parts of it were already moved to the experimental
branch. It turns out the approach with recalculating acceleration
at a constant time interval is exactly right, but works much more
precisely when keeping maths step-based.
2013-10-27 20:31:36 +01:00
Markus Hitter 5df8eeaacf dda.c: fix ACCELERATION_RAMPING #ifdefs. 2013-10-27 20:09:28 +01:00
Markus Hitter fe985a18d3 dda_lookahead.c: simplify bailout condition tests.
We have the nullmove flag already and the current move can't be
a nullmove, because in this case we wouldn't enter the function.
2013-10-27 20:01:51 +01:00
Markus Hitter ed6a66c25d timer.c: the concept of a "new move" was abandoned long time ago.
This doesn't matter much, as the timer overflows 300 times/second
worst case, so the very first step of a series of moves is
delayed never more than 30 milliseconds. Hardly recognizeable
by a human.

Saves a nice 40 bytes and improves max step rate by several percent.
2013-10-27 20:01:51 +01:00
Markus Hitter 0c100fe5f8 According to avr-libc documentation, ISR() handles SREG its self. 2013-10-27 20:01:51 +01:00
Markus Hitter 3343cfc753 dda.c: more notes on rampup_steps calculation. 2013-10-27 20:01:51 +01:00
Markus Hitter a97c65b940 dda.c: update last_dda also when idle. 2013-10-27 20:01:51 +01:00
Roland Brochard a80eff84f8 dda_maths.c/.h: implement an integer inverse square root algorithm.
This 1/sqrt(x) implementation is a 12 bits fixed point implementation
and a bit faster than a 32 bits divide (it takes about 11% less time
to complete) and could be even faster if one requires only 8 bits.
Also, precision starts getting poor for big values of n which are
likely to be required by small acceleration values.
2013-10-27 20:01:51 +01:00
Markus Hitter da5c29a7dd timer.c/.h: make TICK_TIME macros available globally. 2013-10-27 20:01:51 +01:00
Markus Hitter 59599a3552 analog.c: use atomic macros. 2013-10-27 20:01:51 +01:00
Markus Hitter ccec75d9f8 dda.c: allow protected re-entry for time based stepper calculations.
This becomes more important when acceleration is calculated
there, too.
2013-10-27 20:01:51 +01:00
Markus Hitter c7ee530c62 Add config.sanguish.h. 2013-10-27 20:01:51 +01:00
Markus Hitter 01f7c99881 config.h: introduce PS_MOSFET_PIN for Sanguish support. 2013-10-27 20:01:51 +01:00
Markus Hitter e7b7e004f4 Silence a false positive warning. 2013-10-27 20:01:51 +01:00
Roland Brochard af12c7a68a Faster implementation of integer square root.
Implementation by Roland Brochard <zuzuf86@gmail.com>.

Note: If you wonder how code doing multiplications can be faster than
code doing just shifts and increments: I've measured it. One million
square roots in 30 seconds with the new code instead of 220 seconds
with the old code on a Gen7 20 MHz. That's just 30 microseconds or
600 CPU cycles per root.

Code used for the measurement (by a stopwatch) in mendel.c:
...
*include "dda_maths.h"
*include "delay.h"
int main (void)
{
  uint32_t i, j;

  serial_init();
  sei();
  serial_writestr_P(PSTR("start\n"));
  for (i = 0; i < 1000000; i++) {
    j = int_sqrt(i);
  }
  serial_writestr_P(PSTR("done\n"));
  delay_ms(20);
  cli();

  init();
...

--Traumflug
2013-10-27 20:01:51 +01:00
Markus Hitter 13ec2d7521 Move endstop handling into a time-based procedure.
Before, endstops were checked on every step, wasting precious time.
Checking them 500 times a second should be more than sufficient.

Additionally, an endstop stop now properly decelerates the movement.
This is one important step towards handling accidental endstop hits
gracefully, as it avoids step losses in such situations.
2013-10-27 20:01:10 +01:00
Markus Hitter da085670f4 dda_lookahead.c: use the new ATOMIC macros here as well. 2013-07-21 23:28:50 +02:00
Markus Hitter 36c07d3423 dda_queue.c: Simplify queue_flush().
No ATOMIC wrapping required and setTimer(0) actually restarts the timer,
which isn't what we want here.
2013-07-21 23:28:42 +02:00
Markus Hitter 47a5252230 Apply ATOMIC macros in a number of other obvious places. 2013-07-21 23:27:33 +02:00
Markus Hitter 69da7c5b15 Introduce ATOMIC_START and ATOMIC_END.
As a sample application, use it in queue_empty().

There's also ATOMIC_BLOCK() coming with avr-libc, but this requires
a C99 compiler while Arduino IDE insists on running avr-gcc in C89 mode.
2013-07-21 23:23:28 +02:00
Markus Hitter 569adeecd1 Move the branch input-float into an attic.
This was a very interesting approach, but for the forseeable
future it's unlikely the code will replace the current one.
2013-07-11 22:33:41 +02:00
Markus Hitter fc4bfca06a Rename M200 to M119 to meet Sprinter & Marlin.
No functional change.
2013-07-11 22:04:03 +02:00
Markus Hitter 23679bbd49 Remove M84.
Teacup handles motor on/off automatically and if your
intention is to stop the printer, M0 is appropriate (and
conforming with the NIST G-code standard).

That said, M84 is kept as a synonym for M2 to enhance compatibility
with slic3rs default end-G-code.
2013-07-11 22:03:51 +02:00
David Forrest 6ac79b288d temp.c: DEBUG_USER code for raw temp readings. 2013-07-11 22:03:21 +02:00
David Forrest aefd4b6596 usb_serial.c: eliminate type punning compiler warnings 2013-07-11 22:03:01 +02:00
Markus Hitter ea59e634a7 Bring LOOKAHEAD into the config templates. 2013-07-11 22:02:23 +02:00
Markus Hitter 1aca61c277 Make lookahead basically working.
This means, modify existing code to let the lookahead algorithms
do their work. It also means to remove some unused code in
dda_lookahead.c and reordering some code to make it work with
LOOKAHEAD undefined.
2013-07-11 22:02:13 +02:00
Markus Hitter e04b69b9c6 Add Cyberwizzards lookahead. Thanks a lot, Cyberwizzard.
For now only the two new files, tweaked a bit in the #ifdef
area to let them compile without LOOKAHEAD being defined.
2013-07-11 22:02:02 +02:00
Markus Hitter b8f32c627c delay.h: re-add falsely removed #include. 2013-03-24 16:19:25 +01:00
Markus Hitter a2ce509bed Eliminate _delay(), delay() and _delay_us().
Doesn't change much, even the binary size stays the same. Much
cleaner code though, now we have only delay_us() and delay_ms().
2013-03-24 16:19:24 +01:00
Markus Hitter 1114761bed Eliminate _delay_ms().
Lots of duplicate stuff in delay.c/.h ...
2013-03-24 16:19:23 +01:00
Markus Hitter 2ebfd44530 Clean up some unused delay related stuff. 2013-03-24 16:19:21 +01:00
Markus Hitter aece36f6a2 Add support for the AT90USB1286.
Contribution by DaveX. Thank you very much, Dave. See
http://forums.reprap.org/read.php?147,33082,182206#msg-182206
2013-03-24 16:17:54 +01:00