Commit Graph

137 Commits

Author SHA1 Message Date
Nico Tonnhofer 5d5c169f07 gcode_process: change E-axis behavior of M83/G91
Only real relative mode with M83.
G91 moves the E-axis relative but position will be absolute.
M83 moves the E-axis relative. Position will be also relative.
2017-12-02 04:41:20 +01:00
Phil Hord 80136a51d8 mb_tail_dda: some code forgot to check for null 2016-12-20 16:31:21 -08: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 fb49aef14d Make temperature waiting independent from the movement queue.
The plan is to remove this stuff from the movement queue.

We still accept additional G-code ... until a G0 or G1 appears.
This e.g. allows to do homing or read temperature reports while
waiting.

Keep messages exactly as they were before, perhaps some Host
applications try to parse this.

This needs 2 bytes RAM and 138 bytes binary size. Performance is
unchanged. Let's see how this compares to the size reduction when
we remove the temperature handling code from the movement queue.

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19646 bytes      138%       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: 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.
2016-12-05 13:56:09 +01:00
Markus Hitter 7875b50f80 gcode_process.c: remove G30.
This was "Go home via point". The RepRap community has apparently
decided for a super complex Z probing command with this number:

  http://reprap.org/wiki/G-code#G30:_Single_Z-Probe

This reduces binary size by 18 bytes:

  ATmega sizes               '168   '328(P)   '644(P)     '1280
  Program:  19508 bytes      137%       64%       31%       16%
     Data:   2175 bytes      213%      107%       54%       27%
   EEPROM:     32 bytes        4%        2%        2%        1%
2016-11-28 13:39:32 +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 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 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
Phil Hord 4f30e270b2 Don't declare variables which never get used
Fix a compiler warning about "unused variables" when no endstops
are defined.
2015-11-18 14:53:12 -05:00
Phil Hord 890879e7ee Messages: more newlines needed.
The recent switch to send 'ok' postponed requires also sending a
newline in a few places, because this 'ok' is no longer at the
start of the line. Now it appears in its own line.

A recent commit tried to correct this already, but it missed a
few locations.  Also remove the comments promising a forthcoming
newline from gcode_parse.
2015-09-23 08:21:16 -04:00
Markus Hitter 5c203b6689 ARM: get watchdog.c in.
The last .c file of the generic ARM port! Again made sure it
doesn't accidentially slip in.
2015-08-13 17:12:13 +02:00
Markus Hitter fb317fef08 ARM: get spi.c, pff.c and pff_diskio.c (SD card handling) in.
Neither is ported for now, but also not essential for printing,
so it's just made sure it's always disabled on ARM.
2015-08-13 17:12:13 +02:00
Markus Hitter b849e28836 ARM: get home.c in.
As usual, homing works just fine.
2015-08-13 17:12:12 +02:00
Markus Hitter 1aeb04329c heater-arm.c: implement heater_set().
Works very nicely from full off (M106 S0) to full on (M106 S255).

Test: M106 should work now as expected. M106 S0 should turn full
off, M106 S255 should turn full on, both without any spike on the
scope.
2015-08-13 16:41:33 +02:00
Markus Hitter d7b59e2d33 ARM: implement heater-arm.c partially.
Currently at a fixed frequency of 1 kHz and with a fixed duty
cycle of 10%, but PWM does work.

As it turns out, PIO0_11 is not usable for PWM, because its timer
is already in use for the Step timer, and had to be disabled for
Gen7-ARM.

Test: define a heater in board.gen7-arm.h and a square signal
of 1 kHz with 10% duty cycle should appear on the heater pin.
2015-08-13 16:41:33 +02:00
Markus Hitter 8f24fbaad4 ARM: get temp.c in.
No code changes, but quite a few removals of __ARMEL_NOTYET__
guards. 20 such guards left.

Test: M105 should work and report plausible temperatures.

Current code size:

    SIZES          ARM...     lpc1114
    FLASH  :  9460 bytes          29%
    RAM    :  1258 bytes          31%
    EEPROM :     0 bytes           0%
2015-08-12 14:26:37 +02:00
Markus Hitter 5a8d51cb19 ARM: get dda_maths.c, dda_kinematics.c and dda.c in.
All in one chunk, because it's all hardware-independent and doing
them one by one would end up on not more than some typing
exercises.

Compiles fine. For testing, remove if (DEBUG... for M114 in
gcode_process.c. Then one can see how the queue fills up when
sending movements and M114 repeatedly. This time with actual
coordinates.

No stepper movements, yet, because set_timer() is still empty.
2015-08-12 14:26:37 +02:00
Markus Hitter 692a6daeb2 ARM: get dda_queue.c in.
Compiles fine. For testing, remove if (DEBUG... for M114 in
gcode_process.c. Then one can see how the queue fills up when
sending movements and M114 repeatedly.

queue_step() isn't called, yet, the stepper timer is still missing.
2015-08-12 14:26:37 +02:00
Markus Hitter 4faa3cbf8f ARM: bring in pinio.c.
This enables pinio_init(), power_on() and power_off(). Now one
can turn on the power supply with M119 and turn it off with M2.

Code changes were neccessary. Setting a pin first, then making
it an output doesn't work on ARM. A pin has to be an output
before it permanently accepts a given state. As I was never
sure the former strategy actually worked on AVR, the order of
these two steps was changed for both, AVR and ARM.
2015-08-12 14:26:36 +02:00
Markus Hitter 96f7dbd2b1 ARM: bring in gcode_process.c.
Again, the whole file compiled flawlessly without change. Still,
to get it linked as well, most of the functionality had to
be #ifdef'd out.

Nevertheless, the firmware shows first signs of life, e.g. M115
works.
2015-08-12 14:26:36 +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
Markus Hitter 4353403695 gcode_process.c: replace some sersendf() with serial_writestr().
sersendf_P() is only needed for formatted strings, plain strings
can be sent simpler.

Saves 48 bytes binary size on AVR.
2015-08-07 16:16:05 +02:00
Markus Hitter 9c194b42f6 Messages: more newlines needed.
The recent switch to send 'ok' postponed requires also sending a
newline in a few places, because this 'ok' is no longer at the
start of the line. Now it appears in its own line.

Some whitespace at line end was removed in heater.c.

Costs 14 bytes binary size on AVR.
2015-08-07 16:15:17 +02:00
Markus Hitter 2af689a4db gcode_process.c: remove a redundant #ifdef DEBUG and similar. 2015-08-01 18:27:39 +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
Markus Hitter 277de42b00 G-code parser: move gcode_source stuff ...
... from gcode_process.c/.h to gcode_parse.c/.h.
2015-07-17 13:31:10 +02:00
Markus Hitter 23be2d1449 SD card: finally(!) implement printing from SD card.
Turned out to be pretty easy with all the more complex bits
already in place.

Strategy is to always parse a full line from one of the sources.
Accordingly, simply sending a character on the serial line stops
reading from SD until the line coming in over serial is completed.
2015-07-07 19:07:35 +02:00
Markus Hitter d3f548a895 SD card: actually read the characters from the file.
Next to the implementation of sd_read_byte() as well as M24 and
M25, yet another demo: read the file and write it to the serial
line, to show correctness of the implementation.
2015-07-07 14:36:44 +02:00
Michael Moon 983bcfdd46 SD card: initial shoehorning of SD code, part 2.
Part 2 is to implement M23: select file. That's more than just a
few lines, as we also have to teach the gcode-parser to collect
strings.

For now the file is simply tested for successful opening, no
actual printing, yet.

About build size: during development there was another
implementation, which didn't abstract SD card functions into
sd.c/.h, but put them into gcode_process.c directly. At the
feature completeness of this commit, the other implementation
used 70 bytes flash less, but also 23 bytes more RAM. So I decided
for the more abstracted/encapsulated version. --Traumflug

Also, this adds 14 bytes binary size even without SD card support.
A lot more #ifdefs around each use of next_target.read_string
would remove this, but after all we do care a bit about
readability of the source code, so let's sacrify these 14 bytes
to it. --Traumflug
2015-07-05 23:32:48 +02:00
Michael Moon 8f2e1e59ac SD card: initial shoehorning of SD code, part 1.
Part 1 is, implement

 - M20: List SD card.
 - M21: Initialize SD card (has to be done before listing).
 - M22: Release SD card.

Do all this in one chunk, splitting this up wouldn't allow to test
the result.
2015-07-05 23:32:48 +02:00
Markus Hitter 9ea3941ffe gcode_process.c: be more explicit about X_MIN,... type.
Big surprise, this makes the binary a whopping 286 bytes smaller
with software endstops enabled. Looking at the produced assembly,
the former code caused gcc to do the float -> integer conversion
at runtime, using a __floatsisf(). Now the X_MIN, X_MAX... values
are compiled in as integers directly.

This is work related to issue #157.
2015-06-10 13:56:39 +02:00
Markus Hitter 3b02ba5376 gcode_process.c: refine description for G28. 2015-06-06 20:09:19 +02:00
Markus Hitter 9aa1d2337f gcode_process.c: we can't rely on next_target.P being zero.
... simply because P is used for many commands and none of them
cares to clean it after usage.

This fixes a bug where setting the default heater without temp
sensor (M106) worked only after a G4 Pxxx command.
2015-04-21 02:51:32 +02:00
Markus Hitter 55c0be5f41 gcode_process.c: same homing order for all axes.
This is, first towards MIN, then towards MAX. Now also matches order
for homing all, which is defined in home() in home.c. Partially
fixes issue #107.
2014-12-26 19:41:38 +01:00
Markus Hitter b66ba4629a gcode_process.c: sort M112.
Counting to numbers up to 300 is apparently not everyone's
business, he he. :-)
2014-12-26 19:41:38 +01:00
Erik Jonsson fa0e0d37e7 gcode_process.c: added stop message when M2 is recieved.
This shall help stopping a simulator when G-code is done.
2014-08-31 19:12:36 +02:00
Markus Hitter 642948acb2 gcode_process.c: review G28 comment. 2014-08-31 19:12:11 +02:00
David Forrest b12157cb6f gcode_process.c: Add comment on units of P, I, and D parameters. 2014-08-31 19:06:52 +02:00
Phil Hord d3f49b3e95 DDA: Convert TARGET axis vars to array.
In preparation for more efficient and scalable code using axis-loops
for common operations, add two new array-types for signed and unsigned
32-bit values per axis. Make the TARGET type use this array instead of
its current X, Y, Z, and E variables.

Traumflug notes:

- Did the usual conversion to spaces for changed lines.

- Added X = 0 to the enum. Just for peace of mind.

- Excellent patch!

Initially I wanted to make the new array an anonymous union with the
old variables to allow accessing values both ways. This way it would
have been possible to do the transition in smaller pieces. But as
the patch worked so flawlessly and binary size is precisely the
same, I abandoned this idea. Maybe it's a good idea in other areas.
2014-08-31 19:03:17 +02:00
Markus Hitter e76bfa0d05 gcode_process.c: more preprocessor conditions for homing movements.
Well, optimizer isn't _that_ smart. It apparently removes
empty functions in the same compilation unit ( = source code file),
but not ones across units.

This saves 10 bytes binary size per endstop not used, so 30 bytes
in a standard configuration. All without any drawbacks.
2014-07-11 01:38:34 +02:00
Markus Hitter 7611872baa Get rid of E_STARTSTOP_STEPS.
This meant to be a firmware-provided retract feature but was
never really supported by G-code generators. Without their support
(by issueing M101/M103), it's pretty hard to detect extrusion
pauses, so this feature simply has no future.

As this was on by default, it saves over 200 bytes binary size
in a default configuration.
2014-07-11 01:37:48 +02:00
Phil Hord 96b7b8e6c9 Update URLs for new github location 2014-03-04 19:57:08 +01:00
Phil Hord 21e5343552 Add config.h wrapper to simplify test automation
Test code which wants to customize config.h can do so without
touching config.h itself by wrapping config.h in a macro variable
which is passed in to the compiler.  It defaults to "config.h" if
no override is provided.

This change would break makefile dependency checking since the selection
of a different header file on the command line is not noticed by make
as a build-trigger.  To solve this, we add a layer to the BUILDDIR path
so build products are now specific to the USER_CONFIG choice if it is
not "config.h".
2014-03-04 19:56:23 +01:00
Markus Hitter c5871d0303 gcode_process.c: show endstop status in clear text.
This costs 40 bytes, but should be a significant enhancement on
usability.
2013-12-06 19:24:58 +01:00
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
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 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
Markus Hitter b10b3db4f8 Wrap EEPROM storage related stuff in #ifdef EECONFIG.
Saves a whopping 600 bytes. Let's cross fingers stuff still works.
It should, using the hardcoded default values.
2013-02-05 14:10:31 +01:00