Skip to content
Browse files

Using GRBL instead now. Not yet working.

  • Loading branch information...
1 parent 7408add commit 29beb0a5a0c219d7568b3b1be8ae677675e9de9d @timkrins committed
Showing with 2,677 additions and 4,366 deletions.
  1. +2 −17 .gitignore
  2. +165 −0 COPYING
  3. +0 −340 LICENSE
  4. +87 −159 Makefile
  5. +0 −212 README
  6. +0 −55 arduino.h
  7. +0 −363 arduino_644.h
  8. +0 −39 clock.c
  9. +0 −7 clock.h
  10. +46 −236 config.h
  11. +0 −255 config.h.dist
  12. +0 −531 dda.c
  13. +0 −125 dda.h
  14. +0 −130 dda_queue.c
  15. +0 −42 dda_queue.h
  16. +0 −3 debug.c
  17. +0 −21 debug.h
  18. +0 −50 delay.c
  19. +0 −15 delay.h
  20. +151 −0 eeprom.c
  21. +9 −0 eeprom.h
  22. +0 −11 fuses.h
  23. +467 −0 gcode.c
  24. +38 −0 gcode.h
  25. +0 −361 gcode_parse.c
  26. +0 −82 gcode_parse.h
  27. +0 −293 gcode_process.c
  28. +0 −21 gcode_process.h
  29. +55 −0 main.c
  30. +0 −157 mendel.c
  31. +86 −0 motion_control.c
  32. +49 −0 motion_control.h
  33. +35 −0 nuts_bolts.h
  34. +0 −20 pinio.c
  35. +0 −138 pinio.h
  36. +421 −0 planner.c
  37. +76 −0 planner.h
  38. +15 −0 readme.textile
  39. +0 −219 serial.c
  40. +0 −30 serial.h
  41. +77 −0 serial_protocol.c
  42. +30 −0 serial_protocol.h
  43. +0 −53 sermsg.c
  44. +0 −21 sermsg.h
  45. +0 −133 sersendf.c
  46. +0 −9 sersendf.h
  47. +130 −0 settings.c
  48. +70 −0 settings.h
  49. +45 −0 spindle_control.c
  50. +30 −0 spindle_control.h
  51. +297 −0 stepper.c
  52. +40 −0 stepper.h
  53. +0 −120 timer.c
  54. +0 −30 timer.h
  55. +0 −46 watchdog.c
  56. +0 −22 watchdog.h
  57. +211 −0 wiring_serial.c
  58. +45 −0 wiring_serial.h
View
19 .gitignore
@@ -1,19 +1,4 @@
+*.hex
*.o
*.elf
-*.lst
-*.map
-*.sym
-*.lss
-*.eep
-*.srec
-*.bin
-*.hex
-*.al
-*.i
-*.s
-*~
-
-temporal.png
-temporal_data
-config.h
-sim
+*.DS_Store
View
165 COPYING
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
View
340 LICENSE
@@ -1,340 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
-
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
-
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
-
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
-
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
-
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
-
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
- NO WARRANTY
-
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- <one line to give the program's name and a brief idea of what it does.>
- Copyright (C) <year> <name of author>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
- Gnomovision version 69, Copyright (C) year name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
-
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
- <signature of Ty Coon>, 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General
-Public License instead of this License.
View
246 Makefile
@@ -1,161 +1,89 @@
-##############################################################################
-# #
-# FiveD on Arduino - alternative firmware for repraps #
-# #
-# by Triffid Hunter, Traumflug, jakepoz #
-# #
-# #
-# This firmware is Copyright (C) 2009-2010 Michael Moon aka Triffid_Hunter #
-# #
-# This program is free software; you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation; either version 2 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program; if not, write to the Free Software #
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #
-# #
-##############################################################################
-
-MCU_TARGET = atmega644p
-F_CPU = 20000000L
-
-##############################################################################
-# #
-# Available Defines: #
-# #
-# DEBUG #
-# enables tons of debugging output. may cause host-side talkers to choke #
-# XONXOFF #
-# enables XON/XOFF flow control for stupid or crude talkers #
-# ACCELERATION_REPRAP #
-# enables reprap-style acceleration #
-# ACCELERATION_RAMPING #
-# enables start/stop ramping #
-# ACCELERATION_TEMPORAL #
-# enables experimental temporal step algorithm - not technically a type of #
-# acceleration, but since it controls step timing it seems appropriate #
-# GEN3 #
-# build for standard reprap electronics instead of your custom rig #
-# HOST #
-# this is the motherboard for GEN3- don't touch! Extruder has its own #
-# Makefile. #
-# #
-##############################################################################
-
-DEFS = -DF_CPU=$(F_CPU)
-#-DHOST -DGEN3
-# DEFS += "-DDEBUG=1"
-
-##############################################################################
-# #
-# Programmer settings for "make program" #
-# #
-##############################################################################
-
-AVRDUDE = avrdude
-AVRDUDECONF = /etc/avrdude.conf
-
-##############################################################################
-# #
-# udev rule for /dev/arduino (insert into /etc/udev/rules.d/99-local.rules) #
-# SUBSYSTEMS=="usb", ATTRS{idProduct}=="6001", ATTRS{idVendor}=="0403", #
-# NAME="%k", SYMLINK+="arduino", SYMLINK+="arduino_$attr{serial}", #
-# MODE="0660" #
-# #
-##############################################################################
-
-PROGPORT = /dev/arduino
-
-# atmega168
-#PROGBAUD = 19200
-# atmega328p, 644p, 1280
-PROGBAUD = 57600
-
-
-##############################################################################
-# #
-# These defaults should be ok, change if you need to #
-# #
-##############################################################################
-
-PROGRAM = mendel
-
-SOURCES = $(PROGRAM).c serial.c dda.c gcode_parse.c gcode_process.c timer.c sermsg.c dda_queue.c debug.c sersendf.c delay.c pinio.c clock.c watchdog.c
-
-ARCH = avr-
-CC = $(ARCH)gcc
-OBJDUMP = $(ARCH)objdump
-OBJCOPY = $(ARCH)objcopy
-
-OPTIMIZE = -Os -ffunction-sections -finline-functions-called-once -mcall-prologues
-# OPTIMIZE = -O0
-CFLAGS = -g -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS) -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -save-temps
-LDFLAGS = -Wl,--as-needed -Wl,--gc-sections
-
-OBJ = $(patsubst %.c,%.o,${SOURCES})
-
-.PHONY: all program clean size
-.PRECIOUS: %.o %.elf
-
-all: config.h $(PROGRAM).hex $(PROGRAM).lst
-
-program: $(PROGRAM).hex config.h
- stty $(PROGBAUD) raw ignbrk hup < $(PROGPORT)
- @sleep 0.1
- @stty $(PROGBAUD) raw ignbrk hup < $(PROGPORT)
- $(AVRDUDE) -cstk500v1 -b$(PROGBAUD) -p$(MCU_TARGET) -P$(PROGPORT) -C$(AVRDUDECONF) -U flash:w:$^
- stty 115200 raw ignbrk -hup -echo ixoff < $(PROGPORT)
-
-program-fuses:
- avr-objdump -s -j .fuse mendel.o | perl -ne '/\s0000\s([0-9a-f]{2})/ && print "$$1\n"' > lfuse
- avr-objdump -s -j .fuse mendel.o | perl -ne '/\s0000\s..([0-9a-f]{2})/ && print "$$1\n"' > hfuse
- avr-objdump -s -j .fuse mendel.o | perl -ne '/\s0000\s....([0-9a-f]{2})/ && print "$$1\n"' > efuse
- $(AVRDUDE) -cstk500v1 -b$(PROGBAUD) -p$(MCU_TARGET) -P$(PROGPORT) -C$(AVRDUDECONF) -U lfuse:w:lfuse
- $(AVRDUDE) -cstk500v1 -b$(PROGBAUD) -p$(MCU_TARGET) -P$(PROGPORT) -C$(AVRDUDECONF) -U hfuse:w:hfuse
- $(AVRDUDE) -cstk500v1 -b$(PROGBAUD) -p$(MCU_TARGET) -P$(PROGPORT) -C$(AVRDUDECONF) -U efuse:w:efuse
+# Part of Grbl
+#
+# Copyright (c) 2009-2011 Simen Svale Skogsrud
+#
+# Grbl is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Grbl is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Grbl. If not, see <http://www.gnu.org/licenses/>.
+
+
+# This is a prototype Makefile. Modify it according to your needs.
+# You should at least check the settings for
+# DEVICE ....... The AVR device you compile for
+# CLOCK ........ Target AVR clock rate in Hertz
+# OBJECTS ...... The object files created from your source files. This list is
+# usually the same as the list of source files with suffix ".o".
+# PROGRAMMER ... Options to avrdude which define the hardware you use for
+# uploading to the AVR and the interface where this hardware
+# is connected.
+# FUSES ........ Parameters for avrdude to flash the fuses appropriately.
+
+DEVICE = atmega644p
+CLOCK = 20000000L
+PROGRAMMER = -cusbtiny -P usb
+OBJECTS = main.o motion_control.o gcode.o spindle_control.o wiring_serial.o serial_protocol.o stepper.o \
+ eeprom.o settings.o planner.o
+
+
+# Tune the lines below only if you know what you are doing:
+
+AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) -B 10 -F
+COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -I. -ffunction-sections
+
+# symbolic targets:
+all: grbl.hex
+
+.c.o:
+ $(COMPILE) -c $< -o $@
+
+.S.o:
+ $(COMPILE) -x assembler-with-cpp -c $< -o $@
+# "-x assembler-with-cpp" should not be necessary since this is the default
+# file type for the .S (with capital S) extension. However, upper case
+# characters are not always preserved on Windows. To ensure WinAVR
+# compatibility define the file type manually.
+
+.c.s:
+ $(COMPILE) -S $< -o $@
+
+flash: grbl.hex
+ $(AVRDUDE) -cusbtiny -p$(DEVICE) -V -U flash:w:$^
+
+fuse:
+ $(AVRDUDE) $(FUSES)
+
+# Xcode uses the Makefile targets "", "clean" and "install"
+install: flash fuse
+
+# if you use a bootloader, change the command below appropriately:
+load: all
+ bootloadHID grbl.hex
clean:
- rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex *.al *.i *.s *~ *fuse
-
-size: $(PROGRAM).elf
- @echo " SIZE Atmega168 Atmega328p Atmega644"
- @$(OBJDUMP) -h $^ | perl -MPOSIX -ne '/.(text)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; END { printf " FLASH : %5d bytes (%2d%% of %2dkb) (%2d%% of %2dkb) (%2d%% of %2dkb)\n", $$a, ceil($$a * 100 / (15 * 1024)), 15, ceil($$a * 100 / (31 * 1024)), 31, ceil($$a * 100 / (63 * 1024)), 63 }'
- @$(OBJDUMP) -h $^ | perl -MPOSIX -ne '/.(data|bss)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; END { printf " RAM : %5d bytes (%2d%% of %2dkb) (%2d%% of %2dkb) (%2d%% of %2dkb)\n", $$a, ceil($$a * 100 / (1 * 1024)), 1, ceil($$a * 100 / (2 * 1024)), 2, ceil($$a * 100 / (4 * 1024)), 4 }'
- @$(OBJDUMP) -h $^ | perl -MPOSIX -ne '/.(eeprom)\s+([0-9a-f]+)/ && do { $$a += eval "0x$$2" }; END { printf " EEPROM: %5d bytes (%2d%% of %2dkb) (%2d%% of %2dkb) (%2d%% of %2dkb)\n", $$a, ceil($$a * 100 / (1 * 1024)), 1, ceil($$a * 100 / (2 * 1024)), 2, ceil($$a * 100 / (2 * 1024)), 2 }'
-
-config.h: config.h.dist
- @echo "Please review config.h, as config.h.dist is more recent."
- @echo
- @diff -bBEuF '^. [[:digit:]]. [[:upper:]]' config.h config.h.dist
- @false
-
-%.o: %.c config.h Makefile
- @echo " CC $@"
- @$(CC) -c $(CFLAGS) -Wa,-adhlns=$(<:.c=.al) -o $@ $(subst .o,.c,$@)
-
-%.elf: $(OBJ)
- @echo " LINK $@"
- @$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-%.lst: %.elf
- @echo " OBJDUMP $@"
- @$(OBJDUMP) -h -S $< > $@
-
-%.hex: %.elf
- @echo " OBJCOPY $@"
- @$(OBJCOPY) -j .text -j .data -O ihex $< $@
-
-%.bin: %.elf
- @echo " OBJCOPY $@"
- @$(OBJCOPY) -j .text -j .data -O binary $< $@
-
-%.sym: %.elf
- @echo " SYM $@"
- @$(OBJDUMP) -t $< | perl -ne 'BEGIN { printf " ADDR NAME SIZE\n"; } /([0-9a-f]+)\s+(\w+)\s+O\s+\.(bss|data)\s+([0-9a-f]+)\s+(\w+)/ && printf "0x%04x %-20s +%d\n", eval("0x$$1") & 0xFFFF, $$5, eval("0x$$4")' | sort -k1 > $@
+ rm -f grbl.hex main.elf $(OBJECTS)
+
+# file targets:
+main.elf: $(OBJECTS)
+ $(COMPILE) -o main.elf $(OBJECTS) -lm -Wl,--gc-sections
+
+grbl.hex: main.elf
+ rm -f grbl.hex
+ avr-objcopy -j .text -j .data -O ihex main.elf grbl.hex
+# If you have an EEPROM section, you must also create a hex file for the
+# EEPROM and add it to the "flash" target.
+
+# Targets for code debugging and analysis:
+disasm: main.elf
+ avr-objdump -d main.elf
+
+cpp:
+ $(COMPILE) -E main.c
View
212 README
@@ -1,212 +0,0 @@
-Rewrite of Reprap Mendel firmware:
-
-* 100% integer computations
-* serial transmit buffer
-* can fit onto atmega168 depending on selected options
-* works on atmega328p
-* works on atmega644p
-* porting to atmega1280 in progress
-* will work on larger atmegas with minor porting
-
-##############################################################################
-# #
-# How to use #
-# #
-##############################################################################
-
-1) COPY config.h.dist to config.h and edit to suit your electronics
-2) check programming settings in Makefile
-3) make
-4) make program
-4a) if programming blank chip, make program-fuses
-5) ./sender.sh
-6) have a play, go to 1) if not right
-7) try printing something!
-
-##############################################################################
-# #
-# Requirements #
-# #
-##############################################################################
-
-Compile:
- gnu make
- binutils, gcc, etc built for avr target (avr-gcc, avr-as, etc)
- avr-libc
-Program:
- avrdude
- something that avrdude supports: bootloader, separate programmer, whatever
-
-##############################################################################
-# #
-# License #
-# #
-##############################################################################
-
-This firmware is Copyright (C) 2009-2010 Michael Moon aka Triffid_Hunter
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-##############################################################################
-# #
-# Rationale and History #
-# #
-##############################################################################
-
-I started building my electronics with only a regular arduino to test with.
-This was perfectly sufficient for playing with the pololu stepper controllers and the max6675 I bought after reading about all the issues with thermistors that people were having. After a while I decided to check out the official firmware but it required an atmega644. I wondered why.
-So, I decided to skim through the code to see what took up so much space. From what I could see, it was written by someone who was familiar with programming desktop systems and larger embedded devices, but didn't have much experience with small devices such as the atmega168 and atmega644.
-This showed in the use of C++ which served only to make the code harder to read, and the prolific use of floating-point math, with some appearing even in interrupt context!
-I came to the conclusion that there was no reason that the main body of code couldn't fit onto an atmega168 except for the burdensome and unnecessary overheads from object-oriented code and floating point math. A quick count assured me that the atmega168 had enough pins, but only barely, and I started reading the official firmware properly, with an eye to rewriting as much as possible in a fashion suitable for small microcontrollers.
-
-Starting with an arduino skeleton library I had assembled over time, some of my test code and the official firmware, I hacked up a passable integer-only, straight C implementation of the dda, and wrote my own gcode parser from scratch which processed each character as it arrived (with some buffering of course) instead of waiting for a whole line and then trying to process it all at once.
-
-As soon as my new firmware was able to run a few consecutive moves, I released it for peer review.
-
-The forum thread http://forums.reprap.org/read.php?147,33082 has much of the history from this point on.
-
-Traumflug was the first to send patches, and has done a significant amount of work on a number of different parts of this firmware.
-jakepoz ported it to official reprap electronics (gen3 branch)
-Cefiar posted me some thermistors to sponsor addition of thermistor-reading code
-
-Many others have given encouragement and suggestions without which this firmware may never be what it is today.
-
-
-##############################################################################
-# #
-# Architectural Overview #
-# #
-##############################################################################
-
-FiveD on Arduino is quite similar to the official firmware in some ways, and markedly different in others. FiveD on Arduino has as much modularity as I could get away with without sacrificing efficiency.
-
-// FIXME: make next paragraph easier to read
-At startup, the code in mendel.c is run first. This initialises all the modules that need it, then starts polling the clock flags and feeding incoming serial characters to the gcode parser. The gcode parser processes each character individually, keeping track via internal state rather than buffering a line and skipping back and forth. The gcode parser converts floating values to integer or fixed-point representations as soon as it encounters a non-numeric character. It calls many module functions directly, but the most interesting part is move creation, where it passes a target position and speed to enqueue()[dda_queue.c] which adds it to the queue, and fires up dda_start()[dda.c] if the queue was empty. dda_start initialises the dda, figures out the stepper directions and first step timeout and a few other bits of housekeeping, then sets the timer for the appropriate timeout. When the timer fires, it calls dda_step()[dda.c] which sends all the step signals then figures out the next step timeout based on acceleration and speed settings. When the last step has been made, the dda "dies" (sets 'live' property to 0) after which queue_step[dda_queue.c] advances the queue read pointer and starts the next dda.
-
-It is necessary to keep interrupts very short on small microcontrollers, and I have endeavoured to keep them all as short as possible. Unfortunately, dda_step[dda.c] is fairly large. I simply hope that it doesn't take so much time that it interferes with the other interrupts too much.
-
-
-##############################################################################
-# #
-# Interesting code sections #
-# #
-##############################################################################
-
-The serial ringbuffers are critical for good communication, but for some reason the official arduino libraries don't implement a tx queue, all but preventing sending stuff from interrupt context. As long as the queues have a length of 2^n, we can use bitwise operations rather than numerical comparison to trim the read and write pointers. The serial send function (serial_writechar[serial.c]) is necessarily careful about checking if it's in an interrupt and only waiting for space in the queue if it's not.
-The dda queue is also a ringbuffer, although its implementation is harder to see as it's embedded in lots of other stuff.
-
-The gcode parser shows how to parse each character as it comes in, so 99% of a command can be processed before the EOL is even received. It started off as a simple state machine, which then grew and shrank and morphed until it was both smaller and more functional.
-
-The fixed-point stuff is fun, although we have to manually ensure that the decimal point stays in the right spot. decfloat_to_int[gcode.h] is used to convert incoming floats to integer implementations by starting off with a (very!) crude floating point implementation, then choosing appropriate scaling factors within the gcode parser itself. This allows us to do a little stuff that looks like floating-point math without the burdensome overhead of a full fp implementation.
-
-The PID code in heater.c is probably quite generalisable, and seems to work well when tuned. Google knows of plenty of PID tuning guides.
-
-##############################################################################
-# #
-# Resources #
-# #
-##############################################################################
-
-Forum thread: http://forums.reprap.org/read.php?147,33082
-Source Repository: http://github.com/triffid/FiveD_on_Arduino
-Wiki Page: http://objects.reprap.org/wiki/FiveD_on_Arduino
-
-##############################################################################
-# #
-# File descriptions #
-# #
-##############################################################################
-
-*** analog.[ch]
-This is the analog subsystem. Only used if you have a thermistor or ad595
-
-*** arduino.h, arduino_[chip].h
-Pin mappings and helper functions for various atmegas
-
-*** clock.[ch]
-Regular functions that run in main loop rather than an interrupt
-
-*** config.h.dist, config.h
-Configuration for your electronics and hardware. Copy config.h.dist to config.h, edit config.h to suit
-
-*** copier.[ch]
-A totally untested and currently unused chunk of code for copying firmware to another identical chip
-
-*** dda.[ch]
-A rather complex block of math that figures out when to step each axis according to speed and acceleration profiles and received moves
-
-*** dda_queue.[ch]
-The queue of moves received from the host.
-
-*** debug.[ch]
-Debugging aids
-
-*** delay.[ch]
-Delay functions
-
-*** FiveD_on_Arduino.pde
-Allows firmware to be built in arduino ide
-
-*** func.sh
-Lots of host-side shell scripts for talking to firmware
-
-*** gcode_parse.[ch]
-Gcode parser. Scaling of factors to internally used integer or fixed point happens here too.
-
-*** gcode_process.[ch]
-Gcodes actually get executed here after being parsed.
-
-*** heater.[ch]
-Heater management, including PID and PWM algorithms, and some configuration parameters
-
-*** intercom.[ch]
-Gen3 serial link control and communication
-
-*** LICENSE
-Gnu GPL2 license
-
-*** Makefile
-instructions for make on how to build firmware. has a list of modules to build which may need to be updated every so often
-
-*** mendel.c
-Firmware startup and main loop code
-
-*** pinio.h
-A few I/O primitives
-
-*** README
-this file
-
-*** sender.sh
-A simple talker
-
-*** serial.[ch]
-Serial management and buffers
-
-*** sermsg.[ch]
-Functions for sending messages and values to host
-
-*** sersendf.[ch]
-A small, crude printf implementation
-
-*** temp.[ch]
-Temperature sensor management, includes some configuration parameters
-
-*** timer.[ch]
-Timer management, used primarily by dda.c for timing steps
-
-*** watchdog.[ch]
-Watchdog management. resets chip if firmware locks up or does something strange
-
View
55 arduino.h
@@ -1,55 +0,0 @@
-#ifndef _ARDUINO_H
-#define _ARDUINO_H
-
-#include <avr/io.h>
-
-/*
- utility functions
-*/
-
-#ifndef MASK
-#define MASK(PIN) (1 << PIN)
-#endif
-
-/*
- magic I/O routines
-
- now you can simply SET_OUTPUT(STEP); WRITE(STEP, 1); WRITE(STEP, 0);
-*/
-
-#define _READ(IO) (IO ## _RPORT & MASK(IO ## _PIN))
-#define _WRITE(IO, v) do { if (v) { IO ## _WPORT |= MASK(IO ## _PIN); } else { IO ## _WPORT &= ~MASK(IO ## _PIN); }; } while (0)
-#define _TOGGLE(IO) do { IO ## _RPORT = MASK(IO ## _PIN); } while (0)
-
-#define _SET_INPUT(IO) do { IO ## _DDR &= ~MASK(IO ## _PIN); } while (0)
-#define _SET_OUTPUT(IO) do { IO ## _DDR |= MASK(IO ## _PIN); } while (0)
-
-#define _GET_INPUT(IO) ((IO ## _DDR & MASK(IO ## _PIN)) == 0)
-#define _GET_OUTPUT(IO) ((IO ## _DDR & MASK(IO ## _PIN)) != 0)
-
-// why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
-
-#define READ(IO) _READ(IO)
-#define WRITE(IO, v) _WRITE(IO, v)
-#define TOGGLE(IO) _TOGGLE(IO)
-
-#define SET_INPUT(IO) _SET_INPUT(IO)
-#define SET_OUTPUT(IO) _SET_OUTPUT(IO)
-
-#define GET_INPUT(IO) _GET_INPUT(IO)
-#define GET_OUTPUT(IO) _GET_OUTPUT(IO)
-
-/*
- ports and functions
- added as necessary or if I feel like it- not a comprehensive list!
-*/
-
-#if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__)
- #include "arduino_644.h"
-#endif /* _AVR_ATmega{644,644P,644PA}__ */
-
-#ifndef DIO0_PIN
-#error pins for this chip not defined in arduino.h! If you write an appropriate pin definition and have this firmware work on your chip, please tell us via the forum thread
-#endif
-
-#endif /* _ARDUINO_H */
View
363 arduino_644.h
@@ -1,363 +0,0 @@
-// UART
-#define RXD DIO8
-#define TXD DIO9
-#define RXD0 DIO8
-#define TXD0 DIO9
-
-#define RXD1 DIO10
-#define TXD1 DIO11
-
-// SPI
-#define SCK DIO7
-#define MISO DIO6
-#define MOSI DIO5
-#define SS DIO4
-
-// TWI (I2C)
-#define SCL DIO16
-#define SDA DIO17
-
-// timers and PWM
-#define OC0A DIO3
-#define OC0B DIO4
-#define OC1A DIO13
-#define OC1B DIO12
-#define OC2A DIO15
-#define OC2B DIO14
-
-#define DEBUG_LED DIO0
-/*
-pins
-*/
-
-#define DIO0_PIN PINB0
-#define DIO0_RPORT PINB
-#define DIO0_WPORT PORTB
-#define DIO0_DDR DDRB
-
-#define DIO1_PIN PINB1
-#define DIO1_RPORT PINB
-#define DIO1_WPORT PORTB
-#define DIO1_DDR DDRB
-
-#define DIO2_PIN PINB2
-#define DIO2_RPORT PINB
-#define DIO2_WPORT PORTB
-#define DIO2_DDR DDRB
-
-#define DIO3_PIN PINB3
-#define DIO3_RPORT PINB
-#define DIO3_WPORT PORTB
-#define DIO3_DDR DDRB
-
-#define DIO4_PIN PINB4
-#define DIO4_RPORT PINB
-#define DIO4_WPORT PORTB
-#define DIO4_DDR DDRB
-
-#define DIO5_PIN PINB5
-#define DIO5_RPORT PINB
-#define DIO5_WPORT PORTB
-#define DIO5_DDR DDRB
-
-#define DIO6_PIN PINB6
-#define DIO6_RPORT PINB
-#define DIO6_WPORT PORTB
-#define DIO6_DDR DDRB
-
-#define DIO7_PIN PINB7
-#define DIO7_RPORT PINB
-#define DIO7_WPORT PORTB
-#define DIO7_DDR DDRB
-
-#define DIO8_PIN PIND0
-#define DIO8_RPORT PIND
-#define DIO8_WPORT PORTD
-#define DIO8_DDR DDRD
-
-#define DIO9_PIN PIND1
-#define DIO9_RPORT PIND
-#define DIO9_WPORT PORTD
-#define DIO9_DDR DDRD
-
-#define DIO10_PIN PIND2
-#define DIO10_RPORT PIND
-#define DIO10_WPORT PORTD
-#define DIO10_DDR DDRD
-
-#define DIO11_PIN PIND3
-#define DIO11_RPORT PIND
-#define DIO11_WPORT PORTD
-#define DIO11_DDR DDRD
-
-#define DIO12_PIN PIND4
-#define DIO12_RPORT PIND
-#define DIO12_WPORT PORTD
-#define DIO12_DDR DDRD
-
-#define DIO13_PIN PIND5
-#define DIO13_RPORT PIND
-#define DIO13_WPORT PORTD
-#define DIO13_DDR DDRD
-
-#define DIO14_PIN PIND6
-#define DIO14_RPORT PIND
-#define DIO14_WPORT PORTD
-#define DIO14_DDR DDRD
-
-#define DIO15_PIN PIND7
-#define DIO15_RPORT PIND
-#define DIO15_WPORT PORTD
-#define DIO15_DDR DDRD
-
-#define DIO16_PIN PINC0
-#define DIO16_RPORT PINC
-#define DIO16_WPORT PORTC
-#define DIO16_DDR DDRC
-
-#define DIO17_PIN PINC1
-#define DIO17_RPORT PINC
-#define DIO17_WPORT PORTC
-#define DIO17_DDR DDRC
-
-#define DIO18_PIN PINC2
-#define DIO18_RPORT PINC
-#define DIO18_WPORT PORTC
-#define DIO18_DDR DDRC
-
-#define DIO19_PIN PINC3
-#define DIO19_RPORT PINC
-#define DIO19_WPORT PORTC
-#define DIO19_DDR DDRC
-
-#define DIO20_PIN PINC4
-#define DIO20_RPORT PINC
-#define DIO20_WPORT PORTC
-#define DIO20_DDR DDRC
-
-#define DIO21_PIN PINC5
-#define DIO21_RPORT PINC
-#define DIO21_WPORT PORTC
-#define DIO21_DDR DDRC
-
-#define DIO22_PIN PINC6
-#define DIO22_RPORT PINC
-#define DIO22_WPORT PORTC
-#define DIO22_DDR DDRC
-
-#define DIO23_PIN PINC7
-#define DIO23_RPORT PINC
-#define DIO23_WPORT PORTC
-#define DIO23_DDR DDRC
-
-#define DIO24_PIN PINA7
-#define DIO24_RPORT PINA
-#define DIO24_WPORT PORTA
-#define DIO24_DDR DDRA
-
-#define DIO25_PIN PINA6
-#define DIO25_RPORT PINA
-#define DIO25_WPORT PORTA
-#define DIO25_DDR DDRA
-
-#define DIO26_PIN PINA5
-#define DIO26_RPORT PINA
-#define DIO26_WPORT PORTA
-#define DIO26_DDR DDRA
-
-#define DIO27_PIN PINA4
-#define DIO27_RPORT PINA
-#define DIO27_WPORT PORTA
-#define DIO27_DDR DDRA
-
-#define DIO28_PIN PINA3
-#define DIO28_RPORT PINA
-#define DIO28_WPORT PORTA
-#define DIO28_DDR DDRA
-
-#define DIO29_PIN PINA2
-#define DIO29_RPORT PINA
-#define DIO29_WPORT PORTA
-#define DIO29_DDR DDRA
-
-#define DIO30_PIN PINA1
-#define DIO30_RPORT PINA
-#define DIO30_WPORT PORTA
-#define DIO30_DDR DDRA
-
-#define DIO31_PIN PINA0
-#define DIO31_RPORT PINA
-#define DIO31_WPORT PORTA
-#define DIO31_DDR DDRA
-
-#define AIO0_PIN PINA0
-#define AIO0_RPORT PINA
-#define AIO0_WPORT PORTA
-#define AIO0_DDR DDRA
-
-#define AIO1_PIN PINA1
-#define AIO1_RPORT PINA
-#define AIO1_WPORT PORTA
-#define AIO1_DDR DDRA
-
-#define AIO2_PIN PINA2
-#define AIO2_RPORT PINA
-#define AIO2_WPORT PORTA
-#define AIO2_DDR DDRA
-
-#define AIO3_PIN PINA3
-#define AIO3_RPORT PINA
-#define AIO3_WPORT PORTA
-#define AIO3_DDR DDRA
-
-#define AIO4_PIN PINA4
-#define AIO4_RPORT PINA
-#define AIO4_WPORT PORTA
-#define AIO4_DDR DDRA
-
-#define AIO5_PIN PINA5
-#define AIO5_RPORT PINA
-#define AIO5_WPORT PORTA
-#define AIO5_DDR DDRA
-
-#define AIO6_PIN PINA6
-#define AIO6_RPORT PINA
-#define AIO6_WPORT PORTA
-#define AIO6_DDR DDRA
-
-#define AIO7_PIN PINA7
-#define AIO7_RPORT PINA
-#define AIO7_WPORT PORTA
-#define AIO7_DDR DDRA
-
-#define PA0_PIN PINA0
-#define PA0_RPORT PINA
-#define PA0_WPORT PORTA
-#define PA0_DDR DDRA
-#define PA1_PIN PINA1
-#define PA1_RPORT PINA
-#define PA1_WPORT PORTA
-#define PA1_DDR DDRA
-#define PA2_PIN PINA2
-#define PA2_RPORT PINA
-#define PA2_WPORT PORTA
-#define PA2_DDR DDRA
-#define PA3_PIN PINA3
-#define PA3_RPORT PINA
-#define PA3_WPORT PORTA
-#define PA3_DDR DDRA
-#define PA4_PIN PINA4
-#define PA4_RPORT PINA
-#define PA4_WPORT PORTA
-#define PA4_DDR DDRA
-#define PA5_PIN PINA5
-#define PA5_RPORT PINA
-#define PA5_WPORT PORTA
-#define PA5_DDR DDRA
-#define PA6_PIN PINA6
-#define PA6_RPORT PINA
-#define PA6_WPORT PORTA
-#define PA6_DDR DDRA
-#define PA7_PIN PINA7
-#define PA7_RPORT PINA
-#define PA7_WPORT PORTA
-#define PA7_DDR DDRA
-
-#define PB0_PIN PINB0
-#define PB0_RPORT PINB
-#define PB0_WPORT PORTB
-#define PB0_DDR DDRB
-#define PB1_PIN PINB1
-#define PB1_RPORT PINB
-#define PB1_WPORT PORTB
-#define PB1_DDR DDRB
-#define PB2_PIN PINB2
-#define PB2_RPORT PINB
-#define PB2_WPORT PORTB
-#define PB2_DDR DDRB
-#define PB3_PIN PINB3
-#define PB3_RPORT PINB
-#define PB3_WPORT PORTB
-#define PB3_DDR DDRB
-#define PB4_PIN PINB4
-#define PB4_RPORT PINB
-#define PB4_WPORT PORTB
-#define PB4_DDR DDRB
-#define PB5_PIN PINB5
-#define PB5_RPORT PINB
-#define PB5_WPORT PORTB
-#define PB5_DDR DDRB
-#define PB6_PIN PINB6
-#define PB6_RPORT PINB
-#define PB6_WPORT PORTB
-#define PB6_DDR DDRB
-#define PB7_PIN PINB7
-#define PB7_RPORT PINB
-#define PB7_WPORT PORTB
-#define PB7_DDR DDRB
-
-#define PC0_PIN PINC0
-#define PC0_RPORT PINC
-#define PC0_WPORT PORTC
-#define PC0_DDR DDRC
-#define PC1_PIN PINC1
-#define PC1_RPORT PINC
-#define PC1_WPORT PORTC
-#define PC1_DDR DDRC
-#define PC2_PIN PINC2
-#define PC2_RPORT PINC
-#define PC2_WPORT PORTC
-#define PC2_DDR DDRC
-#define PC3_PIN PINC3
-#define PC3_RPORT PINC
-#define PC3_WPORT PORTC
-#define PC3_DDR DDRC
-#define PC4_PIN PINC4
-#define PC4_RPORT PINC
-#define PC4_WPORT PORTC
-#define PC4_DDR DDRC
-#define PC5_PIN PINC5
-#define PC5_RPORT PINC
-#define PC5_WPORT PORTC
-#define PC5_DDR DDRC
-#define PC6_PIN PINC6
-#define PC6_RPORT PINC
-#define PC6_WPORT PORTC
-#define PC6_DDR DDRC
-#define PC7_PIN PINC7
-#define PC7_RPORT PINC
-#define PC7_WPORT PORTC
-#define PC7_DDR DDRC
-
-#define PD0_PIN PIND0
-#define PD0_RPORT PIND
-#define PD0_WPORT PORTD
-#define PD0_DDR DDRD
-#define PD1_PIN PIND1
-#define PD1_RPORT PIND
-#define PD1_WPORT PORTD
-#define PD1_DDR DDRD
-#define PD2_PIN PIND2
-#define PD2_RPORT PIND
-#define PD2_WPORT PORTD
-#define PD2_DDR DDRD
-#define PD3_PIN PIND3
-#define PD3_RPORT PIND
-#define PD3_WPORT PORTD
-#define PD3_DDR DDRD
-#define PD4_PIN PIND4
-#define PD4_RPORT PIND
-#define PD4_WPORT PORTD
-#define PD4_DDR DDRD
-#define PD5_PIN PIND5
-#define PD5_RPORT PIND
-#define PD5_WPORT PORTD
-#define PD5_DDR DDRD
-#define PD6_PIN PIND6
-#define PD6_RPORT PIND
-#define PD6_WPORT PORTD
-#define PD6_DDR DDRD
-#define PD7_PIN PIND7
-#define PD7_RPORT PIND
-#define PD7_WPORT PORTD
-#define PD7_DDR DDRD
View
39 clock.c
@@ -1,39 +0,0 @@
-#include "clock.h"
-
-#include "pinio.h"
-#include "sersendf.h"
-#include "dda_queue.h"
-#include "timer.h"
-#include "debug.h"
-#include "watchdog.h"
-
-void clock_250ms() {
- if (steptimeout > (30 * 4)) {
- power_off();
- }
- else
- steptimeout++;
-
- ifclock(CLOCK_FLAG_1S) {
- if (debug_flags & DEBUG_POSITION) {
- // current position
- sersendf_P(PSTR("Pos: %ld,%ld,%ld,%lu\n"), current_position.X, current_position.Y, current_position.Z, current_position.F);
-
- // target position
- sersendf_P(PSTR("Dst: %ld,%ld,%ld,%lu\n"), movebuffer[mb_tail].endpoint.X, movebuffer[mb_tail].endpoint.Y, movebuffer[mb_tail].endpoint.Z, movebuffer[mb_tail].endpoint.F);
-
- // Queue
- print_queue();
- }
- }
-}
-
-void clock_10ms() {
- // reset watchdog
- wd_reset();
-
- ifclock(CLOCK_FLAG_250MS) {
- clock_250ms();
- }
-}
-
View
7 clock.h
@@ -1,7 +0,0 @@
-#ifndef _CLOCK_H
-#define _CLOCK_H
-
-void clock_250ms(void);
-void clock_10ms(void);
-
-#endif /* _CLOCK_H */
View
282 config.h
@@ -1,255 +1,65 @@
-#ifndef _CONFIG_H
-#define _CONFIG_H
-
-/*
- CONTENTS
-
- 1. Mechanical/Hardware
- 2. Acceleration settings
- 3. Pinouts
- 4. Temperature sensors
- 5. Heaters
- 6. Communication options
- 7. Miscellaneous
-*/
-
-/***************************************************************************\
-* 1. MECHANICAL/HARDWARE * *
-\***************************************************************************/
-
-/*
- Microcontroller type is set to atmega644p in the Makefile.
-*/
-
-/*
- CPU clock rate
-*/
-#ifndef F_CPU
- #define F_CPU 20000000L
-#endif
-
-#define HOST
-
-/*
- Values reflecting the gearing of your machine.
- All numbers are fixed point integers, so no more than 3 digits to the right of the decimal point, please :-)
-*/
-
-// calculate these values appropriate for your machine
-// for threaded rods, this is (steps motor per turn) / (pitch of the thread)
-// for belts, this is (steps per motor turn) / (number of gear teeth) / (belt module)
-// half-stepping doubles the number, quarter stepping requires * 4, etc.
-#define STEPS_PER_MM_X 320.000
-#define STEPS_PER_MM_Y 320.000
-#define STEPS_PER_MM_Z 320.000
-
-/*
- Values depending on the capabilities of your stepper motors and other mechanics.
- All numbers are integers, no decimals allowed.
-
- Units are mm/min
-*/
-
-// used for G0 rapid moves and as a cap for all other feedrates
-#define MAXIMUM_FEEDRATE_X 200
-#define MAXIMUM_FEEDRATE_Y 200
-#define MAXIMUM_FEEDRATE_Z 100
-
-// used when searching endstops and as default feedrate
-#define SEARCH_FEEDRATE_X 50
-#define SEARCH_FEEDRATE_Y 50
-#define SEARCH_FEEDRATE_Z 50
-
-/***************************************************************************\
-* 2. ACCELERATION *
-* IMPORTANT: choose only one! These algorithms choose when to step, trying *
-* to use more than one will have undefined and probably *
-* disastrous results! *
-\***************************************************************************/
-
/*
- acceleration, reprap style.
- Each movement starts at the speed of the previous command and accelerates or decelerates linearly to reach target speed at the end of the movement.
-*/
-// #define ACCELERATION_REPRAP
-
-
-/*
- acceleration and deceleration ramping.
- Each movement starts at (almost) no speed, linearly accelerates to target speed and decelerates just in time to smoothly stop at the target. alternative to ACCELERATION_REPRAP
-*/
-#define ACCELERATION_RAMPING
-
-// how fast to accelerate when using ACCELERATION_RAMPING
-// smaller values give quicker acceleration
-// valid range = 1 to 8,000,000; 500,000 is a good starting point
-#define ACCELERATION_STEEPNESS 500000
+ config.h - compile time configuration
+ Part of Grbl
+ Copyright (c) 2009-2011 Simen Svale Skogsrud
-/*
- temporal step algorithm
- This algorithm causes the timer to fire when any axis needs to step, instead of synchronising to the axis with the most steps ala bresenham.
-
- This algorithm is not a type of acceleration, and I haven't worked out how to integrate acceleration with it.
- However it does control step timing, so acceleration algorithms seemed appropriate
+ Grbl is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- The Bresenham algorithm is great for drawing lines, but not so good for steppers - In the case where X steps 3 times to Y's two, Y experiences massive jitter as it steps in sync with X every 2 out of 3 X steps. This is a worst-case, but the problem exists for most non-45/90 degree moves. At higher speeds, the jitter /will/ cause position loss and unnecessary vibration.
- This algorithm instead calculates when a step occurs on any axis, and sets the timer to that value.
+ Grbl is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
- // TODO: figure out how to add acceleration to this algorithm
+ You should have received a copy of the GNU General Public License
+ along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
-// #define ACCELERATION_TEMPORAL
+#ifndef config_h
+#define config_h
-/***************************************************************************\
-* 3. PINOUTS *
-\***************************************************************************/
-
-/*
- Machine Pin Definitions
- - make sure to avoid duplicate usage of a pin
- - comment out pins not in use, as this drops the corresponding code and makes operations faster
-*/
-
-#include "arduino.h"
-
-#ifndef GEN3
- /*
- user defined pins
- adjust to suit your electronics
- */
-
- #define X_STEP_PIN DIO21 //XSTEP is PC5... ie. DIO21
- #define X_DIR_PIN DIO18 //XDIR pin is PC2. DIO18
- #define X_MIN_PIN DIO0 // XMIN is not correct, we have an XHOME on PB0
-
- #define Y_STEP_PIN DIO22 // PC6 is DIO22
- #define Y_DIR_PIN DIO17 // DIO17 is PC1
- #define Y_MIN_PIN DIO1 // PB1
-
- #define Z_STEP_PIN DIO23 // PC7 is DIO23
- #define Z_DIR_PIN DIO16 // DIO16 is PC0
- #define Z_MIN_PIN DIO7 // PB2
-
- #define STEPPER_ENABLE_PIN DIO19 // PC3 (active low)
- #define STEPPER_RESET_PIN DIO20 // PC4 (needs to be high to move)
-
-
-#else
- /*
- this is the official gen3 reprap motherboard pinout
- */
- #define TX_ENABLE_PIN DIO12
- #define RX_ENABLE_PIN DIO13
-
- #define X_STEP_PIN DIO15
- #define X_DIR_PIN DIO18
- #define X_MIN_PIN DIO20
- #define X_MAX_PIN DIO21
- #define X_ENABLE_PIN DIO19
-
- #define Y_STEP_PIN DIO23
- #define Y_DIR_PIN DIO22
- #define Y_MIN_PIN AIO6
- #define Y_MAX_PIN AIO5
- #define Y_ENABLE_PIN DIO7
-
- #define Z_STEP_PIN AIO4
- #define Z_DIR_PIN AIO3
- #define Z_MIN_PIN AIO1
- #define Z_MAX_PIN AIO0
- #define Z_ENABLE_PIN AIO2
-
- #define E_STEP_PIN DIO16
- #define E_DIR_PIN DIO17
-
- #define SD_CARD_DETECT DIO2
- #define SD_WRITE_PROTECT DIO3
+#ifndef __AVR_ATmega328P__
+#define __AVR_ATmega328P__
#endif
-/***************************************************************************\
-* 5. TEMPERATURE SENSORS *
-\***************************************************************************/
-
-// how many temperature sensors do you have?
-#define NUM_TEMP_SENSORS 0
-
-/***************************************************************************\
-* 5. HEATERS *
-\***************************************************************************/
-
-// number of heaters- for GEN3, set to zero as extruder manages the heater by itself
-#define NUM_HEATERS 0
-
-/***************************************************************************\
-* 6. COMMUNICATION OPTIONS *
-\***************************************************************************/
-
-/*
- RepRap Host changes it's communications protocol from time to time and intentionally avoids backwards compatibility. Set this to the date the source code of your Host was fetched from RepRap's repository, which is likely also the build date.
- See the discussion on the reprap-dev mailing list from 11 Oct. 2010.
-
- Undefine it for best human readability, set it to an old date for compatibility with hosts before August 2010
-*/
-// #define REPRAP_HOST_COMPATIBILITY 19750101
-#define REPRAP_HOST_COMPATIBILITY 20100806
-// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>
-
-/*
- Xon/Xoff flow control.
- Redundant when using RepRap Host for sending GCode, but mandatory when sending GCode files with a plain terminal emulator, like GtkTerm (Linux), CoolTerm (Mac) or HyperTerminal (Windows).
- Can also be set in Makefile
-*/
-#define XONXOFF
-
+#define BAUD_RATE 9600
+// Updated default pin-assignments from 0.6 onwards
+// (see bottom of file for a copy of the old config)
-/***************************************************************************\
-* 7. MISCELLANEOUS OPTIONS *
-\***************************************************************************/
+#define STEPPERS_ENABLE_DDR DDRC
+#define STEPPERS_ENABLE_PORT PORTC
+#define STEPPERS_ENABLE_BIT 3 //PC3
-/*
- DEBUG
- enables /heaps/ of extra output, and some extra M-codes.
- WARNING: this WILL break most host-side talkers that expect particular responses from firmware such as reprap host and replicatorG
- use with serial terminal or other suitable talker only.
-*/
-// #define DEBUG
-
-/*
- move buffer size, in number of moves
- note that each move takes a fair chunk of ram (69 bytes as of this writing) so don't make the buffer too big - a bigger serial readbuffer may help more than increasing this unless your gcodes are more than 70 characters long on average.
- however, a larger movebuffer will probably help with lots of short consecutive moves, as each move takes a bunch of math (hence time) to set up so a longer buffer allows more of the math to be done during preceding longer moves
-*/
-#define MOVEBUFFER_SIZE 8
-
-
-/*
- FiveD on Arduino implements a watchdog, which has to be reset every 250ms or it will reboot the controller. As rebooting (and letting the GCode sending application trying to continue the build with a then different Home point) is probably even worse than just hanging, and there is no better restore code in place, this is disabled for now.
-*/
-// #define USE_WATCHDOG
-
-/*
- analog subsystem stuff
- REFERENCE - which analog reference to use. see analog.h for choices
-*/
-#define REFERENCE REFERENCE_AVCC
+#define STEPPING_DDR DDRC
+#define STEPPING_PORT PORTC
+#define X_STEP_BIT 5 //PC5
+#define Y_STEP_BIT 6 //PC6
+#define Z_STEP_BIT 7 //PC7
+#define X_DIRECTION_BIT 2 //PC2
+#define Y_DIRECTION_BIT 1 //PC1
+#define Z_DIRECTION_BIT 0 //PC0
-/*
- this option makes the step interrupt interruptible (nested).
- this should help immensely with dropped serial characters, but may also make debugging infuriating due to the complexities arising from nested interrupts
-*/
-#define STEP_INTERRUPT_INTERRUPTIBLE 1
+#define LIMIT_DDR DDRA
+#define LIMIT_PORT PORTA
+#define X_LIMIT_BIT 1
+#define Y_LIMIT_BIT 2
+#define Z_LIMIT_BIT 3
-/*
- how often we overflow and update our clock; with F_CPU=16MHz, max is < 4.096ms (TICK_TIME = 65535)
-*/
-#define TICK_TIME 2 MS
-#define TICK_TIME_MS (TICK_TIME / (F_CPU / 1000))
+#define SPINDLE_ENABLE_DDR DDRB
+#define SPINDLE_ENABLE_PORT PORTB
+#define SPINDLE_ENABLE_BIT 4
+#define SPINDLE_DIRECTION_DDR DDRB
+#define SPINDLE_DIRECTION_PORT PORTB
+#define SPINDLE_DIRECTION_BIT 5
-// this is the scaling of internally stored PID values. 1024L is a good value
-#define PID_SCALE 1024L
+// The temporal resolution of the acceleration management subsystem. Higher number
+// give smoother acceleration but may impact performance
+#define ACCELERATION_TICKS_PER_SECOND 40L
-#endif /* _CONFIG_H */
+#endif
View
255 config.h.dist
@@ -1,255 +0,0 @@
-#ifndef _CONFIG_H
-#define _CONFIG_H
-
-/*
- CONTENTS
-
- 1. Mechanical/Hardware
- 2. Acceleration settings
- 3. Pinouts
- 4. Temperature sensors
- 5. Heaters
- 6. Communication options
- 7. Miscellaneous
-*/
-
-/***************************************************************************\
-* 1. MECHANICAL/HARDWARE * *
-\***************************************************************************/
-
-/*
- Microcontroller type is set to atmega644p in the Makefile.
-*/
-
-/*
- CPU clock rate
-*/
-#ifndef F_CPU
- #define F_CPU 20000000L
-#endif
-
-#define HOST
-
-/*
- Values reflecting the gearing of your machine.
- All numbers are fixed point integers, so no more than 3 digits to the right of the decimal point, please :-)
-*/
-
-// calculate these values appropriate for your machine
-// for threaded rods, this is (steps motor per turn) / (pitch of the thread)
-// for belts, this is (steps per motor turn) / (number of gear teeth) / (belt module)
-// half-stepping doubles the number, quarter stepping requires * 4, etc.
-#define STEPS_PER_MM_X 320.000
-#define STEPS_PER_MM_Y 320.000
-#define STEPS_PER_MM_Z 320.000
-
-/*
- Values depending on the capabilities of your stepper motors and other mechanics.
- All numbers are integers, no decimals allowed.
-
- Units are mm/min
-*/
-
-// used for G0 rapid moves and as a cap for all other feedrates
-#define MAXIMUM_FEEDRATE_X 200
-#define MAXIMUM_FEEDRATE_Y 200
-#define MAXIMUM_FEEDRATE_Z 100
-
-// used when searching endstops and as default feedrate
-#define SEARCH_FEEDRATE_X 50
-#define SEARCH_FEEDRATE_Y 50
-#define SEARCH_FEEDRATE_Z 50
-
-/***************************************************************************\
-* 2. ACCELERATION *
-* IMPORTANT: choose only one! These algorithms choose when to step, trying *
-* to use more than one will have undefined and probably *
-* disastrous results! *
-\***************************************************************************/
-
-/*
- acceleration, reprap style.
- Each movement starts at the speed of the previous command and accelerates or decelerates linearly to reach target speed at the end of the movement.
-*/
-// #define ACCELERATION_REPRAP
-
-
-/*
- acceleration and deceleration ramping.
- Each movement starts at (almost) no speed, linearly accelerates to target speed and decelerates just in time to smoothly stop at the target. alternative to ACCELERATION_REPRAP
-*/
-#define ACCELERATION_RAMPING
-
-// how fast to accelerate when using ACCELERATION_RAMPING
-// smaller values give quicker acceleration
-// valid range = 1 to 8,000,000; 500,000 is a good starting point
-#define ACCELERATION_STEEPNESS 500000
-
-
-/*
- temporal step algorithm
- This algorithm causes the timer to fire when any axis needs to step, instead of synchronising to the axis with the most steps ala bresenham.
-
- This algorithm is not a type of acceleration, and I haven't worked out how to integrate acceleration with it.
- However it does control step timing, so acceleration algorithms seemed appropriate
-
- The Bresenham algorithm is great for drawing lines, but not so good for steppers - In the case where X steps 3 times to Y's two, Y experiences massive jitter as it steps in sync with X every 2 out of 3 X steps. This is a worst-case, but the problem exists for most non-45/90 degree moves. At higher speeds, the jitter /will/ cause position loss and unnecessary vibration.
- This algorithm instead calculates when a step occurs on any axis, and sets the timer to that value.
-
- // TODO: figure out how to add acceleration to this algorithm
-*/
-// #define ACCELERATION_TEMPORAL
-
-
-
-/***************************************************************************\
-* 3. PINOUTS *
-\***************************************************************************/
-
-/*
- Machine Pin Definitions
- - make sure to avoid duplicate usage of a pin
- - comment out pins not in use, as this drops the corresponding code and makes operations faster
-*/
-
-#include "arduino.h"
-
-#ifndef GEN3
- /*
- user defined pins
- adjust to suit your electronics
- */
-
- #define X_STEP_PIN DIO21 //XSTEP is PC5... ie. DIO21
- #define X_DIR_PIN DIO18 //XDIR pin is PC2. DIO18
- #define X_MIN_PIN DIO0 // XMIN is not correct, we have an XHOME on PB0
-
- #define Y_STEP_PIN DIO22 // PC6 is DIO22
- #define Y_DIR_PIN DIO17 // DIO17 is PC1
- #define Y_MIN_PIN DIO1 // PB1
-
- #define Z_STEP_PIN DIO23 // PC7 is DIO23
- #define Z_DIR_PIN DIO16 // DIO16 is PC0
- #define Z_MIN_PIN DIO7 // PB2
-
- #define STEPPER_ENABLE_PIN DIO19 // PC3 (active low)
- #define STEPPER_RESET_PIN DIO20 // PC4 (needs to be high to move)
-
-
-#else
- /*
- this is the official gen3 reprap motherboard pinout
- */
- #define TX_ENABLE_PIN DIO12
- #define RX_ENABLE_PIN DIO13
-
- #define X_STEP_PIN DIO15
- #define X_DIR_PIN DIO18
- #define X_MIN_PIN DIO20
- #define X_MAX_PIN DIO21
- #define X_ENABLE_PIN DIO19
-
- #define Y_STEP_PIN DIO23
- #define Y_DIR_PIN DIO22
- #define Y_MIN_PIN AIO6
- #define Y_MAX_PIN AIO5
- #define Y_ENABLE_PIN DIO7
-
- #define Z_STEP_PIN AIO4
- #define Z_DIR_PIN AIO3
- #define Z_MIN_PIN AIO1
- #define Z_MAX_PIN AIO0
- #define Z_ENABLE_PIN AIO2
-
- #define E_STEP_PIN DIO16
- #define E_DIR_PIN DIO17
-
- #define SD_CARD_DETECT DIO2
- #define SD_WRITE_PROTECT DIO3
-#endif
-
-/***************************************************************************\
-* 5. TEMPERATURE SENSORS *
-\***************************************************************************/
-
-// how many temperature sensors do you have?
-#define NUM_TEMP_SENSORS 0
-
-/***************************************************************************\
-* 5. HEATERS *
-\***************************************************************************/
-
-// number of heaters- for GEN3, set to zero as extruder manages the heater by itself
-#define NUM_HEATERS 0
-
-/***************************************************************************\
-* 6. COMMUNICATION OPTIONS *
-\***************************************************************************/
-
-/*
- RepRap Host changes it's communications protocol from time to time and intentionally avoids backwards compatibility. Set this to the date the source code of your Host was fetched from RepRap's repository, which is likely also the build date.
- See the discussion on the reprap-dev mailing list from 11 Oct. 2010.
-
- Undefine it for best human readability, set it to an old date for compatibility with hosts before August 2010
-*/
-// #define REPRAP_HOST_COMPATIBILITY 19750101
-#define REPRAP_HOST_COMPATIBILITY 20100806
-// #define REPRAP_HOST_COMPATIBILITY <date of next RepRap Host compatibility break>
-
-/*
- Xon/Xoff flow control.
- Redundant when using RepRap Host for sending GCode, but mandatory when sending GCode files with a plain terminal emulator, like GtkTerm (Linux), CoolTerm (Mac) or HyperTerminal (Windows).
- Can also be set in Makefile
-*/
-#define XONXOFF
-
-
-
-/***************************************************************************\
-* 7. MISCELLANEOUS OPTIONS *
-\***************************************************************************/
-
-/*
- DEBUG
- enables /heaps/ of extra output, and some extra M-codes.
- WARNING: this WILL break most host-side talkers that expect particular responses from firmware such as reprap host and replicatorG
- use with serial terminal or other suitable talker only.
-*/
-// #define DEBUG
-
-/*
- move buffer size, in number of moves
- note that each move takes a fair chunk of ram (69 bytes as of this writing) so don't make the buffer too big - a bigger serial readbuffer may help more than increasing this unless your gcodes are more than 70 characters long on average.
- however, a larger movebuffer will probably help with lots of short consecutive moves, as each move takes a bunch of math (hence time) to set up so a longer buffer allows more of the math to be done during preceding longer moves
-*/
-#define MOVEBUFFER_SIZE 8
-
-
-/*
- FiveD on Arduino implements a watchdog, which has to be reset every 250ms or it will reboot the controller. As rebooting (and letting the GCode sending application trying to continue the build with a then different Home point) is probably even worse than just hanging, and there is no better restore code in place, this is disabled for now.
-*/
-// #define USE_WATCHDOG
-
-/*
- analog subsystem stuff
- REFERENCE - which analog reference to use. see analog.h for choices
-*/
-#define REFERENCE REFERENCE_AVCC
-
-/*
- this option makes the step interrupt interruptible (nested).
- this should help immensely with dropped serial characters, but may also make debugging infuriating due to the complexities arising from nested interrupts
-*/
-#define STEP_INTERRUPT_INTERRUPTIBLE 1
-
-/*
- how often we overflow and update our clock; with F_CPU=16MHz, max is < 4.096ms (TICK_TIME = 65535)
-*/
-#define TICK_TIME 2 MS
-#define TICK_TIME_MS (TICK_TIME / (F_CPU / 1000))
-
-
-// this is the scaling of internally stored PID values. 1024L is a good value
-#define PID_SCALE 1024L
-
-#endif /* _CONFIG_H */
View
531 dda.c
@@ -1,531 +0,0 @@
-#include "dda.h"
-
-#include <string.h>
-#include <stdlib.h>
-#include <avr/interrupt.h>
-
-#include "timer.h"
-#include "serial.h"
-#include "sermsg.h"
-#include "dda_queue.h"
-#include "debug.h"
-#include "sersendf.h"
-#include "pinio.h"
-#include "config.h"
-
-/*
- Used in distance calculation during DDA setup
-*/
-#define UM_PER_STEP_X 1000L / ((uint32_t) STEPS_PER_MM_X)
-#define UM_PER_STEP_Y 1000L / ((uint32_t) STEPS_PER_MM_Y)
-#define UM_PER_STEP_Z 1000L / ((uint32_t) STEPS_PER_MM_Z)
-
-/*
- step timeout
-*/
-
-uint8_t steptimeout = 0;
-
-/*
- position tracking
-*/
-
-TARGET startpoint __attribute__ ((__section__ (".bss")));
-TARGET current_position __attribute__ ((__section__ (".bss")));
-
-/*
- utility functions
-*/
-
-// courtesy of http://www.flipcode.com/archives/Fast_Approximate_Distance_Functions.shtml
-uint32_t approx_distance( uint32_t dx, uint32_t dy )
-{
- uint32_t min, max, approx;
-
- if ( dx < dy )
- {
- min = dx;
- max = dy;
- } else {
- min = dy;
- max = dx;
- }
-
- approx = ( max * 1007 ) + ( min * 441 );
- if ( max < ( min << 4 ))
- approx -= ( max * 40 );
-
- // add 512 for proper rounding
- return (( approx + 512 ) >> 10 );
-}
-
-// courtesy of http://www.oroboro.com/rafael/docserv.php/index/programming/article/distance
-uint32_t approx_distance_3( uint32_t dx, uint32_t dy, uint32_t dz )
-{
- uint32_t min, med, max, approx;
-
- if ( dx < dy )
- {
- min = dy;
- med = dx;
- } else {
- min = dx;
- med = dy;
- }
-
- if ( dz < min )
- {
- max = med;
- med = min;
- min = dz;
- } else if ( dz < med ) {
- max = med;
- med = dz;
- } else {
- max = dz;
- }
-
- approx = ( max * 860 ) + ( med * 851 ) + ( min * 520 );
- if ( max < ( med << 1 )) approx -= ( max * 294 );
- if ( max < ( min << 2 )) approx -= ( max * 113 );
- if ( med < ( min << 2 )) approx -= ( med * 40 );
-
- // add 512 for proper rounding
- return (( approx + 512 ) >> 10 );
-}
-
-// this is an ultra-crude pseudo-logarithm routine, such that:
-// 2 ^ msbloc(v) >= v
-const uint8_t msbloc (uint32_t v) {
- uint8_t i;
- uint32_t c;
- for (i = 31, c = 0x80000000; i; i--) {
- if (v & c)
- return i;
- c >>= 1;
- }
- return 0;
-}
-
-/*
- CREATE a dda given current_position and a target, save to passed location so we can write directly into the queue
-*/
-
-void dda_create(DDA *dda, TARGET *target) {
- uint32_t distance, c_limit, c_limit_calc;
-
- // initialise DDA to a known state
- dda->allflags = 0;
-
- if (debug_flags & DEBUG_DDA)
- serial_writestr_P(PSTR("\n{DDA_CREATE: ["));
-
- // we end at the passed target
- memcpy(&(dda->endpoint), target, sizeof(TARGET));
-
- dda->x_delta = labs(target->X - startpoint.X);
- dda->y_delta = labs(target->Y - startpoint.Y);
- dda->z_delta = labs(target->Z - startpoint.Z);
-
- dda->x_direction = (target->X >= startpoint.X)?1:0;
- dda->y_direction = (target->Y >= startpoint.Y)?1:0;
- dda->z_direction = (target->Z >= startpoint.Z)?1:0;
-
- if (debug_flags & DEBUG_DDA)
- sersendf_P(PSTR("%ld,%ld,%ld] ["), target->X - startpoint.X, target->Y - startpoint.Y, target->Z - startpoint.Z);
-
- dda->total_steps = dda->x_delta;
- if (dda->y_delta > dda->total_steps)
- dda->total_steps = dda->y_delta;
- if (dda->z_delta > dda->total_steps)
- dda->total_steps = dda->z_delta;
-
- if (debug_flags & DEBUG_DDA)
- sersendf_P(PSTR("ts:%lu"), dda->total_steps);
-
- if (dda->total_steps == 0) {
- dda->nullmove = 1;
- }
- else {
- // get steppers ready to go
- steptimeout = 0;
- power_on();
- x_enable();
- y_enable();
- if (dda->z_delta)
- z_enable();
-
- // 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.
- if (dda->z_delta == 0)
- distance = approx_distance(dda->x_delta * UM_PER_STEP_X, dda->y_delta * UM_PER_STEP_Y);
- else if (dda->x_delta == 0 && dda->y_delta == 0)
- distance = dda->z_delta * UM_PER_STEP_Z;
- else
- 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);
-
- if (debug_flags & DEBUG_DDA)
- sersendf_P(PSTR(",ds:%lu"), distance);
-
- #ifdef ACCELERATION_TEMPORAL
- // bracket part of this equation in an attempt to avoid overflow: 60 * 16MHz * 5mm is >32 bits
- uint32_t move_duration = distance * (60 * F_CPU / startpoint.F);
- #else
- dda->x_counter = dda->y_counter = dda->z_counter =
- -(dda->total_steps >> 1);
-
- // pre-calculate move speed in millimeter microseconds per step minute for less math in interrupt context
- // mm (distance) * 60000000 us/min / step (total_steps) = mm.us per step.min
- // note: um (distance) * 60000 == mm * 60000000
- // so in the interrupt we must simply calculate
- // mm.us per step.min / mm per min (F) = us per step
-
- // break this calculation up a bit and lose some precision because 300,000um * 60000 is too big for a uint32
- // calculate this with a uint64 if you need the precision, but it'll take longer so routines with lots of short moves may suffer
- // 2^32/6000 is about 715mm which should be plenty
-
- // changed * 10 to * (F_CPU / 100000) so we can work in cpu_ticks rather than microseconds.
- // timer.c setTimer() routine altered for same reason
-
- // changed distance * 6000 .. * F_CPU / 100000 to
- // distance * 2400 .. * F_CPU / 40000 so we can move a distance of up to 1800mm without overflowing
- uint32_t move_duration = ((distance * 2400) / dda->total_steps) * (F_CPU / 40000);
- #endif
-
- // similarly, find out how fast we can run our axes.
- // do this for each axis individually, as the combined speed of two or more axes can be higher than the capabilities of a single one.
- c_limit = 0;
- // check X axis
- c_limit_calc = ( (dda->x_delta * (UM_PER_STEP_X * 2400L)) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_X) << 8;
- if (c_limit_calc > c_limit)
- c_limit = c_limit_calc;
- // check Y axis
- c_limit_calc = ( (dda->y_delta * (UM_PER_STEP_Y * 2400L)) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_Y) << 8;
- if (c_limit_calc > c_limit)
- c_limit = c_limit_calc;
- // check Z axis
- c_limit_calc = ( (dda->z_delta * (UM_PER_STEP_Z * 2400L)) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_Z) << 8;
- if (c_limit_calc > c_limit)
- c_limit = c_limit_calc;
-
- #ifdef ACCELERATION_REPRAP
- // c is initial step time in IOclk ticks
- dda->c = (move_duration / startpoint.F) << 8;
- if (dda->c < c_limit)
- dda->c = c_limit;
- dda->end_c = (move_duration / target->F) << 8;
- if (dda->end_c < c_limit)
- dda->end_c = c_limit;
-
- if (debug_flags & DEBUG_DDA)
- sersendf_P(PSTR(",md:%lu,c:%lu"), move_duration, dda->c >> 8);
-
- if (dda->c != dda->end_c) {
- uint32_t stF = startpoint.F / 4;
- uint32_t enF = target->F / 4;
- // now some constant acceleration stuff, courtesy of http://www.embedded.com/columns/technicalinsights/56800129?printable=true
- uint32_t ssq = (stF * stF);
- uint32_t esq = (enF * enF);
- int32_t dsq = (int32_t) (esq - ssq) / 4;
-
- uint8_t msb_ssq = msbloc(ssq);
- uint8_t msb_tot = msbloc(dda->total_steps);
-
- // the raw equation WILL overflow at high step rates, but 64 bit math routines take waay too much space
- // at 65536 mm/min (1092mm/s), ssq/esq overflows, and dsq is also close to overflowing if esq/ssq is small
- // but if ssq-esq is small, ssq/dsq is only a few bits
- // we'll have to do it a few different ways depending on the msb locations of each
- if ((msb_tot + msb_ssq) <= 30) {
- // we have room to do all the multiplies first
- if (debug_flags & DEBUG_DDA)
- serial_writechar('A');
- dda->n = ((int32_t) (dda->total_steps * ssq) / dsq) + 1;
- }
- else if (msb_tot >= msb_ssq) {
- // total steps has more precision
- if (debug_flags & DEBUG_DDA)
- serial_writechar('B');
- dda->n = (((int32_t) dda->total_steps / dsq) * (int32_t) ssq) + 1;
- }
- else {
- // otherwise
- if (debug_flags & DEBUG_DDA)
- serial_writechar('C');
- dda->n = (((int32_t) ssq / dsq) * (int32_t) dda->total_steps) + 1;
- }
-
- if (debug_flags & DEBUG_DDA)
- sersendf_P(PSTR("\n{DDA:CA end_c:%lu, n:%ld, md:%lu, ssq:%lu, esq:%lu, dsq:%lu, msbssq:%u, msbtot:%u}\n"), dda->end_c >> 8, dda->n, move_duration, ssq, esq, dsq, msb_ssq, msb_tot);
-
- dda->accel = 1;
- }
- else
- dda->accel = 0;
- #elif defined ACCELERATION_RAMPING
- // add the last bit of dda->total_steps to always round up
- dda->ramp_steps = dda->total_steps / 2 + (dda->total_steps & 1);
- dda->step_no = 0;
- // c is initial step time in IOclk ticks
- dda->c = ACCELERATION_STEEPNESS << 8;
- dda->c_min = (move_duration / target->F) << 8;
- if (dda->c_min < c_limit)
- dda->c_min = c_limit;
- dda->n = 1;
- dda->ramp_state = RAMP_UP;
- #elif defined ACCELERATION_TEMPORAL
- dda->x_counter = dda->x_step_interval = move_duration / dda->x_delta;
- dda->y_counter = dda->y_step_interval = move_duration / dda->y_delta;
- dda->z_counter = dda->z_step_interval = move_duration / dda->z_delta;
-
- dda->c = dda->x_step_interval;
- if (dda->y_step_interval < dda->c)
- dda->c = dda->y_step_interval;
- if (dda->z_step_interval < dda->c)
- dda->c = dda->z_step_interval;
-
- dda->c <<= 8;
- #else
- dda->c = (move_duration / target->F) << 8;
- if (dda->c < c_limit)
- dda->c = c_limit;
- #endif
- }
-
- if (debug_flags & DEBUG_DDA)
- serial_writestr_P(PSTR("] }\n"));
-
- // next dda starts where we finish
- memcpy(&startpoint, target, sizeof(TARGET));
- // E is always relative, reset it here
-}
-
-/*
- Start a prepared DDA
-*/
-
-void dda_start(DDA *dda) {
- // called from interrupt context: keep it simple!
- if (dda->nullmove) {
- // just change speed?
- current_position.F = dda->endpoint.F;
- // keep dda->live = 0
- }
- else {
-/* if (dda->waitfor_temp) {
- #ifndef REPRAP_HOST_COMPATIBILITY
- serial_writestr_P(PSTR("Waiting for target temp\n"));
- #endif
- }
- else {*/
- // ensure steppers are ready to go
- steptimeout = 0;
- power_on();
- x_enable();
- y_enable();
- if (dda->z_delta)
- z_enable();
-
- // set direction outputs
- x_direction(dda->x_direction);
- y_direction(dda->y_direction);
- z_direction(dda->z_direction);
-
-
-// }
-
- // ensure this dda starts
- dda->live = 1;
-
- // set timeout for first step
- setTimer(dda->c >> 8);
- }
-}
-
-/*
- STEP
-*/
-
-void dda_step(DDA *dda) {
- // called from interrupt context! keep it as simple as possible
- uint8_t did_step = 0;
-
- #ifdef ACCELERATION_TEMPORAL
- if (dda->x_counter <= 0) {
- if ((current_position.X != dda->endpoint.X) /* &&
- (x_max() != dda->x_direction) && (x_min() == dda->x_direction) */) {
- x_step();
- if (dda->x_direction)
- current_position.X++;
- else
- current_position.X--;
- }
- dda->x_counter += dda->x_step_interval;
- dda->x_delta--;
- }
- if (dda->y_counter <= 0) {
- if ((current_position.Y != dda->endpoint.Y) /* &&
- (y_max() != dda->y_direction) && (y_min() == dda->y_direction) */) {
- y_step();
- if (dda->y_direction)
- current_position.Y++;
- else
- current_position.Y--;
- }
- dda->y_counter += dda->y_step_interval;
- dda->y_delta--;
- }
- if (dda->z_counter <= 0) {
- if ((current_position.Z != dda->endpoint.Z) /* &&
- (z_max() != dda->z_direction) && (z_min() == dda->z_direction) */) {
- z_step();
- if (dda->z_direction)
- current_position.Z++;
- else
- current_position.Z--;
- }
- dda->z_counter += dda->z_step_interval;
- dda->z_delta--;
- }
-
- #else
- if ((current_position.X != dda->endpoint.X) /* &&
- (x_max() != dda->x_direction) && (x_min() == dda->x_direction) */) {
- dda->x_counter -= dda->x_delta;
- if (dda->x_counter < 0) {
- x_step();
- did_step = 1;
- if (dda->x_direction)
- current_position.X++;
- else
- current_position.X--;
-
- dda->x_counter += dda->total_steps;
- }
- }
-
- if ((current_position.Y != dda->endpoint.Y) /* &&
- (y_max() != dda->y_direction) && (y_min() == dda->y_direction) */) {
- dda->y_counter -= dda->y_delta;
- if (dda->y_counter < 0) {
- y_step();
- did_step = 1;
- if (dda->y_direction)
- current_position.Y++;
- else
- current_position.Y--;
-
- dda->y_counter += dda->total_steps;
- }
- }
-
- if ((current_position.Z != dda->endpoint.Z) /* &&
- (z_max() != dda->z_direction) && (z_min() == dda->z_direction) */) {
- dda->z_counter -= dda->z_delta;
- if (dda->z_counter < 0) {
- z_step();
- did_step = 1;
- if (dda->z_direction)
- current_position.Z++;
- else
- current_position.Z--;
-
- dda->z_counter += dda->total_steps;
- }
- }