Go to file
Markus Hitter 0ba62800eb config template: adjust the comments for the heaters.
For example, heaters currently don't work on non-PWM pins. Also,
mention special names.
2012-08-04 22:08:43 +02:00
LUFA@baa0979c77 Add LUFA as submodule to support USB-capable Atmel chips. 2011-03-06 09:18:31 +11:00
extruder extruder: Add dummy temp sensor so analog_mask includes trim pot. 2011-04-12 20:38:28 +02:00
lufa_serial lufa_serial.c: Remove commented-out attempt to promote LF to CRLF. 2011-03-06 09:19:15 +11:00
.gitignore Move ThermistorTable.h out of the repository. 2011-11-12 23:26:12 +01:00
.gitmodules Add LUFA as submodule to support USB-capable Atmel chips. 2011-03-06 09:18:31 +11:00
Doxyfile Massive Doxygen documentation addition 2011-03-22 01:34:36 +11:00
LICENSE licensing- GPL-2 at the moment 2010-10-20 18:15:09 +11:00
Makefile Makefile: change wording regarding a newer config.default.h again. 2012-08-04 22:07:51 +02:00
README README: hint to Pronterface. 2012-03-26 17:49:50 +02:00
Teacup_Firmware.pde arduino ide: .pde must have the same name as the folder. 2011-02-27 22:08:41 +01:00
ThermistorTable.double.h ThermistorTables.h: add a const to temptable. 2012-03-26 17:43:40 +02:00
ThermistorTable.single.h ThermistorTables.h: add a const to temptable. 2012-03-26 17:43:40 +02:00
analog.c Save status register on each interrupt. 2012-03-04 19:02:38 +01:00
analog.h Massive Doxygen documentation addition 2011-03-22 01:34:36 +11:00
arduino.h Add support for the ATmega1284/1284P. 2012-05-13 20:14:12 +02:00
arduino_168_328p.h improve and simplify heater pin initialisation by moving to io_init[mendel.c] and using macro magic with DEFINE_HEATER 2011-05-05 00:02:06 +10:00
arduino_644.h improve and simplify heater pin initialisation by moving to io_init[mendel.c] and using macro magic with DEFINE_HEATER 2011-05-05 00:02:06 +10:00
arduino_1280.h improve and simplify heater pin initialisation by moving to io_init[mendel.c] and using macro magic with DEFINE_HEATER 2011-05-05 00:02:06 +10:00
arduino_usb1287.h improve and simplify heater pin initialisation by moving to io_init[mendel.c] and using macro magic with DEFINE_HEATER 2011-05-05 00:02:06 +10:00
calc.pl setting up new branch 2 2010-08-10 14:26:24 +10:00
clock.c Review power supply timeout. 2012-07-16 20:13:12 +02:00
clock.h Merge release-candidate-triffid branch 2011-01-07 23:09:13 +11:00
config.default.h config template: adjust the comments for the heaters. 2012-08-04 22:08:43 +02:00
config.gen3.h config template: adjust the comments for the heaters. 2012-08-04 22:08:43 +02:00
config.gen6.h config template: adjust the comments for the heaters. 2012-08-04 22:08:43 +02:00
config.gen7-v1.1-v1.3.h config template: adjust the comments for the heaters. 2012-08-04 22:08:43 +02:00
config.gen7-v1.4.h config template: adjust the comments for the heaters. 2012-08-04 22:08:43 +02:00
config.ramps-v1.2.h config template: adjust the comments for the heaters. 2012-08-04 22:08:43 +02:00
config.ramps-v1.3.h config template: adjust the comments for the heaters. 2012-08-04 22:08:43 +02:00
config.sanguinololu-v1.1.h config template: adjust the comments for the heaters. 2012-08-04 22:08:43 +02:00
config.sanguinololu-v1.2.h config template: adjust the comments for the heaters. 2012-08-04 22:08:43 +02:00
copier.c Merge release-candidate-triffid branch 2011-01-07 23:09:13 +11:00
copier.h setting up new branch 2 2010-08-10 14:26:24 +10:00
crc.c Massive Doxygen documentation addition 2011-03-22 01:34:36 +11:00
crc.h use CRC16 to verify heater PID settings in eeprom 2011-02-20 17:13:09 +11:00
createTemperatureLookup.py add encoding to createTemperatureLookup.py 2011-03-30 12:18:42 +11:00
dda.c dda: Fix signed-ness mismatch in handling of dda->e_delta 2012-08-04 22:07:43 +02:00
dda.h Move utility functions from dda.c to dda_math.c. 2012-08-04 22:07:24 +02:00
dda_maths.c Move utility functions from dda.c to dda_math.c. 2012-08-04 22:07:24 +02:00
dda_maths.h Move utility functions from dda.c to dda_math.c. 2012-08-04 22:07:24 +02:00
dda_queue.c timer.c: get rid of explicitely disabling the step timer. 2011-11-21 09:54:41 +01:00
dda_queue.h Rework endstop homing. 2011-10-23 19:51:40 +02:00
debug.c setting up new branch 2 2010-08-10 14:26:24 +10:00
debug.h Sort DEBUG_ECHO properly. 2012-05-11 13:51:03 +02:00
delay.c Clean up delay functions and rename them to be consistent with 2011-05-15 09:56:32 +10:00
delay.h Clean up delay functions and rename them to be consistent with 2011-05-15 09:56:32 +10:00
extract.py Added gcode documentation and extraction tool 2011-06-03 02:02:46 +10:00
func.sh func.sh: Fix a potential infinite loop in mendel_readsym_target 2011-05-08 00:36:55 +10:00
fuses.h make it even harder to unintentionally include fuse definitions 2011-02-04 11:04:15 +11:00
gcode_parse.c gcode_parse.c: drop an obsolete comment. 2012-05-11 13:51:06 +02:00
gcode_parse.h Introduce gcode_init() and honor E_ABSOLUTE as the default. 2012-05-11 13:50:51 +02:00
gcode_process.c Fix temperature printing. 2012-08-04 22:08:17 +02:00
gcode_process.h gcode_process.c: make special moves non-public. 2011-02-27 11:55:01 +01:00
graycode.c disable greycode by default in arduino IDE 2011-02-17 21:52:15 +11:00
heater.c Fix compilation with HEATER_SANITY_CHECK defined. 2012-07-02 12:33:44 +02:00
heater.h Introduce TEMP_NONE, a "sensor" just storing the target temperature. 2011-09-01 19:03:33 +02:00
home.c Revert the new relative handling for X, Y and Z. 2012-05-11 13:50:47 +02:00
home.h Fixed single inclusion of file. Added missing define. 2011-08-16 14:09:49 +02:00
intercom.c Make intercom recognize memory barriers. 2012-03-28 12:39:10 +02:00
intercom.h Massive Doxygen documentation addition 2011-03-22 01:34:36 +11:00
memory_barrier.h Add CLI_SEI_BUG_MEMORY_BARRIER() macro that inserts a memory barrier for older versions of avr-libc that do not include a memory barrier as part of the definition of SEI() and CLI(). 2011-05-15 09:56:32 +10:00
mendel.c Introduce gcode_init() and honor E_ABSOLUTE as the default. 2012-05-11 13:50:51 +02:00
mendel_cmd Merge release-candidate-triffid branch 2011-01-07 23:09:13 +11:00
pinio.c Review power supply timeout. 2012-07-16 20:13:12 +02:00
pinio.h Review power supply timeout. 2012-07-16 20:13:12 +02:00
sd.c add sd.c for future, currently unused 2011-02-08 22:37:17 +11:00
sender-mac.sh sender-mac.sh: another minor fix. 2011-09-30 21:02:25 +02:00
sender.sh sender.sh: Allow for "ok" to be surrounded by DEBUG output. 2011-03-04 19:42:00 +11:00
serial.c Save status register on each interrupt. 2012-03-04 19:02:38 +01:00
serial.h Merge release-candidate-triffid branch 2011-01-07 23:09:13 +11:00
sermsg.c M114 returns millimeters instead of steps 2011-04-26 14:44:17 +10:00
sermsg.h M114 returns millimeters instead of steps 2011-04-26 14:44:17 +10:00
sersendf.c sersendf.c: simplify code and save 4 bytes of RAM. 2012-07-02 17:53:36 +02:00
sersendf.h Merge release-candidate-triffid branch 2011-01-07 23:09:13 +11:00
temp.c Fix temperature printing. 2012-08-04 22:08:17 +02:00
temp.h Introduce TEMP_NONE, a "sensor" just storing the target temperature. 2011-09-01 19:03:33 +02:00
timer.c Save status register on each interrupt. 2012-03-04 19:02:38 +01:00
timer.h Get rid of defered enabling of the step interrupt again. 2011-11-21 09:54:38 +01:00
watchdog.c Save status register on each interrupt. 2012-03-04 19:02:38 +01:00
watchdog.h Wrap the watchdog in #ifdefs and disable it for now. My poor imagination 2010-10-02 16:15:29 +02:00

README

For installation instructions, see
http://reprap.org/wiki/Teacup_Firmware#Simple_Installation

##############################################################################
#                                                                            #
# Teacup (formely FiveD on Arduino) firmware                                 #
#                                                                            #
##############################################################################

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
* works on at90usb1287 with direct USB serial
* porting to atmega1280 in progress
* will work on larger atmegas with minor porting

Forum Thread: http://forums.reprap.org/read.php?147
Post all queries, comments, etc here

Github: http://github.com/triffid/Teacup_Firmware
patches, issues go here

##############################################################################
#                                                                            #
# How to use                                                                 #
#                                                                            #
##############################################################################

0) If using USB serial via LUFA, fetch the submodule with:
        git submodule init; git submodule update
1) COPY config.YOURBOARDHERE.h to config.h and edit to suit your electronics
2) check programming settings in Makefile (chip type, avrdude settings, etc)
3) make
4) make program
4a) if programming blank chip, make program-fuses
5) ./sender.sh (or use a GUI G-code sender, like Pronterface)
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.

Markus Hitter was the first to send patches, and has done a significant amount of work on a number of different parts of this firmware, particularly math and sequencing.
Jake Poznanski did the initial port to official gen3 electronics with separate extruder board
Cefiar posted me some thermistors to sponsor addition of thermistor-reading code
Markus Amsler has done a significant amount of work on the new intercom protocol and the latest timer code, as well as tons of test results in the forum
Stephen Walter provided the excellent simulation code, plus some fascinating preprocessor abuse which makes configuration significantly easier

Many others have given patches, encouragement and suggestions without which this firmware may never be what it is today.


##############################################################################
#                                                                            #
# Architectural Overview                                                     #
#                                                                            #
##############################################################################

Teacup is quite similar to the official FiveD firmware in some ways, and markedly different in others. Teacup 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. (FIXME: obsoleted by input-float branch if we ever merge it)

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/Teacup_Firmware
Wiki Page: http://objects.reprap.org/wiki/Teacup_Firmware

##############################################################################
#                                                                            #
# 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, config.*.h
Configuration for your electronics and hardware and a bunch of templates to create your own. Copy the template closest to your hardware to config.h and edit it further

*** copier.[ch]
A totally untested and currently unused chunk of code for copying firmware to another identical chip

*** crc.[ch]
block crc16 routine

*** createTemperatureLookup.py
A python script to generate your TemperatureTable.h

*** 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.h
Delay functions

*** Teacup.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.

*** graycode.c
routines to drive stepper h-bridges directly instead of step/dir

*** heater.[ch]
Heater management, including PID and PWM algorithms, and some configuration parameters

*** home.[ch]
Home using endstop routines

*** 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 primitive messages and values to host

*** sersendf.[ch]
A small, crude printf implementation

*** temp.[ch]
Temperature sensor management, includes some configuration parameters

*** ThermistorTable.h
linear interpolation table for your thermistor, maps analog reading -> temperature

*** 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