Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1

This commit is contained in:
Bernhard 2011-12-22 09:22:39 +01:00
commit 4bababf5b0
14 changed files with 5873 additions and 5599 deletions

View file

@ -43,16 +43,20 @@
// 5 is ParCan supplied 104GT-2 100K
// 6 is EPCOS 100k
// 7 is 100k Honeywell thermistor 135-104LAG-J01
//#define THERMISTORHEATER_0 3
//#define THERMISTORHEATER_1 3
//#define THERMISTORBED 3
//#define THERMISTORHEATER_1 1
//#define THERMISTORHEATER_2 1
//#define HEATER_0_USES_THERMISTOR
//#define HEATER_1_USES_THERMISTOR
//#define HEATER_2_USES_THERMISTOR
#define HEATER_0_USES_AD595
//#define HEATER_1_USES_AD595
//#define HEATER_2_USES_AD595
// Select one of these only to define how the bed temp is read.
//#define THERMISTORBED 1
//#define BED_USES_THERMISTOR
//#define BED_USES_AD595
@ -65,12 +69,13 @@
//#define WATCHPERIOD 20000 //20 seconds
// Actual temperature must be close to target for this long before M109 returns success
//#define TEMP_RESIDENCY_TIME 20 // (seconds)
//#define TEMP_HYSTERESIS 5 // (C°) range of +/- temperatures considered "close" to the target one
#define TEMP_RESIDENCY_TIME 30 // (seconds)
#define TEMP_HYSTERESIS 3 // (C°) range of +/- temperatures considered "close" to the target one
//// The minimal temperature defines the temperature below which the heater will not be enabled
#define HEATER_0_MINTEMP 5
//#define HEATER_1_MINTEMP 5
//#define HEATER_2_MINTEMP 5
//#define BED_MINTEMP 5
@ -79,6 +84,7 @@
// You should use MINTEMP for thermistor short/failure protection.
#define HEATER_0_MAXTEMP 275
//#define HEATER_1_MAXTEMP 275
//#define HEATER_2_MAXTEMP 275
//#define BED_MAXTEMP 150
@ -90,21 +96,17 @@
// Heating is finished if a temperature close to this degree shift is reached
#define HEATING_EARLY_FINISH_DEG_OFFSET 1 //Degree
// PID settings:
// Uncomment the following line to enable PID support.
#define PIDTEMP
#define PID_MAX 255 // limits current to nozzle; 255=full current
#ifdef PIDTEMP
#if MOTHERBOARD == 62
#error Sanguinololu does not support PID, sorry. Please disable it.
#endif
//#define PID_DEBUG // Sends debug data to the serial port.
//#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
#define PID_MAX 255 // limits current to nozzle; 255=full current
#define PID_INTEGRAL_DRIVE_MAX 255 //limit for the integral term
#define K1 0.95 //smoothing factor withing the PID
#define PID_dT 0.1 //sampling period of the PID
#define PID_dT 0.128 //sampling period of the PID
//To develop some PID settings for your machine, you can initiall follow
// the Ziegler-Nichols method.
@ -132,6 +134,11 @@
#define DEFAULT_Ki (1.25*PID_dT)
#define DEFAULT_Kd (99/PID_dT)
// Makergear
// #define DEFAULT_Kp 7.0
// #define DEFAULT_Ki 0.1
// #define DEFAULT_Kd 12
// Mendel Parts V9 on 12V
// #define DEFAULT_Kp 63.0
// #define DEFAULT_Ki (2.25*PID_dT)
@ -149,7 +156,7 @@
// if Kc is choosen well, the additional required power due to increased melting should be compensated.
#define PID_ADD_EXTRUSION_RATE
#ifdef PID_ADD_EXTRUSION_RATE
#define DEFAULT_Kc (3) //heatingpower=Kc*(e_speed)
#define DEFAULT_Kc (1) //heatingpower=Kc*(e_speed)
#endif
#endif // PIDTEMP
@ -169,36 +176,39 @@
// Endstop Settings
#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
const bool X_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
const bool Y_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
// For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
//#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
#define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
#define X_ENABLE_ON 0
#define Y_ENABLE_ON 0
#define Z_ENABLE_ON 0
#define E_ENABLE_ON 0
#define E_ENABLE_ON 0 // For all extruders
// Disables axis when it's not being used.
#define DISABLE_X false
#define DISABLE_Y false
#define DISABLE_Z false
#define DISABLE_E false
#define DISABLE_E false // For all extruders
// Inverting axis direction
//#define INVERT_X_DIR false // for Mendel set to false, for Orca set to true
//#define INVERT_Y_DIR true // for Mendel set to true, for Orca set to false
//#define INVERT_Z_DIR false // for Mendel set to false, for Orca set to true
//#define INVERT_E_DIR true // for direct drive extruder v9 set to true, for geared extruder set to false
//#define INVERT_E*_DIR true // for direct drive extruder v9 set to true, for geared extruder set to false, used for all extruders
#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true
#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true
#define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false
#define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true
#define INVERT_E_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false
#define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false
#define INVERT_E1_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false
#define INVERT_E2_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false
//// ENDSTOP SETTINGS:
// Sets direction of endstops when homing; 1=MAX, -1=MIN
@ -206,11 +216,11 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
#define Y_HOME_DIR -1
#define Z_HOME_DIR -1
#define min_software_endstops false //If true, axis won't move to coordinates less than zero.
#define max_software_endstops false //If true, axis won't move to coordinates greater than the defined lengths below.
#define X_MAX_LENGTH 210
#define Y_MAX_LENGTH 210
#define Z_MAX_LENGTH 210
#define min_software_endstops true //If true, axis won't move to coordinates less than zero.
#define max_software_endstops true //If true, axis won't move to coordinates greater than the defined lengths below.
#define X_MAX_LENGTH 205
#define Y_MAX_LENGTH 205
#define Z_MAX_LENGTH 200
//// MOVEMENT SETTINGS
#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
@ -229,7 +239,8 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
// default settings
#define DEFAULT_AXIS_STEPS_PER_UNIT {78.7402,78.7402,200*8/3,760*1.1} // default steps per unit for ultimaker
//#define DEFAULT_AXIS_STEPS_PER_UNIT {40, 40, 3333.92, 67} //sells mendel with v9 extruder
//#define DEFAULT_AXIS_STEPS_PER_UNIT {40, 40, 3333.92, 360} //sells mendel with v9 extruder
//#define DEFAULT_AXIS_STEPS_PER_UNIT {80.3232, 80.8900, 2284.7651, 757.2218} // SAE Prusa w/ Wade extruder
#define DEFAULT_MAX_FEEDRATE {500, 500, 5, 45} // (mm/sec)
#define DEFAULT_MAX_ACCELERATION {9000,9000,100,10000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.
@ -285,10 +296,10 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
// hooke's law says: force = k * distance
// bernoulli's priniciple says: v ^ 2 / 2 + g . h + pressure / density = constant
// so: v ^ 2 is proportional to number of steps we advance the extruder
//#define ADVANCE
#define ADVANCE
#ifdef ADVANCE
#define EXTRUDER_ADVANCE_K .3
#define EXTRUDER_ADVANCE_K .0
#define D_FILAMENT 2.85
#define STEPS_MM_E 836
@ -304,7 +315,7 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th
#define SD_FINISHED_STEPPERRELEASE true //if sd support and the file is finished: disable steppers?
#define SD_FINISHED_RELEASECOMMAND "M84 X Y E" // no z because of layer shift.
//#define ULTIPANEL
#define ULTIPANEL
#ifdef ULTIPANEL
//#define NEWPANEL //enable this if you have a click-encoder panel
#define SDSUPPORT

View file

@ -101,14 +101,31 @@ void manage_inactivity(byte debug);
#define disable_z() ;
#endif
#if E_ENABLE_PIN > -1
#define enable_e() WRITE(E_ENABLE_PIN, E_ENABLE_ON)
#define disable_e() WRITE(E_ENABLE_PIN,!E_ENABLE_ON)
#if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1)
#define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON)
#define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON)
#else
#define enable_e() ;
#define disable_e() ;
#define enable_e0() /* nothing */
#define disable_e0() /* nothing */
#endif
#if (EXTRUDERS > 1) && defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
#define enable_e1() WRITE(E1_ENABLE_PIN, E_ENABLE_ON)
#define disable_e1() WRITE(E1_ENABLE_PIN,!E_ENABLE_ON)
#else
#define enable_e1() /* nothing */
#define disable_e1() /* nothing */
#endif
#if (EXTRUDERS > 2) && defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
#define enable_e2() WRITE(E2_ENABLE_PIN, E_ENABLE_ON)
#define disable_e2() WRITE(E2_ENABLE_PIN,!E_ENABLE_ON)
#else
#define enable_e2() /* nothing */
#define disable_e2() /* nothing */
#endif
enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3};
@ -133,4 +150,7 @@ extern float current_position[NUM_AXIS] ;
extern float add_homeing[3];
extern bool stop_heating_wait;
// Handling multiple extruders pins
extern uint8_t active_extruder;
#endif

View file

@ -122,7 +122,6 @@
//===========================================================================
//=============================imported variables============================
//===========================================================================
extern float HeaterPower;
//===========================================================================
@ -136,9 +135,11 @@ bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
volatile int feedmultiply=100; //100->1 200->2
int saved_feedmultiply;
volatile bool feedmultiplychanged=false;
float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 };
float add_homeing[3]={0,0,0};
uint8_t active_extruder = 0;
bool stop_heating_wait=false;
//===========================================================================
//=============================private variables=============================
//===========================================================================
@ -470,16 +471,16 @@ FORCE_INLINE bool code_seen(char code)
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); \
destination[LETTER##_AXIS] = 1.5 * LETTER##_MAX_LENGTH * LETTER##_HOME_DIR; \
feedrate = homing_feedrate[LETTER##_AXIS]; \
prepare_move(); \
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
\
current_position[LETTER##_AXIS] = 0;\
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
destination[LETTER##_AXIS] = -LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
prepare_move(); \
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
\
destination[LETTER##_AXIS] = 2*LETTER##_HOME_RETRACT_MM * LETTER##_HOME_DIR;\
feedrate = homing_feedrate[LETTER##_AXIS]/2 ; \
prepare_move(); \
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); \
\
current_position[LETTER##_AXIS] = (LETTER##_HOME_DIR == -1) ? 0 : LETTER##_MAX_LENGTH;\
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);\
@ -543,6 +544,7 @@ FORCE_INLINE void process_commands()
if( code_seen(axis_codes[0]) && code_seen(axis_codes[1]) ) //first diagonal move
{
current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0;
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR;
feedrate = homing_feedrate[X_AXIS];
@ -582,7 +584,7 @@ FORCE_INLINE void process_commands()
}
if(code_seen(axis_codes[Y_AXIS])) {
current_position[1]=code_value()+add_homeing[1];
current_position[1]=code_value()+add_homeing[1];
}
if(code_seen(axis_codes[Z_AXIS])) {
@ -610,9 +612,11 @@ FORCE_INLINE void process_commands()
if(code_seen(axis_codes[i])) {
current_position[i] = code_value()+add_homeing[i];
if(i == E_AXIS) {
current_position[i] = code_value();
plan_set_e_position(current_position[E_AXIS]);
}
else {
current_position[i] = code_value()+add_homeing[i];
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
}
}
@ -623,7 +627,6 @@ FORCE_INLINE void process_commands()
else if(code_seen('M'))
{
switch( (int)code_value() )
{
case 17:
@ -631,10 +634,12 @@ FORCE_INLINE void process_commands()
enable_x();
enable_y();
enable_z();
enable_e();
enable_e0();
enable_e1();
enable_e2();
break;
#ifdef SDSUPPORT
#ifdef SDSUPPORT
case 20: // M20 - list SD card
SERIAL_PROTOCOLLNPGM("Begin file list");
card.ls();
@ -663,9 +668,8 @@ FORCE_INLINE void process_commands()
card.pauseSDPrint();
break;
case 26: //M26 - Set SD index
if(card.cardOK && code_seen('S')){
if(card.cardOK && code_seen('S')) {
card.setIndex(code_value_long());
}
break;
case 27: //M27 - Get SD status
@ -679,16 +683,15 @@ FORCE_INLINE void process_commands()
*(starpos-1) = '\0';
}
card.openFile(strchr_pointer+4,false);
break;
case 29: //M29 - Stop SD write
//processed in write to file routine above
//card,saving = false;
break;
#endif //SDSUPPORT
#endif //SDSUPPORT
case 30: //M30 take time since the start of the SD print or an M109 command
{
{
stoptime=millis();
char time[30];
unsigned long t=(stoptime-starttime)/1000;
@ -700,8 +703,8 @@ FORCE_INLINE void process_commands()
SERIAL_ECHOLN(time);
LCD_MESSAGE(time);
autotempShutdown();
}
break;
}
break;
case 42: //M42 -Change pin status via gcode
if (code_seen('S'))
{
@ -755,21 +758,20 @@ FORCE_INLINE void process_commands()
break;
}
}
#if (TEMP_0_PIN > -1) || (TEMP_2_PIN > -1)
#if (TEMP_0_PIN > -1)
SERIAL_PROTOCOLPGM("ok T:");
SERIAL_PROTOCOL( degHotend(tmp_extruder));
#if TEMP_1_PIN > -1
SERIAL_PROTOCOL(degHotend(tmp_extruder));
#if TEMP_BED_PIN > -1
SERIAL_PROTOCOLPGM(" B:");
SERIAL_PROTOCOL(degBed());
#endif //TEMP_1_PIN
#endif //TEMP_BED_PIN
#else
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("No thermistors - no temp");
#endif
#ifdef PIDTEMP
SERIAL_PROTOCOLPGM(" @:");
SERIAL_PROTOCOL( HeaterPower);
SERIAL_PROTOCOL(getHeaterPower(tmp_extruder));
#endif
SERIAL_PROTOCOLLN("");
return;
@ -812,19 +814,33 @@ FORCE_INLINE void process_commands()
residencyStart = -1;
/* continue to loop until we have reached the target temp
_and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
while((target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder))) ||
(residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
while((residencyStart == -1) ||
(residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
#else
while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
#endif //TEMP_RESIDENCY_TIME
if( (millis() - codenum) > 1000 )
{ //Print Temp Reading every 1 second while heating up/cooling down
SERIAL_PROTOCOLPGM("T:");
SERIAL_PROTOCOLLN( degHotend(tmp_extruder) );
codenum = millis();
}
manage_heater();
LCD_STATUS;
if( (millis() - codenum) > 1000 )
{ //Print Temp Reading and remaining time every 1 second while heating up/cooling down
SERIAL_PROTOCOLPGM("T:");
SERIAL_PROTOCOL( degHotend(tmp_extruder) );
SERIAL_PROTOCOLPGM(" E:");
SERIAL_PROTOCOL( (int)tmp_extruder );
#ifdef TEMP_RESIDENCY_TIME
SERIAL_PROTOCOLPGM(" W:");
if(residencyStart > -1)
{
codenum = TEMP_RESIDENCY_TIME - ((millis() - residencyStart) / 1000);
SERIAL_PROTOCOLLN( codenum );
}
else
{
SERIAL_PROTOCOLLN( "?" );
}
#endif
codenum = millis();
}
manage_heater();
LCD_STATUS;
if(stop_heating_wait) break;
#ifdef TEMP_RESIDENCY_TIME
/* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
@ -842,8 +858,8 @@ FORCE_INLINE void process_commands()
previous_millis_cmd = millis();
}
break;
case 190: // M190 - Wait bed for heater to reach target.
#if TEMP_1_PIN > -1
case 190: // M190 - Wait for bed heater to reach target.
#if TEMP_BED_PIN > -1
LCD_MESSAGEPGM("Bed Heating.");
if (code_seen('S')) setTargetBed(code_value());
codenum = millis();
@ -851,13 +867,13 @@ FORCE_INLINE void process_commands()
{
if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
{
float tt=degHotend0();
float tt=degHotend(active_extruder);
SERIAL_PROTOCOLPGM("T:");
SERIAL_PROTOCOLLN(tt );
SERIAL_PROTOCOLPGM("ok T:");
SERIAL_PROTOCOL(tt );
SERIAL_PROTOCOL(tt);
SERIAL_PROTOCOLPGM(" E:");
SERIAL_PROTOCOL( (int)active_extruder );
SERIAL_PROTOCOLPGM(" B:");
SERIAL_PROTOCOLLN(degBed() );
SERIAL_PROTOCOLLN(degBed());
codenum = millis();
}
manage_heater();
@ -910,6 +926,9 @@ FORCE_INLINE void process_commands()
bool all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))|| (code_seen(axis_codes[3])));
if(all_axis)
{
disable_e0();
disable_e1();
disable_e2();
finishAndDisableSteppers();
}
else
@ -918,8 +937,12 @@ FORCE_INLINE void process_commands()
if(code_seen('X')) disable_x();
if(code_seen('Y')) disable_y();
if(code_seen('Z')) disable_z();
#if ((E_ENABLE_PIN != X_ENABLE_PIN) && (E_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS
if(code_seen('E')) disable_e();
#if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS
if(code_seen('E')) {
disable_e0();
disable_e1();
disable_e2();
}
#endif
LCD_MESSAGEPGM("Partial Release");
}
@ -1100,7 +1123,9 @@ FORCE_INLINE void process_commands()
}
}
else if(code_seen('T')) {
else if(code_seen('T'))
{
tmp_extruder = code_value();
if(tmp_extruder >= EXTRUDERS) {
SERIAL_ECHO_START;
@ -1110,8 +1135,12 @@ FORCE_INLINE void process_commands()
}
else {
active_extruder = tmp_extruder;
SERIAL_ECHO_START;
SERIAL_ECHO("Active Extruder: ");
SERIAL_PROTOCOLLN((int)active_extruder);
}
}
else
{
SERIAL_ECHO_START;
@ -1219,8 +1248,8 @@ void manage_inactivity(byte debug)
if( (millis()-previous_millis_cmd) > EXTRUDER_RUNOUT_SECONDS*1000 )
if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP)
{
bool oldstatus=READ(E_ENABLE_PIN);
enable_e();
bool oldstatus=READ(E0_ENABLE_PIN);
enable_e0();
float oldepos=current_position[E_AXIS];
float oldedes=destination[E_AXIS];
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS],
@ -1232,7 +1261,7 @@ void manage_inactivity(byte debug)
previous_millis_cmd=millis();
//enquecommand(DEFAULT_STEPPER_DEACTIVE_COMMAND);
st_synchronize();
WRITE(E_ENABLE_PIN,oldstatus);
WRITE(E0_ENABLE_PIN,oldstatus);
}
#endif
check_axes_activity();
@ -1240,12 +1269,15 @@ void manage_inactivity(byte debug)
void kill()
{
cli(); // Stop interrupts
disable_heater();
disable_x();
disable_y();
disable_z();
disable_e();
disable_e0();
disable_e1();
disable_e2();
if(PS_ON_PIN > -1) pinMode(PS_ON_PIN,INPUT);
SERIAL_ERROR_START;

View file

@ -442,4 +442,4 @@ void CardReader::printingHasFinished()
}
autotempShutdown();
}
#endif //SDSUPPORT
#endif //SDSUPPORT

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -56,9 +56,9 @@
//#include <math.h>
//#include <stdlib.h>
#include "Marlin.h"
#include "Configuration.h"
#include "pins.h"
#include "Marlin.h"
#include "fastio.h"
#include "planner.h"
#include "stepper.h"
@ -81,8 +81,6 @@ float max_z_jerk;
float mintravelfeedrate;
unsigned long axis_steps_per_sqr_second[NUM_AXIS];
uint8_t active_extruder = 0;
// The current position of the tool in absolute steps
long position[4]; //rescaled from extern when axis_steps_per_unit are changed by gcode
static float previous_speed[4]; // Speed of previous path line segment
@ -95,7 +93,6 @@ static float previous_nominal_speed; // Nominal speed of previous path line segm
bool autotemp_enabled=false;
#endif
//===========================================================================
//=================semi-private variables, used in inline functions =====
//===========================================================================
@ -196,8 +193,8 @@ void calculate_trapezoid_for_block(block_t *block, float entry_factor, float exi
}
#ifdef ADVANCE
long initial_advance = block->advance*entry_factor*entry_factor;
long final_advance = block->advance*exit_factor*exit_factor;
volatile long initial_advance = block->advance*entry_factor*entry_factor;
volatile long final_advance = block->advance*exit_factor*exit_factor;
#endif // ADVANCE
// block->accelerate_until = accelerate_steps;
@ -439,7 +436,7 @@ void check_axes_activity() {
if((DISABLE_X) && (x_active == 0)) disable_x();
if((DISABLE_Y) && (y_active == 0)) disable_y();
if((DISABLE_Z) && (z_active == 0)) disable_z();
if((DISABLE_E) && (e_active == 0)) disable_e();
if((DISABLE_E) && (e_active == 0)) { disable_e0();disable_e1();disable_e2(); }
}
@ -514,15 +511,10 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa
if(block->steps_x != 0) enable_x();
if(block->steps_y != 0) enable_y();
if(block->steps_z != 0) enable_z();
if(extruder == 0) {
if(block->steps_e != 0) enable_e();
}
#if (EXTRUDERS > 1)
if(extruder == 1) {
if(block->steps_e != 0) enable_e1();
}
#endif
// Enable all
if(block->steps_e != 0) { enable_e0();enable_e1();enable_e2(); }
float delta_mm[4];
delta_mm[X_AXIS] = (target[X_AXIS]-position[X_AXIS])/axis_steps_per_unit[X_AXIS];
delta_mm[Y_AXIS] = (target[Y_AXIS]-position[Y_AXIS])/axis_steps_per_unit[Y_AXIS];
@ -809,4 +801,4 @@ void allow_cold_extrudes(bool allow)
#ifdef PREVENT_DANGEROUS_EXTRUDE
allow_cold_extrude=allow;
#endif
}
}

View file

@ -91,8 +91,6 @@ extern float max_z_jerk;
extern float mintravelfeedrate;
extern unsigned long axis_steps_per_sqr_second[NUM_AXIS];
extern uint8_t active_extruder;
#ifdef AUTOTEMP
extern bool autotemp_enabled;
extern float autotemp_max;

View file

@ -24,9 +24,9 @@
#include "stepper.h"
#include "Configuration.h"
#include "pins.h"
#include "Marlin.h"
#include "planner.h"
#include "pins.h"
#include "fastio.h"
#include "temperature.h"
#include "ultralcd.h"
@ -41,7 +41,6 @@
block_t *current_block; // A pointer to the block currently being traced
//===========================================================================
//=============================private variables ============================
//===========================================================================
@ -58,7 +57,7 @@ volatile static unsigned long step_events_completed; // The number of step event
static long advance_rate, advance, final_advance = 0;
static long old_advance = 0;
#endif
static long e_steps;
static long e_steps[3];
static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
static long acceleration_time, deceleration_time;
//static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
@ -267,7 +266,7 @@ FORCE_INLINE void trapezoid_generator_reset() {
advance = current_block->initial_advance;
final_advance = current_block->final_advance;
// Do E steps + advance steps
e_steps += ((advance >>8) - old_advance);
e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
old_advance = advance >>8;
#endif
deceleration_time = 0;
@ -304,8 +303,8 @@ ISR(TIMER1_COMPA_vect)
counter_z = counter_x;
counter_e = counter_x;
step_events_completed = 0;
// #ifdef ADVANCE
e_steps = 0;
// #ifdef ADVANCE
// e_steps[current_block->active_extruder] = 0;
// #endif
}
else {
@ -419,11 +418,11 @@ ISR(TIMER1_COMPA_vect)
#ifndef ADVANCE
if ((out_bits & (1<<E_AXIS)) != 0) { // -direction
WRITE(E_DIR_PIN,INVERT_E_DIR);
REV_E_DIR();
count_direction[E_AXIS]=-1;
}
else { // +direction
WRITE(E_DIR_PIN,!INVERT_E_DIR);
NORM_E_DIR();
count_direction[E_AXIS]=-1;
}
#endif //!ADVANCE
@ -438,10 +437,10 @@ ISR(TIMER1_COMPA_vect)
if (counter_e > 0) {
counter_e -= current_block->step_event_count;
if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
e_steps--;
e_steps[current_block->active_extruder]--;
}
else {
e_steps++;
e_steps[current_block->active_extruder]++;
}
}
#endif //ADVANCE
@ -473,9 +472,9 @@ ISR(TIMER1_COMPA_vect)
#ifndef ADVANCE
counter_e += current_block->steps_e;
if (counter_e > 0) {
WRITE(E_STEP_PIN, HIGH);
WRITE_E_STEP(HIGH);
counter_e -= current_block->step_event_count;
WRITE(E_STEP_PIN, LOW);
WRITE_E_STEP(LOW);
count_position[E_AXIS]+=count_direction[E_AXIS];
}
#endif //!ADVANCE
@ -504,7 +503,7 @@ ISR(TIMER1_COMPA_vect)
}
//if(advance > current_block->advance) advance = current_block->advance;
// Do E steps + advance steps
e_steps += ((advance >>8) - old_advance);
e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
old_advance = advance >>8;
#endif
@ -533,7 +532,7 @@ ISR(TIMER1_COMPA_vect)
}
if(advance < final_advance) advance = final_advance;
// Do E steps + advance steps
e_steps += ((advance >>8) - old_advance);
e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
old_advance = advance >>8;
#endif //ADVANCE
}
@ -558,27 +557,57 @@ ISR(TIMER1_COMPA_vect)
old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
OCR0A = old_OCR0A;
// Set E direction (Depends on E direction + advance)
for(unsigned char i=0; i<4;) {
WRITE(E_STEP_PIN, LOW);
if (e_steps == 0) break;
i++;
if (e_steps < 0) {
WRITE(E_DIR_PIN,INVERT_E_DIR);
e_steps++;
WRITE(E_STEP_PIN, HIGH);
}
else if (e_steps > 0) {
WRITE(E_DIR_PIN,!INVERT_E_DIR);
e_steps--;
WRITE(E_STEP_PIN, HIGH);
for(unsigned char i=0; i<4;i++) {
if (e_steps[0] != 0) {
WRITE(E0_STEP_PIN, LOW);
if (e_steps[0] < 0) {
WRITE(E0_DIR_PIN, INVERT_E0_DIR);
e_steps[0]++;
WRITE(E0_STEP_PIN, HIGH);
}
else if (e_steps[0] > 0) {
WRITE(E0_DIR_PIN, !INVERT_E0_DIR);
e_steps[0]--;
WRITE(E0_STEP_PIN, HIGH);
}
}
#if EXTRUDERS > 1
if (e_steps[1] != 0) {
WRITE(E1_STEP_PIN, LOW);
if (e_steps[1] < 0) {
WRITE(E1_DIR_PIN, INVERT_E1_DIR);
e_steps[1]++;
WRITE(E1_STEP_PIN, HIGH);
}
else if (e_steps[1] > 0) {
WRITE(E1_DIR_PIN, !INVERT_E1_DIR);
e_steps[1]--;
WRITE(E1_STEP_PIN, HIGH);
}
}
#endif
#if EXTRUDERS > 2
if (e_steps[2] != 0) {
WRITE(E2_STEP_PIN, LOW);
if (e_steps[2] < 0) {
WRITE(E2_DIR_PIN, INVERT_E2_DIR);
e_steps[2]++;
WRITE(E2_STEP_PIN, HIGH);
}
else if (e_steps[2] > 0) {
WRITE(E2_DIR_PIN, !INVERT_E2_DIR);
e_steps[2]--;
WRITE(E2_STEP_PIN, HIGH);
}
}
#endif
}
}
#endif // ADVANCE
void st_init()
{
//Initialize Dir Pins
//Initialize Dir Pins
#if X_DIR_PIN > -1
SET_OUTPUT(X_DIR_PIN);
#endif
@ -588,8 +617,14 @@ void st_init()
#if Z_DIR_PIN > -1
SET_OUTPUT(Z_DIR_PIN);
#endif
#if E_DIR_PIN > -1
SET_OUTPUT(E_DIR_PIN);
#if E0_DIR_PIN > -1
SET_OUTPUT(E0_DIR_PIN);
#endif
#if defined(E1_DIR_PIN) && (E1_DIR_PIN > -1)
SET_OUTPUT(E1_DIR_PIN);
#endif
#if defined(E2_DIR_PIN) && (E2_DIR_PIN > -1)
SET_OUTPUT(E2_DIR_PIN);
#endif
//Initialize Enable Pins - steppers default to disabled.
@ -606,9 +641,17 @@ void st_init()
SET_OUTPUT(Z_ENABLE_PIN);
if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
#endif
#if (E_ENABLE_PIN > -1)
SET_OUTPUT(E_ENABLE_PIN);
if(!E_ENABLE_ON) WRITE(E_ENABLE_PIN,HIGH);
#if (E0_ENABLE_PIN > -1)
SET_OUTPUT(E0_ENABLE_PIN);
if(!E_ENABLE_ON) WRITE(E0_ENABLE_PIN,HIGH);
#endif
#if defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
SET_OUTPUT(E1_ENABLE_PIN);
if(!E_ENABLE_ON) WRITE(E1_ENABLE_PIN,HIGH);
#endif
#if defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
SET_OUTPUT(E2_ENABLE_PIN);
if(!E_ENABLE_ON) WRITE(E2_ENABLE_PIN,HIGH);
#endif
//endstops and pullups
@ -669,8 +712,14 @@ void st_init()
#if (Z_STEP_PIN > -1)
SET_OUTPUT(Z_STEP_PIN);
#endif
#if (E_STEP_PIN > -1)
SET_OUTPUT(E_STEP_PIN);
#if (E0_STEP_PIN > -1)
SET_OUTPUT(E0_STEP_PIN);
#endif
#if defined(E1_STEP_PIN) && (E1_STEP_PIN > -1)
SET_OUTPUT(E1_STEP_PIN);
#endif
#if defined(E2_STEP_PIN) && (E2_STEP_PIN > -1)
SET_OUTPUT(E2_STEP_PIN);
#endif
// waveform generation = 0100 = CTC
@ -693,7 +742,9 @@ void st_init()
TCCR0A &= ~(1<<WGM01);
TCCR0A &= ~(1<<WGM00);
#endif
e_steps = 0;
e_steps[0] = 0;
e_steps[1] = 0;
e_steps[2] = 0;
TIMSK0 |= (1<<OCIE0A);
#endif //ADVANCE
@ -750,7 +801,9 @@ void finishAndDisableSteppers()
disable_x();
disable_y();
disable_z();
disable_e();
disable_e0();
disable_e1();
disable_e2();
}
void quickStop()

View file

@ -23,6 +23,21 @@
#include "planner.h"
#if EXTRUDERS > 2
#define WRITE_E_STEP(v) { if(current_block->active_extruder == 2) { WRITE(E2_STEP_PIN, v); } else { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }}}
#define NORM_E_DIR() { if(current_block->active_extruder == 2) { WRITE(!E2_DIR_PIN, INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(!E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}}
#define REV_E_DIR() { if(current_block->active_extruder == 2) { WRITE(E2_DIR_PIN, INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}}
#elif EXTRUDERS > 1
#define WRITE_E_STEP(v) { if(current_block->active_extruder == 1) { WRITE(E1_STEP_PIN, v); } else { WRITE(E0_STEP_PIN, v); }}
#define NORM_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, !INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, !INVERT_E0_DIR); }}
#define REV_E_DIR() { if(current_block->active_extruder == 1) { WRITE(E1_DIR_PIN, INVERT_E1_DIR); } else { WRITE(E0_DIR_PIN, INVERT_E0_DIR); }}
#else
#define WRITE_E_STEP(v) WRITE(E0_STEP_PIN, v)
#define NORM_E_DIR() WRITE(E0_DIR_PIN, !INVERT_E0_DIR)
#define REV_E_DIR() WRITE(E0_DIR_PIN, INVERT_E0_DIR)
#endif
// Initialize and start the stepper motor subsystem
void st_init();

View file

@ -26,7 +26,6 @@
It has preliminary support for Matthew Roberts advance algorithm
http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
This firmware is optimized for gen6 electronics.
*/
#include <avr/pgmspace.h>
@ -41,17 +40,14 @@
//===========================================================================
//=============================public variables============================
//===========================================================================
int target_raw[3] = {0, 0, 0};
int current_raw[3] = {0, 0, 0};
int heatingtarget_raw[3]= {0, 0, 0};
int target_raw[EXTRUDERS] = { 0 };
int target_raw_bed = 0;
int current_raw[EXTRUDERS] = { 0 };
int current_raw_bed = 0;
#ifdef PIDTEMP
// probably used external
float HeaterPower;
float pid_setpoint = 0.0;
// used external
float pid_setpoint[EXTRUDERS] = { 0.0 };
float Kp=DEFAULT_Kp;
float Ki=DEFAULT_Ki;
@ -72,45 +68,83 @@ static unsigned long previous_millis_bed_heater;
#ifdef PIDTEMP
//static cannot be external:
static float temp_iState = 0;
static float temp_dState = 0;
static float pTerm;
static float iTerm;
static float dTerm;
static float temp_iState[EXTRUDERS] = { 0 };
static float temp_dState[EXTRUDERS] = { 0 };
static float pTerm[EXTRUDERS];
static float iTerm[EXTRUDERS];
static float dTerm[EXTRUDERS];
//int output;
static float pid_error;
static float temp_iState_min;
static float temp_iState_max;
// static float pid_input;
// static float pid_output;
static bool pid_reset;
static float pid_error[EXTRUDERS];
static float temp_iState_min[EXTRUDERS];
static float temp_iState_max[EXTRUDERS];
// static float pid_input[EXTRUDERS];
// static float pid_output[EXTRUDERS];
static bool pid_reset[EXTRUDERS];
#endif //PIDTEMP
static unsigned char soft_pwm[EXTRUDERS];
#ifdef WATCHPERIOD
static int watch_raw[EXTRUDERS] = { -1000 }; // the first value used for all
static int watch_oldtemp[3] = {0,0,0};
static unsigned long watchmillis = 0;
#endif //WATCHPERIOD
// Init min and max temp with extreme values to prevent false errors during startup
static int minttemp_0 = 0;
static int maxttemp_0 = 16383;
//static int minttemp_1 = 0;
//static int maxttemp_1 = 16383;
static int minttemp[EXTRUDERS] = { 0 };
static int maxttemp[EXTRUDERS] = { 16383 }; // the first value used for all
static int bed_minttemp = 0;
static int bed_maxttemp = 16383;
static int heater_pin_map[EXTRUDERS] = { HEATER_0_PIN
#if EXTRUDERS > 1
, HEATER_1_PIN
#endif
#if EXTRUDERS > 2
, HEATER_2_PIN
#endif
#if EXTRUDERS > 3
#error Unsupported number of extruders
#endif
};
static void *heater_ttbl_map[EXTRUDERS] = { (void *)heater_0_temptable
#if EXTRUDERS > 1
, (void *)heater_1_temptable
#endif
#if EXTRUDERS > 2
, (void *)heater_2_temptable
#endif
#if EXTRUDERS > 3
#error Unsupported number of extruders
#endif
};
static int heater_ttbllen_map[EXTRUDERS] = { heater_0_temptable_len
#if EXTRUDERS > 1
, heater_1_temptable_len
#endif
#if EXTRUDERS > 2
, heater_2_temptable_len
#endif
#if EXTRUDERS > 3
#error Unsupported number of extruders
#endif
};
//===========================================================================
//=============================functions ============================
//============================= functions ============================
//===========================================================================
void updatePID()
{
#ifdef PIDTEMP
temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
for(int e = 0; e < EXTRUDERS; e++) {
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;
}
#endif
}
int getHeaterPower(int heater) {
return soft_pwm[heater];
}
void manage_heater()
{
#ifdef USE_WATCHDOG
@ -119,73 +153,67 @@ void manage_heater()
float pid_input;
float pid_output;
if(temp_meas_ready != true) //better readability
return;
CRITICAL_SECTION_START;
temp_meas_ready = false;
temp_meas_ready = false;
CRITICAL_SECTION_END;
for(int e = 0; e < EXTRUDERS; e++)
{
#ifdef PIDTEMP
pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);
pid_input = analog2temp(current_raw[e], e);
#ifndef PID_OPENLOOP
pid_error = pid_setpoint - pid_input;
if(pid_error > 10){
pid_error[e] = pid_setpoint[e] - pid_input;
if(pid_error[e] > 10) {
pid_output = PID_MAX;
pid_reset = true;
pid_reset[e] = true;
}
else if(pid_error < -10) {
else if(pid_error[e] < -10) {
pid_output = 0;
pid_reset = true;
pid_reset[e] = true;
}
else {
if(pid_reset == true) {
temp_iState = 0.0;
pid_reset = false;
if(pid_reset[e] == true) {
temp_iState[e] = 0.0;
pid_reset[e] = false;
}
pTerm = Kp * pid_error;
temp_iState += pid_error;
temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
iTerm = Ki * temp_iState;
pTerm[e] = Kp * pid_error[e];
temp_iState[e] += pid_error[e];
temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]);
iTerm[e] = Ki * temp_iState[e];
//K1 defined in Configuration.h in the PID settings
#define K2 (1.0-K1)
dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm);
temp_dState = pid_input;
// #ifdef PID_ADD_EXTRUSION_RATE
// pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high
// #endif
pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX);
dTerm[e] = (Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
temp_dState[e] = pid_input;
pid_output = constrain(pTerm[e] + iTerm[e] - dTerm[e], 0, PID_MAX);
}
#endif //PID_OPENLOOP
#ifdef PID_DEBUG
//SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);
SERIAL_ECHOLN(" PIDDEBUG "<<e<<": Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm[e]<<" iTerm "<<iTerm[e]<<" dTerm "<<dTerm[e]);
#endif //PID_DEBUG
HeaterPower=pid_output;
// Check if temperature is within the correct range
if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) {
analogWrite(HEATER_0_PIN, pid_output);
#else /* PID off */
pid_output = 0;
if(current_raw[e] < target_raw[e]) {
pid_output = PID_MAX;
}
else {
analogWrite(HEATER_0_PIN, 0);
}
#endif //PIDTEMP
#ifndef PIDTEMP
// Check if temperature is within the correct range
if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) {
if(current_raw[TEMPSENSOR_HOTEND_0] >= target_raw[TEMPSENSOR_HOTEND_0]) {
WRITE(HEATER_0_PIN,LOW);
}
else {
WRITE(HEATER_0_PIN,HIGH);
}
}
else {
WRITE(HEATER_0_PIN,LOW);
}
#endif
// Check if temperature is within the correct range
if((current_raw[e] > minttemp[e]) && (current_raw[e] < maxttemp[e]))
{
//analogWrite(heater_pin_map[e], pid_output);
soft_pwm[e] = (int)pid_output >> 1;
}
else {
//analogWrite(heater_pin_map[e], 0);
soft_pwm[e] = 0;
}
} // End extruder for loop
#ifdef WATCHPERIOD
if(watchmillis && millis() - watchmillis > WATCHPERIOD){
@ -204,20 +232,20 @@ void manage_heater()
return;
previous_millis_bed_heater = millis();
#if TEMP_1_PIN > -1
#if TEMP_BED_PIN > -1
// Check if temperature is within the correct range
if((current_raw[TEMPSENSOR_BED] > bed_minttemp) && (current_raw[TEMPSENSOR_BED] < bed_maxttemp)) {
if(current_raw[TEMPSENSOR_BED] >= target_raw[TEMPSENSOR_BED])
if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) {
if(current_raw_bed >= target_raw_bed)
{
WRITE(HEATER_1_PIN,LOW);
WRITE(HEATER_BED_PIN,LOW);
}
else
{
WRITE(HEATER_1_PIN,HIGH);
WRITE(HEATER_BED_PIN,HIGH);
}
}
else {
WRITE(HEATER_1_PIN,LOW);
WRITE(HEATER_BED_PIN,LOW);
}
#endif
}
@ -227,30 +255,38 @@ void manage_heater()
// For a thermistor, it uses the RepRap thermistor temp table.
// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
int temp2analog(int celsius) {
#ifdef HEATER_0_USES_THERMISTOR
int temp2analog(int celsius, uint8_t e) {
if(e >= EXTRUDERS)
{
SERIAL_ERROR_START;
SERIAL_ERROR((int)e);
SERIAL_ERRORLNPGM(" - Invalid extruder number!");
kill();
}
if(heater_ttbl_map[e] != 0)
{
int raw = 0;
byte i;
short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
for (i=1; i<NUMTEMPS_HEATER_0; i++)
for (i=1; i<heater_ttbllen_map[e]; i++)
{
if (PGM_RD_W(heater_0_temptable[i][1]) < celsius)
if (PGM_RD_W((*tt)[i][1]) < celsius)
{
raw = PGM_RD_W(heater_0_temptable[i-1][0]) +
(celsius - PGM_RD_W(heater_0_temptable[i-1][1])) *
(PGM_RD_W(heater_0_temptable[i][0]) - PGM_RD_W(heater_0_temptable[i-1][0])) /
(PGM_RD_W(heater_0_temptable[i][1]) - PGM_RD_W(heater_0_temptable[i-1][1]));
raw = PGM_RD_W((*tt)[i-1][0]) +
(celsius - PGM_RD_W((*tt)[i-1][1])) *
(PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i-1][0])) /
(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1]));
break;
}
}
// Overflow: Set to last value in the table
if (i == NUMTEMPS_HEATER_0) raw = PGM_RD_W(heater_0_temptable[i-1][0]);
if (i == heater_ttbllen_map[e]) raw = PGM_RD_W((*tt)[i-1][0]);
return (1023 * OVERSAMPLENR) - raw;
#elif defined HEATER_0_USES_AD595
return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
#endif
}
return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
}
// Takes bed temperature value as input and returns corresponding raw value.
@ -258,12 +294,11 @@ int temp2analog(int celsius) {
// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
int temp2analogBed(int celsius) {
#ifdef BED_USES_THERMISTOR
#ifdef BED_USES_THERMISTOR
int raw = 0;
byte i;
for (i=1; i<BNUMTEMPS; i++)
for (i=1; i<bedtemptable_len; i++)
{
if (PGM_RD_W(bedtemptable[i][1]) < celsius)
{
@ -277,45 +312,52 @@ int temp2analogBed(int celsius) {
}
// Overflow: Set to last value in the table
if (i == BNUMTEMPS) raw = PGM_RD_W(bedtemptable[i-1][0]);
if (i == bedtemptable_len) raw = PGM_RD_W(bedtemptable[i-1][0]);
return (1023 * OVERSAMPLENR) - raw;
#elif defined BED_USES_AD595
#elif defined BED_USES_AD595
return lround(celsius * (1024.0 * OVERSAMPLENR/ (5.0 * 100.0) ) );
#else
#else
#warning No heater-type defined for the bed.
#endif
return 0;
return 0;
#endif
}
// Derived from RepRap FiveD extruder::getTemperature()
// For hot end temperature measurement.
float analog2temp(int raw) {
#ifdef HEATER_0_USES_THERMISTOR
float analog2temp(int raw, uint8_t e) {
if(e >= EXTRUDERS)
{
SERIAL_ERROR_START;
SERIAL_ERROR((int)e);
SERIAL_ERRORLNPGM(" - Invalid extruder number !");
kill();
}
if(heater_ttbl_map[e] != 0)
{
float celsius = 0;
byte i;
short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
raw = (1023 * OVERSAMPLENR) - raw;
for (i=1; i<NUMTEMPS_HEATER_0; i++)
for (i=1; i<heater_ttbllen_map[e]; i++)
{
if (PGM_RD_W(heater_0_temptable[i][0]) > raw)
if (PGM_RD_W((*tt)[i][0]) > raw)
{
celsius = PGM_RD_W(heater_0_temptable[i-1][1]) +
(raw - PGM_RD_W(heater_0_temptable[i-1][0])) *
(float)(PGM_RD_W(heater_0_temptable[i][1]) - PGM_RD_W(heater_0_temptable[i-1][1])) /
(float)(PGM_RD_W(heater_0_temptable[i][0]) - PGM_RD_W(heater_0_temptable[i-1][0]));
celsius = PGM_RD_W((*tt)[i-1][1]) +
(raw - PGM_RD_W((*tt)[i-1][0])) *
(float)(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1])) /
(float)(PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i-1][0]));
break;
}
}
// Overflow: Set to last value in the table
if (i == NUMTEMPS_HEATER_0) celsius = PGM_RD_W(heater_0_temptable[i-1][1]);
if (i == heater_ttbllen_map[e]) celsius = PGM_RD_W((*tt)[i-1][1]);
return celsius;
#elif defined HEATER_0_USES_AD595
return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
#else
#error PLEASE DEFINE HEATER TYPE
#endif
}
return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
}
// Derived from RepRap FiveD extruder::getTemperature()
@ -327,7 +369,7 @@ float analog2tempBed(int raw) {
raw = (1023 * OVERSAMPLENR) - raw;
for (i=1; i<BNUMTEMPS; i++)
for (i=1; i<bedtemptable_len; i++)
{
if (PGM_RD_W(bedtemptable[i][0]) > raw)
{
@ -341,7 +383,7 @@ float analog2tempBed(int raw) {
}
// Overflow: Set to last value in the table
if (i == BNUMTEMPS) celsius = PGM_RD_W(bedtemptable[i-1][1]);
if (i == bedtemptable_len) celsius = PGM_RD_W(bedtemptable[i-1][1]);
return celsius;
@ -355,6 +397,19 @@ float analog2tempBed(int raw) {
void tp_init()
{
// Finish init of mult extruder arrays
for(int e = 0; e < EXTRUDERS; e++) {
// populate with the first value
#ifdef WATCHPERIOD
watch_raw[e] = watch_raw[0];
#endif
maxttemp[e] = maxttemp[0];
#ifdef PIDTEMP
temp_iState_min[e] = 0.0;
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki;
#endif //PIDTEMP
}
#if (HEATER_0_PIN > -1)
SET_OUTPUT(HEATER_0_PIN);
#endif
@ -364,11 +419,12 @@ void tp_init()
#if (HEATER_2_PIN > -1)
SET_OUTPUT(HEATER_2_PIN);
#endif
#ifdef PIDTEMP
temp_iState_min = 0.0;
temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
#endif //PIDTEMP
#if (HEATER_BED_PIN > -1)
SET_OUTPUT(HEATER_BED_PIN);
#endif
#if (FAN_PIN > -1)
SET_OUTPUT(FAN_PIN);
#endif
// Set analog inputs
ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
@ -381,7 +437,6 @@ void tp_init()
DIDR0 |= 1 << TEMP_0_PIN;
#else
DIDR2 |= 1<<(TEMP_0_PIN - 8);
ADCSRB = 1<<MUX5;
#endif
#endif
#if (TEMP_1_PIN > -1)
@ -389,7 +444,6 @@ void tp_init()
DIDR0 |= 1<<TEMP_1_PIN;
#else
DIDR2 |= 1<<(TEMP_1_PIN - 8);
ADCSRB = 1<<MUX5;
#endif
#endif
#if (TEMP_2_PIN > -1)
@ -397,7 +451,13 @@ void tp_init()
DIDR0 |= 1 << TEMP_2_PIN;
#else
DIDR2 = 1<<(TEMP_2_PIN - 8);
ADCSRB = 1<<MUX5;
#endif
#endif
#if (TEMP_BED_PIN > -1)
#if TEMP_BED_PIN < 8
DIDR0 |= 1<<TEMP_BED_PIN;
#else
DIDR2 |= 1<<(TEMP_BED_PIN - 8);
#endif
#endif
@ -407,27 +467,34 @@ void tp_init()
TIMSK0 |= (1<<OCIE0B);
// Wait for temperature measurement to settle
delay(200);
delay(250);
#ifdef HEATER_0_MINTEMP
minttemp_0 = temp2analog(HEATER_0_MINTEMP);
minttemp[0] = temp2analog(HEATER_0_MINTEMP, 0);
#endif //MINTEMP
#ifdef HEATER_0_MAXTEMP
maxttemp_0 = temp2analog(HEATER_0_MAXTEMP);
maxttemp[0] = temp2analog(HEATER_0_MAXTEMP, 0);
#endif //MAXTEMP
#ifdef HEATER_1_MINTEMP
minttemp_1 = temp2analog(HEATER_1_MINTEMP);
#endif //MINTEMP
#ifdef HEATER_1_MAXTEMP
maxttemp_1 = temp2analog(HEATER_1_MAXTEMP);
#endif //MAXTEMP
#if (EXTRUDERS > 1) && defined(HEATER_1_MINTEMP)
minttemp[1] = temp2analog(HEATER_1_MINTEMP, 1);
#endif // MINTEMP 1
#if (EXTRUDERS > 1) && defined(HEATER_1_MAXTEMP)
maxttemp[1] = temp2analog(HEATER_1_MAXTEMP, 1);
#endif //MAXTEMP 1
#if (EXTRUDERS > 2) && defined(HEATER_2_MINTEMP)
minttemp[2] = temp2analog(HEATER_2_MINTEMP, 2);
#endif //MINTEMP 2
#if (EXTRUDERS > 2) && defined(HEATER_2_MAXTEMP)
maxttemp[2] = temp2analog(HEATER_2_MAXTEMP, 2);
#endif //MAXTEMP 2
#ifdef BED_MINTEMP
bed_minttemp = temp2analog(BED_MINTEMP);
bed_minttemp = temp2analogBed(BED_MINTEMP);
#endif //BED_MINTEMP
#ifdef BED_MAXTEMP
bed_maxttemp = temp2analog(BED_MAXTEMP);
bed_maxttemp = temp2analogBed(BED_MAXTEMP);
#endif //BED_MAXTEMP
}
@ -436,15 +503,17 @@ void tp_init()
void setWatch()
{
#ifdef WATCHPERIOD
if(isHeatingHotend0())
int t = 0;
for (int e = 0; e < EXTRUDERS; e++)
{
watchmillis = max(1,millis());
if(isHeatingHotend(e))
watch_oldtemp[TEMPSENSOR_HOTEND_0] = degHotend(0);
{
t = max(t,millis());
watch_raw[e] = current_raw[e];
}
}
else
{
watchmillis = 0;
}
watchmillis = t;
#endif
}
@ -453,6 +522,7 @@ void disable_heater()
{
#if TEMP_0_PIN > -1
target_raw[0]=0;
soft_pwm[0]=0;
#if HEATER_0_PIN > -1
digitalWrite(HEATER_0_PIN,LOW);
#endif
@ -460,6 +530,7 @@ void disable_heater()
#if TEMP_1_PIN > -1
target_raw[1]=0;
soft_pwm[1]=0;
#if HEATER_1_PIN > -1
digitalWrite(HEATER_1_PIN,LOW);
#endif
@ -467,10 +538,38 @@ void disable_heater()
#if TEMP_2_PIN > -1
target_raw[2]=0;
soft_pwm[2]=0;
#if HEATER_2_PIN > -1
digitalWrite(HEATER_2_PIN,LOW);
#endif
#endif
#if TEMP_BED_PIN > -1
target_raw_bed=0;
#if HEATER_BED_PIN > -1
digitalWrite(HEATER_BED_PIN,LOW);
#endif
#endif
}
void max_temp_error(uint8_t e) {
digitalWrite(heater_pin_map[e], 0);
SERIAL_ERROR_START;
SERIAL_ERRORLN(e);
SERIAL_ERRORLNPGM(": Extruder switched off. MAXTEMP triggered !");
}
void min_temp_error(uint8_t e) {
digitalWrite(heater_pin_map[e], 0);
SERIAL_ERROR_START;
SERIAL_ERRORLN(e);
SERIAL_ERRORLNPGM(": Extruder switched off. MINTEMP triggered !");
}
void bed_max_temp_error(void) {
digitalWrite(HEATER_BED_PIN, 0);
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
}
// Timer 0 is shared with millies
@ -481,7 +580,35 @@ ISR(TIMER0_COMPB_vect)
static unsigned long raw_temp_0_value = 0;
static unsigned long raw_temp_1_value = 0;
static unsigned long raw_temp_2_value = 0;
static unsigned long raw_temp_bed_value = 0;
static unsigned char temp_state = 0;
static unsigned char pwm_count = 1;
static unsigned char soft_pwm_0;
static unsigned char soft_pwm_1;
static unsigned char soft_pwm_2;
if(pwm_count == 0){
soft_pwm_0 = soft_pwm[0];
if(soft_pwm_0 > 0) WRITE(HEATER_0_PIN,1);
#if EXTRUDERS > 1
soft_pwm_1 = soft_pwm[1];
if(soft_pwm_1 > 0) WRITE(HEATER_1_PIN,1);
#endif
#if EXTRUDERS > 2
soft_pwm_2 = soft_pwm[2];
if(soft_pwm_2 > 0) WRITE(HEATER_2_PIN,1);
#endif
}
if(soft_pwm_0 <= pwm_count) WRITE(HEATER_0_PIN,0);
#if EXTRUDERS > 1
if(soft_pwm_1 <= pwm_count) WRITE(HEATER_1_PIN,0);
#endif
#if EXTRUDERS > 2
if(soft_pwm_2 <= pwm_count) WRITE(HEATER_2_PIN,0);
#endif
pwm_count++;
pwm_count &= 0x7f;
switch(temp_state) {
case 0: // Prepare TEMP_0
@ -505,7 +632,26 @@ ISR(TIMER0_COMPB_vect)
#endif
temp_state = 2;
break;
case 2: // Prepare TEMP_1
case 2: // Prepare TEMP_BED
#if (TEMP_BED_PIN > -1)
#if TEMP_BED_PIN > 7
ADCSRB = 1<<MUX5;
#endif
ADMUX = ((1 << REFS0) | (TEMP_BED_PIN & 0x07));
ADCSRA |= 1<<ADSC; // Start conversion
#endif
#ifdef ULTIPANEL
buttons_check();
#endif
temp_state = 3;
break;
case 3: // Measure TEMP_BED
#if (TEMP_BED_PIN > -1)
raw_temp_bed_value += ADC;
#endif
temp_state = 4;
break;
case 4: // Prepare TEMP_1
#if (TEMP_1_PIN > -1)
#if TEMP_1_PIN > 7
ADCSRB = 1<<MUX5;
@ -518,15 +664,15 @@ ISR(TIMER0_COMPB_vect)
#ifdef ULTIPANEL
buttons_check();
#endif
temp_state = 3;
temp_state = 5;
break;
case 3: // Measure TEMP_1
case 5: // Measure TEMP_1
#if (TEMP_1_PIN > -1)
raw_temp_1_value += ADC;
#endif
temp_state = 4;
temp_state = 6;
break;
case 4: // Prepare TEMP_2
case 6: // Prepare TEMP_2
#if (TEMP_2_PIN > -1)
#if TEMP_2_PIN > 7
ADCSRB = 1<<MUX5;
@ -539,39 +685,49 @@ ISR(TIMER0_COMPB_vect)
#ifdef ULTIPANEL
buttons_check();
#endif
temp_state = 5;
temp_state = 7;
break;
case 5: // Measure TEMP_2
case 7: // Measure TEMP_2
#if (TEMP_2_PIN > -1)
raw_temp_2_value += ADC;
#endif
temp_state = 0;
temp_count++;
break;
default:
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temp measurement error!");
break;
// default:
// SERIAL_ERROR_START;
// SERIAL_ERRORLNPGM("Temp measurement error!");
// break;
}
if(temp_count >= 16) // 6 ms * 16 = 96ms.
if(temp_count >= 16) // 8 ms * 16 = 128ms.
{
#ifdef HEATER_0_USES_AD595
current_raw[0] = raw_temp_0_value;
#else
current_raw[0] = 16383 - raw_temp_0_value;
#endif
#if EXTRUDERS > 1
#ifdef HEATER_1_USES_AD595
current_raw[1] = raw_temp_1_value;
#else
current_raw[1] = 16383 - raw_temp_1_value;
#endif
#endif
#if EXTRUDERS > 2
#ifdef HEATER_2_USES_AD595
current_raw[2] = raw_temp_2_value;
#else
current_raw[2] = 16383 - raw_temp_2_value;
#endif
#endif
#ifdef BED_USES_AD595
current_raw[1] = raw_temp_1_value;
current_raw_bed = raw_temp_bed_value;
#else
current_raw[1] = 16383 - raw_temp_1_value;
current_raw_bed = 16383 - raw_temp_bed_value;
#endif
temp_meas_ready = true;
@ -579,77 +735,28 @@ ISR(TIMER0_COMPB_vect)
raw_temp_0_value = 0;
raw_temp_1_value = 0;
raw_temp_2_value = 0;
#ifdef HEATER_0_MAXTEMP
#if (HEATER_0_PIN > -1)
if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
target_raw[TEMPSENSOR_HOTEND_0] = 0;
digitalWrite(HEATER_0_PIN, 0);
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MAXTEMP triggered !!");
raw_temp_bed_value = 0;
for(unsigned char e = 0; e < EXTRUDERS; e++) {
if(current_raw[e] >= maxttemp[e]) {
target_raw[e] = 0;
max_temp_error(e);
kill();;
}
if(current_raw[e] <= minttemp[e]) {
target_raw[e] = 0;
min_temp_error(e);
kill();
}
#endif
#endif
#ifdef HEATER_1_MAXTEMP
#if (HEATER_1_PIN > -1)
if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
target_raw[TEMPSENSOR_HOTEND_1] = 0;
digitalWrite(HEATER_2_PIN, 0);
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MAXTEMP triggered !!");
kill();
}
#endif
#endif //MAXTEMP
}
}
#ifdef HEATER_0_MINTEMP
#if (HEATER_0_PIN > -1)
if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
target_raw[TEMPSENSOR_HOTEND_0] = 0;
digitalWrite(HEATER_0_PIN, 0);
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MINTEMP triggered !!");
kill();
}
#endif
#endif
#ifdef HEATER_1_MINTEMP
#if (HEATER_2_PIN > -1)
if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
target_raw[TEMPSENSOR_HOTEND_1] = 0;
digitalWrite(HEATER_2_PIN, 0);
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MINTEMP triggered !!");
kill();
}
#endif
#endif //MAXTEMP
#ifdef BED_MINTEMP
#if (HEATER_1_PIN > -1)
if(current_raw[1] <= bed_minttemp) {
target_raw[1] = 0;
digitalWrite(HEATER_1_PIN, 0);
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temperatur heated bed switched off. MINTEMP triggered !!");
kill();
}
#endif
#endif
#ifdef BED_MAXTEMP
#if (HEATER_1_PIN > -1)
if(current_raw[1] >= bed_maxttemp) {
target_raw[1] = 0;
digitalWrite(HEATER_1_PIN, 0);
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
kill();
}
#endif
#endif
#if defined(BED_MAXTEMP) && (HEATER_BED_PIN > -1)
if(current_raw_bed >= bed_maxttemp) {
target_raw_bed = 0;
bed_max_temp_error();
kill();
}
#endif
}
}

View file

@ -32,95 +32,111 @@
void tp_init(); //initialise the heating
void manage_heater(); //it is critical that this is called periodically.
enum TempSensor {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2};
//low leven conversion routines
// do not use this routines and variables outsie of temperature.cpp
int temp2analog(int celsius);
int temp2analog(int celsius, uint8_t e);
int temp2analogBed(int celsius);
float analog2temp(int raw);
float analog2temp(int raw, uint8_t e);
float analog2tempBed(int raw);
extern int target_raw[3];
extern int heatingtarget_raw[3];
extern int current_raw[3];
extern int target_raw[EXTRUDERS];
extern int heatingtarget_raw[EXTRUDERS];
extern int current_raw[EXTRUDERS];
extern int target_raw_bed;
extern int current_raw_bed;
extern float Kp,Ki,Kd,Kc;
#ifdef PIDTEMP
extern float pid_setpoint ;
extern float pid_setpoint[EXTRUDERS];
#endif
// #ifdef WATCHPERIOD
// extern int watch_raw[3] ;
extern int watch_raw[EXTRUDERS] ;
// extern unsigned long watchmillis;
// #endif
//high level conversion routines, for use outside of temperature.cpp
//inline so that there is no performance decrease.
//deg=degreeCelsius
FORCE_INLINE float degHotend0(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);};
FORCE_INLINE float degHotend1(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);};
FORCE_INLINE float degBed() { return analog2tempBed(current_raw[TEMPSENSOR_BED]);};
FORCE_INLINE float degHotend(uint8_t extruder){
if(extruder == 0) return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);
if(extruder == 1) return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);
FORCE_INLINE float degHotend(uint8_t extruder) {
return analog2temp(current_raw[extruder], extruder);
};
FORCE_INLINE float degTargetHotend0() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);};
FORCE_INLINE float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);};
FORCE_INLINE float degTargetHotend(uint8_t extruder){
if(extruder == 0) return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);
if(extruder == 1) return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);
FORCE_INLINE float degBed() {
return analog2tempBed(current_raw_bed);
};
FORCE_INLINE float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);};
FORCE_INLINE void setTargetHotend0(const float &celsius)
{
target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius);
heatingtarget_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius-HEATING_EARLY_FINISH_DEG_OFFSET);
#ifdef PIDTEMP
pid_setpoint = celsius;
#endif //PIDTEMP
FORCE_INLINE float degTargetHotend(uint8_t extruder) {
return analog2temp(target_raw[extruder], extruder);
};
FORCE_INLINE float degTargetBed() {
return analog2tempBed(target_raw_bed);
};
FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
target_raw[extruder] = temp2analog(celsius, extruder);
#ifdef PIDTEMP
pid_setpoint[extruder] = celsius;
#endif //PIDTEMP
};
FORCE_INLINE void setTargetBed(const float &celsius) {
target_raw_bed = temp2analogBed(celsius);
};
FORCE_INLINE void setTargetHotend1(const float &celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);};
FORCE_INLINE void setTargetHotend(const float &celcius, uint8_t extruder){
if(extruder == 0) setTargetHotend0(celcius);
if(extruder == 1) setTargetHotend1(celcius);
};
FORCE_INLINE void setTargetBed(const float &celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);};
FORCE_INLINE bool isHeatingHotend0() {return heatingtarget_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];};
FORCE_INLINE bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];};
FORCE_INLINE bool isHeatingHotend(uint8_t extruder){
if(extruder == 0) return heatingtarget_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];
if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];
return false;
return target_raw[extruder] > current_raw[extruder];
};
FORCE_INLINE bool isHeatingBed() {return target_raw[TEMPSENSOR_BED] > current_raw[TEMPSENSOR_BED];};
FORCE_INLINE bool isCoolingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];};
FORCE_INLINE bool isCoolingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];};
FORCE_INLINE bool isCoolingHotend(uint8_t extruder){
if(extruder == 0) return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];
if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];
return false;
FORCE_INLINE bool isHeatingBed() {
return target_raw_bed > current_raw_bed;
};
FORCE_INLINE bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMPSENSOR_BED];};
FORCE_INLINE bool isCoolingHotend(uint8_t extruder) {
return target_raw[extruder] < current_raw[extruder];
};
FORCE_INLINE bool isCoolingBed() {
return target_raw_bed < current_raw_bed;
};
#define degHotend0() degHotend(0)
#define degTargetHotend0() degTargetHotend(0)
#define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0)
#define isHeatingHotend0() isHeatingHotend(0)
#define isCoolingHotend0() isCoolingHotend(0)
#if EXTRUDERS > 1
#define degHotend1() degHotend(1)
#define degTargetHotend1() degTargetHotend(1)
#define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1)
#define isHeatingHotend1() isHeatingHotend(1)
#define isCoolingHotend1() isCoolingHotend(1)
#endif
#if EXTRUDERS > 2
#define degHotend2() degHotend(2)
#define degTargetHotend2() degTargetHotend(2)
#define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2)
#define isHeatingHotend2() isHeatingHotend(2)
#define isCoolingHotend2() isCoolingHotend(2)
#endif
#if EXTRUDERS > 3
#error Invalid number of extruders
#endif
FORCE_INLINE void autotempShutdown(){
#ifdef AUTOTEMP
if(autotemp_enabled)
{
autotemp_enabled=false;
if(degTargetHotend0()>autotemp_min)
setTargetHotend0(0);
if(degTargetHotend(ACTIVE_EXTRUDER)>autotemp_min)
setTargetHotend(0,ACTIVE_EXTRUDER);
}
#endif
}
int getHeaterPower(int heater);
void disable_heater();
void setWatch();
void updatePID();

View file

@ -5,10 +5,9 @@
#define OVERSAMPLENR 16
#if (THERMISTORHEATER_0 == 1) || (THERMISTORHEATER_1 == 1) || (THERMISTORBED == 1) //100k bed thermistor
#if (THERMISTORHEATER_0 == 1) || (THERMISTORHEATER_1 == 1) || (THERMISTORHEATER_2 == 1) || (THERMISTORBED == 1) //100k bed thermistor
#define NUMTEMPS_1 61
const short temptable_1[NUMTEMPS_1][2] PROGMEM = {
const short temptable_1[][2] PROGMEM = {
{ 23*OVERSAMPLENR , 300 },
{ 25*OVERSAMPLENR , 295 },
{ 27*OVERSAMPLENR , 290 },
@ -72,9 +71,8 @@ const short temptable_1[NUMTEMPS_1][2] PROGMEM = {
{ 1008*OVERSAMPLENR , 0 } //safety
};
#endif
#if (THERMISTORHEATER_0 == 2) || (THERMISTORHEATER_1 == 2) || (THERMISTORBED == 2) //200k bed thermistor
#define NUMTEMPS_2 21
const short temptable_2[NUMTEMPS_2][2] PROGMEM = {
#if (THERMISTORHEATER_0 == 2) || (THERMISTORHEATER_1 == 2) || (THERMISTORHEATER_2 == 2) || (THERMISTORBED == 2) //200k bed thermistor
const short temptable_2[][2] PROGMEM = {
{1*OVERSAMPLENR, 848},
{54*OVERSAMPLENR, 275},
{107*OVERSAMPLENR, 228},
@ -99,9 +97,8 @@ const short temptable_2[NUMTEMPS_2][2] PROGMEM = {
};
#endif
#if (THERMISTORHEATER_0 == 3) || (THERMISTORHEATER_1 == 3) || (THERMISTORBED == 3) //mendel-parts
#define NUMTEMPS_3 28
const short temptable_3[NUMTEMPS_3][2] PROGMEM = {
#if (THERMISTORHEATER_0 == 3) || (THERMISTORHEATER_1 == 3) || (THERMISTORHEATER_2 == 3) || (THERMISTORBED == 3) //mendel-parts
const short temptable_3[][2] PROGMEM = {
{1*OVERSAMPLENR,864},
{21*OVERSAMPLENR,300},
{25*OVERSAMPLENR,290},
@ -133,10 +130,8 @@ const short temptable_3[NUMTEMPS_3][2] PROGMEM = {
};
#endif
#if (THERMISTORHEATER_0 == 4) || (THERMISTORHEATER_1 == 4) || (THERMISTORBED == 4) //10k thermistor
#define NUMTEMPS_4 20
const short temptable_4[NUMTEMPS_4][2] PROGMEM = {
#if (THERMISTORHEATER_0 == 4) || (THERMISTORHEATER_1 == 4) || (THERMISTORHEATER_2 == 4) || (THERMISTORBED == 4) //10k thermistor
const short temptable_4[][2] PROGMEM = {
{1*OVERSAMPLENR, 430},
{54*OVERSAMPLENR, 137},
{107*OVERSAMPLENR, 107},
@ -160,10 +155,8 @@ const short temptable_4[NUMTEMPS_4][2] PROGMEM = {
};
#endif
#if (THERMISTORHEATER_0 == 5) || (THERMISTORHEATER_1 == 5) || (THERMISTORBED == 5) //100k ParCan thermistor (104GT-2)
#define NUMTEMPS_5 61
const short temptable_5[NUMTEMPS_5][2] PROGMEM = {
#if (THERMISTORHEATER_0 == 5) || (THERMISTORHEATER_1 == 5) || (THERMISTORHEATER_2 == 5) || (THERMISTORBED == 5) //100k ParCan thermistor (104GT-2)
const short temptable_5[][2] PROGMEM = {
{1*OVERSAMPLENR, 713},
{18*OVERSAMPLENR, 316},
{35*OVERSAMPLENR, 266},
@ -228,9 +221,8 @@ const short temptable_5[NUMTEMPS_5][2] PROGMEM = {
};
#endif
#if (THERMISTORHEATER_0 == 6) || (THERMISTORHEATER_1 == 6) || (THERMISTORBED == 6) // 100k Epcos thermistor
#define NUMTEMPS_6 36
const short temptable_6[NUMTEMPS_6][2] PROGMEM = {
#if (THERMISTORHEATER_0 == 6) || (THERMISTORHEATER_1 == 6) || (THERMISTORHEATER_2 == 6) || (THERMISTORBED == 6) // 100k Epcos thermistor
const short temptable_6[][2] PROGMEM = {
{28*OVERSAMPLENR, 250},
{31*OVERSAMPLENR, 245},
{35*OVERSAMPLENR, 240},
@ -270,9 +262,8 @@ const short temptable_6[NUMTEMPS_6][2] PROGMEM = {
};
#endif
#if (THERMISTORHEATER_0 == 7) || (THERMISTORHEATER_1 == 7) || (THERMISTORBED == 7) // 100k Honeywell 135-104LAG-J01
#define NUMTEMPS_7 54
const short temptable_7[NUMTEMPS_7][2] PROGMEM = {
#if (THERMISTORHEATER_0 == 7) || (THERMISTORHEATER_1 == 7) || (THERMISTORHEATER_2 == 7) || (THERMISTORBED == 7) // 100k Honeywell 135-104LAG-J01
const short temptable_7[][2] PROGMEM = {
{46*OVERSAMPLENR, 270},
{50*OVERSAMPLENR, 265},
{54*OVERSAMPLENR, 260},
@ -330,82 +321,52 @@ const short temptable_7[NUMTEMPS_7][2] PROGMEM = {
};
#endif
#define _TT_NAME(_N) temptable_ ## _N
#define TT_NAME(_N) _TT_NAME(_N)
#if THERMISTORHEATER_0 == 1
#define NUMTEMPS_HEATER_0 NUMTEMPS_1
#define heater_0_temptable temptable_1
#elif THERMISTORHEATER_0 == 2
#define NUMTEMPS_HEATER_0 NUMTEMPS_2
#define heater_0_temptable temptable_2
#elif THERMISTORHEATER_0 == 3
#define NUMTEMPS_HEATER_0 NUMTEMPS_3
#define heater_0_temptable temptable_3
#elif THERMISTORHEATER_0 == 4
#define NUMTEMPS_HEATER_0 NUMTEMPS_4
#define heater_0_temptable temptable_4
#elif THERMISTORHEATER_0 == 5
#define NUMTEMPS_HEATER_0 NUMTEMPS_5
#define heater_0_temptable temptable_5
#elif THERMISTORHEATER_0 == 6
#define NUMTEMPS_HEATER_0 NUMTEMPS_6
#define heater_0_temptable temptable_6
#elif THERMISTORHEATER_0 == 7
#define NUMTEMPS_HEATER_0 NUMTEMPS_7
#define heater_0_temptable temptable_7
#elif defined HEATER_0_USES_THERMISTOR
#error No heater 0 thermistor table specified
#ifdef THERMISTORHEATER_0
#define heater_0_temptable TT_NAME(THERMISTORHEATER_0)
#define heater_0_temptable_len (sizeof(heater_0_temptable)/sizeof(*heater_0_temptable))
#else
#ifdef HEATER_0_USES_THERMISTOR
#error No heater 0 thermistor table specified
#else // HEATER_0_USES_THERMISTOR
#define heater_0_temptable 0
#define heater_0_temptable_len 0
#endif // HEATER_0_USES_THERMISTOR
#endif
#if THERMISTORHEATER_1 == 1
#define NUMTEMPS_HEATER_1 NUMTEMPS_1
#define heater_1_temptable temptable_1
#elif THERMISTORHEATER_1 == 2
#define NUMTEMPS_HEATER_1 NUMTEMPS_2
#define heater_1_temptable temptable_2
#elif THERMISTORHEATER_1 == 3
#define NUMTEMPS_HEATER_1 NUMTEMPS_3
#define heater_1_temptable temptable_3
#elif THERMISTORHEATER_1 == 4
#define NUMTEMPS_HEATER_1 NUMTEMPS_4
#define heater_1_temptable temptable_4
#elif THERMISTORHEATER_1 == 5
#define NUMTEMPS_HEATER_1 NUMTEMPS_5
#define heater_1_temptable temptable_5
#elif THERMISTORHEATER_1 == 6
#define NUMTEMPS_HEATER_1 NUMTEMPS_6
#define heater_1_temptable temptable_6
#elif THERMISTORHEATER_1 == 7
#define NUMTEMPS_HEATER_1 NUMTEMPS_7
#define heater_1_temptable temptable_7
#elif defined HEATER_1_USES_THERMISTOR
#error No heater 1 thermistor table specified
#ifdef THERMISTORHEATER_1
#define heater_1_temptable TT_NAME(THERMISTORHEATER_1)
#define heater_1_temptable_len (sizeof(heater_1_temptable)/sizeof(*heater_1_temptable))
#else
#ifdef HEATER_1_USES_THERMISTOR
#error No heater 1 thermistor table specified
#else // HEATER_1_USES_THERMISTOR
#define heater_1_temptable 0
#define heater_1_temptable_len 0
#endif // HEATER_1_USES_THERMISTOR
#endif
#ifdef THERMISTORHEATER_2
#define heater_2_temptable TT_NAME(THERMISTORHEATER_2)
#define heater_2_temptable_len (sizeof(heater_2_temptable)/sizeof(*heater_2_temptable))
#else
#ifdef HEATER_2_USES_THERMISTOR
#error No heater 2 thermistor table specified
#else // HEATER_2_USES_THERMISTOR
#define heater_2_temptable 0
#define heater_2_temptable_len 0
#endif // HEATER_2_USES_THERMISTOR
#endif
#if THERMISTORBED == 1
#define BNUMTEMPS NUMTEMPS_1
#define bedtemptable temptable_1
#elif THERMISTORBED == 2
#define BNUMTEMPS NUMTEMPS_2
#define bedtemptable temptable_2
#elif THERMISTORBED == 3
#define BNUMTEMPS NUMTEMPS_3
#define bedtemptable temptable_3
#elif THERMISTORBED == 4
#define BNUMTEMPS NUMTEMPS_4
#define bedtemptable temptable_4
#elif THERMISTORBED == 5
#define BNUMTEMPS NUMTEMPS_5
#define bedtemptable temptable_5
#elif THERMISTORBED == 6
#define BNUMTEMPS NUMTEMPS_6
#define bedtemptable temptable_6
#elif THERMISTORBED == 7
#define BNUMTEMPS NUMTEMPS_7
#define bedtemptable temptable_7
#elif defined BED_USES_THERMISTOR
#error No bed thermistor table specified
#ifdef THERMISTORBED
#define bedtemptable TT_NAME(THERMISTORBED)
#define bedtemptable_len (sizeof(bedtemptable)/sizeof(*bedtemptable))
#else
#ifdef BED_USES_THERMISTOR
#error No bed thermistor table specified
#endif // BED_USES_THERMISTOR
#endif
#endif //THERMISTORTABLES_H_

File diff suppressed because it is too large Load diff