Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed most references to heaters, temperatures and extruders.

I realise that I could have expanded on the definitions, and specified whether or not you have an extruder in the Makefile, but for the moment, its a sunny day outside :)
  • Loading branch information...
commit eab4875ee59cd5e1508b3b92b7799531451fe829 1 parent 4088371
@timkrins authored
View
15 Makefile
@@ -23,18 +23,8 @@
# #
##############################################################################
-##############################################################################
-# #
-# Change these to suit your hardware #
-# #
-##############################################################################
-
-# MCU_TARGET = atmega168
-# MCU_TARGET = atmega328p
MCU_TARGET = atmega644p
-# MCU_TARGET = atmega1280
-
-# F_CPU = 16000000L
+F_CPU = 20000000L
##############################################################################
# #
@@ -59,7 +49,8 @@ MCU_TARGET = atmega644p
# #
##############################################################################
-# DEFS = -DF_CPU=$(F_CPU) -DHOST -DGEN3
+DEFS = -DF_CPU=$(F_CPU)
+#-DHOST -DGEN3
# DEFS += "-DDEBUG=1"
##############################################################################
View
103 analog.c
@@ -1,103 +0,0 @@
-#include "analog.h"
-
-#include <avr/interrupt.h>
-
-#ifndef ANALOG_MASK
- #warning ANALOG_MASK not defined - analog subsystem disabled
- #define ANALOG_MASK 0
-#endif
-
-uint8_t adc_running_mask, adc_counter;
-
-#if ANALOG_MASK & 2
- #define ANALOG_START 1
- #define ANALOG_START_MASK 2
-#elif ANALOG_MASK & 4
- #define ANALOG_START 2
- #define ANALOG_START_MASK 4
-#elif ANALOG_MASK & 8
- #define ANALOG_START 3
- #define ANALOG_START_MASK 8
-#elif ANALOG_MASK & 16
- #define ANALOG_START 4
- #define ANALOG_START_MASK 16
-#elif ANALOG_MASK & 32
- #define ANALOG_START 5
- #define ANALOG_START_MASK 32
-#elif ANALOG_MASK & 64
- #define ANALOG_START 6
- #define ANALOG_START_MASK 64
-#elif ANALOG_MASK & 128
- #define ANALOG_START 7
- #define ANALOG_START_MASK 128
-#else
- // ANALOG_MASK == 1 or 0, either way defines are the same except they're not used if ANALOG_MASK == 0
- #define ANALOG_START 0
- #define ANALOG_START_MASK 1
-#endif
-
-volatile uint16_t adc_result[8] __attribute__ ((__section__ (".bss")));
-
-void analog_init() {
- #if ANALOG_MASK > 0
- #ifdef PRR
- PRR &= ~MASK(PRADC);
- #elif defined PRR0
- PRR0 &= ~MASK(PRADC);
- #endif
-
- ADMUX = REFERENCE;
-
- // ADC frequency must be less than 200khz or we lose precision. At 16MHz system clock, we must use the full prescale value of 128 to get an ADC clock of 125khz.
- ADCSRA = MASK(ADEN) | MASK(ADPS2) | MASK(ADPS1) | MASK(ADPS0);
-
- adc_counter = 0;
- adc_running_mask = 1;
-
- AIO0_DDR &= ANALOG_MASK;
- DIDR0 = ANALOG_MASK & 0x3F;
-
- // now we start the first conversion and leave the rest to the interrupt
- ADCSRA |= MASK(ADIE) | MASK(ADSC);
- #endif /* ANALOG_MASK > 0 */
-}
-
-ISR(ADC_vect, ISR_NOBLOCK) {
- // emulate free-running mode but be more deterministic about exactly which result we have, since this project has long-running interrupts
- adc_result[ADMUX & 0x0F] = ADC;
- // find next channel
- do {
- adc_counter++;
- adc_running_mask <<= 1;
- if (adc_counter == 8) {
- adc_counter = ANALOG_START;
- adc_running_mask = ANALOG_START_MASK;
- }
- } while ((adc_running_mask & ANALOG_MASK) == 0);
-
- // start next conversion
- ADMUX = (adc_counter) | REFERENCE;
- ADCSRA |= MASK(ADSC);
-}
-
-uint16_t analog_read(uint8_t channel) {
- #if ANALOG_MASK > 0
- uint16_t r;
-
- uint8_t sreg;
- // save interrupt flag
- sreg = SREG;
- // disable interrupts
- cli();
-
- // atomic 16-bit copy
- r = adc_result[channel];
-
- // restore interrupt flag
- SREG = sreg;
-
- return r;
- #else
- return 0;
- #endif
-}
View
31 analog.h
@@ -1,31 +0,0 @@
-#ifndef _ANALOG_H
-#define _ANALOG_H
-
-#include <stdint.h>
-
-#define REFERENCE_AREF 0
-#define REFERENCE_AVCC 64
-#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
- #define REFERENCE_1V1 192
-#elif defined (__AVR_ATmega_644__) || defined (__AVR_ATmega644p__)
- #define REFERENCE_1V1 128
- #define REFERENCE_2V56 192
-#endif
-
-#include "config.h"
-
-#ifndef REFERENCE
-#warning define REFERENCE as one of
-#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
- #warning REFERENCE_AREF, REFERENCE_AVCC or REFERENCE_1V1
-#elif defined (__AVR_ATmega_644__) || defined (__AVR_ATmega644p__)
- #warning REFERENCE_AREF, REFERENCE_AVCC, REFERENCE_1V1 or REFERENCE_2V56
-#endif
-#warning in your config.h
-#error REFERENCE undefined
-#endif
-
-void analog_init(void);
-uint16_t analog_read(uint8_t channel);
-
-#endif /* _ANALOG_H */
View
9 arduino.h
@@ -41,22 +41,13 @@
/*
ports and functions
-
added as necessary or if I feel like it- not a comprehensive list!
*/
-#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
- #include "arduino_168_328p.h"
-#endif /* _AVR_ATmega{168,328,328P}__ */
-
#if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__)
#include "arduino_644.h"
#endif /* _AVR_ATmega{644,644P,644PA}__ */
-#if defined (__AVR_ATmega1280__)
- #include "arduino_1280.h"
-#endif /* __AVR_ATmega1280__ */
-
#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
View
86 calc.pl
@@ -1,86 +0,0 @@
-#!/usr/bin/perl
-
-my ($ss, $es, $f, $dn, $dt, $a, $n0, $nn, $np, $c0, $cn, $cp, $n, $c, $t, $tp, $v, $vp);
-my ($c0_exact, $cn_exact, $v_exact, $t_exact, $vp_exact, $tp_exact);
-my ($n_pre);
-
-$ss = 300;
-$es = 400;
-$f = 16000000;
-$dn = 50000;
-
-$ssq = $ss * $ss;
-$esq = $es * $es;
-$dsq = ($esq - $ssq);
-
-# $a = $dsq / ($dn << 1);
-
-#$n0 = int(($ss * $ss) / (2 * $a));
-#$nn = int(($es * $es) / (2 * $a));
-# $n0 = int($ssq * $dn / $dsq);
-# $nn = int($esq * $dn / $dsq);
-
-$c0 = int($f / $ss);
-# $c0_exact = $f * sqrt(2 / abs($a));
-
-
-# $dt = ($es - $ss) / $a;
-
-# printf "A:\t%d-%d/%g: %d\n", $es, $ss, $dt, $a;
-# printf "N:\t%d-%d %d:%d\n", $n0, $nn, $nn - $n0, $dn, $a;
-# printf "C:\t%d\t%g\n", $c0, $c0_exact * (sqrt(abs($n0) + 1) - sqrt(abs($n0)));
-# $n = $np = $n0;
-$c = $cp = int($f / $ss);
-$end_c = int($f / $es);
-$t = $tp = $t_exact = 0;
-# $v = $vp = $ss;
-
-$n_pre = int(4 * $ssq * $dn / $dsq) | 1;
-
-# $cn_exact = $c0_exact * (sqrt(abs($n0) + 1) - sqrt(abs($n0)));
-# $v_exact = $vp_exact = $f / $cn_exact;
-
-printf "\tt:i\t\t\tdt\tn\tV\t\ta\n";
-for (0..$dn) {
- # approximation
- # $c = int($c * 1000) / 1000;
- printf "Approx:\t%8.6f:%i\t%10d\t%d\t%12.3f\t%12.3f\n", $t, $_, $c, ($n_pre / 4) - 1, $f / $c, ($t > 0)?($v - $ss) / ($t):0;
-
-# $tp = $t;
-# $cp = $c;
-# $np = $n;
-# $vp = $v;
-
- $t += $c / $f;
- if (
- (($n_pre > 0) && ($c > $end_c)) ||
- (($n_pre < 0) && ($c < $end_c))
- ) {
- $c = int($c - ((2 * $c) / $n_pre));
- $n_pre += 4;
- }
-# $v = $f / $c;
-
- # exact
-# printf "Exact:\t%8.6f:%i\t%10.3f\t%i\t%12.3f\t%12.3f\n\n", $t_exact, $_, $cn_exact, $n, $v_exact, ($t_exact > 0)?($v_exact - $ss) / ($t_exact):0
-# if ($_ % 10 == 0);
-#
-# $vp_exact = $v_exact;
-# $tp_exact = $t_exact;
-#
-# $t_exact += $cn_exact / $f;
-# $cn_exact = $c0_exact * (sqrt(abs($n) + 1) - sqrt(abs($n)));
-# $v_exact = $f / $cn_exact;
-
- # loop increment
-# if ($nn > $n0) {
-# $n++;
- $n_pre += 4;
-# }
-# else {
-# $n--;
-# $n_pre -= 4;
-# }
-}
-
-printf "dt:%8.3f\tv:%8.3f\n", int(($f / $es) + 0.5), $f / int(($f / $es) + 0.5);
View
11 clock.c
@@ -3,8 +3,6 @@
#include "pinio.h"
#include "sersendf.h"
#include "dda_queue.h"
-#include "watchdog.h"
-#include "temp.h"
#include "timer.h"
#include "debug.h"
@@ -18,17 +16,14 @@ void clock_250ms() {
ifclock(CLOCK_FLAG_1S) {
if (debug_flags & DEBUG_POSITION) {
// current position
- sersendf_P(PSTR("Pos: %ld,%ld,%ld,%ld,%lu\n"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F);
+ 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,%ld,%lu\n"), movebuffer[mb_tail].endpoint.X, movebuffer[mb_tail].endpoint.Y, movebuffer[mb_tail].endpoint.Z, movebuffer[mb_tail].endpoint.E, movebuffer[mb_tail].endpoint.F);
+ 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();
}
- // temperature
- /* if (temp_get_target())
- temp_print();*/
}
}
@@ -36,8 +31,6 @@ void clock_10ms() {
// reset watchdog
wd_reset();
- temp_tick();
-
ifclock(CLOCK_FLAG_250MS) {
clock_250ms();
}
View
435 config.h.dist
@@ -1,435 +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
- 8. Appendix A - PWMable pins and mappings
-*/
-
-/***************************************************************************\
-* *
-* 1. MECHANICAL/HARDWARE *
-* *
-\***************************************************************************/
-
-/*
- Set your microcontroller type in Makefile! atmega168/atmega328p/atmega644p/atmega1280
-
- If you want to port this to a new chip, start off with arduino.h and see how you go.
-*/
-
-/*
- CPU clock rate
-*/
-#ifndef F_CPU
- #define F_CPU 16000000L
-#endif
-
-/*
- Are you using the official GEN3 motherboard with separate extruder controller?
-*/
-#define GEN3
-
-/*
- This is the motherboard, as opposed to the extruder. See extruder/ directory for GEN3 extruder firmware
-*/
-#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
-
-// http://blog.arcol.hu/?p=157 may help with this next one
-#define STEPS_PER_MM_E 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
-#define MAXIMUM_FEEDRATE_E 200
-
-// used when searching endstops and as default feedrate
-#define SEARCH_FEEDRATE_X 50
-#define SEARCH_FEEDRATE_Y 50
-#define SEARCH_FEEDRATE_Z 50
-#define SEARCH_FEEDRATE_E 50
-
-// this is how many steps to suck back the filament by when we stop. set to zero to disable
-#define E_STARTSTOP_STEPS 20
-
-
-
-/***************************************************************************\
-* *
-* 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,
- or adjust your electronics to suit this
- */
-
- #define X_STEP_PIN AIO0
- #define X_DIR_PIN AIO1
- #define X_MIN_PIN AIO2
-
- #define Y_STEP_PIN AIO3
- #define Y_DIR_PIN AIO4
- #define Y_MIN_PIN AIO5
-
- #define Z_STEP_PIN DIO2
- #define Z_DIR_PIN DIO3
- #define Z_MIN_PIN DIO4
-
- #define E_STEP_PIN DIO7
- #define E_DIR_PIN DIO8
-
- #define PS_ON_PIN DIO9
-#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
-
-
-
-/***************************************************************************\
-* *
-* 4. TEMPERATURE SENSORS *
-* *
-\***************************************************************************/
-
-/*
- TEMP_HYSTERESIS: actual temperature must be target +/- hysteresis before target temperature can be achieved.
- NOTE: format is 30.2 fixed point, so value of 20 actually means +/- 5 degrees
-
- TEMP_RESIDENCY_TIME: actual temperature must be close to target for this long before target is achieved
-
- temperature is "achieved" for purposes of M109 and friends when actual temperature is within [hysteresis] of target for [residency] seconds
-*/
-#define TEMP_HYSTERESIS 20
-#define TEMP_RESIDENCY_TIME 60
-
-// which temperature sensors are you using? (intercom is the gen3-style separate extruder board)
-// #define TEMP_MAX6675
-// #define TEMP_THERMISTOR
-// #define TEMP_AD595
-// #define TEMP_PT100
-#define TEMP_INTERCOM
-
-// if you selected thermistor or AD595, what pin is it on? (this value only used to fill ANALOG_MASK for you)
-#define TEMP_PIN_CHANNEL AIO0_PIN
-
-// ANALOG_MASK is a bitmask of all analog channels used- if you use more than one analog input (more than one temp sensor?), bitwise-or them all together
-#define ANALOG_MASK MASK(TEMP_PIN_CHANNEL)
-
-// how many temperature sensors do you have?
-#define NUM_TEMP_SENSORS 1
-
-/***************************************************************************\
-* *
-* Fill in the following struct according to your hardware *
-* *
-* If your temperature sensor has no associated heater, enter '255' as the *
-* heater index. Unassociated temperature sensors are still read, but they *
-* do not affect firmware operation *
-* *
-* for GEN3 set temp_type to TT_INTERCOM, temp_pin to 0 and heater index to *
-* 255 - the extruder manages the heater for us *
-* *
-* Types are same as TEMP_ list above- TT_MAX6675, TT_THERMISTOR, TT_AD595, *
-* TT_PT100, TT_INTERCOM. See list in temp.c. *
-* *
-\***************************************************************************/
-
-#ifdef TEMP_C
-struct {
- uint8_t temp_type;
- uint8_t temp_pin;
-
- uint8_t heater_index;
-} temp_sensors[NUM_TEMP_SENSORS] =
-{
- // type pin heater
- { TT_INTERCOM, 0, 255 }
-};
-#endif
-
-
-
-/***************************************************************************\
-* *
-* 5. HEATERS *
-* *
-\***************************************************************************/
-
-// number of heaters- for GEN3, set to zero as extruder manages the heater by itself
-#define NUM_HEATERS 0
-
-// check if heater responds to changes in target temperature, disable and spit errors if not
-// #define HEATER_SANITY_CHECK
-
-/***************************************************************************\
-* *
-* Fill in the following struct according to your hardware *
-* *
-* If your heater isn't on a PWM-able pin, set heater_pwm to zero and we'll *
-* use bang-bang output. Note that PID will still be used *
-* *
-* If a heater isn't attached to a temperature sensor above, it can still be *
-* controlled by host but otherwise is ignored by firmware *
-* *
-\***************************************************************************/
-
-#ifdef HEATER_C
-struct {
- volatile uint8_t *heater_port;
- uint8_t heater_pin;
- volatile uint8_t *heater_pwm;
-} heaters[NUM_HEATERS]/* =
-{
- // port pin pwm
- { &PORTD, PIND6, &OCR0A },
- { &PORTD, PIND5, &OCR0B }
-}*/;
-#endif
-
-
-
-/***************************************************************************\
-* *
-* 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
-
-/*
- DC extruder
- If you have a DC motor extruder, configure it as a "heater" above and define this value as the index.
-*/
-// #define DC_EXTRUDER 1
-// #define DC_EXTRUDER_PWM 180
-
-/*
- 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))
-
-/*
- temperature history count. This is how many temperature readings to keep in order to calculate derivative in PID loop
- higher values make PID derivative term more stable at the expense of reaction time
-*/
-#define TH_COUNT 8
-
-// this is the scaling of internally stored PID values. 1024L is a good value
-#define PID_SCALE 1024L
-
-
-
-/***************************************************************************\
-* *
-* 8. APPENDIX A - PWMABLE PINS AND MAPPINGS *
-* *
-* *
-* list of PWM-able pins and corresponding timers *
-* timer1 is used for step timing so don't use OC1A/OC1B *
-* they are omitted from this listing for that reason *
-* *
-* For the atmega168/328, timer/pin mappings are as follows *
-* *
-* OCR0A - PD6 *
-* OCR0B - PD5 *
-* OCR2A - PB3 *
-* OCR2B - PD3 *
-* *
-* For the atmega644, timer/pin mappings are as follows *
-* *
-* OCR0A - PB3 *
-* OCR0B - PB4 *
-* OCR2A - PD7 *
-* OCR2B - PD6 *
-* *
-* For the atmega1280, timer/pin mappings are as follows *
-* *
-* OC0A - PB7 *
-* OC0B - PG5 *
-* OC2A - PB4 *
-* OC2B - PH6 *
-* OC3A - PE3 *
-* OC3B - PE4 *
-* OC3C - PE5 *
-* OC4A - PH3 *
-* OC4B - PH4 *
-* OC4C - PH5 *
-* OC5A - PL3 *
-* OC5B - PL4 *
-* OC5C - PL5 *
-* *
-\***************************************************************************/
-
-#endif /* _CONFIG_H */
View
101 copier.c
@@ -1,101 +0,0 @@
-#ifdef COPIER
-
-#include "copier.h"
-
-#include <avr/pgmspace.h>
-#include <avr/boot.h>
-
-#include "arduino.h"
-#include "delay.h"
-
-uint32_t copier_xchange(uint32_t cmd) {
- uint32_t r = 0, c = cmd;
- uint8_t i = 0;
-
- for (i = 0; i < 32; i++) {
- WRITE(COPIER_MOSI, c & 0x80000000); delay_us(5);
- c <<= 1;
- WRITE(COPIER_SCK, 1); delay_us(5);
- r = (r << 1) | (READ(COPIER_MISO)?1:0);
- WRITE(COPIER_SCK, 0);
- }
-
- delay_us(5);
-
- return r;
-}
-
-void init_chip(void);
-void init_chip() {
- do {
- WRITE(COPIER_SCK, 0);
- // power up
- WRITE(COPIER_RESET, 1);
- delay_ms(10);
- WRITE(COPIER_RESET, 0);
- delay_ms(10);
- // hopefully enter programming mode
- } while ((copier_xchange(CMD_PROGRAMMING_ENABLE) & (CMD_PROGRAMMING_ENABLE >> 8)) != (CMD_PROGRAMMING_ENABLE >> 8));
-}
-
-void copy() {
- // initialise
- WRITE(COPIER_RESET, 0); SET_OUTPUT(COPIER_RESET);
- WRITE(COPIER_SCK, 0); SET_OUTPUT(COPIER_SCK);
- WRITE(COPIER_MOSI, 0); SET_OUTPUT(COPIER_MOSI);
- SET_INPUT(COPIER_MISO); WRITE(COPIER_MISO, 1);
-
- delay_ms(50);
-
- init_chip();
-
- // verify device signature- should be same as current chip since we haven't the space for the functionality necessary to program anything else
- if ((copier_xchange(CMD_READ_SIGNATURE | 0x00) & 0xFF) != SIGNATURE_0)
- return;
- if ((copier_xchange(CMD_READ_SIGNATURE | 0x01) & 0xFF) != SIGNATURE_1)
- return;
- if ((copier_xchange(CMD_READ_SIGNATURE | 0x02) & 0xFF) != SIGNATURE_2)
- return;
-
- // erase chip
- copier_xchange(CMD_CHIP_ERASE);
- delay_ms(15); //minimum is 9.0ms
-
- // re-initialise
- init_chip();
-
- uint8_t f;
- // copy fuses
- // first low byte
- f = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS);
- copier_xchange(CMD_WRITE_FUSE_BITS | f);
-
- // high byte
- f = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
- copier_xchange(CMD_WRITE_FUSE_HIGH_BITS | f);
-
- // extended byte
- f = boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS);
- copier_xchange(CMD_WRITE_FUSE_EXTENDED_BITS | f);
-
- // start copying flash
- uint16_t i;
- for (i = 0; i < (FLASHEND / 2); i += (SPM_PAGESIZE / 2)) {
- uint8_t j;
- for (j = 0; j < (SPM_PAGESIZE / 2); j++) {
- uint16_t w = pgm_read_word_near((i | j) << 1);
- copier_xchange(CMD_LOAD_PROGMEM_LOW_BYTE | (j << 8) | (w & 0xFF));
- copier_xchange(CMD_LOAD_PROGMEM_HIGH_BYTE | (j << 8) | (w >> 8));
- }
- copier_xchange(CMD_WRITE_PROGMEM_PAGE | ((i / (SPM_PAGESIZE / 2)) << 8));
- delay_ms(10); //minimum is 4.5ms
- }
-
- // reset
- delay_ms(10);
- SET_INPUT(MOSI);
- SET_INPUT(SCK);
- SET_INPUT(COPIER_RESET);
-}
-
-#endif /* COPIER */
View
45 copier.h
@@ -1,45 +0,0 @@
-#ifndef _COPIER_H
-#define _COPIER_H
-
-// operation instructions
-#define CMD_PROGRAMMING_ENABLE 0xAC530000
-#define CMD_CHIP_ERASE 0xAC800000
-#define CMD_POLL 0xF0000000
-
-// load instructions
-#define CMD_LOAD_EXTENDED_ADDRESS 0x4D000000
-#define CMD_LOAD_PROGMEM_HIGH_BYTE 0x48000000
-#define CMD_LOAD_PROGMEM_LOW_BYTE 0x40000000
-#define CMD_LOAD_EEPROM_PAGE 0xC1000000
-
-// read instructions
-#define CMD_READ_PROGMEM_HIGH_BYTE 0x28000000
-#define CMD_READ_PROGMEM_LOW_BYTE 0x20000000
-#define CMD_READ_EEPROM 0xA0000000
-#define CMD_READ_LOCK_BITS 0x58000000
-#define CMD_READ_SIGNATURE 0x30000000
-#define CMD_READ_FUSE_BITS 0x50000000
-#define CMD_READ_FUSE_HIGH_BITS 0x58080000
-#define CMD_READ_FUSE_EXTENDED_BITS 0x50080000
-#define CMD_READ_CALIBRATION_BYTE 0x38000000
-
-// write instructions
-#define CMD_WRITE_PROGMEM_PAGE 0x4C000000
-#define CMD_WRITE_EEPROM 0xC0000000
-#define CMD_WRITE_EEPROM_PAGE 0xC2000000
-#define CMD_WRITE_LOCK_BITS 0xACE00000
-#define CMD_WRITE_FUSE_BITS 0xACA00000
-#define CMD_WRITE_FUSE_HIGH_BITS 0xACA80000
-#define CMD_WRITE_FUSE_EXTENDED_BITS 0xACA40000
-
-//pinout
-#define COPIER_RESET AIO1
-#define COPIER_SCK AIO2
-#define COPIER_MOSI AIO3
-#define COPIER_MISO AIO4
-
-//functions
-
-void copy(void);
-
-#endif /* _COPIER_H */
View
66 dda.c
@@ -13,17 +13,12 @@
#include "pinio.h"
#include "config.h"
-#ifdef DC_EXTRUDER
- #include "heater.h"
-#endif
-
/*
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)
-#define UM_PER_STEP_E 1000L / ((uint32_t) STEPS_PER_MM_E)
/*
step timeout
@@ -131,12 +126,10 @@ void dda_create(DDA *dda, TARGET *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->e_delta = labs(target->E - startpoint.E);
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;
- dda->e_direction = (target->E >= startpoint.E)?1:0;
if (debug_flags & DEBUG_DDA)
sersendf_P(PSTR("%ld,%ld,%ld,%ld] ["), target->X - startpoint.X, target->Y - startpoint.Y, target->Z - startpoint.Z, target->E - startpoint.E);
@@ -146,8 +139,6 @@ void dda_create(DDA *dda, TARGET *target) {
dda->total_steps = dda->y_delta;
if (dda->z_delta > dda->total_steps)
dda->total_steps = dda->z_delta;
- if (dda->e_delta > dda->total_steps)
- dda->total_steps = dda->e_delta;
if (debug_flags & DEBUG_DDA)
sersendf_P(PSTR("ts:%lu"), dda->total_steps);
@@ -172,9 +163,6 @@ void dda_create(DDA *dda, TARGET *target) {
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 (distance < 2)
- distance = dda->e_delta * UM_PER_STEP_E;
-
if (debug_flags & DEBUG_DDA)
sersendf_P(PSTR(",ds:%lu"), distance);
@@ -182,7 +170,7 @@ void dda_create(DDA *dda, TARGET *target) {
// 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->e_counter =
+ 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
@@ -218,10 +206,6 @@ void dda_create(DDA *dda, TARGET *target) {
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;
- // check E axis
- c_limit_calc = ( (dda->e_delta * (UM_PER_STEP_E * 2400L)) / dda->total_steps * (F_CPU / 40000) / MAXIMUM_FEEDRATE_E) << 8;
- if (c_limit_calc > c_limit)
- c_limit = c_limit_calc;
#ifdef ACCELERATION_REPRAP
// c is initial step time in IOclk ticks
@@ -291,15 +275,12 @@ void dda_create(DDA *dda, TARGET *target) {
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->e_counter = dda->e_step_interval = move_duration / dda->e_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;
- if (dda->e_step_interval < dda->c)
- dda->c = dda->e_step_interval;
dda->c <<= 8;
#else
@@ -315,7 +296,6 @@ void dda_create(DDA *dda, TARGET *target) {
// next dda starts where we finish
memcpy(&startpoint, target, sizeof(TARGET));
// E is always relative, reset it here
- startpoint.E = 0;
}
/*
@@ -348,12 +328,7 @@ void dda_start(DDA *dda) {
x_direction(dda->x_direction);
y_direction(dda->y_direction);
z_direction(dda->z_direction);
- e_direction(dda->e_direction);
- #ifdef DC_EXTRUDER
- if (dda->e_delta)
- heater_set(DC_EXTRUDER, DC_EXTRUDER_PWM);
- #endif
// }
@@ -410,18 +385,7 @@ void dda_step(DDA *dda) {
dda->z_counter += dda->z_step_interval;
dda->z_delta--;
}
- if (dda->e_counter <= 0) {
- if ((current_position.E != dda->endpoint.E) /* &&
- (e_max() != dda->e_direction) && (e_min() == dda->e_direction) */) {
- e_step();
- if (dda->e_direction)
- current_position.E++;
- else
- current_position.E--;
- }
- dda->e_counter += dda->e_step_interval;
- dda->e_delta--;
- }
+
#else
if ((current_position.X != dda->endpoint.X) /* &&
(x_max() != dda->x_direction) && (x_min() == dda->x_direction) */) {
@@ -467,20 +431,6 @@ void dda_step(DDA *dda) {
dda->z_counter += dda->total_steps;
}
}
-
- if (current_position.E != dda->endpoint.E) {
- dda->e_counter -= dda->e_delta;
- if (dda->e_counter < 0) {
- e_step();
- did_step = 1;
- if (dda->e_direction)
- current_position.E++;
- else
- current_position.E--;
-
- dda->e_counter += dda->total_steps;
- }
- }
#endif
#if STEP_INTERRUPT_INTERRUPTIBLE
@@ -542,8 +492,6 @@ void dda_step(DDA *dda) {
dda->c = dda->y_counter;
if (dda->z_counter < dda->c)
dda->c = dda->z_counter;
- if (dda->e_counter < dda->c)
- dda->c = dda->e_counter;
if (dda->x_delta)
dda->x_counter -= dda->c;
@@ -551,13 +499,10 @@ void dda_step(DDA *dda) {
dda->y_counter -= dda->c;
if (dda->z_delta)
dda->z_counter -= dda->c;
- if (dda->e_delta)
- dda->e_counter -= dda->c;
if (
(dda->x_delta > 0) ||
(dda->y_delta > 0) ||
- (dda->z_delta > 0) ||
- (dda->e_delta > 0))
+ (dda->z_delta > 0)
did_step = 1;
dda->c <<= 8;
@@ -572,14 +517,9 @@ void dda_step(DDA *dda) {
}
else {
dda->live = 0;
- // reset E- always relative
- current_position.E = 0;
// linear acceleration code doesn't alter F during a move, so we must update it here
// in theory, we *could* update F every step, but that would require a divide in interrupt context which should be avoided if at all possible
current_position.F = dda->endpoint.F;
- #ifdef DC_EXTRUDER
- heater_set(DC_EXTRUDER, 0);
- #endif
}
setTimer(dda->c >> 8);
View
7 dda.h
@@ -24,7 +24,6 @@ typedef struct {
int32_t X;
int32_t Y;
int32_t Z;
- int32_t E;
uint32_t F;
} TARGET;
@@ -49,7 +48,6 @@ typedef struct {
uint8_t x_direction :1;
uint8_t y_direction :1;
uint8_t z_direction :1;
- uint8_t e_direction :1;
};
uint8_t allflags; // used for clearing all flags
};
@@ -58,15 +56,13 @@ typedef struct {
uint32_t x_delta;
uint32_t y_delta;
uint32_t z_delta;
- uint32_t e_delta;
// bresenham counters
int32_t x_counter;
int32_t y_counter;
int32_t z_counter;
- int32_t e_counter;
- // total number of steps: set to max(x_delta, y_delta, z_delta, e_delta)
+ // total number of steps: set to max(x_delta, y_delta, z_delta)
uint32_t total_steps;
// linear acceleration variables: c and end_c are 24.8 fixed point timer values, n is the tracking variable
@@ -90,7 +86,6 @@ typedef struct {
uint32_t x_step_interval;
uint32_t y_step_interval;
uint32_t z_step_interval;
- uint32_t e_step_interval;
#endif
} DDA;
View
1  dda_queue.c
@@ -7,7 +7,6 @@
#include "timer.h"
#include "serial.h"
#include "sermsg.h"
-#include "temp.h"
#include "delay.h"
#include "sersendf.h"
#include "clock.h"
View
312 func.sh
@@ -1,312 +0,0 @@
-#!/bin/bash
-
-#
-# this file is designed to be sourced into your current shell like this:
-#
-# source ./func.sh
-#
-# and then used like this:
-#
-# $ mendel_cmd G1 X100
-# $ mendel_cmd M250
-#
-# {X:4200,Y:0,Z:0,E:0,F:300,c:19334400}
-# {X:4200,Y:0,Z:0,E:0,F:300,c:0}
-# Q1/1E
-# $ mendel_readsym_uint8 mb_head
-# 1
-# $ mendel_readsym_target startpoint
-# X: 2100
-# Y: 0
-# Z: 0
-# E: 0
-# F: 300
-# $ mendel_readsym_mb
-# [0] {
-# eX: 0 eY: 0 eZ: 0 eE: 0 eF: 0
-# flags: 0
-# dX: 0 dY: 0 dZ: 0 dE: 0
-# cX: 0 cY: 0 cZ: 0 cE: 0
-# ts: 0
-# c: 0 ec: 0 n: 0
-# }
-# [HEAD,TAIL:1] {
-# eX: 4200 eY: 0 eZ: 0 eE: 0 eF: 300
-# flags: 120
-# dX: 4200 dY: 0 dZ: 0 dE: 0
-# cX: -2100 cY: -2100 cZ: -2100 cE: -2100
-# ts: 4200
-# c: 19334400 ec: 0 n: 0
-# }
-# [2] {
-# eX: 0 eY: 0 eZ: 0 eE: 0 eF: 0
-# flags: 0
-# dX: 0 dY: 0 dZ: 0 dE: 0
-# cX: 0 cY: 0 cZ: 0 cE: 0
-# ts: 0
-# c: 0 ec: 0 n: 0
-# }
-# [3] {
-# eX: 0 eY: 0 eZ: 0 eE: 0 eF: 0
-# flags: 0
-# dX: 0 dY: 0 dZ: 0 dE: 0
-# cX: 0 cY: 0 cZ: 0 cE: 0
-# ts: 0
-# c: 0 ec: 0 n: 0
-# }
-# [4] {
-# eX: 0 eY: 0 eZ: 0 eE: 0 eF: 0
-# flags: 0
-# dX: 0 dY: 0 dZ: 0 dE: 0
-# cX: 0 cY: 0 cZ: 0 cE: 0
-# ts: 0
-# c: 0 ec: 0 n: 0
-# }
-# [5] {
-# eX: 0 eY: 0 eZ: 0 eE: 0 eF: 0
-# flags: 0
-# dX: 0 dY: 0 dZ: 0 dE: 0
-# cX: 0 cY: 0 cZ: 0 cE: 0
-# ts: 0
-# c: 0 ec: 0 n: 0
-# }
-# [6] {
-# eX: 0 eY: 0 eZ: 0 eE: 0 eF: 0
-# flags: 0
-# dX: 0 dY: 0 dZ: 0 dE: 0
-# cX: 0 cY: 0 cZ: 0 cE: 0
-# ts: 0
-# c: 0 ec: 0 n: 0
-# }
-# [7] {
-# eX: 0 eY: 0 eZ: 0 eE: 0 eF: 0
-# flags: 0
-# dX: 0 dY: 0 dZ: 0 dE: 0
-# cX: 0 cY: 0 cZ: 0 cE: 0
-# ts: 0
-# c: 0 ec: 0 n: 0
-# }
-
-
-mendel_setup() {
- stty 115200 raw ignbrk -hup -echo ixoff < /dev/arduino
-}
-
-mendel_reset() {
- stty hup < /dev/arduino
- stty hup < /dev/arduino
- mendel_setup
-}
-
-mendel_talk() {
- ( cat <&3 & cat >&3; kill $! ; ) 3<>/dev/arduino
-}
-
-mendel_cmd() {
- (
- local IFS=$' \t\n'
- local RSC=0
- local cmd="$*"
- echo "$cmd" >&3;
- local REPLY=""
- while ! [[ "$REPLY" =~ ^OK ]] && ! [[ "$REPLY" =~ ^ok ]]
- do
- read -u 3
- echo "${REPLY##ok }"
- if [[ "$REPLY" =~ ^RESEND ]] || [[ "$REPLY" =~ ^rs ]]
- then
- if [ "$RSC" -le 3 ]
- then
- echo "$cmd" >&3
- RSC=$(( $RSC + 1 ))
- else
- REPLY="OK"
- echo "Too many retries: aborting" >&2
- fi
- fi
- done
- ) 3<>/dev/arduino;
-}
-
-mendel_cmd_hr() {
- (
- local IFS=$' \t\n'
- local cmd="$*"
- local RSC=0
- echo "$cmd" >&3
- echo "S> $cmd"
- local REPLY=""
- while ! [[ "$REPLY" =~ ^OK ]] && ! [[ "$REPLY" =~ ^ok ]]
- do
- read -u 3
- echo "<R $REPLY"
- if [[ "$REPLY" =~ ^RESEND ]] || [[ "$REPLY" =~ ^rs ]]
- then
- if [ "$RSC" -le 3 ]
- then
- echo "$cmd" >&3
- echo "S> $cmd"
- RSC=$(( $RSC + 1))
- else
- REPLY="OK"
- echo "Too many retries: aborting" >&2
- fi
- fi
- done
- ) 3<>/dev/arduino;
-}
-
-mendel_print() {
- (
- for F in "$@"
- do
- local IFS=$'\n'
- for L in $(< $F)
- do
- mendel_cmd_hr "$L"
- done
- done
- )
-}
-
-mendel_readsym() {
- (
- local IFS=$' \t\n'
- local sym=$1
- if [ -n "$sym" ]
- then
- if [[ "$sym" =~ ^(0?x?[0-9A-Fa-f]+)(:([0-9]+))?$ ]]
- then
- local ADDR=$(( ${BASH_REMATCH[1]} ))
- local SIZE=$(( ${BASH_REMATCH[3]} ))
- if [ "$SIZE" -le 1 ]
- then
- SIZE=1
- fi
- mendel_cmd "M253 S$ADDR P$SIZE"
- else
- make mendel.sym &>/dev/null
- if egrep -q '\b'$sym'\b' mendel.sym
- then
- local ADDR=$(( $(egrep '\b'$sym'\b' mendel.sym | cut -d\ -f1) ))
- local SIZE=$(egrep '\b'$sym'\b' mendel.sym | cut -d+ -f2)
- mendel_cmd "M253 S$ADDR P$SIZE"
- else
- echo "unknown symbol: $sym"
- fi
- fi
- else
- echo "what symbol?" > /dev/fd/2
- fi
- )
-}
-
-mendel_readsym_uint8() {
- local sym=$1
- local val=$(mendel_readsym $sym)
- perl -e 'printf "%u\n", eval "0x".$ARGV[0]' $val
-}
-
-mendel_readsym_int8() {
- local sym=$1
- local val=$(mendel_readsym $sym)
- perl -e 'printf "%d\n", ((eval "0x".$ARGV[0]) & 0x7F) - (((eval "0x".$ARGV[0]) & 0x80)?0x80:0)' $val
-}
-
-mendel_readsym_uint16() {
- local sym=$1
- local val=$(mendel_readsym $sym)
- perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%u\n", eval "0x$2$1"' $val
-}
-
-mendel_readsym_int16() {
- local sym=$1
- local val=$(mendel_readsym $sym)
- perl -e '$ARGV[0] =~ m#(..)(..)# && printf "%d\n", ((eval "0x$2$1") & 0x7FFF) - (((eval "0x$2$1") & 0x8000)?0x8000:0)' $val
-}
-
-mendel_readsym_uint32() {
- local sym=$1
- local val=$(mendel_readsym $sym)
- perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%u\n", eval "0x$4$3$2$1"' $val
-}
-
-mendel_readsym_int32() {
- local sym=$1
- local val=$(mendel_readsym $sym)
- perl -e '$ARGV[0] =~ m#(..)(..)(..)(..)# && printf "%d\n", eval "0x$4$3$2$1"' $val
-}
-
-mendel_readsym_target() {
- local sym=$1
- local val=$(mendel_readsym "$sym")
- if [ -n "$val" ]
- then
- perl -e '@a = qw/X Y Z E F/; $c = 0; while (length $ARGV[0]) { $ARGV[0] =~ s#^(..)(..)(..)(..)##; printf "%s: %d\n", $a[$c], eval "0x$4$3$2$1"; $c++; }' "$val"
- fi
-}
-
-mendel_readsym_mb() {
- local val=$(mendel_readsym movebuffer)
- local mbhead=$(mendel_readsym mb_head)
- local mbtail=$(mendel_readsym mb_tail)
- perl - <<'ENDPERL' -- $val $mbhead $mbtail
- $i = -1;
- @a = qw/eX 4 eY 4 eZ 4 eE 4 eF 4 flags 9 dX 12 dY 4 dZ 4 dE 4 cX 12 cY 4 cZ 4 cE 4 ts 12 c 12 rs 4 sn 4 cm 4 n 4 rs 1/;
- $c = 0;
- $c = 1234567;
- while (length $ARGV[1]) {
- if ($c > ($#a / 2)) {
- $i++;
- $c = 0;
- printf "\n}\n"
- if ($i > 0);
- printf "[%s%d] {\n", (($i == $ARGV[2])?"HEAD":"").(($ARGV[2] == $ARGV[3] && $ARGV[2] == $i)?",":"").(($i == $ARGV[3])?"TAIL":"").(($i == $ARGV[2] || $i == $ARGV[3])?":":""), $i
- }
- if ($a[$c * 2 + 1] & 8) {
- printf "\n";
- }
- if (($a[$c * 2 + 1] & 7) == 4) {
- $ARGV[1] =~ s#^(..)(..)(..)(..)##;
- printf "\t%s: %d", $a[$c * 2], eval "0x$4$3$2$1";
- }
- elsif (($a[$c * 2 + 1] & 7) == 1) {
- $ARGV[1] =~ s#^(..)##;
- printf "\t%s: %d", $a[$c * 2], eval "0x$1";
- }
- $c++;
- }
- printf "\n}\n";
-ENDPERL
-}
-
-mendel_heater_pid() {
- local P=$(mendel_readsym_int16 heater_p)
- local I=$(mendel_readsym_int16 heater_i)
- local D=$(mendel_readsym_int16 heater_d)
-
- local PF=$(mendel_readsym_int32 p_factor)
- local IF=$(mendel_readsym_int32 i_factor)
- local DF=$(mendel_readsym_int32 d_factor)
-
- local O=$(mendel_readsym_uint8 0x27)
- local T=$(mendel_cmd M105 | cut -d\ -f2 | cut -d/ -f1)
-
- echo "P=$P pf=$PF r="$(($P * $PF))
- echo "I=$I if=$IF r="$(($I * $IF))
- echo "D=$D df=$DF r="$(($D * $DF))
- echo "R="$(( $(($P * $PF)) + $(($I * $IF)) + $(($D * $DF)) )) / 1024
- echo "R="$(( $(( $(($P * $PF)) + $(($I * $IF)) + $(($D * $DF)) )) / 1024 ))
- echo "R="$(( $(( $(( $(($P * $PF)) + $(($I * $IF)) + $(($D * $DF)) )) / 1024 )) + 128 ))
- echo "O=$O T=$T"
-}
-
-if [[ "$0" =~ ^mendel_(setup|reset|cmd|readsym|heater_pid) ]]
-then
- eval "$0" "$@"
-fi
-
-if [[ "$1" =~ ^mendel_(setup|reset|cmd|readsym|heater_pid) ]]
-then
- eval "$@"
-fi
View
22 fuses.h
@@ -1,23 +1,5 @@
#ifdef FUSES
- #if defined (__AVR_ATmega168__)
- FUSES = {
- .low = FUSE_CKSEL3 & FUSE_SUT0,
- .high = FUSE_SPIEN,
- .extended = FUSE_BOOTSZ1 & FUSE_BOOTSZ0,
- };
- #elif defined (__AVR_ATmega328P__)
- FUSES = {
- .low = FUSE_CKSEL3 & FUSE_SUT0,
- .high = FUSE_SPIEN & FUSE_BOOTSZ0 & FUSE_BOOTSZ1,
- .extended = EFUSE_DEFAULT,
- };
- #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__)
- FUSES = {
- .low = FUSE_CKSEL3 & FUSE_SUT0,
- .high = FUSE_SPIEN & FUSE_BOOTSZ0 & FUSE_BOOTSZ1,
- .extended = EFUSE_DEFAULT,
- };
- #elif defined (__AVR_ATmega1280__)
+ #if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__)
FUSES = {
.low = FUSE_CKSEL3 & FUSE_SUT0,
.high = FUSE_SPIEN & FUSE_BOOTSZ0 & FUSE_BOOTSZ1,
@@ -26,4 +8,4 @@
#else
#warning No fuse definitions for this chip in fuses.h!
#endif
-#endif /* FUSES */
+#endif /* FUSES */
View
26 gcode_parse.c
@@ -6,7 +6,6 @@
#include "sermsg.h"
#include "dda_queue.h"
#include "debug.h"
-#include "heater.h"
#include "sersendf.h"
#include "gcode_process.h"
@@ -28,7 +27,6 @@
#define STEPS_PER_M_X ((uint32_t) ((STEPS_PER_MM_X * 1000.0) + 0.5))
#define STEPS_PER_M_Y ((uint32_t) ((STEPS_PER_MM_Y * 1000.0) + 0.5))
#define STEPS_PER_M_Z ((uint32_t) ((STEPS_PER_MM_Z * 1000.0) + 0.5))
-#define STEPS_PER_M_E ((uint32_t) ((STEPS_PER_MM_E * 1000.0) + 0.5))
/*
mm -> inch conversion
@@ -37,7 +35,6 @@
#define STEPS_PER_IN_X ((uint32_t) ((25.4 * STEPS_PER_MM_X) + 0.5))
#define STEPS_PER_IN_Y ((uint32_t) ((25.4 * STEPS_PER_MM_Y) + 0.5))
#define STEPS_PER_IN_Z ((uint32_t) ((25.4 * STEPS_PER_MM_Z) + 0.5))
-#define STEPS_PER_IN_E ((uint32_t) ((25.4 * STEPS_PER_MM_E) + 0.5))
uint8_t last_field = 0;
@@ -78,11 +75,9 @@ static int32_t decfloat_to_int(decfloat *df, int32_t multiplicand, uint32_t deno
return df->sign ? -r : r;
}
-/****************************************************************************
-* *
+/***************************************************************************\
* Character Received - add it to our command *
-* *
-****************************************************************************/
+\***************************************************************************/
void gcode_parse_char(uint8_t c) {
#ifdef ASTERISK_IN_CHECKSUM_INCLUDED
@@ -134,14 +129,6 @@ void gcode_parse_char(uint8_t c) {
if (debug_flags & DEBUG_ECHO)
serwrite_int32(next_target.target.Z);
break;
- case 'E':
- if (next_target.option_inches)
- next_target.target.E = decfloat_to_int(&read_digit, STEPS_PER_IN_E, 1);
- else
- next_target.target.E = decfloat_to_int(&read_digit, STEPS_PER_M_E, 1000);
- if (debug_flags & DEBUG_ECHO)
- serwrite_uint32(next_target.target.E);
- break;
case 'F':
// just use raw integer, we need move distance and n_steps to convert it to a useful value, so wait until we have those to convert it
if (next_target.option_inches)
@@ -228,9 +215,6 @@ void gcode_parse_char(uint8_t c) {
case 'Z':
next_target.seen_Z = 1;
break;
- case 'E':
- next_target.seen_E = 1;
- break;
case 'F':
next_target.seen_F = 1;
break;
@@ -347,7 +331,7 @@ void gcode_parse_char(uint8_t c) {
// reset variables
next_target.seen_X = next_target.seen_Y = next_target.seen_Z = \
- next_target.seen_E = next_target.seen_F = next_target.seen_S = \
+ next_target.seen_F = next_target.seen_S = \
next_target.seen_P = next_target.seen_T = next_target.seen_N = \
next_target.seen_M = next_target.seen_checksum = next_target.seen_semi_comment = \
next_target.seen_parens_comment = next_target.checksum_read = \
@@ -361,17 +345,13 @@ void gcode_parse_char(uint8_t c) {
if (next_target.option_relative) {
next_target.target.X = next_target.target.Y = next_target.target.Z = 0;
- next_target.target.E = 0;
}
}
}
/***************************************************************************\
-* *
* Request a resend of the current line - used from various places. *
-* *
* Relies on the global variable next_target.N being valid. *
-* *
\***************************************************************************/
void request_resend(void) {
View
1  gcode_parse.h
@@ -39,7 +39,6 @@ typedef struct {
uint8_t seen_X :1;
uint8_t seen_Y :1;
uint8_t seen_Z :1;
- uint8_t seen_E :1;
uint8_t seen_F :1;
uint8_t seen_S :1;
View
148 gcode_process.c
@@ -5,12 +5,9 @@
#include "gcode_parse.h"
#include "dda_queue.h"
-#include "watchdog.h"
#include "delay.h"
#include "serial.h"
#include "sermsg.h"
-#include "temp.h"
-#include "heater.h"
#include "timer.h"
#include "sersendf.h"
#include "pinio.h"
@@ -48,19 +45,6 @@ void zero_z(void) {
enqueue(&t);
}
-void zero_e(void) {
- TARGET t = startpoint;
- t.E = 0;
- enqueue(&t);
-}
-
-void SpecialMoveE(int32_t e, uint32_t f) {
- TARGET t = startpoint;
- t.E = e;
- t.F = f;
- enqueue(&t);
-}
-
/****************************************************************************
* *
* Command Received - process it *
@@ -76,11 +60,6 @@ void process_gcode_command() {
next_target.target.Y += startpoint.Y;
next_target.target.Z += startpoint.Z;
}
- // E ALWAYS relative, otherwise we overflow our registers after only a few layers
- // next_target.target.E += startpoint.E;
- // easier way to do this
- // startpoint.E = 0;
- // moved to dda.c, end of dda_create() and dda_queue.c, next_move()
if (next_target.seen_T) {
next_tool = next_target.T;
@@ -153,10 +132,6 @@ void process_gcode_command() {
zero_z();
axisSelected = 1;
}
- if (next_target.seen_E) {
- zero_e();
- axisSelected = 1;
- }
break;
@@ -187,15 +162,10 @@ void process_gcode_command() {
startpoint.Z = current_position.Z = next_target.target.Z;
axisSelected = 1;
}
- if (next_target.seen_E) {
- startpoint.E = current_position.E = next_target.target.E;
- axisSelected = 1;
- }
if (axisSelected == 0) {
startpoint.X = current_position.X =
startpoint.Y = current_position.Y =
- startpoint.Z = current_position.Z =
- startpoint.E = current_position.E = 0;
+ startpoint.Z = current_position.Z = 0;
}
break;
@@ -223,84 +193,6 @@ void process_gcode_command() {
case 6:
tool = next_tool;
break;
- // M3/M101- extruder on
- case 3:
- case 101:
- if (temp_achieved() == 0) {
- enqueue(NULL);
- }
- #ifdef DC_EXTRUDER
- heater_set(DC_EXTRUDER, DC_EXTRUDER_PWM);
- #elif E_STARTSTOP_STEPS > 0
- do {
- // backup feedrate, move E very quickly then restore feedrate
- backup_f = startpoint.F;
- startpoint.F = MAXIMUM_FEEDRATE_E;
- SpecialMoveE(E_STARTSTOP_STEPS, MAXIMUM_FEEDRATE_E);
- startpoint.F = backup_f;
- } while (0);
- #endif
- break;
-
- // M102- extruder reverse
-
- // M5/M103- extruder off
- case 5:
- case 103:
- #ifdef DC_EXTRUDER
- heater_set(DC_EXTRUDER, 0);
- #elif E_STARTSTOP_STEPS > 0
- do {
- // backup feedrate, move E very quickly then restore feedrate
- backup_f = startpoint.F;
- startpoint.F = MAXIMUM_FEEDRATE_E;
- SpecialMoveE(-E_STARTSTOP_STEPS, MAXIMUM_FEEDRATE_E);
- startpoint.F = backup_f;
- } while (0);
- #endif
- break;
-
- // M104- set temperature
- case 104:
- temp_set(next_target.P, next_target.S);
- if (next_target.S) {
- power_on();
- }
- else {
- disable_heater();
- }
- break;
-
- // M105- get temperature
- case 105:
- temp_print(next_target.P);
- break;
-
- // M7/M106- fan on
- #if NUM_HEATERS > 1
- case 7:
- case 106:
- heater_set(1, 255);
- break;
- // M107- fan off
- case 9:
- case 107:
- heater_set(1, 0);
- break;
- #endif
-
- // M109- set temp and wait
- case 109:
- temp_set(next_target.P, next_target.S);
- if (next_target.S) {
- power_on();
- enable_heater();
- }
- else {
- disable_heater();
- }
- enqueue(NULL);
- break;
// M110- set line number
case 110:
@@ -321,46 +213,14 @@ void process_gcode_command() {
// M113- extruder PWM
// M114- report XYZEF to host
case 114:
- sersendf_P(PSTR("X:%ld,Y:%ld,Z:%ld,E:%ld,F:%ld"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F);
+ sersendf_P(PSTR("X:%ld,Y:%ld,Z:%ld,F:%ld"), current_position.X, current_position.Y, current_position.Z, current_position.F);
// newline is sent from gcode_parse after we return
break;
// M115- capabilities string
case 115:
- sersendf_P(PSTR("FIRMWARE_NAME:FiveD_on_Arduino FIRMWARE_URL:http%%3A//github.com/triffid/FiveD_on_Arduino/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:%d TEMP_SENSOR_COUNT:%d HEATER_COUNT:%d"), 1, NUM_TEMP_SENSORS, NUM_HEATERS);
+ sersendf_P(PSTR("FIRMWARE_NAME:FiveD_on_Arduino FIRMWARE_URL:http%%3A//github.com/triffid/FiveD_on_Arduino/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:%d TEMP_SENSOR_COUNT:%d HEATER_COUNT:%d"), 1, 0, 0);
// newline is sent from gcode_parse after we return
break;
-
- #if NUM_HEATERS > 0
- // M130- heater P factor
- case 130:
- if (next_target.seen_S)
- pid_set_p(next_target.P, next_target.S);
- break;
- // M131- heater I factor
- case 131:
- if (next_target.seen_S)
- pid_set_i(next_target.P, next_target.S);
- break;
- // M132- heater D factor
- case 132:
- if (next_target.seen_S)
- pid_set_d(next_target.P, next_target.S);
- break;
- // M133- heater I limit
- case 133:
- if (next_target.seen_S)
- pid_set_i_limit(next_target.P, next_target.S);
- break;
- // M134- save PID settings to eeprom
- case 134:
- heater_save_settings();
- break;
- // M135- set heater output
- case 135:
- if (next_target.seen_S)
- heater_set(next_target.P, next_target.S);
- break;
- #endif /* NUM_HEATERS > 0 */
// M190- power on
case 190:
@@ -394,7 +254,7 @@ void process_gcode_command() {
// DEBUG: return current position, end position, queue
case 250:
- sersendf_P(PSTR("{X:%ld,Y:%ld,Z:%ld,E:%ld,F:%lu,c:%lu}\t{X:%ld,Y:%ld,Z:%ld,E:%ld,F:%lu,c:%lu}\t"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F, movebuffer[mb_tail].c, movebuffer[mb_tail].endpoint.X, movebuffer[mb_tail].endpoint.Y, movebuffer[mb_tail].endpoint.Z, movebuffer[mb_tail].endpoint.E, movebuffer[mb_tail].endpoint.F,
+ sersendf_P(PSTR("{X:%ld,Y:%ld,Z:%ld,F:%lu,c:%lu}\t{X:%ld,Y:%ld,Z:%ld,F:%lu,c:%lu}\t"), current_position.X, current_position.Y, current_position.Z, current_position.F, movebuffer[mb_tail].c, movebuffer[mb_tail].endpoint.X, movebuffer[mb_tail].endpoint.Y, movebuffer[mb_tail].endpoint.Z, movebuffer[mb_tail].endpoint.F,
#ifdef ACCELERATION_REPRAP
movebuffer[mb_tail].end_c
#else
View
1  gcode_process.h
@@ -11,7 +11,6 @@ extern uint8_t next_tool;
void zero_x(void);
void zero_y(void);
void zero_z(void);
-void zero_e(void);
// this is where we construct a move without a gcode command, useful for gcodes which require multiple moves eg; homing
void SpecialMoveE(int32_t e, uint32_t f);
View
253 heater.c
@@ -1,253 +0,0 @@
-#include "heater.h"
-
-#include <stdlib.h>
-#include <avr/eeprom.h>
-#include <avr/pgmspace.h>
-
-#include "arduino.h"
-#include "debug.h"
-#ifndef EXTRUDER
-#include "sersendf.h"
-#endif
-
-#define HEATER_C
-#include "config.h"
-
-// this struct holds the heater PID factors that are stored in the EEPROM during poweroff
-struct {
- int32_t p_factor;
- int32_t i_factor;
- int32_t d_factor;
- int16_t i_limit;
-} heaters_pid[NUM_HEATERS];
-
-// this struct holds the runtime heater data- PID integrator history, temperature history, sanity checker
-struct {
- int16_t heater_i;
-
- uint16_t temp_history[TH_COUNT];
- uint8_t temp_history_pointer;
-
- #ifdef HEATER_SANITY_CHECK
- uint16_t sanity_counter;
- uint16_t sane_temperature;
- #endif
-} heaters_runtime[NUM_HEATERS];
-
-#define DEFAULT_P 8192
-#define DEFAULT_I 512
-#define DEFAULT_D 24576
-#define DEFAULT_I_LIMIT 384
-
-// this lives in the eeprom so we can save our PID settings for each heater
-typedef struct {
- int32_t EE_p_factor;
- int32_t EE_i_factor;
- int32_t EE_d_factor;
- int16_t EE_i_limit;
-} EE_factor;
-
-EE_factor EEMEM EE_factors[NUM_HEATERS];
-
-void heater_init() {
- #if NUM_HEATERS > 0
- uint8_t i;
- // setup pins
- for (i = 0; i < NUM_HEATERS; i++) {
- *(heaters[i].heater_port) &= ~MASK(heaters[i].heater_pin);
- // DDR is always 1 address below PORT. ugly code but saves ram and an extra field in heaters[] which will never be used anywhere but here
- *(heaters[i].heater_port - 1) |= MASK(heaters[i].heater_pin);
- if (heaters[i].heater_pwm) {
- *heaters[i].heater_pwm = 0;
- // this is somewhat ugly too, but switch() won't accept pointers for reasons unknown
- switch((uint16_t) heaters[i].heater_pwm) {
- case (uint16_t) &OCR0A:
- TCCR0A |= MASK(COM0A1);
- break;
- case (uint16_t) &OCR0B:
- TCCR0A |= MASK(COM0B1);
- break;
- case (uint16_t) &OCR2A:
- TCCR2A |= MASK(COM2A1);
- break;
- case (uint16_t) &OCR2B:
- TCCR2A |= MASK(COM2B1);
- break;
- }
- }
-
- #ifdef HEATER_SANITY_CHECK
- // 0 is a "sane" temperature when we're trying to cool down
- heaters_runtime[i].sane_temperature = 0;
- #endif
-
- // read factors from eeprom
- heaters_pid[i].p_factor = eeprom_read_dword((uint32_t *) &EE_factors[i].EE_p_factor);
- heaters_pid[i].i_factor = eeprom_read_dword((uint32_t *) &EE_factors[i].EE_i_factor);
- heaters_pid[i].d_factor = eeprom_read_dword((uint32_t *) &EE_factors[i].EE_d_factor);
- heaters_pid[i].i_limit = eeprom_read_word((uint16_t *) &EE_factors[i].EE_i_limit);
-
- if ((heaters_pid[i].p_factor == 0) && (heaters_pid[i].i_factor == 0) && (heaters_pid[i].d_factor == 0) && (heaters_pid[i].i_limit == 0)) {
- heaters_pid[i].p_factor = DEFAULT_P;
- heaters_pid[i].i_factor = DEFAULT_I;
- heaters_pid[i].d_factor = DEFAULT_D;
- heaters_pid[i].i_limit = DEFAULT_I_LIMIT;
- }
- }
- #endif /* NUM_HEATERS > 0 */
-}
-
-void heater_save_settings() {
- #if NUM_HEATERS > 0
- uint8_t i;
- for (i = 0; i < NUM_HEATERS; i++) {
- eeprom_write_dword((uint32_t *) &EE_factors[i].EE_p_factor, heaters_pid[i].p_factor);
- eeprom_write_dword((uint32_t *) &EE_factors[i].EE_i_factor, heaters_pid[i].i_factor);
- eeprom_write_dword((uint32_t *) &EE_factors[i].EE_d_factor, heaters_pid[i].d_factor);
- eeprom_write_word((uint16_t *) &EE_factors[i].EE_i_limit, heaters_pid[i].i_limit);
- }
- #endif /* NUM_HEATERS > 0 */
-}
-
-void heater_tick(uint8_t h, uint8_t t, uint16_t current_temp, uint16_t target_temp) {
- #if (NUM_HEATERS > 0) && (NUM_TEMP_SENSORS > 0)
- int16_t heater_p;
- int16_t heater_d;
- uint8_t pid_output;
-
- int16_t t_error = target_temp - current_temp;
-
- heaters_runtime[h].temp_history[heaters_runtime[h].temp_history_pointer++] = current_temp;
- heaters_runtime[h].temp_history_pointer &= (TH_COUNT - 1);
-
- // PID stuff
- // proportional
- heater_p = t_error;
-
- // integral
- heaters_runtime[h].heater_i += t_error;
- // prevent integrator wind-up
- if (heaters_runtime[h].heater_i > heaters_pid[h].i_limit)
- heaters_runtime[h].heater_i = heaters_pid[h].i_limit;
- else if (heaters_runtime[h].heater_i < -heaters_pid[h].i_limit)
- heaters_runtime[h].heater_i = -heaters_pid[h].i_limit;
-
- // derivative
- // note: D follows temp rather than error so there's no large derivative when the target changes
- heater_d = heaters_runtime[h].temp_history[heaters_runtime[h].temp_history_pointer] - current_temp;
-
- // combine factors
- int32_t pid_output_intermed = (
- (
- (((int32_t) heater_p) * heaters_pid[h].p_factor) +
- (((int32_t) heaters_runtime[h].heater_i) * heaters_pid[h].i_factor) +
- (((int32_t) heater_d) * heaters_pid[h].d_factor)
- ) / PID_SCALE
- );
-
- // rebase and limit factors
- if (pid_output_intermed > 255)
- pid_output = 255;
- else if (pid_output_intermed < 0)
- pid_output = 0;
- else
- pid_output = pid_output_intermed & 0xFF;
-
- #ifdef DEBUG
- if (debug_flags & DEBUG_PID)
- sersendf_P(PSTR("T{E:%d, P:%d * %ld = %ld / I:%d * %ld = %ld / D:%d * %ld = %ld # O: %ld = %u}\n"), t_error, heater_p, heaters_pid[h].p_factor, (int32_t) heater_p * heaters_pid[h].p_factor / PID_SCALE, heaters_runtime[h].heater_i, heaters_pid[h].i_factor, (int32_t) heaters_runtime[h].heater_i * heaters_pid[h].i_factor / PID_SCALE, heater_d, heaters_pid[h].d_factor, (int32_t) heater_d * heaters_pid[h].d_factor / PID_SCALE, pid_output_intermed, pid_output);
- #endif
-
- #ifdef HEATER_SANITY_CHECK
- // check heater sanity
- // implementation is a moving window with some slow-down to compensate for thermal mass
- if (target_temp > (current_temp + TEMP_HYSTERESIS)) {
- // heating
- if (current_temp > heaters_runtime[h].sane_temperature)
- // hotter than sane- good since we're heating unless too hot
- heaters_runtime[h].sane_temperature = current_temp;
- else {
- if (heaters_runtime[h].sanity_counter < 40)
- heaters_runtime[h].sanity_counter++;
- else {
- heaters_runtime[h].sanity_counter = 0;
- // ratchet up expected temp
- heaters_runtime[h].sane_temperature++;
- }
- }
- // limit to target, so if we overshoot by too much for too long an error is flagged
- if (heaters_runtime[h].sane_temperature > target_temp)
- heaters_runtime[h].sane_temperature = target_temp;
- }
- else if (target_temp < (current_temp - TEMP_HYSTERESIS)) {
- // cooling
- if (current_temp < heaters_runtime[h].sane_temperature)
- // cooler than sane- good since we're cooling
- heaters_runtime[h].sane_temperature = current_temp;
- else {
- if (heaters_runtime[h].sanity_counter < 125)
- heaters_runtime[h].sanity_counter++;
- else {
- heaters_runtime[h].sanity_counter = 0;
- // ratchet down expected temp
- heaters_runtime[h].sane_temperature--;
- }
- }
- // if we're at or below 60 celsius, don't freak out if we can't drop any more.
- if (current_temp <= 240)
- heaters_runtime[h].sane_temperature = current_temp;
- // limit to target, so if we don't cool down for too long an error is flagged
- else if (heaters_runtime[h].sane_temperature < target_temp)
- heaters_runtime[h].sane_temperature = target_temp;
- }
- // we're within HYSTERESIS of our target
- else {
- heaters_runtime[h].sane_temperature = current_temp;
- heaters_runtime[h].sanity_counter = 0;
- }
-
- // compare where we're at to where we should be
- if (labs(current_temp - heaters_runtime[h].sane_temperature) > TEMP_HYSTERESIS) {
- // no change, or change in wrong direction for a long time- heater is broken!
- pid_output = 0;
- sersendf_P(PSTR("!! heater %d or temp sensor %d broken- temp is %d.%dC, target is %d.%dC, didn't reach %d.%dC in %d0 milliseconds\n"), h, t, current_temp >> 2, (current_temp & 3) * 25, target_temp >> 2, (target_temp & 3) * 25, heaters_runtime[h].sane_temperature >> 2, (heaters_runtime[h].sane_temperature & 3) * 25, heaters_runtime[h].sanity_counter);
- }
- #endif /* HEATER_SANITY_CHECK */
-
- heater_set(h, pid_output);
- #endif /* if NUM_HEATERS > 0 && NUM_TEMP_SENSORS > 0 */
-}
-
-void heater_set(uint8_t index, uint8_t value) {
- #if NUM_HEATERS > 0
- if (heaters[index].heater_pwm) {
- *(heaters[index].heater_pwm) = value;
- #ifdef DEBUG
- if (debug_flags & DEBUG_PID)
- sersendf_P(PSTR("PWM{%u = %u}\n"), index, OCR0A);
- #endif
- }
- else {
- if (value >= 8)
- *(heaters[index].heater_port) |= MASK(heaters[index].heater_pin);
- else
- *(heaters[index].heater_port) &= ~MASK(heaters[index].heater_pin);
- }
- #endif /* if NUM_HEATERS > 0 */
-}
-
-void pid_set_p(uint8_t index, int32_t p) {
- heaters_pid[index].p_factor = p;
-}
-
-void pid_set_i(uint8_t index, int32_t i) {
- heaters_pid[index].i_factor = i;
-}
-
-void pid_set_d(uint8_t index, int32_t d) {
- heaters_pid[index].d_factor = d;
-}
-
-void pid_set_i_limit(uint8_t index, int32_t i_limit) {
- heaters_pid[index].i_limit = i_limit;
-}
View
20 heater.h
@@ -1,20 +0,0 @@
-#ifndef _HEATER_H
-#define _HEATER_H
-
-#include <stdint.h>
-
-#define enable_heater() heater_set(0, 64)
-#define disable_heater() heater_set(0, 0)
-
-void heater_init(void);
-void heater_save_settings(void);
-
-void heater_set(uint8_t index, uint8_t value);
-void heater_tick(uint8_t h, uint8_t t, uint16_t current_temp, uint16_t target_temp);
-
-void pid_set_p(uint8_t index, int32_t p);
-void pid_set_i(uint8_t index, int32_t i);
-void pid_set_d(uint8_t index, int32_t d);
-void pid_set_i_limit(uint8_t index, int32_t i_limit);
-
-#endif /* _HEATER_H */
View
219 intercom.c
@@ -1,219 +0,0 @@
-#include "intercom.h"
-
-#include <avr/interrupt.h>
-
-#include "config.h"
-#include "delay.h"
-
-#ifdef GEN3
-#define INTERCOM_BAUD 57600
-
-#define enable_transmit() do { WRITE(TX_ENABLE_PIN,1); WRITE(RX_ENABLE_PIN,0); } while(0)
-#define disable_transmit() do { WRITE(TX_ENABLE_PIN,0); WRITE(RX_ENABLE_PIN,0); } while(0)
-
-/*
- Defines a super simple intercom interface using the RS485 modules
-
- Host will say: START1 START2 PWM_CMD PWM_CHK
- Extruder will reply: START1 START2 TMP_CMD TMP_CHK
-
- CHK = 255-CMD, if they match do the work, if not, ignore this packet
-
- in a loop
-*/
-
-
-#define START1 0xAA
-#define START2 0x55
-
-typedef enum {
- SEND_START1,
- SEND_START2,
- SEND_CMD,
- SEND_CHK,
- SEND_DONE,
-
- READ_START1,
- READ_START2,
- READ_CMD,
- READ_CHK,
-} intercom_state_e;
-
-
-intercom_state_e state = READ_START1;
-uint8_t cmd, chk, send_cmd, read_cmd;
-
-void intercom_init(void)
-{
-#ifdef HOST
- #if INTERCOM_BAUD > 38401
- UCSR1A = MASK(U2X1);
- UBRR1 = (((F_CPU / 8) / INTERCOM_BAUD) - 0.5);
- #else
- UCSR1A = 0;
- UBRR1 = (((F_CPU / 16) / INTERCOM_BAUD) - 0.5);
- #endif
- UCSR1B = MASK(RXEN1) | MASK(TXEN1);
- UCSR1C = MASK(UCSZ11) | MASK(UCSZ10);
-
- UCSR1B |= MASK(RXCIE1) | MASK(TXCIE1);
-#else
- #if INTERCOM_BAUD > 38401
- UCSR0A = MASK(U2X0);
- UBRR0 = (((F_CPU / 8) / INTERCOM_BAUD) - 0.5);
- #else
- UCSR0A = 0;
- UBRR0 = (((F_CPU / 16) / INTERCOM_BAUD) - 0.5);
- #endif
- UCSR0B = MASK(RXEN0) | MASK(TXEN0);
- UCSR0C = MASK(UCSZ01) | MASK(UCSZ00);
-
- UCSR0B |= MASK(RXCIE0) | MASK(TXCIE0);
-#endif
-}
-
-void update_send_cmd(uint8_t new_send_cmd) {
- send_cmd = new_send_cmd;
-}
-
-uint8_t get_read_cmd(void) {
- return read_cmd;
-}
-
-static void write_byte(uint8_t val) {
-#ifdef HOST
- UDR1 = val;
-#else
- UDR0 = val;
-#endif
-}
-
-
-void start_send(void) {
- state = SEND_START1;
- enable_transmit();
- delay_us(15);
- //Enable interrupts so we can send next characters
-#ifdef HOST
- UCSR1B |= MASK(UDRIE1);
-#else
- UCSR0B |= MASK(UDRIE0);
-#endif
-}
-
-static void finish_send(void) {
- state = READ_START1;
- disable_transmit();
-}
-
-
-/*
- Interrupts, UART 0 for mendel
-*/
-#ifdef HOST
-ISR(USART1_RX_vect)
-#else
-ISR(USART_RX_vect)
-#endif
-{
- static uint8_t c;
-
-#ifdef HOST
- c = UDR1;
- UCSR1A &= ~MASK(FE1) & ~MASK(DOR1) & ~MASK(UPE1);
-#else
- c = UDR0;
- UCSR0A &= ~MASK(FE0) & ~MASK(DOR0) & ~MASK(UPE0);
-#endif
-
- if (state >= READ_START1) {
-
- switch(state) {
- case READ_START1:
- if (c == START1) state = READ_START2;
- break;
- case READ_START2:
- if (c == START2) state = READ_CMD;
- else state = READ_START1;
- break;
- case READ_CMD:
- cmd = c;
- state = READ_CHK;
- break;
- case READ_CHK:
- chk = c;
-
- if (chk == 255 - cmd) {
- //Values are correct, do something useful
- WRITE(DEBUG_LED,1);
- read_cmd = cmd;
-#ifdef EXTRUDER
- start_send();
-#endif
- }
- else
- {
- state = READ_START1;
- }
- break;
- default:
- break;
- }
- }
-
-}
-
-#ifdef HOST
-ISR(USART1_TX_vect)
-#else
-ISR(USART_TX_vect)
-#endif
-{
- if (state == SEND_DONE) {
- finish_send();
-
-
-#ifdef HOST
- UCSR1B &= ~MASK(TXCIE1);
-#else
- UCSR0B &= ~MASK(TXCIE0);
-#endif
- }
-}
-
-#ifdef HOST
-ISR(USART1_UDRE_vect)
-#else
-ISR(USART_UDRE_vect)
-#endif
-{
- switch(state) {
- case SEND_START1:
- write_byte(START1);
- state = SEND_START2;
- break;
- case SEND_START2:
- write_byte(START2);
- state = SEND_CMD;
- break;
- case SEND_CMD:
- write_byte(send_cmd);
- state = SEND_CHK;
- break;
- case SEND_CHK:
- write_byte(255 - send_cmd);
- state = SEND_DONE;
-#ifdef HOST
- UCSR1B &= ~MASK(UDRIE1);
- UCSR1B |= MASK(TXCIE1);
-#else
- UCSR0B &= ~MASK(UDRIE0);
- UCSR0B |= MASK(TXCIE0);
-#endif
- break;
- default:
- break;
- }
-}
-
-#endif /* GEN3 */
View
17 intercom.h
@@ -1,17 +0,0 @@
-#ifndef _INTERCOM_H
-#define _INTERCOM_H
-
-#include <stdint.h>
-
-// initialise serial subsystem
-void intercom_init(void);
-
-//Update the message we are sending over intercom
-void update_send_cmd(uint8_t new_send_cmd);
-
-void start_send(void);
-
-//Read the message we are receiving over intercom
-uint8_t get_read_cmd(void);
-
-#endif /* _INTERCOM_H */
View
13 mendel.c
@@ -10,13 +10,9 @@
#include "dda.h"
#include "gcode_parse.h"