reformating and some minor bugs/things found on the way.
This commit is contained in:
parent
900e0c9bf2
commit
1d171e9e52
17 changed files with 1204 additions and 1192 deletions
|
@ -1,5 +1,5 @@
|
||||||
#ifndef CONFIGURATION_H
|
#ifndef __CONFIGURATION_H
|
||||||
#define CONFIGURATION_H
|
#define __CONFIGURATION_H
|
||||||
|
|
||||||
//#define DEBUG_STEPS
|
//#define DEBUG_STEPS
|
||||||
|
|
||||||
|
@ -118,10 +118,7 @@ const int dropsegments=5; //everything with this number of steps will be ignore
|
||||||
#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
|
#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
|
||||||
//note: on bernhards ultimaker 200 200 12 are working well.
|
//note: on bernhards ultimaker 200 200 12 are working well.
|
||||||
#define HOMING_FEEDRATE {50*60, 50*60, 12*60, 0} // set the homing speeds
|
#define HOMING_FEEDRATE {50*60, 50*60, 12*60, 0} // set the homing speeds
|
||||||
//the followint checks if an extrusion is existent in the move. if _not_, the speed of the move is set to the maximum speed.
|
|
||||||
//!!!!!!Use only if you know that your printer works at the maximum declared speeds.
|
|
||||||
// works around the skeinforge cool-bug. There all moves are slowed to have a minimum layer time. However slow travel moves= ooze
|
|
||||||
#define TRAVELING_AT_MAXSPEED
|
|
||||||
#define AXIS_RELATIVE_MODES {false, false, false, false}
|
#define AXIS_RELATIVE_MODES {false, false, false, false}
|
||||||
|
|
||||||
#define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
|
#define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
|
||||||
|
@ -177,41 +174,50 @@ const int dropsegments=5; //everything with this number of steps will be ignore
|
||||||
//#define_HEATER_1_MAXTEMP 275
|
//#define_HEATER_1_MAXTEMP 275
|
||||||
//#define BED_MAXTEMP 150
|
//#define BED_MAXTEMP 150
|
||||||
|
|
||||||
|
/// PID settings:
|
||||||
|
// Uncomment the following line to enable PID support.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define PIDTEMP
|
#define PIDTEMP
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
/// PID settings:
|
|
||||||
// Uncomment the following line to enable PID support.
|
|
||||||
//#define SMOOTHING
|
|
||||||
//#define SMOOTHFACTOR 5.0
|
|
||||||
//float current_raw_average=0;
|
|
||||||
#define K1 0.95 //smoothing of the PID
|
|
||||||
//#define PID_DEBUG // Sends debug data to the serial port.
|
//#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_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
|
||||||
#define PID_MAX 255 // limits current to nozzle
|
|
||||||
#define PID_INTEGRAL_DRIVE_MAX 255
|
#define PID_MAX 255 // limits current to nozzle; 255=full current
|
||||||
#define PID_dT 0.1
|
#define PID_INTEGRAL_DRIVE_MAX 255 //limit for the integral term
|
||||||
//machine with red silicon: 1950:45 second ; with fan fully blowin 3000:47
|
#define K1 0.95 //smoothing factor withing the PID
|
||||||
|
#define PID_dT 0.1 //sampling period of the PID
|
||||||
|
|
||||||
|
//To develop some PID settings for your machine, you can initiall follow
|
||||||
|
// the Ziegler-Nichols method.
|
||||||
|
// set Ki and Kd to zero.
|
||||||
|
// heat with a defined Kp and see if the temperature stabilizes
|
||||||
|
// ideally you do this graphically with repg.
|
||||||
|
// the PID_CRITIAL_GAIN should be the Kp at which temperature oscillatins are not dampned out/decreas in amplitutde
|
||||||
|
// PID_SWING_AT_CRITIAL is the time for a full period of the oscillations at the critical Gain
|
||||||
|
// usually further manual tunine is necessary.
|
||||||
|
|
||||||
#define PID_CRITIAL_GAIN 3000
|
#define PID_CRITIAL_GAIN 3000
|
||||||
#define PID_SWING_AT_CRITIAL 45 //seconds
|
#define PID_SWING_AT_CRITIAL 45 //seconds
|
||||||
#define PIDIADD 5
|
|
||||||
/*
|
|
||||||
//PID according to Ziegler-Nichols method
|
|
||||||
float Kp = 0.6*PID_CRITIAL_GAIN;
|
|
||||||
float Ki =PIDIADD+2*Kp/PID_SWING_AT_CRITIAL*PID_dT;
|
|
||||||
float Kd = Kp*PID_SWING_AT_CRITIAL/8./PID_dT;
|
|
||||||
*/
|
|
||||||
//PI according to Ziegler-Nichols method
|
|
||||||
#define DEFAULT_Kp (PID_CRITIAL_GAIN/2.2)
|
|
||||||
#define DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT)
|
|
||||||
#define DEFAULT_Kd (0)
|
|
||||||
|
|
||||||
|
#define PID_PI //no differentail term
|
||||||
|
//#define PID_PID //normal PID
|
||||||
|
|
||||||
|
#ifdef PID_PID
|
||||||
|
//PID according to Ziegler-Nichols method
|
||||||
|
#define DEFAULT_Kp (0.6*PID_CRITIAL_GAIN)
|
||||||
|
#define DEFAULT_Ki (2*Kp/PID_SWING_AT_CRITIAL*PID_dT)
|
||||||
|
#define DEFAULT_Kd (PID_SWING_AT_CRITIAL/8./PID_dT)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PID_PI
|
||||||
|
//PI according to Ziegler-Nichols method
|
||||||
|
#define DEFAULT_Kp (PID_CRITIAL_GAIN/2.2)
|
||||||
|
#define DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT)
|
||||||
|
#define DEFAULT_Kd (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// this adds an experimental additional term to the heatingpower, proportional to the extrusion speed.
|
||||||
|
// if Kc is choosen well, the additional required power due to increased melting should be compensated.
|
||||||
#define PID_ADD_EXTRUSION_RATE
|
#define PID_ADD_EXTRUSION_RATE
|
||||||
#ifdef PID_ADD_EXTRUSION_RATE
|
#ifdef PID_ADD_EXTRUSION_RATE
|
||||||
#define DEFAULT_Kc (5) //heatingpower=Kc*(e_speed)
|
#define DEFAULT_Kc (5) //heatingpower=Kc*(e_speed)
|
||||||
|
@ -228,22 +234,21 @@ const int dropsegments=5; //everything with this number of steps will be ignore
|
||||||
//#define ADVANCE
|
//#define ADVANCE
|
||||||
|
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
#define EXTRUDER_ADVANCE_K .3
|
#define EXTRUDER_ADVANCE_K .3
|
||||||
|
|
||||||
#define D_FILAMENT 1.7
|
#define D_FILAMENT 1.7
|
||||||
#define STEPS_MM_E 65
|
#define STEPS_MM_E 65
|
||||||
#define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
|
#define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
|
||||||
#define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA)
|
#define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA)
|
||||||
|
|
||||||
#endif // ADVANCE
|
#endif // ADVANCE
|
||||||
|
|
||||||
// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, e.g. 8,16,32
|
|
||||||
#if defined SDSUPPORT
|
|
||||||
// The number of linear motions that can be in the plan at any give time.
|
// The number of linear motions that can be in the plan at any give time.
|
||||||
|
// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, i.g. 8,16,32 because shifts and ors are used to do the ringbuffering.
|
||||||
|
#if defined SDSUPPORT
|
||||||
#define BLOCK_BUFFER_SIZE 16 // SD,LCD,Buttons take more memory, block buffer needs to be smaller
|
#define BLOCK_BUFFER_SIZE 16 // SD,LCD,Buttons take more memory, block buffer needs to be smaller
|
||||||
#else
|
#else
|
||||||
#define BLOCK_BUFFER_SIZE 16 // maximize block buffer
|
#define BLOCK_BUFFER_SIZE 16 // maximize block buffer
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif //__CONFIGURATION_H
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,39 +1,42 @@
|
||||||
#ifndef __EEPROMH
|
#ifndef __EEPROMH
|
||||||
#define __EEPROMH
|
#define __EEPROMH
|
||||||
|
|
||||||
|
#include "Marlin.h"
|
||||||
#include "planner.h"
|
#include "planner.h"
|
||||||
#include "temperature.h"
|
#include "temperature.h"
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#include "Marlin.h"
|
|
||||||
#include "streaming.h"
|
|
||||||
|
|
||||||
//======================================================================================
|
|
||||||
template <class T> int EEPROM_writeAnything(int &ee, const T& value)
|
template <class T> int EEPROM_writeAnything(int &ee, const T& value)
|
||||||
{
|
{
|
||||||
const byte* p = (const byte*)(const void*)&value;
|
const byte* p = (const byte*)(const void*)&value;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < (int)sizeof(value); i++)
|
for (i = 0; i < (int)sizeof(value); i++)
|
||||||
EEPROM.write(ee++, *p++);
|
EEPROM.write(ee++, *p++);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
//======================================================================================
|
|
||||||
template <class T> int EEPROM_readAnything(int &ee, T& value)
|
template <class T> int EEPROM_readAnything(int &ee, T& value)
|
||||||
{
|
{
|
||||||
byte* p = (byte*)(void*)&value;
|
byte* p = (byte*)(void*)&value;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < (int)sizeof(value); i++)
|
for (i = 0; i < (int)sizeof(value); i++)
|
||||||
*p++ = EEPROM.read(ee++);
|
*p++ = EEPROM.read(ee++);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
//======================================================================================
|
//======================================================================================
|
||||||
|
|
||||||
#define EEPROM_OFFSET 100
|
#define EEPROM_OFFSET 100
|
||||||
|
|
||||||
#define EEPROM_VERSION "V04" // IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
|
|
||||||
// in the functions below, also increment the version number. This makes sure that
|
// IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
|
||||||
// the default values are used whenever there is a change to the data, to prevent
|
// in the functions below, also increment the version number. This makes sure that
|
||||||
// wrong data being written to the variables.
|
// the default values are used whenever there is a change to the data, to prevent
|
||||||
// ALSO: always make sure the variables in the Store and retrieve sections are in the same order.
|
// wrong data being written to the variables.
|
||||||
void StoreSettings() {
|
// ALSO: always make sure the variables in the Store and retrieve sections are in the same order.
|
||||||
|
#define EEPROM_VERSION "V04"
|
||||||
|
|
||||||
|
void StoreSettings()
|
||||||
|
{
|
||||||
char ver[4]= "000";
|
char ver[4]= "000";
|
||||||
int i=EEPROM_OFFSET;
|
int i=EEPROM_OFFSET;
|
||||||
EEPROM_writeAnything(i,ver); // invalidate data first
|
EEPROM_writeAnything(i,ver); // invalidate data first
|
||||||
|
@ -48,52 +51,55 @@ void StoreSettings() {
|
||||||
EEPROM_writeAnything(i,max_xy_jerk);
|
EEPROM_writeAnything(i,max_xy_jerk);
|
||||||
EEPROM_writeAnything(i,max_z_jerk);
|
EEPROM_writeAnything(i,max_z_jerk);
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
EEPROM_writeAnything(i,Kp);
|
EEPROM_writeAnything(i,Kp);
|
||||||
EEPROM_writeAnything(i,Ki);
|
EEPROM_writeAnything(i,Ki);
|
||||||
EEPROM_writeAnything(i,Kd);
|
EEPROM_writeAnything(i,Kd);
|
||||||
#else
|
#else
|
||||||
EEPROM_writeAnything(i,3000);
|
EEPROM_writeAnything(i,3000);
|
||||||
EEPROM_writeAnything(i,0);
|
EEPROM_writeAnything(i,0);
|
||||||
EEPROM_writeAnything(i,0);
|
EEPROM_writeAnything(i,0);
|
||||||
#endif
|
#endif
|
||||||
char ver2[4]=EEPROM_VERSION;
|
char ver2[4]=EEPROM_VERSION;
|
||||||
i=EEPROM_OFFSET;
|
i=EEPROM_OFFSET;
|
||||||
EEPROM_writeAnything(i,ver2); // validate data
|
EEPROM_writeAnything(i,ver2); // validate data
|
||||||
SERIAL_ECHOLN("Settings Stored");
|
SERIAL_ECHOLN("Settings Stored");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RetrieveSettings(bool def=false){ // if def=true, the default values will be used
|
void RetrieveSettings(bool def=false)
|
||||||
|
{ // if def=true, the default values will be used
|
||||||
int i=EEPROM_OFFSET;
|
int i=EEPROM_OFFSET;
|
||||||
char stored_ver[4];
|
char stored_ver[4];
|
||||||
char ver[4]=EEPROM_VERSION;
|
char ver[4]=EEPROM_VERSION;
|
||||||
EEPROM_readAnything(i,stored_ver); //read stored version
|
EEPROM_readAnything(i,stored_ver); //read stored version
|
||||||
// SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
|
// SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]");
|
||||||
if ((!def)&&(strncmp(ver,stored_ver,3)==0)) { // version number match
|
if ((!def)&&(strncmp(ver,stored_ver,3)==0))
|
||||||
EEPROM_readAnything(i,axis_steps_per_unit);
|
{ // version number match
|
||||||
EEPROM_readAnything(i,max_feedrate);
|
EEPROM_readAnything(i,axis_steps_per_unit);
|
||||||
EEPROM_readAnything(i,max_acceleration_units_per_sq_second);
|
EEPROM_readAnything(i,max_feedrate);
|
||||||
EEPROM_readAnything(i,acceleration);
|
EEPROM_readAnything(i,max_acceleration_units_per_sq_second);
|
||||||
EEPROM_readAnything(i,retract_acceleration);
|
EEPROM_readAnything(i,acceleration);
|
||||||
EEPROM_readAnything(i,minimumfeedrate);
|
EEPROM_readAnything(i,retract_acceleration);
|
||||||
EEPROM_readAnything(i,mintravelfeedrate);
|
EEPROM_readAnything(i,minimumfeedrate);
|
||||||
EEPROM_readAnything(i,minsegmenttime);
|
EEPROM_readAnything(i,mintravelfeedrate);
|
||||||
EEPROM_readAnything(i,max_xy_jerk);
|
EEPROM_readAnything(i,minsegmenttime);
|
||||||
EEPROM_readAnything(i,max_z_jerk);
|
EEPROM_readAnything(i,max_xy_jerk);
|
||||||
#ifndef PIDTEMP
|
EEPROM_readAnything(i,max_z_jerk);
|
||||||
|
#ifndef PIDTEMP
|
||||||
float Kp,Ki,Kd;
|
float Kp,Ki,Kd;
|
||||||
#endif
|
#endif
|
||||||
EEPROM_readAnything(i,Kp);
|
EEPROM_readAnything(i,Kp);
|
||||||
EEPROM_readAnything(i,Ki);
|
EEPROM_readAnything(i,Ki);
|
||||||
EEPROM_readAnything(i,Kd);
|
EEPROM_readAnything(i,Kd);
|
||||||
|
|
||||||
SERIAL_ECHOLN("Stored settings retreived:");
|
SERIAL_ECHOLN("Stored settings retreived:");
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
|
float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
|
||||||
float tmp2[]=DEFAULT_MAX_FEEDRATE;
|
float tmp2[]=DEFAULT_MAX_FEEDRATE;
|
||||||
long tmp3[]=DEFAULT_MAX_ACCELERATION;
|
long tmp3[]=DEFAULT_MAX_ACCELERATION;
|
||||||
for (int i=0;i<4;i++) {
|
for (short i=0;i<4;i++)
|
||||||
|
{
|
||||||
axis_steps_per_unit[i]=tmp1[i];
|
axis_steps_per_unit[i]=tmp1[i];
|
||||||
max_feedrate[i]=tmp2[i];
|
max_feedrate[i]=tmp2[i];
|
||||||
max_acceleration_units_per_sq_second[i]=tmp3[i];
|
max_acceleration_units_per_sq_second[i]=tmp3[i];
|
||||||
|
@ -117,11 +123,10 @@ void RetrieveSettings(bool def=false){ // if def=true, the default values will
|
||||||
SERIAL_ECHOLN(" M204 S" <<_FLOAT(acceleration,2) << " T" << _FLOAT(retract_acceleration,2));
|
SERIAL_ECHOLN(" M204 S" <<_FLOAT(acceleration,2) << " T" << _FLOAT(retract_acceleration,2));
|
||||||
SERIAL_ECHOLN("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum xY jerk (mm/s), Z=maximum Z jerk (mm/s)");
|
SERIAL_ECHOLN("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum xY jerk (mm/s), Z=maximum Z jerk (mm/s)");
|
||||||
SERIAL_ECHOLN(" M205 S" <<_FLOAT(minimumfeedrate/60,2) << " T" << _FLOAT(mintravelfeedrate/60,2) << " B" << _FLOAT(minsegmenttime,2) << " X" << _FLOAT(max_xy_jerk/60,2) << " Z" << _FLOAT(max_z_jerk/60,2));
|
SERIAL_ECHOLN(" M205 S" <<_FLOAT(minimumfeedrate/60,2) << " T" << _FLOAT(mintravelfeedrate/60,2) << " B" << _FLOAT(minsegmenttime,2) << " X" << _FLOAT(max_xy_jerk/60,2) << " Z" << _FLOAT(max_z_jerk/60,2));
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
SERIAL_ECHOLN("PID settings:");
|
SERIAL_ECHOLN("PID settings:");
|
||||||
SERIAL_ECHOLN(" M301 P" << _FLOAT(Kp,3) << " I" << _FLOAT(Ki,3) << " D" << _FLOAT(Kd,3));
|
SERIAL_ECHOLN(" M301 P" << _FLOAT(Kp,3) << " I" << _FLOAT(Ki,3) << " D" << _FLOAT(Kd,3));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,41 +18,39 @@ void process_commands();
|
||||||
void manage_inactivity(byte debug);
|
void manage_inactivity(byte debug);
|
||||||
|
|
||||||
#if X_ENABLE_PIN > -1
|
#if X_ENABLE_PIN > -1
|
||||||
#define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
|
#define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
|
||||||
#define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON)
|
#define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON)
|
||||||
#else
|
#else
|
||||||
#define enable_x() ;
|
#define enable_x() ;
|
||||||
#define disable_x() ;
|
#define disable_x() ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if Y_ENABLE_PIN > -1
|
#if Y_ENABLE_PIN > -1
|
||||||
#define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
|
#define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
|
||||||
#define disable_y() WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON)
|
#define disable_y() WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON)
|
||||||
#else
|
#else
|
||||||
#define enable_y() ;
|
#define enable_y() ;
|
||||||
#define disable_y() ;
|
#define disable_y() ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if Z_ENABLE_PIN > -1
|
#if Z_ENABLE_PIN > -1
|
||||||
#define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
|
#define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
|
||||||
#define disable_z() WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON)
|
#define disable_z() WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON)
|
||||||
#else
|
#else
|
||||||
#define enable_z() ;
|
#define enable_z() ;
|
||||||
#define disable_z() ;
|
#define disable_z() ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if E_ENABLE_PIN > -1
|
#if E_ENABLE_PIN > -1
|
||||||
|
#define enable_e() WRITE(E_ENABLE_PIN, E_ENABLE_ON)
|
||||||
#define enable_e() WRITE(E_ENABLE_PIN, E_ENABLE_ON)
|
#define disable_e() WRITE(E_ENABLE_PIN,!E_ENABLE_ON)
|
||||||
#define disable_e() WRITE(E_ENABLE_PIN,!E_ENABLE_ON)
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define enable_e() ;
|
#define enable_e() ;
|
||||||
#define disable_e() ;
|
#define disable_e() ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define X_AXIS 0
|
enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3};
|
||||||
#define Y_AXIS 1
|
|
||||||
#define Z_AXIS 2
|
|
||||||
#define E_AXIS 3
|
|
||||||
|
|
||||||
void FlushSerialRequestResend();
|
void FlushSerialRequestResend();
|
||||||
void ClearToSend();
|
void ClearToSend();
|
||||||
|
@ -61,26 +59,15 @@ void get_coordinates();
|
||||||
void prepare_move();
|
void prepare_move();
|
||||||
void kill();
|
void kill();
|
||||||
|
|
||||||
//void check_axes_activity();
|
|
||||||
//void plan_init();
|
|
||||||
//void st_init();
|
|
||||||
//void tp_init();
|
|
||||||
//void plan_buffer_line(float x, float y, float z, float e, float feed_rate);
|
|
||||||
//void plan_set_position(float x, float y, float z, float e);
|
|
||||||
//void st_wake_up();
|
|
||||||
//void st_synchronize();
|
|
||||||
void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer.
|
void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer.
|
||||||
|
|
||||||
|
|
||||||
#ifndef CRITICAL_SECTION_START
|
#ifndef CRITICAL_SECTION_START
|
||||||
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
|
#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
|
||||||
#define CRITICAL_SECTION_END SREG = _sreg;
|
#define CRITICAL_SECTION_END SREG = _sreg;
|
||||||
#endif //CRITICAL_SECTION_START
|
#endif //CRITICAL_SECTION_START
|
||||||
|
|
||||||
extern float homing_feedrate[];
|
extern float homing_feedrate[];
|
||||||
extern bool axis_relative_modes[];
|
extern bool axis_relative_modes[];
|
||||||
|
|
||||||
|
|
||||||
void kill();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
|
http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <EEPROM.h>
|
||||||
#include "EEPROMwrite.h"
|
#include "EEPROMwrite.h"
|
||||||
#include "fastio.h"
|
#include "fastio.h"
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
|
@ -37,14 +38,11 @@
|
||||||
#include "temperature.h"
|
#include "temperature.h"
|
||||||
#include "motion_control.h"
|
#include "motion_control.h"
|
||||||
|
|
||||||
#ifdef SIMPLE_LCD
|
|
||||||
#include "Simplelcd.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char version_string[] = "1.0.0 Alpha 1";
|
char version_string[] = "1.0.0 Alpha 1";
|
||||||
|
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
#include "SdFat.h"
|
#include "SdFat.h"
|
||||||
#endif //SDSUPPORT
|
#endif //SDSUPPORT
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,12 +107,9 @@ char version_string[] = "1.0.0 Alpha 1";
|
||||||
|
|
||||||
//Stepper Movement Variables
|
//Stepper Movement Variables
|
||||||
|
|
||||||
char axis_codes[NUM_AXIS] = {
|
const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
|
||||||
'X', 'Y', 'Z', 'E'};
|
float destination[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
|
||||||
float destination[NUM_AXIS] = {
|
float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
|
||||||
0.0, 0.0, 0.0, 0.0};
|
|
||||||
float current_position[NUM_AXIS] = {
|
|
||||||
0.0, 0.0, 0.0, 0.0};
|
|
||||||
float offset[3] = {0.0, 0.0, 0.0};
|
float offset[3] = {0.0, 0.0, 0.0};
|
||||||
bool home_all_axis = true;
|
bool home_all_axis = true;
|
||||||
float feedrate = 1500.0, next_feedrate, saved_feedrate;
|
float feedrate = 1500.0, next_feedrate, saved_feedrate;
|
||||||
|
@ -131,6 +126,7 @@ uint8_t fanpwm=0;
|
||||||
volatile int feedmultiply=100; //100->1 200->2
|
volatile int feedmultiply=100; //100->1 200->2
|
||||||
int saved_feedmultiply;
|
int saved_feedmultiply;
|
||||||
volatile bool feedmultiplychanged=false;
|
volatile bool feedmultiplychanged=false;
|
||||||
|
|
||||||
// comm variables
|
// comm variables
|
||||||
#define MAX_CMD_SIZE 96
|
#define MAX_CMD_SIZE 96
|
||||||
#define BUFSIZE 4
|
#define BUFSIZE 4
|
||||||
|
@ -146,13 +142,10 @@ boolean comment_mode = false;
|
||||||
char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc
|
char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc
|
||||||
extern float HeaterPower;
|
extern float HeaterPower;
|
||||||
|
|
||||||
#include "EEPROM.h"
|
|
||||||
|
|
||||||
const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42
|
const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42
|
||||||
|
|
||||||
float tt = 0, bt = 0;
|
float tt = 0, bt = 0;
|
||||||
|
|
||||||
|
|
||||||
//Inactivity shutdown variables
|
//Inactivity shutdown variables
|
||||||
unsigned long previous_millis_cmd = 0;
|
unsigned long previous_millis_cmd = 0;
|
||||||
unsigned long max_inactive_time = 0;
|
unsigned long max_inactive_time = 0;
|
||||||
|
@ -161,73 +154,81 @@ unsigned long stepper_inactive_time = 0;
|
||||||
unsigned long starttime=0;
|
unsigned long starttime=0;
|
||||||
unsigned long stoptime=0;
|
unsigned long stoptime=0;
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
Sd2Card card;
|
Sd2Card card;
|
||||||
SdVolume volume;
|
SdVolume volume;
|
||||||
SdFile root;
|
SdFile root;
|
||||||
SdFile file;
|
SdFile file;
|
||||||
uint32_t filesize = 0;
|
uint32_t filesize = 0;
|
||||||
uint32_t sdpos = 0;
|
uint32_t sdpos = 0;
|
||||||
bool sdmode = false;
|
bool sdmode = false;
|
||||||
bool sdactive = false;
|
bool sdactive = false;
|
||||||
bool savetosd = false;
|
bool savetosd = false;
|
||||||
int16_t n;
|
int16_t n;
|
||||||
unsigned long autostart_atmillis=0;
|
unsigned long autostart_atmillis=0;
|
||||||
|
|
||||||
void initsd()
|
bool autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
|
||||||
{
|
|
||||||
sdactive = false;
|
|
||||||
#if SDSS >- 1
|
|
||||||
if(root.isOpen())
|
|
||||||
root.close();
|
|
||||||
if (!card.init(SPI_FULL_SPEED,SDSS))
|
|
||||||
{
|
|
||||||
//if (!card.init(SPI_HALF_SPEED,SDSS))
|
|
||||||
SERIAL_ECHOLN("SD init fail");
|
|
||||||
}
|
|
||||||
else if (!volume.init(&card))
|
|
||||||
{
|
|
||||||
SERIAL_ERRORLN("volume.init failed");
|
|
||||||
}
|
|
||||||
else if (!root.openRoot(&volume))
|
|
||||||
{
|
|
||||||
SERIAL_ERRORLN("openRoot failed");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sdactive = true;
|
|
||||||
SERIAL_ECHOLN("SD card ok");
|
|
||||||
}
|
|
||||||
#endif //SDSS
|
|
||||||
}
|
|
||||||
|
|
||||||
void quickinitsd(){
|
|
||||||
sdactive=false;
|
|
||||||
autostart_atmillis=millis()+5000;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void write_command(char *buf){
|
void initsd()
|
||||||
char* begin = buf;
|
{
|
||||||
char* npos = 0;
|
sdactive = false;
|
||||||
char* end = buf + strlen(buf) - 1;
|
#if SDSS >- 1
|
||||||
|
if(root.isOpen())
|
||||||
|
root.close();
|
||||||
|
if (!card.init(SPI_FULL_SPEED,SDSS))
|
||||||
|
{
|
||||||
|
//if (!card.init(SPI_HALF_SPEED,SDSS))
|
||||||
|
SERIAL_ECHOLN("SD init fail");
|
||||||
|
}
|
||||||
|
else if (!volume.init(&card))
|
||||||
|
{
|
||||||
|
SERIAL_ERRORLN("volume.init failed");
|
||||||
|
}
|
||||||
|
else if (!root.openRoot(&volume))
|
||||||
|
{
|
||||||
|
SERIAL_ERRORLN("openRoot failed");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sdactive = true;
|
||||||
|
SERIAL_ECHOLN("SD card ok");
|
||||||
|
}
|
||||||
|
#endif //SDSS
|
||||||
|
}
|
||||||
|
|
||||||
file.writeError = false;
|
void quickinitsd()
|
||||||
if((npos = strchr(buf, 'N')) != NULL){
|
{
|
||||||
begin = strchr(npos, ' ') + 1;
|
sdactive=false;
|
||||||
end = strchr(npos, '*') - 1;
|
autostart_atmillis=millis()+5000;
|
||||||
}
|
}
|
||||||
end[1] = '\r';
|
|
||||||
end[2] = '\n';
|
inline void write_command(char *buf)
|
||||||
end[3] = '\0';
|
{
|
||||||
//Serial.println(begin);
|
char* begin = buf;
|
||||||
file.write(begin);
|
char* npos = 0;
|
||||||
if (file.writeError){
|
char* end = buf + strlen(buf) - 1;
|
||||||
SERIAL_ERRORLN("error writing to file");
|
|
||||||
|
file.writeError = false;
|
||||||
|
if((npos = strchr(buf, 'N')) != NULL)
|
||||||
|
{
|
||||||
|
begin = strchr(npos, ' ') + 1;
|
||||||
|
end = strchr(npos, '*') - 1;
|
||||||
|
}
|
||||||
|
end[1] = '\r';
|
||||||
|
end[2] = '\n';
|
||||||
|
end[3] = '\0';
|
||||||
|
file.write(begin);
|
||||||
|
if (file.writeError)
|
||||||
|
{
|
||||||
|
SERIAL_ERRORLN("error writing to file");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif //SDSUPPORT
|
#endif //SDSUPPORT
|
||||||
|
|
||||||
|
|
||||||
///adds an command to the main command buffer
|
//adds an command to the main command buffer
|
||||||
|
//thats really done in a non-safe way.
|
||||||
|
//needs overworking someday
|
||||||
void enquecommand(const char *cmd)
|
void enquecommand(const char *cmd)
|
||||||
{
|
{
|
||||||
if(buflen < BUFSIZE)
|
if(buflen < BUFSIZE)
|
||||||
|
@ -242,106 +243,93 @@ void enquecommand(const char *cmd)
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
Serial.begin(BAUDRATE);
|
Serial.begin(BAUDRATE);
|
||||||
SERIAL_ECHOLN("Marlin "<<version_string);
|
SERIAL_ECHOLN("Marlin "<<version_string);
|
||||||
Serial.println("start");
|
Serial.println("start");
|
||||||
#if defined FANCY_LCD || defined SIMPLE_LCD
|
for(int i = 0; i < BUFSIZE; i++)
|
||||||
lcd_init();
|
{
|
||||||
#endif
|
|
||||||
for(int i = 0; i < BUFSIZE; i++){
|
|
||||||
fromsd[i] = false;
|
fromsd[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RetrieveSettings(); // loads data from EEPROM if available
|
RetrieveSettings(); // loads data from EEPROM if available
|
||||||
|
|
||||||
|
for(int i=0; i < NUM_AXIS; i++)
|
||||||
for(int i=0; i < NUM_AXIS; i++){
|
{
|
||||||
axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
|
axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
//power to SD reader
|
//power to SD reader
|
||||||
#if SDPOWER > -1
|
#if SDPOWER > -1
|
||||||
SET_OUTPUT(SDPOWER);
|
SET_OUTPUT(SDPOWER);
|
||||||
WRITE(SDPOWER,HIGH);
|
WRITE(SDPOWER,HIGH);
|
||||||
#endif //SDPOWER
|
#endif //SDPOWER
|
||||||
quickinitsd();
|
quickinitsd();
|
||||||
|
#endif //SDSUPPORT
|
||||||
|
|
||||||
#endif //SDSUPPORT
|
|
||||||
plan_init(); // Initialize planner;
|
plan_init(); // Initialize planner;
|
||||||
st_init(); // Initialize stepper;
|
st_init(); // Initialize stepper;
|
||||||
tp_init(); // Initialize temperature loop
|
tp_init(); // Initialize temperature loop
|
||||||
//checkautostart();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
bool autostart_stilltocheck=true;
|
|
||||||
|
|
||||||
|
|
||||||
void checkautostart(bool force)
|
void checkautostart(bool force)
|
||||||
{
|
{
|
||||||
//this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
|
//this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
|
||||||
if(!force)
|
if(!force)
|
||||||
{
|
{
|
||||||
if(!autostart_stilltocheck)
|
if(!autostart_stilltocheck)
|
||||||
return;
|
return;
|
||||||
if(autostart_atmillis<millis())
|
if(autostart_atmillis<millis())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
autostart_stilltocheck=false;
|
autostart_stilltocheck=false;
|
||||||
if(!sdactive)
|
if(!sdactive)
|
||||||
{
|
{
|
||||||
initsd();
|
initsd();
|
||||||
if(!sdactive) //fail
|
if(!sdactive) //fail
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
static int lastnr=0;
|
static int lastnr=0;
|
||||||
char autoname[30];
|
char autoname[30];
|
||||||
sprintf(autoname,"auto%i.g",lastnr);
|
sprintf(autoname,"auto%i.g",lastnr);
|
||||||
for(int i=0;i<(int)strlen(autoname);i++)
|
for(int i=0;i<(int)strlen(autoname);i++)
|
||||||
autoname[i]=tolower(autoname[i]);
|
autoname[i]=tolower(autoname[i]);
|
||||||
dir_t p;
|
dir_t p;
|
||||||
|
|
||||||
root.rewind();
|
root.rewind();
|
||||||
//char filename[11];
|
|
||||||
//int cnt=0;
|
|
||||||
|
|
||||||
bool found=false;
|
bool found=false;
|
||||||
while (root.readDir(p) > 0)
|
while (root.readDir(p) > 0)
|
||||||
{
|
{
|
||||||
for(int i=0;i<(int)strlen((char*)p.name);i++)
|
for(int i=0;i<(int)strlen((char*)p.name);i++)
|
||||||
p.name[i]=tolower(p.name[i]);
|
p.name[i]=tolower(p.name[i]);
|
||||||
//Serial.print((char*)p.name);
|
//Serial.print((char*)p.name);
|
||||||
//Serial.print(" ");
|
//Serial.print(" ");
|
||||||
//Serial.println(autoname);
|
//Serial.println(autoname);
|
||||||
if(p.name[9]!='~') //skip safety copies
|
if(p.name[9]!='~') //skip safety copies
|
||||||
if(strncmp((char*)p.name,autoname,5)==0)
|
if(strncmp((char*)p.name,autoname,5)==0)
|
||||||
{
|
{
|
||||||
char cmd[30];
|
char cmd[30];
|
||||||
|
|
||||||
sprintf(cmd,"M23 %s",autoname);
|
|
||||||
//sprintf(cmd,"M115");
|
|
||||||
//enquecommand("G92 Z0");
|
|
||||||
//enquecommand("G1 Z10 F2000");
|
|
||||||
//enquecommand("G28 X-105 Y-105");
|
|
||||||
enquecommand(cmd);
|
|
||||||
enquecommand("M24");
|
|
||||||
found=true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!found)
|
|
||||||
lastnr=-1;
|
|
||||||
else
|
|
||||||
lastnr++;
|
|
||||||
|
|
||||||
|
sprintf(cmd,"M23 %s",autoname);
|
||||||
|
//sprintf(cmd,"M115");
|
||||||
|
//enquecommand("G92 Z0");
|
||||||
|
//enquecommand("G1 Z10 F2000");
|
||||||
|
//enquecommand("G28 X-105 Y-105");
|
||||||
|
enquecommand(cmd);
|
||||||
|
enquecommand("M24");
|
||||||
|
found=true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!found)
|
||||||
|
lastnr=-1;
|
||||||
|
else
|
||||||
|
lastnr++;
|
||||||
}
|
}
|
||||||
#else
|
#else //NO SD SUPORT
|
||||||
|
inline void checkautostart(bool x){}
|
||||||
inline void checkautostart(bool x)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -349,28 +337,32 @@ void loop()
|
||||||
{
|
{
|
||||||
if(buflen<3)
|
if(buflen<3)
|
||||||
get_command();
|
get_command();
|
||||||
checkautostart(false);
|
checkautostart(false);
|
||||||
if(buflen)
|
if(buflen)
|
||||||
{
|
{
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
if(savetosd){
|
if(savetosd)
|
||||||
if(strstr(cmdbuffer[bufindr],"M29") == NULL){
|
{
|
||||||
write_command(cmdbuffer[bufindr]);
|
if(strstr(cmdbuffer[bufindr],"M29") == NULL)
|
||||||
Serial.println("ok");
|
{
|
||||||
|
write_command(cmdbuffer[bufindr]);
|
||||||
|
Serial.println("ok");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file.sync();
|
||||||
|
file.close();
|
||||||
|
savetosd = false;
|
||||||
|
Serial.println("Done saving file.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
file.sync();
|
{
|
||||||
file.close();
|
process_commands();
|
||||||
savetosd = false;
|
|
||||||
Serial.println("Done saving file.");
|
|
||||||
}
|
}
|
||||||
}
|
#else
|
||||||
else{
|
|
||||||
process_commands();
|
process_commands();
|
||||||
}
|
#endif //SDSUPPORT
|
||||||
#else
|
|
||||||
process_commands();
|
|
||||||
#endif //SDSUPPORT
|
|
||||||
buflen = (buflen-1);
|
buflen = (buflen-1);
|
||||||
bufindr = (bufindr + 1)%BUFSIZE;
|
bufindr = (bufindr + 1)%BUFSIZE;
|
||||||
}
|
}
|
||||||
|
@ -449,10 +441,10 @@ inline void get_command()
|
||||||
case 1:
|
case 1:
|
||||||
case 2:
|
case 2:
|
||||||
case 3:
|
case 3:
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
if(savetosd)
|
if(savetosd)
|
||||||
break;
|
break;
|
||||||
#endif //SDSUPPORT
|
#endif //SDSUPPORT
|
||||||
Serial.println("ok");
|
Serial.println("ok");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -473,7 +465,7 @@ inline void get_command()
|
||||||
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
|
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
if(!sdmode || serial_count!=0){
|
if(!sdmode || serial_count!=0){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -486,18 +478,19 @@ inline void get_command()
|
||||||
if(sdpos >= filesize){
|
if(sdpos >= filesize){
|
||||||
sdmode = false;
|
sdmode = false;
|
||||||
Serial.println("echo: Done printing file");
|
Serial.println("echo: Done printing file");
|
||||||
stoptime=millis();
|
stoptime=millis();
|
||||||
char time[30];
|
char time[30];
|
||||||
unsigned long t=(stoptime-starttime)/1000;
|
unsigned long t=(stoptime-starttime)/1000;
|
||||||
int sec,min;
|
int sec,min;
|
||||||
min=t/60;
|
min=t/60;
|
||||||
sec=t%60;
|
sec=t%60;
|
||||||
sprintf(time,"echo: %i min, %i sec",min,sec);
|
sprintf(time,"echo: %i min, %i sec",min,sec);
|
||||||
Serial.println(time);
|
Serial.println(time);
|
||||||
LCD_MESSAGE(time);
|
LCD_MESSAGE(time);
|
||||||
checkautostart(true);
|
checkautostart(true);
|
||||||
}
|
}
|
||||||
if(!serial_count) return; //if empty line
|
if(!serial_count)
|
||||||
|
return; //if empty line
|
||||||
cmdbuffer[bufindw][serial_count] = 0; //terminate string
|
cmdbuffer[bufindw][serial_count] = 0; //terminate string
|
||||||
if(!comment_mode){
|
if(!comment_mode){
|
||||||
fromsd[bufindw] = true;
|
fromsd[bufindw] = true;
|
||||||
|
@ -513,20 +506,23 @@ inline void get_command()
|
||||||
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
|
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif //SDSUPPORT
|
#endif //SDSUPPORT
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline float code_value() {
|
inline float code_value()
|
||||||
|
{
|
||||||
return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL));
|
return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL));
|
||||||
}
|
}
|
||||||
inline long code_value_long() {
|
inline long code_value_long()
|
||||||
|
{
|
||||||
return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10));
|
return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10));
|
||||||
}
|
}
|
||||||
inline bool code_seen(char code_string[]) {
|
inline bool code_seen(char code_string[]) //Return True if the string was found
|
||||||
|
{
|
||||||
return (strstr(cmdbuffer[bufindr], code_string) != NULL);
|
return (strstr(cmdbuffer[bufindr], code_string) != NULL);
|
||||||
} //Return True if the string was found
|
}
|
||||||
|
|
||||||
inline bool code_seen(char code)
|
inline bool code_seen(char code)
|
||||||
{
|
{
|
||||||
|
@ -579,10 +575,10 @@ inline void process_commands()
|
||||||
destination[i] = current_position[i];
|
destination[i] = current_position[i];
|
||||||
}
|
}
|
||||||
feedrate = 0.0;
|
feedrate = 0.0;
|
||||||
|
|
||||||
home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));
|
home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));
|
||||||
|
|
||||||
if((home_all_axis) || (code_seen(axis_codes[X_AXIS]))) {
|
if((home_all_axis) || (code_seen(axis_codes[X_AXIS])))
|
||||||
|
{
|
||||||
if ((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1)){
|
if ((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1)){
|
||||||
// st_synchronize();
|
// st_synchronize();
|
||||||
current_position[X_AXIS] = 0;
|
current_position[X_AXIS] = 0;
|
||||||
|
@ -689,7 +685,7 @@ inline void process_commands()
|
||||||
|
|
||||||
switch( (int)code_value() )
|
switch( (int)code_value() )
|
||||||
{
|
{
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
|
|
||||||
case 20: // M20 - list SD card
|
case 20: // M20 - list SD card
|
||||||
Serial.println("Begin file list");
|
Serial.println("Begin file list");
|
||||||
|
@ -781,6 +777,8 @@ inline void process_commands()
|
||||||
//processed in write to file routine above
|
//processed in write to file routine above
|
||||||
//savetosd = false;
|
//savetosd = false;
|
||||||
break;
|
break;
|
||||||
|
#endif //SDSUPPORT
|
||||||
|
|
||||||
case 30: //M30 take time since the start of the SD print or an M109 command
|
case 30: //M30 take time since the start of the SD print or an M109 command
|
||||||
{
|
{
|
||||||
stoptime=millis();
|
stoptime=millis();
|
||||||
|
@ -794,133 +792,134 @@ inline void process_commands()
|
||||||
LCD_MESSAGE(time);
|
LCD_MESSAGE(time);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif //SDSUPPORT
|
case 42: //M42 -Change pin status via gcode
|
||||||
case 42: //M42 -Change pin status via gcode
|
if (code_seen('S'))
|
||||||
if (code_seen('S'))
|
{
|
||||||
|
int pin_status = code_value();
|
||||||
|
if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
|
||||||
{
|
{
|
||||||
int pin_status = code_value();
|
int pin_number = code_value();
|
||||||
if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
|
for(int i = 0; i < (int)sizeof(sensitive_pins); i++)
|
||||||
{
|
{
|
||||||
int pin_number = code_value();
|
if (sensitive_pins[i] == pin_number)
|
||||||
for(int i = 0; i < (int)sizeof(sensitive_pins); i++)
|
|
||||||
{
|
{
|
||||||
if (sensitive_pins[i] == pin_number)
|
pin_number = -1;
|
||||||
{
|
break;
|
||||||
pin_number = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pin_number > -1)
|
if (pin_number > -1)
|
||||||
{
|
{
|
||||||
pinMode(pin_number, OUTPUT);
|
pinMode(pin_number, OUTPUT);
|
||||||
digitalWrite(pin_number, pin_status);
|
digitalWrite(pin_number, pin_status);
|
||||||
analogWrite(pin_number, pin_status);
|
analogWrite(pin_number, pin_status);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 104: // M104
|
break;
|
||||||
if (code_seen('S')) setTargetHotend0(code_value());
|
case 104: // M104
|
||||||
setWatch();
|
if (code_seen('S')) setTargetHotend0(code_value());
|
||||||
break;
|
setWatch();
|
||||||
case 140: // M140 set bed temp
|
break;
|
||||||
if (code_seen('S')) setTargetBed(code_value());
|
case 140: // M140 set bed temp
|
||||||
break;
|
if (code_seen('S')) setTargetBed(code_value());
|
||||||
case 105: // M105
|
break;
|
||||||
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
|
case 105: // M105
|
||||||
tt = degHotend0();
|
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
|
||||||
#endif
|
tt = degHotend0();
|
||||||
|
#endif
|
||||||
|
#if TEMP_1_PIN > -1
|
||||||
|
bt = degBed();
|
||||||
|
#endif
|
||||||
|
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
|
||||||
|
Serial.print("ok T:");
|
||||||
|
Serial.print(tt);
|
||||||
#if TEMP_1_PIN > -1
|
#if TEMP_1_PIN > -1
|
||||||
bt = degBed();
|
#ifdef PIDTEMP
|
||||||
#endif
|
|
||||||
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
|
|
||||||
Serial.print("ok T:");
|
|
||||||
Serial.print(tt);
|
|
||||||
// Serial.print(", raw:");
|
|
||||||
// Serial.print(current_raw);
|
|
||||||
#if TEMP_1_PIN > -1
|
|
||||||
#ifdef PIDTEMP
|
|
||||||
Serial.print(" B:");
|
Serial.print(" B:");
|
||||||
#if TEMP_1_PIN > -1
|
#if TEMP_1_PIN > -1
|
||||||
Serial.println(bt);
|
Serial.println(bt);
|
||||||
#else
|
#else
|
||||||
Serial.println(HeaterPower);
|
Serial.println(HeaterPower);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else //not PIDTEMP
|
||||||
Serial.println();
|
Serial.println();
|
||||||
#endif
|
#endif //PIDTEMP
|
||||||
#else
|
#else
|
||||||
Serial.println();
|
Serial.println();
|
||||||
#endif
|
#endif //TEMP_1_PIN
|
||||||
#else
|
#else
|
||||||
Serial.println("echo: No thermistors - no temp");
|
Serial.println("echo: No thermistors - no temp");
|
||||||
#endif
|
|
||||||
return;
|
|
||||||
//break;
|
|
||||||
case 109: {// M109 - Wait for extruder heater to reach target.
|
|
||||||
LCD_MESSAGE("Heating...");
|
|
||||||
if (code_seen('S')) setTargetHotend0(code_value());
|
|
||||||
|
|
||||||
setWatch();
|
|
||||||
codenum = millis();
|
|
||||||
|
|
||||||
/* See if we are heating up or cooling down */
|
|
||||||
bool target_direction = isHeatingHotend0(); // true if heating, false if cooling
|
|
||||||
|
|
||||||
#ifdef TEMP_RESIDENCY_TIME
|
|
||||||
long residencyStart;
|
|
||||||
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 ? (isHeatingHotend0()) : (isCoolingHotend0()) ||
|
|
||||||
(residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
|
|
||||||
#else
|
|
||||||
while ( target_direction ? (isHeatingHotend0()) : (isCoolingHotend0()) ) {
|
|
||||||
#endif //TEMP_RESIDENCY_TIME
|
|
||||||
if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down
|
|
||||||
Serial.print("T:");
|
|
||||||
Serial.println( degHotend0() );
|
|
||||||
codenum = millis();
|
|
||||||
}
|
|
||||||
manage_heater();
|
|
||||||
LCD_STATUS;
|
|
||||||
#ifdef TEMP_RESIDENCY_TIME
|
|
||||||
/* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
|
|
||||||
or when current temp falls outside the hysteresis after target temp was reached */
|
|
||||||
if ((residencyStart == -1 && target_direction && !isHeatingHotend0()) ||
|
|
||||||
(residencyStart == -1 && !target_direction && !isCoolingHotend0()) ||
|
|
||||||
(residencyStart > -1 && labs(degHotend0() - degTargetHotend0()) > TEMP_HYSTERESIS) ) {
|
|
||||||
residencyStart = millis();
|
|
||||||
}
|
|
||||||
#endif //TEMP_RESIDENCY_TIME
|
|
||||||
}
|
|
||||||
LCD_MESSAGE("Heating done.");
|
|
||||||
starttime=millis();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 190: // M190 - Wait bed for heater to reach target.
|
|
||||||
#if TEMP_1_PIN > -1
|
|
||||||
if (code_seen('S')) setTargetBed(code_value());
|
|
||||||
codenum = millis();
|
|
||||||
while(isHeatingBed())
|
|
||||||
{
|
|
||||||
if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
|
|
||||||
{
|
|
||||||
float tt=degHotend0();
|
|
||||||
Serial.print("T:");
|
|
||||||
Serial.println( tt );
|
|
||||||
Serial.print("ok T:");
|
|
||||||
Serial.print( tt );
|
|
||||||
Serial.print(" B:");
|
|
||||||
Serial.println( degBed() );
|
|
||||||
codenum = millis();
|
|
||||||
}
|
|
||||||
manage_heater();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
return;
|
||||||
break;
|
break;
|
||||||
#if FAN_PIN > -1
|
case 109:
|
||||||
|
{// M109 - Wait for extruder heater to reach target.
|
||||||
|
LCD_MESSAGE("Heating...");
|
||||||
|
if (code_seen('S')) setTargetHotend0(code_value());
|
||||||
|
|
||||||
|
setWatch();
|
||||||
|
codenum = millis();
|
||||||
|
|
||||||
|
/* See if we are heating up or cooling down */
|
||||||
|
bool target_direction = isHeatingHotend0(); // true if heating, false if cooling
|
||||||
|
|
||||||
|
#ifdef TEMP_RESIDENCY_TIME
|
||||||
|
long residencyStart;
|
||||||
|
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 ? (isHeatingHotend0()) : (isCoolingHotend0()) ||
|
||||||
|
(residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
|
||||||
|
#else
|
||||||
|
while ( target_direction ? (isHeatingHotend0()) : (isCoolingHotend0()) ) {
|
||||||
|
#endif //TEMP_RESIDENCY_TIME
|
||||||
|
if( (millis() - codenum) > 1000 )
|
||||||
|
{ //Print Temp Reading every 1 second while heating up/cooling down
|
||||||
|
Serial.print("T:");
|
||||||
|
Serial.println( degHotend0() );
|
||||||
|
codenum = millis();
|
||||||
|
}
|
||||||
|
manage_heater();
|
||||||
|
LCD_STATUS;
|
||||||
|
#ifdef TEMP_RESIDENCY_TIME
|
||||||
|
/* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
|
||||||
|
or when current temp falls outside the hysteresis after target temp was reached */
|
||||||
|
if ((residencyStart == -1 && target_direction && !isHeatingHotend0()) ||
|
||||||
|
(residencyStart == -1 && !target_direction && !isCoolingHotend0()) ||
|
||||||
|
(residencyStart > -1 && labs(degHotend0() - degTargetHotend0()) > TEMP_HYSTERESIS) )
|
||||||
|
{
|
||||||
|
residencyStart = millis();
|
||||||
|
}
|
||||||
|
#endif //TEMP_RESIDENCY_TIME
|
||||||
|
}
|
||||||
|
LCD_MESSAGE("Heating done.");
|
||||||
|
starttime=millis();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 190: // M190 - Wait bed for heater to reach target.
|
||||||
|
#if TEMP_1_PIN > -1
|
||||||
|
if (code_seen('S')) setTargetBed(code_value());
|
||||||
|
codenum = millis();
|
||||||
|
while(isHeatingBed())
|
||||||
|
{
|
||||||
|
if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
|
||||||
|
{
|
||||||
|
float tt=degHotend0();
|
||||||
|
Serial.print("T:");
|
||||||
|
Serial.println( tt );
|
||||||
|
Serial.print("ok T:");
|
||||||
|
Serial.print( tt );
|
||||||
|
Serial.print(" B:");
|
||||||
|
Serial.println( degBed() );
|
||||||
|
codenum = millis();
|
||||||
|
}
|
||||||
|
manage_heater();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
|
||||||
|
#if FAN_PIN > -1
|
||||||
case 106: //M106 Fan On
|
case 106: //M106 Fan On
|
||||||
if (code_seen('S')){
|
if (code_seen('S')){
|
||||||
WRITE(FAN_PIN,HIGH);
|
WRITE(FAN_PIN,HIGH);
|
||||||
|
@ -937,27 +936,29 @@ inline void process_commands()
|
||||||
WRITE(FAN_PIN,LOW);
|
WRITE(FAN_PIN,LOW);
|
||||||
analogWrite(FAN_PIN, 0);
|
analogWrite(FAN_PIN, 0);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif //FAN_PIN
|
||||||
#if (PS_ON_PIN > -1)
|
|
||||||
|
#if (PS_ON_PIN > -1)
|
||||||
case 80: // M80 - ATX Power On
|
case 80: // M80 - ATX Power On
|
||||||
SET_OUTPUT(PS_ON_PIN); //GND
|
SET_OUTPUT(PS_ON_PIN); //GND
|
||||||
break;
|
break;
|
||||||
case 81: // M81 - ATX Power Off
|
case 81: // M81 - ATX Power Off
|
||||||
SET_INPUT(PS_ON_PIN); //Floating
|
SET_INPUT(PS_ON_PIN); //Floating
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 82:
|
case 82:
|
||||||
axis_relative_modes[3] = false;
|
axis_relative_modes[3] = false;
|
||||||
break;
|
break;
|
||||||
case 83:
|
case 83:
|
||||||
axis_relative_modes[3] = true;
|
axis_relative_modes[3] = true;
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18: //compatibility
|
||||||
case 84:
|
case 84:
|
||||||
if(code_seen('S')){
|
if(code_seen('S')){
|
||||||
stepper_inactive_time = code_value() * 1000;
|
stepper_inactive_time = code_value() * 1000;
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
st_synchronize();
|
st_synchronize();
|
||||||
disable_x();
|
disable_x();
|
||||||
disable_y();
|
disable_y();
|
||||||
|
@ -970,13 +971,14 @@ inline void process_commands()
|
||||||
max_inactive_time = code_value() * 1000;
|
max_inactive_time = code_value() * 1000;
|
||||||
break;
|
break;
|
||||||
case 92: // M92
|
case 92: // M92
|
||||||
for(int i=0; i < NUM_AXIS; i++) {
|
for(int i=0; i < NUM_AXIS; i++)
|
||||||
if(code_seen(axis_codes[i])) axis_steps_per_unit[i] = code_value();
|
{
|
||||||
|
if(code_seen(axis_codes[i]))
|
||||||
|
axis_steps_per_unit[i] = code_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 115: // M115
|
case 115: // M115
|
||||||
Serial.println("FIRMWARE_NAME:Sprinter/grbl mashup for gen6 FIRMWARE_URL:http://www.mendel-parts.com PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1");
|
Serial.println("FIRMWARE_NAME:Marlin; Sprinter/grbl mashup for gen6 FIRMWARE_URL:http://www.mendel-parts.com PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1");
|
||||||
break;
|
break;
|
||||||
case 114: // M114
|
case 114: // M114
|
||||||
Serial.print("X:");
|
Serial.print("X:");
|
||||||
|
@ -998,45 +1000,46 @@ inline void process_commands()
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
break;
|
break;
|
||||||
case 119: // M119
|
case 119: // M119
|
||||||
#if (X_MIN_PIN > -1)
|
#if (X_MIN_PIN > -1)
|
||||||
Serial.print("x_min:");
|
Serial.print("x_min:");
|
||||||
Serial.print((READ(X_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
Serial.print((READ(X_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
||||||
#endif
|
#endif
|
||||||
#if (X_MAX_PIN > -1)
|
#if (X_MAX_PIN > -1)
|
||||||
Serial.print("x_max:");
|
Serial.print("x_max:");
|
||||||
Serial.print((READ(X_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
Serial.print((READ(X_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
||||||
#endif
|
#endif
|
||||||
#if (Y_MIN_PIN > -1)
|
#if (Y_MIN_PIN > -1)
|
||||||
Serial.print("y_min:");
|
Serial.print("y_min:");
|
||||||
Serial.print((READ(Y_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
Serial.print((READ(Y_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
||||||
#endif
|
#endif
|
||||||
#if (Y_MAX_PIN > -1)
|
#if (Y_MAX_PIN > -1)
|
||||||
Serial.print("y_max:");
|
Serial.print("y_max:");
|
||||||
Serial.print((READ(Y_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
Serial.print((READ(Y_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
||||||
#endif
|
#endif
|
||||||
#if (Z_MIN_PIN > -1)
|
#if (Z_MIN_PIN > -1)
|
||||||
Serial.print("z_min:");
|
Serial.print("z_min:");
|
||||||
Serial.print((READ(Z_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
Serial.print((READ(Z_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
||||||
#endif
|
#endif
|
||||||
#if (Z_MAX_PIN > -1)
|
#if (Z_MAX_PIN > -1)
|
||||||
Serial.print("z_max:");
|
Serial.print("z_max:");
|
||||||
Serial.print((READ(Z_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
Serial.print((READ(Z_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
|
||||||
#endif
|
#endif
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
break;
|
break;
|
||||||
//TODO: update for all axis, use for loop
|
//TODO: update for all axis, use for loop
|
||||||
case 201: // M201
|
case 201: // M201
|
||||||
for(int i=0; i < NUM_AXIS; i++) {
|
for(int i=0; i < NUM_AXIS; i++)
|
||||||
|
{
|
||||||
if(code_seen(axis_codes[i])) axis_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
|
if(code_seen(axis_codes[i])) axis_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#if 0 // Not used for Sprinter/grbl gen6
|
#if 0 // Not used for Sprinter/grbl gen6
|
||||||
case 202: // M202
|
case 202: // M202
|
||||||
for(int i=0; i < NUM_AXIS; i++) {
|
for(int i=0; i < NUM_AXIS; i++) {
|
||||||
if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
|
if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 203: // M203 max feedrate mm/sec
|
case 203: // M203 max feedrate mm/sec
|
||||||
for(int i=0; i < NUM_AXIS; i++) {
|
for(int i=0; i < NUM_AXIS; i++) {
|
||||||
if(code_seen(axis_codes[i])) max_feedrate[i] = code_value()*60 ;
|
if(code_seen(axis_codes[i])) max_feedrate[i] = code_value()*60 ;
|
||||||
|
@ -1048,59 +1051,52 @@ inline void process_commands()
|
||||||
if(code_seen('T')) retract_acceleration = code_value() ;
|
if(code_seen('T')) retract_acceleration = code_value() ;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 205: //M205 advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk
|
case 205: //M205 advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk
|
||||||
|
{
|
||||||
|
if(code_seen('S')) minimumfeedrate = code_value()*60 ;
|
||||||
|
if(code_seen('T')) mintravelfeedrate = code_value()*60 ;
|
||||||
|
if(code_seen('B')) minsegmenttime = code_value() ;
|
||||||
|
if(code_seen('X')) max_xy_jerk = code_value()*60 ;
|
||||||
|
if(code_seen('Z')) max_z_jerk = code_value()*60 ;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 220: // M220 S<factor in percent>- set speed factor override percentage
|
||||||
|
{
|
||||||
|
if(code_seen('S'))
|
||||||
{
|
{
|
||||||
if(code_seen('S')) minimumfeedrate = code_value()*60 ;
|
feedmultiply = code_value() ;
|
||||||
if(code_seen('T')) mintravelfeedrate = code_value()*60 ;
|
feedmultiplychanged=true;
|
||||||
if(code_seen('B')) minsegmenttime = code_value() ;
|
|
||||||
if(code_seen('X')) max_xy_jerk = code_value()*60 ;
|
|
||||||
if(code_seen('Z')) max_z_jerk = code_value()*60 ;
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 220: // M220 S<factor in percent>- set speed factor override percentage
|
break;
|
||||||
{
|
|
||||||
if(code_seen('S'))
|
#ifdef PIDTEMP
|
||||||
{
|
|
||||||
feedmultiply = code_value() ;
|
|
||||||
feedmultiplychanged=true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#ifdef PIDTEMP
|
|
||||||
case 301: // M301
|
case 301: // M301
|
||||||
if(code_seen('P')) Kp = code_value();
|
if(code_seen('P')) Kp = code_value();
|
||||||
if(code_seen('I')) Ki = code_value()*PID_dT;
|
if(code_seen('I')) Ki = code_value()*PID_dT;
|
||||||
if(code_seen('D')) Kd = code_value()/PID_dT;
|
if(code_seen('D')) Kd = code_value()/PID_dT;
|
||||||
// SERIAL_ECHOLN("Kp "<<_FLOAT(Kp,2));
|
|
||||||
// SERIAL_ECHOLN("Ki "<<_FLOAT(Ki/PID_dT,2));
|
|
||||||
// SERIAL_ECHOLN("Kd "<<_FLOAT(Kd*PID_dT,2));
|
|
||||||
|
|
||||||
// temp_iState_min = 0.0;
|
|
||||||
// if (Ki!=0) {
|
|
||||||
// temp_iState_max = PID_INTEGRAL_DRIVE_MAX / (Ki/100.0);
|
|
||||||
// }
|
|
||||||
// else temp_iState_max = 1.0e10;
|
|
||||||
break;
|
|
||||||
#endif //PIDTEMP
|
|
||||||
case 500: // Store settings in EEPROM
|
|
||||||
{
|
|
||||||
StoreSettings();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 501: // Read settings from EEPROM
|
|
||||||
{
|
|
||||||
RetrieveSettings();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 502: // Revert to default settings
|
|
||||||
{
|
|
||||||
RetrieveSettings(true);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
#endif //PIDTEMP
|
||||||
|
case 500: // Store settings in EEPROM
|
||||||
|
{
|
||||||
|
StoreSettings();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 501: // Read settings from EEPROM
|
||||||
|
{
|
||||||
|
RetrieveSettings();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 502: // Revert to default settings
|
||||||
|
{
|
||||||
|
RetrieveSettings(true);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
Serial.print("echo: Unknown command:\"");
|
Serial.print("echo: Unknown command:\"");
|
||||||
Serial.print(cmdbuffer[bufindr]);
|
Serial.print(cmdbuffer[bufindr]);
|
||||||
Serial.println("\"");
|
Serial.println("\"");
|
||||||
|
@ -1121,10 +1117,10 @@ void FlushSerialRequestResend()
|
||||||
void ClearToSend()
|
void ClearToSend()
|
||||||
{
|
{
|
||||||
previous_millis_cmd = millis();
|
previous_millis_cmd = millis();
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
if(fromsd[bufindr])
|
if(fromsd[bufindr])
|
||||||
return;
|
return;
|
||||||
#endif //SDSUPPORT
|
#endif //SDSUPPORT
|
||||||
Serial.println("ok");
|
Serial.println("ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1132,7 +1128,7 @@ inline void get_coordinates()
|
||||||
{
|
{
|
||||||
for(int i=0; i < NUM_AXIS; i++) {
|
for(int i=0; i < NUM_AXIS; i++) {
|
||||||
if(code_seen(axis_codes[i])) destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i];
|
if(code_seen(axis_codes[i])) destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i];
|
||||||
else destination[i] = current_position[i]; //Are these else lines really needed?
|
else destination[i] = current_position[i]; //Are these else lines really needed?
|
||||||
}
|
}
|
||||||
if(code_seen('F')) {
|
if(code_seen('F')) {
|
||||||
next_feedrate = code_value();
|
next_feedrate = code_value();
|
||||||
|
@ -1276,14 +1272,19 @@ void prepare_arc_move(char isclockwise) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void manage_inactivity(byte debug) {
|
void manage_inactivity(byte debug)
|
||||||
if( (millis()-previous_millis_cmd) > max_inactive_time ) if(max_inactive_time) kill();
|
{
|
||||||
if( (millis()-previous_millis_cmd) > stepper_inactive_time ) if(stepper_inactive_time) {
|
if( (millis()-previous_millis_cmd) > max_inactive_time )
|
||||||
disable_x();
|
if(max_inactive_time)
|
||||||
disable_y();
|
kill();
|
||||||
disable_z();
|
if( (millis()-previous_millis_cmd) > stepper_inactive_time )
|
||||||
disable_e();
|
if(stepper_inactive_time)
|
||||||
}
|
{
|
||||||
|
disable_x();
|
||||||
|
disable_y();
|
||||||
|
disable_z();
|
||||||
|
disable_e();
|
||||||
|
}
|
||||||
check_axes_activity();
|
check_axes_activity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,8 @@
|
||||||
void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8_t axis_1,
|
void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8_t axis_1,
|
||||||
uint8_t axis_linear, float feed_rate, float radius, uint8_t isclockwise)
|
uint8_t axis_linear, float feed_rate, float radius, uint8_t isclockwise)
|
||||||
{
|
{
|
||||||
// int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled();
|
// int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled();
|
||||||
// plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc
|
// plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc
|
||||||
SERIAL_ECHOLN("mc_arc.");
|
SERIAL_ECHOLN("mc_arc.");
|
||||||
float center_axis0 = position[axis_0] + offset[axis_0];
|
float center_axis0 = position[axis_0] + offset[axis_0];
|
||||||
float center_axis1 = position[axis_1] + offset[axis_1];
|
float center_axis1 = position[axis_1] + offset[axis_1];
|
||||||
|
@ -52,12 +52,12 @@ void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8
|
||||||
float millimeters_of_travel = hypot(angular_travel*radius, fabs(linear_travel));
|
float millimeters_of_travel = hypot(angular_travel*radius, fabs(linear_travel));
|
||||||
if (millimeters_of_travel == 0.0) { return; }
|
if (millimeters_of_travel == 0.0) { return; }
|
||||||
uint16_t segments = floor(millimeters_of_travel/MM_PER_ARC_SEGMENT);
|
uint16_t segments = floor(millimeters_of_travel/MM_PER_ARC_SEGMENT);
|
||||||
/*
|
/*
|
||||||
// Multiply inverse feed_rate to compensate for the fact that this movement is approximated
|
// Multiply inverse feed_rate to compensate for the fact that this movement is approximated
|
||||||
// by a number of discrete segments. The inverse feed_rate should be correct for the sum of
|
// by a number of discrete segments. The inverse feed_rate should be correct for the sum of
|
||||||
// all segments.
|
// all segments.
|
||||||
if (invert_feed_rate) { feed_rate *= segments; }
|
if (invert_feed_rate) { feed_rate *= segments; }
|
||||||
*/
|
*/
|
||||||
float theta_per_segment = angular_travel/segments;
|
float theta_per_segment = angular_travel/segments;
|
||||||
float linear_per_segment = linear_travel/segments;
|
float linear_per_segment = linear_travel/segments;
|
||||||
|
|
||||||
|
@ -128,6 +128,6 @@ void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8
|
||||||
// Ensure last segment arrives at target location.
|
// Ensure last segment arrives at target location.
|
||||||
plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feed_rate);
|
plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feed_rate);
|
||||||
|
|
||||||
// plan_set_acceleration_manager_enabled(acceleration_manager_was_enabled);
|
// plan_set_acceleration_manager_enabled(acceleration_manager_was_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -557,6 +557,74 @@
|
||||||
#define FAN_PIN 7
|
#define FAN_PIN 7
|
||||||
#define PS_ON_PIN 12
|
#define PS_ON_PIN 12
|
||||||
#define KILL_PIN -1
|
#define KILL_PIN -1
|
||||||
|
|
||||||
|
#ifdef ULTRA_LCD
|
||||||
|
|
||||||
|
#ifdef NEWPANEL
|
||||||
|
//arduino pin witch triggers an piezzo beeper
|
||||||
|
#define BEEPER 18
|
||||||
|
|
||||||
|
#define LCD_PINS_RS 20
|
||||||
|
#define LCD_PINS_ENABLE 17
|
||||||
|
#define LCD_PINS_D4 16
|
||||||
|
#define LCD_PINS_D5 21
|
||||||
|
#define LCD_PINS_D6 5
|
||||||
|
#define LCD_PINS_D7 6
|
||||||
|
|
||||||
|
//buttons are directly attached
|
||||||
|
#define BTN_EN1 40
|
||||||
|
#define BTN_EN2 42
|
||||||
|
#define BTN_ENC 19 //the click
|
||||||
|
|
||||||
|
#define BLEN_C 2
|
||||||
|
#define BLEN_B 1
|
||||||
|
#define BLEN_A 0
|
||||||
|
|
||||||
|
#define SDCARDDETECT 38
|
||||||
|
|
||||||
|
//encoder rotation values
|
||||||
|
#define encrot0 0
|
||||||
|
#define encrot1 2
|
||||||
|
#define encrot2 3
|
||||||
|
#define encrot3 1
|
||||||
|
#else //old style panel with shift register
|
||||||
|
//arduino pin witch triggers an piezzo beeper
|
||||||
|
#define BEEPER 18
|
||||||
|
|
||||||
|
//buttons are attached to a shift register
|
||||||
|
#define SHIFT_CLK 38
|
||||||
|
#define SHIFT_LD 42
|
||||||
|
#define SHIFT_OUT 40
|
||||||
|
#define SHIFT_EN 17
|
||||||
|
|
||||||
|
#define LCD_PINS_RS 16
|
||||||
|
#define LCD_PINS_ENABLE 5
|
||||||
|
#define LCD_PINS_D4 6
|
||||||
|
#define LCD_PINS_D5 21
|
||||||
|
#define LCD_PINS_D6 20
|
||||||
|
#define LCD_PINS_D7 19
|
||||||
|
|
||||||
|
//encoder rotation values
|
||||||
|
#define encrot0 0
|
||||||
|
#define encrot1 2
|
||||||
|
#define encrot2 3
|
||||||
|
#define encrot3 1
|
||||||
|
|
||||||
|
|
||||||
|
//bits in the shift register that carry the buttons for:
|
||||||
|
// left up center down right red
|
||||||
|
#define BL_LE 7
|
||||||
|
#define BL_UP 6
|
||||||
|
#define BL_MI 5
|
||||||
|
#define BL_DW 4
|
||||||
|
#define BL_RI 3
|
||||||
|
#define BL_ST 2
|
||||||
|
|
||||||
|
#define BLEN_B 1
|
||||||
|
#define BLEN_A 0
|
||||||
|
#endif
|
||||||
|
#endif //ULTRA_LCD
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ static volatile unsigned char block_buffer_head; // Index of the next
|
||||||
static volatile unsigned char block_buffer_tail; // Index of the block to process now
|
static volatile unsigned char block_buffer_tail; // Index of the block to process now
|
||||||
|
|
||||||
// The current position of the tool in absolute steps
|
// The current position of the tool in absolute steps
|
||||||
long position[4];
|
long position[4];
|
||||||
|
|
||||||
#define ONE_MINUTE_OF_MICROSECONDS 60000000.0
|
#define ONE_MINUTE_OF_MICROSECONDS 60000000.0
|
||||||
|
|
||||||
|
@ -123,10 +123,10 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit
|
||||||
long initial_rate = ceil(block->nominal_rate*entry_factor);
|
long initial_rate = ceil(block->nominal_rate*entry_factor);
|
||||||
long final_rate = ceil(block->nominal_rate*exit_factor);
|
long final_rate = ceil(block->nominal_rate*exit_factor);
|
||||||
|
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
long initial_advance = block->advance*entry_factor*entry_factor;
|
long initial_advance = block->advance*entry_factor*entry_factor;
|
||||||
long final_advance = block->advance*exit_factor*exit_factor;
|
long final_advance = block->advance*exit_factor*exit_factor;
|
||||||
#endif // ADVANCE
|
#endif // ADVANCE
|
||||||
|
|
||||||
// Limit minimal step rate (Otherwise the timer will overflow.)
|
// Limit minimal step rate (Otherwise the timer will overflow.)
|
||||||
if(initial_rate <120) initial_rate=120;
|
if(initial_rate <120) initial_rate=120;
|
||||||
|
@ -155,10 +155,10 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit
|
||||||
block->decelerate_after = decelerate_after;
|
block->decelerate_after = decelerate_after;
|
||||||
block->initial_rate = initial_rate;
|
block->initial_rate = initial_rate;
|
||||||
block->final_rate = final_rate;
|
block->final_rate = final_rate;
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
block->initial_advance = initial_advance;
|
block->initial_advance = initial_advance;
|
||||||
block->final_advance = final_advance;
|
block->final_advance = final_advance;
|
||||||
#endif //ADVANCE
|
#endif //ADVANCE
|
||||||
}
|
}
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END;
|
||||||
}
|
}
|
||||||
|
@ -166,18 +166,15 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit
|
||||||
// Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the
|
// Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the
|
||||||
// acceleration within the allotted distance.
|
// acceleration within the allotted distance.
|
||||||
inline float max_allowable_speed(float acceleration, float target_velocity, float distance) {
|
inline float max_allowable_speed(float acceleration, float target_velocity, float distance) {
|
||||||
return(
|
return sqrt(target_velocity*target_velocity-2*acceleration*60*60*distance);
|
||||||
sqrt(target_velocity*target_velocity-2*acceleration*60*60*distance)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Junction jerk" in this context is the immediate change in speed at the junction of two blocks.
|
// "Junction jerk" in this context is the immediate change in speed at the junction of two blocks.
|
||||||
// This method will calculate the junction jerk as the euclidean distance between the nominal
|
// This method will calculate the junction jerk as the euclidean distance between the nominal
|
||||||
// velocities of the respective blocks.
|
// velocities of the respective blocks.
|
||||||
inline float junction_jerk(block_t *before, block_t *after) {
|
inline float junction_jerk(block_t *before, block_t *after) {
|
||||||
return(sqrt(
|
return sqrt(
|
||||||
pow((before->speed_x-after->speed_x), 2)+
|
pow((before->speed_x-after->speed_x), 2)+pow((before->speed_y-after->speed_y), 2));
|
||||||
pow((before->speed_y-after->speed_y), 2)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the safe speed which is max_jerk/2, e.g. the
|
// Return the safe speed which is max_jerk/2, e.g. the
|
||||||
|
@ -185,8 +182,10 @@ inline float junction_jerk(block_t *before, block_t *after) {
|
||||||
float safe_speed(block_t *block) {
|
float safe_speed(block_t *block) {
|
||||||
float safe_speed;
|
float safe_speed;
|
||||||
safe_speed = max_xy_jerk/2;
|
safe_speed = max_xy_jerk/2;
|
||||||
if(abs(block->speed_z) > max_z_jerk/2) safe_speed = max_z_jerk/2;
|
if(abs(block->speed_z) > max_z_jerk/2)
|
||||||
if (safe_speed > block->nominal_speed) safe_speed = block->nominal_speed;
|
safe_speed = max_z_jerk/2;
|
||||||
|
if (safe_speed > block->nominal_speed)
|
||||||
|
safe_speed = block->nominal_speed;
|
||||||
return safe_speed;
|
return safe_speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,9 +378,8 @@ void check_axes_activity() {
|
||||||
// Add a new linear movement to the buffer. steps_x, _y and _z is the absolute position in
|
// Add a new linear movement to the buffer. steps_x, _y and _z is the absolute position in
|
||||||
// mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
|
// mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
|
||||||
// calculation the caller must also provide the physical length of the line in millimeters.
|
// calculation the caller must also provide the physical length of the line in millimeters.
|
||||||
void plan_buffer_line(float x, float y, float z, float e, float feed_rate) {
|
void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate)
|
||||||
|
{
|
||||||
|
|
||||||
// Calculate the buffer head after we push this byte
|
// Calculate the buffer head after we push this byte
|
||||||
int next_buffer_head = (block_buffer_head + 1) & (BLOCK_BUFFER_SIZE - 1);
|
int next_buffer_head = (block_buffer_head + 1) & (BLOCK_BUFFER_SIZE - 1);
|
||||||
|
|
||||||
|
@ -469,11 +467,8 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) {
|
||||||
// Limit speed per axis
|
// Limit speed per axis
|
||||||
float speed_factor = 1; //factor <=1 do decrease speed
|
float speed_factor = 1; //factor <=1 do decrease speed
|
||||||
if(abs(block->speed_x) > max_feedrate[X_AXIS]) {
|
if(abs(block->speed_x) > max_feedrate[X_AXIS]) {
|
||||||
//// [ErikDeBruijn] IS THIS THE BUG WE'RE LOOING FOR????
|
|
||||||
//// [bernhard] No its not, according to Zalm.
|
|
||||||
//// the if would always be true, since tmp_speedfactor <=0 due the inial if, so its safe to set. the next lines actually compare.
|
|
||||||
speed_factor = max_feedrate[X_AXIS] / abs(block->speed_x);
|
speed_factor = max_feedrate[X_AXIS] / abs(block->speed_x);
|
||||||
//if(speed_factor > tmp_speed_factor) speed_factor = tmp_speed_factor;
|
//if(speed_factor > tmp_speed_factor) speed_factor = tmp_speed_factor; /is not need here because auf the init above
|
||||||
}
|
}
|
||||||
if(abs(block->speed_y) > max_feedrate[Y_AXIS]){
|
if(abs(block->speed_y) > max_feedrate[Y_AXIS]){
|
||||||
float tmp_speed_factor = max_feedrate[Y_AXIS] / abs(block->speed_y);
|
float tmp_speed_factor = max_feedrate[Y_AXIS] / abs(block->speed_y);
|
||||||
|
@ -495,7 +490,8 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) {
|
||||||
block->nominal_speed = block->millimeters * multiplier;
|
block->nominal_speed = block->millimeters * multiplier;
|
||||||
block->nominal_rate = ceil(block->step_event_count * multiplier / 60);
|
block->nominal_rate = ceil(block->step_event_count * multiplier / 60);
|
||||||
|
|
||||||
if(block->nominal_rate < 120) block->nominal_rate = 120;
|
if(block->nominal_rate < 120)
|
||||||
|
block->nominal_rate = 120;
|
||||||
block->entry_speed = safe_speed(block);
|
block->entry_speed = safe_speed(block);
|
||||||
|
|
||||||
// Compute the acceleration rate for the trapezoid generator.
|
// Compute the acceleration rate for the trapezoid generator.
|
||||||
|
@ -527,25 +523,25 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) {
|
||||||
block->acceleration = block->acceleration_st * travel_per_step;
|
block->acceleration = block->acceleration_st * travel_per_step;
|
||||||
block->acceleration_rate = (long)((float)block->acceleration_st * 8.388608);
|
block->acceleration_rate = (long)((float)block->acceleration_st * 8.388608);
|
||||||
|
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
// Calculate advance rate
|
// Calculate advance rate
|
||||||
if((block->steps_e == 0) || (block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0)) {
|
if((block->steps_e == 0) || (block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0)) {
|
||||||
block->advance_rate = 0;
|
|
||||||
block->advance = 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_st);
|
|
||||||
float advance = (STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K) *
|
|
||||||
(block->speed_e * block->speed_e * EXTRUTION_AREA * EXTRUTION_AREA / 3600.0)*65536;
|
|
||||||
block->advance = advance;
|
|
||||||
if(acc_dist == 0) {
|
|
||||||
block->advance_rate = 0;
|
block->advance_rate = 0;
|
||||||
|
block->advance = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
block->advance_rate = advance / (float)acc_dist;
|
long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_st);
|
||||||
|
float advance = (STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K) *
|
||||||
|
(block->speed_e * block->speed_e * EXTRUTION_AREA * EXTRUTION_AREA / 3600.0)*65536;
|
||||||
|
block->advance = advance;
|
||||||
|
if(acc_dist == 0) {
|
||||||
|
block->advance_rate = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
block->advance_rate = advance / (float)acc_dist;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
#endif // ADVANCE
|
||||||
#endif // ADVANCE
|
|
||||||
|
|
||||||
// compute a preliminary conservative acceleration trapezoid
|
// compute a preliminary conservative acceleration trapezoid
|
||||||
float safespeed = safe_speed(block);
|
float safespeed = safe_speed(block);
|
||||||
|
@ -576,7 +572,7 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) {
|
||||||
st_wake_up();
|
st_wake_up();
|
||||||
}
|
}
|
||||||
|
|
||||||
void plan_set_position(float x, float y, float z, float e)
|
void plan_set_position(const float &x, const float &y, const float &z, const float &e)
|
||||||
{
|
{
|
||||||
position[X_AXIS] = lround(x*axis_steps_per_unit[X_AXIS]);
|
position[X_AXIS] = lround(x*axis_steps_per_unit[X_AXIS]);
|
||||||
position[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]);
|
position[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]);
|
||||||
|
|
|
@ -32,16 +32,16 @@ typedef struct {
|
||||||
// Fields used by the bresenham algorithm for tracing the line
|
// Fields used by the bresenham algorithm for tracing the line
|
||||||
long steps_x, steps_y, steps_z, steps_e; // Step count along each axis
|
long steps_x, steps_y, steps_z, steps_e; // Step count along each axis
|
||||||
long step_event_count; // The number of step events required to complete this block
|
long step_event_count; // The number of step events required to complete this block
|
||||||
volatile long accelerate_until; // The index of the step event on which to stop acceleration
|
volatile long accelerate_until; // The index of the step event on which to stop acceleration
|
||||||
volatile long decelerate_after; // The index of the step event on which to start decelerating
|
volatile long decelerate_after; // The index of the step event on which to start decelerating
|
||||||
volatile long acceleration_rate; // The acceleration rate used for acceleration calculation
|
volatile long acceleration_rate; // The acceleration rate used for acceleration calculation
|
||||||
unsigned char direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
|
unsigned char direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
long advance_rate;
|
long advance_rate;
|
||||||
volatile long initial_advance;
|
volatile long initial_advance;
|
||||||
volatile long final_advance;
|
volatile long final_advance;
|
||||||
float advance;
|
float advance;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Fields used by the motion planner to manage acceleration
|
// Fields used by the motion planner to manage acceleration
|
||||||
float speed_x, speed_y, speed_z, speed_e; // Nominal mm/minute for each axis
|
float speed_x, speed_y, speed_z, speed_e; // Nominal mm/minute for each axis
|
||||||
|
@ -63,10 +63,11 @@ void plan_init();
|
||||||
|
|
||||||
// Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in
|
// Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in
|
||||||
// millimaters. Feed rate specifies the speed of the motion.
|
// millimaters. Feed rate specifies the speed of the motion.
|
||||||
void plan_buffer_line(float x, float y, float z, float e, float feed_rate);
|
void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate);
|
||||||
|
|
||||||
// Set position. Used for G92 instructions.
|
// Set position. Used for G92 instructions.
|
||||||
void plan_set_position(float x, float y, float z, float e);
|
void plan_set_position(const float &x, const float &y, const float &z, const float &e);
|
||||||
|
|
||||||
|
|
||||||
// Called when the current block is no longer needed. Discards the block and makes the memory
|
// Called when the current block is no longer needed. Discards the block and makes the memory
|
||||||
// availible for new blocks.
|
// availible for new blocks.
|
||||||
|
|
|
@ -37,6 +37,7 @@ uint16_t speed_lookuptable_fast[256][2] PROGMEM = {\
|
||||||
{ 32, 0}, { 32, 0}, { 32, 0}, { 32, 0}, { 32, 1}, { 31, 0}, { 31, 0}, { 31, 0},
|
{ 32, 0}, { 32, 0}, { 32, 0}, { 32, 0}, { 32, 1}, { 31, 0}, { 31, 0}, { 31, 0},
|
||||||
{ 31, 0}, { 31, 0}, { 31, 0}, { 31, 1}, { 30, 0}, { 30, 0}, { 30, 0}, { 30, 0}
|
{ 31, 0}, { 31, 0}, { 31, 0}, { 31, 1}, { 30, 0}, { 30, 0}, { 30, 0}, { 30, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
uint16_t speed_lookuptable_slow[256][2] PROGMEM = {\
|
uint16_t speed_lookuptable_slow[256][2] PROGMEM = {\
|
||||||
{ 62500, 12500}, { 50000, 8334}, { 41666, 5952}, { 35714, 4464}, { 31250, 3473}, { 27777, 2777}, { 25000, 2273}, { 22727, 1894},
|
{ 62500, 12500}, { 50000, 8334}, { 41666, 5952}, { 35714, 4464}, { 31250, 3473}, { 27777, 2777}, { 25000, 2273}, { 22727, 1894},
|
||||||
{ 20833, 1603}, { 19230, 1373}, { 17857, 1191}, { 16666, 1041}, { 15625, 920}, { 14705, 817}, { 13888, 731}, { 13157, 657},
|
{ 20833, 1603}, { 19230, 1373}, { 17857, 1191}, { 16666, 1041}, { 15625, 920}, { 14705, 817}, { 13888, 731}, { 13157, 657},
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
// if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
|
// if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
|
||||||
// for debugging purposes only, should be disabled by default
|
// for debugging purposes only, should be disabled by default
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
|
volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
|
||||||
volatile int count_direction[NUM_AXIS] = { 1, 1, 1, 1};
|
volatile int count_direction[NUM_AXIS] = { 1, 1, 1, 1};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,6 +117,8 @@ asm volatile ( \
|
||||||
|
|
||||||
block_t *current_block; // A pointer to the block currently being traced
|
block_t *current_block; // A pointer to the block currently being traced
|
||||||
|
|
||||||
|
//static makes it inpossible to be called from outside of this file by extern.!
|
||||||
|
|
||||||
// Variables used by The Stepper Driver Interrupt
|
// Variables used by The Stepper Driver Interrupt
|
||||||
static unsigned char out_bits; // The next stepping-bits to be output
|
static unsigned char out_bits; // The next stepping-bits to be output
|
||||||
static long counter_x, // Counter variables for the bresenham line tracer
|
static long counter_x, // Counter variables for the bresenham line tracer
|
||||||
|
@ -125,9 +127,9 @@ static long counter_x, // Counter variables for the bresenham line tracer
|
||||||
counter_e;
|
counter_e;
|
||||||
static unsigned long step_events_completed; // The number of step events executed in the current block
|
static unsigned long step_events_completed; // The number of step events executed in the current block
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
static long advance_rate, advance, final_advance = 0;
|
static long advance_rate, advance, final_advance = 0;
|
||||||
static short old_advance = 0;
|
static short old_advance = 0;
|
||||||
static short e_steps;
|
static short e_steps;
|
||||||
#endif
|
#endif
|
||||||
static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
|
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 long acceleration_time, deceleration_time;
|
||||||
|
@ -195,10 +197,10 @@ inline unsigned short calc_timer(unsigned short step_rate) {
|
||||||
// Initializes the trapezoid generator from the current block. Called whenever a new
|
// Initializes the trapezoid generator from the current block. Called whenever a new
|
||||||
// block begins.
|
// block begins.
|
||||||
inline void trapezoid_generator_reset() {
|
inline void trapezoid_generator_reset() {
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
advance = current_block->initial_advance;
|
advance = current_block->initial_advance;
|
||||||
final_advance = current_block->final_advance;
|
final_advance = current_block->final_advance;
|
||||||
#endif
|
#endif
|
||||||
deceleration_time = 0;
|
deceleration_time = 0;
|
||||||
// advance_rate = current_block->advance_rate;
|
// advance_rate = current_block->advance_rate;
|
||||||
// step_rate to timer interval
|
// step_rate to timer interval
|
||||||
|
@ -211,7 +213,8 @@ inline void trapezoid_generator_reset() {
|
||||||
// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
|
// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
|
||||||
ISR(TIMER1_COMPA_vect)
|
ISR(TIMER1_COMPA_vect)
|
||||||
{
|
{
|
||||||
if(busy){ SERIAL_ERRORLN(*(unsigned short *)OCR1A<< " ISR overtaking itself.");
|
if(busy){
|
||||||
|
SERIAL_ERRORLN(*(unsigned short *)OCR1A<< " ISR overtaking itself.");
|
||||||
return;
|
return;
|
||||||
} // The busy-flag is used to avoid reentering this interrupt
|
} // The busy-flag is used to avoid reentering this interrupt
|
||||||
|
|
||||||
|
@ -242,74 +245,74 @@ ISR(TIMER1_COMPA_vect)
|
||||||
// Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
|
// Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
|
||||||
out_bits = current_block->direction_bits;
|
out_bits = current_block->direction_bits;
|
||||||
|
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
// Calculate E early.
|
// Calculate E early.
|
||||||
counter_e += current_block->steps_e;
|
counter_e += current_block->steps_e;
|
||||||
if (counter_e > 0) {
|
if (counter_e > 0) {
|
||||||
counter_e -= current_block->step_event_count;
|
counter_e -= current_block->step_event_count;
|
||||||
if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
|
if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
|
||||||
|
CRITICAL_SECTION_START;
|
||||||
|
e_steps--;
|
||||||
|
CRITICAL_SECTION_END;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
CRITICAL_SECTION_START;
|
||||||
|
e_steps++;
|
||||||
|
CRITICAL_SECTION_END;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Do E steps + advance steps
|
||||||
CRITICAL_SECTION_START;
|
CRITICAL_SECTION_START;
|
||||||
e_steps--;
|
e_steps += ((advance >> 16) - old_advance);
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END;
|
||||||
}
|
old_advance = advance >> 16;
|
||||||
else {
|
#endif //ADVANCE
|
||||||
CRITICAL_SECTION_START;
|
|
||||||
e_steps++;
|
|
||||||
CRITICAL_SECTION_END;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Do E steps + advance steps
|
|
||||||
CRITICAL_SECTION_START;
|
|
||||||
e_steps += ((advance >> 16) - old_advance);
|
|
||||||
CRITICAL_SECTION_END;
|
|
||||||
old_advance = advance >> 16;
|
|
||||||
#endif //ADVANCE
|
|
||||||
|
|
||||||
// Set direction en check limit switches
|
// Set direction en check limit switches
|
||||||
if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
||||||
WRITE(X_DIR_PIN, INVERT_X_DIR);
|
WRITE(X_DIR_PIN, INVERT_X_DIR);
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
count_direction[X_AXIS]=-1;
|
count_direction[X_AXIS]=-1;
|
||||||
|
#endif
|
||||||
|
#if X_MIN_PIN > -1
|
||||||
|
if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
|
||||||
|
step_events_completed = current_block->step_event_count;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if X_MIN_PIN > -1
|
|
||||||
if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
|
|
||||||
step_events_completed = current_block->step_event_count;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else { // +direction
|
else { // +direction
|
||||||
WRITE(X_DIR_PIN,!INVERT_X_DIR);
|
WRITE(X_DIR_PIN,!INVERT_X_DIR);
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
count_direction[X_AXIS]=1;
|
count_direction[X_AXIS]=1;
|
||||||
#endif
|
#endif
|
||||||
#if X_MAX_PIN > -1
|
#if X_MAX_PIN > -1
|
||||||
if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x >0)){
|
if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x >0)){
|
||||||
step_events_completed = current_block->step_event_count;
|
step_events_completed = current_block->step_event_count;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((out_bits & (1<<Y_AXIS)) != 0) { // -direction
|
if ((out_bits & (1<<Y_AXIS)) != 0) { // -direction
|
||||||
WRITE(Y_DIR_PIN,INVERT_Y_DIR);
|
WRITE(Y_DIR_PIN,INVERT_Y_DIR);
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
count_direction[Y_AXIS]=-1;
|
count_direction[Y_AXIS]=-1;
|
||||||
|
#endif
|
||||||
|
#if Y_MIN_PIN > -1
|
||||||
|
if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {
|
||||||
|
step_events_completed = current_block->step_event_count;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if Y_MIN_PIN > -1
|
|
||||||
if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {
|
|
||||||
step_events_completed = current_block->step_event_count;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else { // +direction
|
else { // +direction
|
||||||
WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
|
WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
count_direction[Y_AXIS]=1;
|
count_direction[Y_AXIS]=1;
|
||||||
|
#endif
|
||||||
|
#if Y_MAX_PIN > -1
|
||||||
|
if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){
|
||||||
|
step_events_completed = current_block->step_event_count;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
#if Y_MAX_PIN > -1
|
|
||||||
if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){
|
|
||||||
step_events_completed = current_block->step_event_count;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((out_bits & (1<<Z_AXIS)) != 0) { // -direction
|
if ((out_bits & (1<<Z_AXIS)) != 0) { // -direction
|
||||||
|
@ -317,30 +320,30 @@ if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
count_direction[Z_AXIS]=-1;
|
count_direction[Z_AXIS]=-1;
|
||||||
#endif
|
#endif
|
||||||
#if Z_MIN_PIN > -1
|
#if Z_MIN_PIN > -1
|
||||||
if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {
|
if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {
|
||||||
step_events_completed = current_block->step_event_count;
|
step_events_completed = current_block->step_event_count;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else { // +direction
|
else { // +direction
|
||||||
WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
|
WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
count_direction[Z_AXIS]=1;
|
count_direction[Z_AXIS]=1;
|
||||||
#endif
|
#endif
|
||||||
#if Z_MAX_PIN > -1
|
#if Z_MAX_PIN > -1
|
||||||
if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z >0)){
|
if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z >0)){
|
||||||
step_events_completed = current_block->step_event_count;
|
step_events_completed = current_block->step_event_count;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ADVANCE
|
#ifndef ADVANCE
|
||||||
if ((out_bits & (1<<E_AXIS)) != 0) // -direction
|
if ((out_bits & (1<<E_AXIS)) != 0) // -direction
|
||||||
WRITE(E_DIR_PIN,INVERT_E_DIR);
|
WRITE(E_DIR_PIN,INVERT_E_DIR);
|
||||||
else // +direction
|
else // +direction
|
||||||
WRITE(E_DIR_PIN,!INVERT_E_DIR);
|
WRITE(E_DIR_PIN,!INVERT_E_DIR);
|
||||||
#endif //!ADVANCE
|
#endif //!ADVANCE
|
||||||
|
|
||||||
for(char i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
|
for(char i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
|
||||||
counter_x += current_block->steps_x;
|
counter_x += current_block->steps_x;
|
||||||
|
@ -349,7 +352,7 @@ if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
||||||
counter_x -= current_block->step_event_count;
|
counter_x -= current_block->step_event_count;
|
||||||
WRITE(X_STEP_PIN, LOW);
|
WRITE(X_STEP_PIN, LOW);
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
count_position[X_AXIS]+=count_direction[X_AXIS];
|
count_position[X_AXIS]+=count_direction[X_AXIS];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +362,7 @@ if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
||||||
counter_y -= current_block->step_event_count;
|
counter_y -= current_block->step_event_count;
|
||||||
WRITE(Y_STEP_PIN, LOW);
|
WRITE(Y_STEP_PIN, LOW);
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
count_position[Y_AXIS]+=count_direction[Y_AXIS];
|
count_position[Y_AXIS]+=count_direction[Y_AXIS];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,18 +372,18 @@ if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
||||||
counter_z -= current_block->step_event_count;
|
counter_z -= current_block->step_event_count;
|
||||||
WRITE(Z_STEP_PIN, LOW);
|
WRITE(Z_STEP_PIN, LOW);
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
count_position[Z_AXIS]+=count_direction[Z_AXIS];
|
count_position[Z_AXIS]+=count_direction[Z_AXIS];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ADVANCE
|
#ifndef ADVANCE
|
||||||
counter_e += current_block->steps_e;
|
counter_e += current_block->steps_e;
|
||||||
if (counter_e > 0) {
|
if (counter_e > 0) {
|
||||||
WRITE(E_STEP_PIN, HIGH);
|
WRITE(E_STEP_PIN, HIGH);
|
||||||
counter_e -= current_block->step_event_count;
|
counter_e -= current_block->step_event_count;
|
||||||
WRITE(E_STEP_PIN, LOW);
|
WRITE(E_STEP_PIN, LOW);
|
||||||
}
|
}
|
||||||
#endif //!ADVANCE
|
#endif //!ADVANCE
|
||||||
step_events_completed += 1;
|
step_events_completed += 1;
|
||||||
if(step_events_completed >= current_block->step_event_count) break;
|
if(step_events_completed >= current_block->step_event_count) break;
|
||||||
}
|
}
|
||||||
|
@ -397,9 +400,9 @@ if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
||||||
|
|
||||||
// step_rate to timer interval
|
// step_rate to timer interval
|
||||||
timer = calc_timer(acc_step_rate);
|
timer = calc_timer(acc_step_rate);
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
advance += advance_rate;
|
advance += advance_rate;
|
||||||
#endif
|
#endif
|
||||||
acceleration_time += timer;
|
acceleration_time += timer;
|
||||||
OCR1A = timer;
|
OCR1A = timer;
|
||||||
}
|
}
|
||||||
|
@ -419,11 +422,11 @@ if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
||||||
|
|
||||||
// step_rate to timer interval
|
// step_rate to timer interval
|
||||||
timer = calc_timer(step_rate);
|
timer = calc_timer(step_rate);
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
advance -= advance_rate;
|
advance -= advance_rate;
|
||||||
if(advance < final_advance)
|
if(advance < final_advance)
|
||||||
advance = final_advance;
|
advance = final_advance;
|
||||||
#endif //ADVANCE
|
#endif //ADVANCE
|
||||||
deceleration_time += timer;
|
deceleration_time += timer;
|
||||||
OCR1A = timer;
|
OCR1A = timer;
|
||||||
}
|
}
|
||||||
|
@ -438,127 +441,126 @@ if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
|
unsigned char old_OCR0A;
|
||||||
unsigned char old_OCR0A;
|
// Timer interrupt for E. e_steps is set in the main routine;
|
||||||
// Timer interrupt for E. e_steps is set in the main routine;
|
// Timer 0 is shared with millies
|
||||||
// Timer 0 is shared with millies
|
ISR(TIMER0_COMPA_vect)
|
||||||
ISR(TIMER0_COMPA_vect)
|
{
|
||||||
{
|
// Critical section needed because Timer 1 interrupt has higher priority.
|
||||||
// Critical section needed because Timer 1 interrupt has higher priority.
|
// The pin set functions are placed on trategic position to comply with the stepper driver timing.
|
||||||
// The pin set functions are placed on trategic position to comply with the stepper driver timing.
|
WRITE(E_STEP_PIN, LOW);
|
||||||
WRITE(E_STEP_PIN, LOW);
|
// Set E direction (Depends on E direction + advance)
|
||||||
// Set E direction (Depends on E direction + advance)
|
if (e_steps < 0) {
|
||||||
if (e_steps < 0) {
|
WRITE(E_DIR_PIN,INVERT_E_DIR);
|
||||||
WRITE(E_DIR_PIN,INVERT_E_DIR);
|
e_steps++;
|
||||||
e_steps++;
|
WRITE(E_STEP_PIN, HIGH);
|
||||||
WRITE(E_STEP_PIN, HIGH);
|
}
|
||||||
|
if (e_steps > 0) {
|
||||||
|
WRITE(E_DIR_PIN,!INVERT_E_DIR);
|
||||||
|
e_steps--;
|
||||||
|
WRITE(E_STEP_PIN, HIGH);
|
||||||
|
}
|
||||||
|
old_OCR0A += 25; // 10kHz interrupt
|
||||||
|
OCR0A = old_OCR0A;
|
||||||
}
|
}
|
||||||
if (e_steps > 0) {
|
|
||||||
WRITE(E_DIR_PIN,!INVERT_E_DIR);
|
|
||||||
e_steps--;
|
|
||||||
WRITE(E_STEP_PIN, HIGH);
|
|
||||||
}
|
|
||||||
old_OCR0A += 25; // 10kHz interrupt
|
|
||||||
OCR0A = old_OCR0A;
|
|
||||||
}
|
|
||||||
#endif // ADVANCE
|
#endif // ADVANCE
|
||||||
|
|
||||||
void st_init()
|
void st_init()
|
||||||
{
|
{
|
||||||
//Initialize Dir Pins
|
//Initialize Dir Pins
|
||||||
#if X_DIR_PIN > -1
|
#if X_DIR_PIN > -1
|
||||||
SET_OUTPUT(X_DIR_PIN);
|
SET_OUTPUT(X_DIR_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if Y_DIR_PIN > -1
|
#if Y_DIR_PIN > -1
|
||||||
SET_OUTPUT(Y_DIR_PIN);
|
SET_OUTPUT(Y_DIR_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if Z_DIR_PIN > -1
|
#if Z_DIR_PIN > -1
|
||||||
SET_OUTPUT(Z_DIR_PIN);
|
SET_OUTPUT(Z_DIR_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if E_DIR_PIN > -1
|
#if E_DIR_PIN > -1
|
||||||
SET_OUTPUT(E_DIR_PIN);
|
SET_OUTPUT(E_DIR_PIN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//Initialize Enable Pins - steppers default to disabled.
|
//Initialize Enable Pins - steppers default to disabled.
|
||||||
|
|
||||||
#if (X_ENABLE_PIN > -1)
|
#if (X_ENABLE_PIN > -1)
|
||||||
SET_OUTPUT(X_ENABLE_PIN);
|
SET_OUTPUT(X_ENABLE_PIN);
|
||||||
if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH);
|
if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#if (Y_ENABLE_PIN > -1)
|
#if (Y_ENABLE_PIN > -1)
|
||||||
SET_OUTPUT(Y_ENABLE_PIN);
|
SET_OUTPUT(Y_ENABLE_PIN);
|
||||||
if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH);
|
if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#if (Z_ENABLE_PIN > -1)
|
#if (Z_ENABLE_PIN > -1)
|
||||||
SET_OUTPUT(Z_ENABLE_PIN);
|
SET_OUTPUT(Z_ENABLE_PIN);
|
||||||
if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
|
if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#if (E_ENABLE_PIN > -1)
|
#if (E_ENABLE_PIN > -1)
|
||||||
SET_OUTPUT(E_ENABLE_PIN);
|
SET_OUTPUT(E_ENABLE_PIN);
|
||||||
if(!E_ENABLE_ON) WRITE(E_ENABLE_PIN,HIGH);
|
if(!E_ENABLE_ON) WRITE(E_ENABLE_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//endstops and pullups
|
//endstops and pullups
|
||||||
#ifdef ENDSTOPPULLUPS
|
#ifdef ENDSTOPPULLUPS
|
||||||
#if X_MIN_PIN > -1
|
#if X_MIN_PIN > -1
|
||||||
SET_INPUT(X_MIN_PIN);
|
SET_INPUT(X_MIN_PIN);
|
||||||
WRITE(X_MIN_PIN,HIGH);
|
WRITE(X_MIN_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#if X_MAX_PIN > -1
|
#if X_MAX_PIN > -1
|
||||||
SET_INPUT(X_MAX_PIN);
|
SET_INPUT(X_MAX_PIN);
|
||||||
WRITE(X_MAX_PIN,HIGH);
|
WRITE(X_MAX_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#if Y_MIN_PIN > -1
|
#if Y_MIN_PIN > -1
|
||||||
SET_INPUT(Y_MIN_PIN);
|
SET_INPUT(Y_MIN_PIN);
|
||||||
WRITE(Y_MIN_PIN,HIGH);
|
WRITE(Y_MIN_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#if Y_MAX_PIN > -1
|
#if Y_MAX_PIN > -1
|
||||||
SET_INPUT(Y_MAX_PIN);
|
SET_INPUT(Y_MAX_PIN);
|
||||||
WRITE(Y_MAX_PIN,HIGH);
|
WRITE(Y_MAX_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#if Z_MIN_PIN > -1
|
#if Z_MIN_PIN > -1
|
||||||
SET_INPUT(Z_MIN_PIN);
|
SET_INPUT(Z_MIN_PIN);
|
||||||
WRITE(Z_MIN_PIN,HIGH);
|
WRITE(Z_MIN_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#if Z_MAX_PIN > -1
|
#if Z_MAX_PIN > -1
|
||||||
SET_INPUT(Z_MAX_PIN);
|
SET_INPUT(Z_MAX_PIN);
|
||||||
WRITE(Z_MAX_PIN,HIGH);
|
WRITE(Z_MAX_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#else //ENDSTOPPULLUPS
|
#else //ENDSTOPPULLUPS
|
||||||
#if X_MIN_PIN > -1
|
#if X_MIN_PIN > -1
|
||||||
SET_INPUT(X_MIN_PIN);
|
SET_INPUT(X_MIN_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if X_MAX_PIN > -1
|
#if X_MAX_PIN > -1
|
||||||
SET_INPUT(X_MAX_PIN);
|
SET_INPUT(X_MAX_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if Y_MIN_PIN > -1
|
#if Y_MIN_PIN > -1
|
||||||
SET_INPUT(Y_MIN_PIN);
|
SET_INPUT(Y_MIN_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if Y_MAX_PIN > -1
|
#if Y_MAX_PIN > -1
|
||||||
SET_INPUT(Y_MAX_PIN);
|
SET_INPUT(Y_MAX_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if Z_MIN_PIN > -1
|
#if Z_MIN_PIN > -1
|
||||||
SET_INPUT(Z_MIN_PIN);
|
SET_INPUT(Z_MIN_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if Z_MAX_PIN > -1
|
#if Z_MAX_PIN > -1
|
||||||
SET_INPUT(Z_MAX_PIN);
|
SET_INPUT(Z_MAX_PIN);
|
||||||
#endif
|
#endif
|
||||||
#endif //ENDSTOPPULLUPS
|
#endif //ENDSTOPPULLUPS
|
||||||
|
|
||||||
|
|
||||||
//Initialize Step Pins
|
//Initialize Step Pins
|
||||||
#if (X_STEP_PIN > -1)
|
#if (X_STEP_PIN > -1)
|
||||||
SET_OUTPUT(X_STEP_PIN);
|
SET_OUTPUT(X_STEP_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if (Y_STEP_PIN > -1)
|
#if (Y_STEP_PIN > -1)
|
||||||
SET_OUTPUT(Y_STEP_PIN);
|
SET_OUTPUT(Y_STEP_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if (Z_STEP_PIN > -1)
|
#if (Z_STEP_PIN > -1)
|
||||||
SET_OUTPUT(Z_STEP_PIN);
|
SET_OUTPUT(Z_STEP_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if (E_STEP_PIN > -1)
|
#if (E_STEP_PIN > -1)
|
||||||
SET_OUTPUT(E_STEP_PIN);
|
SET_OUTPUT(E_STEP_PIN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// waveform generation = 0100 = CTC
|
// waveform generation = 0100 = CTC
|
||||||
TCCR1B &= ~(1<<WGM13);
|
TCCR1B &= ~(1<<WGM13);
|
||||||
|
@ -574,10 +576,10 @@ void st_init()
|
||||||
OCR1A = 0x4000;
|
OCR1A = 0x4000;
|
||||||
DISABLE_STEPPER_DRIVER_INTERRUPT();
|
DISABLE_STEPPER_DRIVER_INTERRUPT();
|
||||||
|
|
||||||
#ifdef ADVANCE
|
#ifdef ADVANCE
|
||||||
e_steps = 0;
|
e_steps = 0;
|
||||||
TIMSK0 |= (1<<OCIE0A);
|
TIMSK0 |= (1<<OCIE0A);
|
||||||
#endif //ADVANCE
|
#endif //ADVANCE
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,8 @@ void st_wake_up();
|
||||||
// if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
|
// if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
|
||||||
// for debugging purposes only, should be disabled by default
|
// for debugging purposes only, should be disabled by default
|
||||||
#ifdef DEBUG_STEPS
|
#ifdef DEBUG_STEPS
|
||||||
extern volatile long count_position[NUM_AXIS];
|
extern volatile long count_position[NUM_AXIS];
|
||||||
extern volatile int count_direction[NUM_AXIS];
|
extern volatile int count_direction[NUM_AXIS];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern block_t *current_block; // A pointer to the block currently being traced
|
extern block_t *current_block; // A pointer to the block currently being traced
|
||||||
|
|
|
@ -74,24 +74,24 @@ unsigned long previous_millis_heater, previous_millis_bed_heater;
|
||||||
#endif //WATCHPERIOD
|
#endif //WATCHPERIOD
|
||||||
|
|
||||||
#ifdef HEATER_0_MINTEMP
|
#ifdef HEATER_0_MINTEMP
|
||||||
int minttemp_0 = temp2analog(HEATER_0_MINTEMP);
|
int minttemp_0 = temp2analog(HEATER_0_MINTEMP);
|
||||||
#endif //MINTEMP
|
#endif //MINTEMP
|
||||||
#ifdef HEATER_0_MAXTEMP
|
#ifdef HEATER_0_MAXTEMP
|
||||||
int maxttemp_0 = temp2analog(HEATER_0_MAXTEMP);
|
int maxttemp_0 = temp2analog(HEATER_0_MAXTEMP);
|
||||||
#endif //MAXTEMP
|
#endif //MAXTEMP
|
||||||
|
|
||||||
#ifdef HEATER_1_MINTEMP
|
#ifdef HEATER_1_MINTEMP
|
||||||
int minttemp_1 = temp2analog(HEATER_1_MINTEMP);
|
int minttemp_1 = temp2analog(HEATER_1_MINTEMP);
|
||||||
#endif //MINTEMP
|
#endif //MINTEMP
|
||||||
#ifdef HEATER_1_MAXTEMP
|
#ifdef HEATER_1_MAXTEMP
|
||||||
int maxttemp_1 = temp2analog(HEATER_1_MAXTEMP);
|
int maxttemp_1 = temp2analog(HEATER_1_MAXTEMP);
|
||||||
#endif //MAXTEMP
|
#endif //MAXTEMP
|
||||||
|
|
||||||
#ifdef BED_MINTEMP
|
#ifdef BED_MINTEMP
|
||||||
int bed_minttemp = temp2analog(BED_MINTEMP);
|
int bed_minttemp = temp2analog(BED_MINTEMP);
|
||||||
#endif //BED_MINTEMP
|
#endif //BED_MINTEMP
|
||||||
#ifdef BED_MAXTEMP
|
#ifdef BED_MAXTEMP
|
||||||
int bed_maxttemp = temp2analog(BED_MAXTEMP);
|
int bed_maxttemp = temp2analog(BED_MAXTEMP);
|
||||||
#endif //BED_MAXTEMP
|
#endif //BED_MAXTEMP
|
||||||
|
|
||||||
void manage_heater()
|
void manage_heater()
|
||||||
|
@ -105,50 +105,49 @@ void manage_heater()
|
||||||
if(temp_meas_ready != true) //better readability
|
if(temp_meas_ready != true) //better readability
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CRITICAL_SECTION_START;
|
CRITICAL_SECTION_START;
|
||||||
temp_meas_ready = false;
|
temp_meas_ready = false;
|
||||||
CRITICAL_SECTION_END;
|
CRITICAL_SECTION_END;
|
||||||
|
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);
|
pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);
|
||||||
|
|
||||||
#ifndef PID_OPENLOOP
|
#ifndef PID_OPENLOOP
|
||||||
pid_error = pid_setpoint - pid_input;
|
pid_error = pid_setpoint - pid_input;
|
||||||
if(pid_error > 10){
|
if(pid_error > 10){
|
||||||
pid_output = PID_MAX;
|
pid_output = PID_MAX;
|
||||||
pid_reset = true;
|
pid_reset = true;
|
||||||
}
|
}
|
||||||
else if(pid_error < -10) {
|
else if(pid_error < -10) {
|
||||||
pid_output = 0;
|
pid_output = 0;
|
||||||
pid_reset = true;
|
pid_reset = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(pid_reset == true) {
|
if(pid_reset == true) {
|
||||||
temp_iState = 0.0;
|
temp_iState = 0.0;
|
||||||
pid_reset = false;
|
pid_reset = false;
|
||||||
}
|
}
|
||||||
pTerm = Kp * pid_error;
|
pTerm = Kp * pid_error;
|
||||||
temp_iState += pid_error;
|
temp_iState += pid_error;
|
||||||
temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
|
temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
|
||||||
iTerm = Ki * temp_iState;
|
iTerm = Ki * temp_iState;
|
||||||
//K1 defined in Configuration.h in the PID settings
|
//K1 defined in Configuration.h in the PID settings
|
||||||
#define K2 (1.0-K1)
|
#define K2 (1.0-K1)
|
||||||
dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm);
|
dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm);
|
||||||
temp_dState = pid_input;
|
temp_dState = pid_input;
|
||||||
#ifdef PID_ADD_EXTRUSION_RATE
|
#ifdef PID_ADD_EXTRUSION_RATE
|
||||||
pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high
|
pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high
|
||||||
#endif
|
#endif
|
||||||
pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX);
|
pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX);
|
||||||
}
|
}
|
||||||
#endif //PID_OPENLOOP
|
#endif //PID_OPENLOOP
|
||||||
#ifdef PID_DEBUG
|
#ifdef PID_DEBUG
|
||||||
SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);
|
SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);
|
||||||
|
#endif //PID_DEBUG
|
||||||
#endif //PID_DEBUG
|
|
||||||
analogWrite(HEATER_0_PIN, pid_output);
|
analogWrite(HEATER_0_PIN, pid_output);
|
||||||
#endif //PIDTEMP
|
#endif //PIDTEMP
|
||||||
|
|
||||||
#ifndef PIDTEMP
|
#ifndef PIDTEMP
|
||||||
if(current_raw[0] >= target_raw[0])
|
if(current_raw[0] >= target_raw[0])
|
||||||
{
|
{
|
||||||
WRITE(HEATER_0_PIN,LOW);
|
WRITE(HEATER_0_PIN,LOW);
|
||||||
|
@ -157,7 +156,7 @@ CRITICAL_SECTION_END;
|
||||||
{
|
{
|
||||||
WRITE(HEATER_0_PIN,HIGH);
|
WRITE(HEATER_0_PIN,HIGH);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
|
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
|
||||||
return;
|
return;
|
||||||
|
@ -173,7 +172,7 @@ CRITICAL_SECTION_END;
|
||||||
WRITE(HEATER_1_PIN,HIGH);
|
WRITE(HEATER_1_PIN,HIGH);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes hot end temperature value as input and returns corresponding raw value.
|
// Takes hot end temperature value as input and returns corresponding raw value.
|
||||||
// For a thermistor, it uses the RepRap thermistor temp table.
|
// For a thermistor, it uses the RepRap thermistor temp table.
|
||||||
|
@ -300,26 +299,26 @@ float analog2tempBed(int raw) {
|
||||||
|
|
||||||
void tp_init()
|
void tp_init()
|
||||||
{
|
{
|
||||||
#if (HEATER_0_PIN > -1)
|
#if (HEATER_0_PIN > -1)
|
||||||
SET_OUTPUT(HEATER_0_PIN);
|
SET_OUTPUT(HEATER_0_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if (HEATER_1_PIN > -1)
|
#if (HEATER_1_PIN > -1)
|
||||||
SET_OUTPUT(HEATER_1_PIN);
|
SET_OUTPUT(HEATER_1_PIN);
|
||||||
#endif
|
#endif
|
||||||
#if (HEATER_2_PIN > -1)
|
#if (HEATER_2_PIN > -1)
|
||||||
SET_OUTPUT(HEATER_2_PIN);
|
SET_OUTPUT(HEATER_2_PIN);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
temp_iState_min = 0.0;
|
temp_iState_min = 0.0;
|
||||||
temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
|
temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
|
||||||
#endif //PIDTEMP
|
#endif //PIDTEMP
|
||||||
|
|
||||||
// Set analog inputs
|
// Set analog inputs
|
||||||
ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
|
ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
|
||||||
|
|
||||||
// Use timer0 for temperature measurement
|
// Use timer0 for temperature measurement
|
||||||
// Interleave temperature interrupt with millies interrupt
|
// Interleave temperature interrupt with millies interrupt
|
||||||
OCR0B = 128;
|
OCR0B = 128;
|
||||||
TIMSK0 |= (1<<OCIE0B);
|
TIMSK0 |= (1<<OCIE0B);
|
||||||
}
|
}
|
||||||
|
@ -344,23 +343,25 @@ void setWatch()
|
||||||
|
|
||||||
void disable_heater()
|
void disable_heater()
|
||||||
{
|
{
|
||||||
#if TEMP_0_PIN > -1
|
#if TEMP_0_PIN > -1
|
||||||
target_raw[0]=0;
|
target_raw[0]=0;
|
||||||
#if HEATER_0_PIN > -1
|
#if HEATER_0_PIN > -1
|
||||||
WRITE(HEATER_0_PIN,LOW);
|
WRITE(HEATER_0_PIN,LOW);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TEMP_1_PIN > -1
|
#if TEMP_1_PIN > -1
|
||||||
target_raw[1]=0;
|
target_raw[1]=0;
|
||||||
#if HEATER_1_PIN > -1
|
#if HEATER_1_PIN > -1
|
||||||
WRITE(HEATER_1_PIN,LOW);
|
WRITE(HEATER_1_PIN,LOW);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TEMP_2_PIN > -1
|
#if TEMP_2_PIN > -1
|
||||||
target_raw[2]=0;
|
target_raw[2]=0;
|
||||||
#if HEATER_2_PIN > -1
|
#if HEATER_2_PIN > -1
|
||||||
WRITE(HEATER_2_PIN,LOW);
|
WRITE(HEATER_2_PIN,LOW);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,75 +377,75 @@ ISR(TIMER0_COMPB_vect)
|
||||||
|
|
||||||
switch(temp_state) {
|
switch(temp_state) {
|
||||||
case 0: // Prepare TEMP_0
|
case 0: // Prepare TEMP_0
|
||||||
#if (TEMP_0_PIN > -1)
|
#if (TEMP_0_PIN > -1)
|
||||||
#if TEMP_0_PIN < 8
|
#if TEMP_0_PIN < 8
|
||||||
DIDR0 = 1 << TEMP_0_PIN;
|
DIDR0 = 1 << TEMP_0_PIN;
|
||||||
#else
|
#else
|
||||||
DIDR2 = 1<<(TEMP_0_PIN - 8);
|
DIDR2 = 1<<(TEMP_0_PIN - 8);
|
||||||
ADCSRB = 1<<MUX5;
|
ADCSRB = 1<<MUX5;
|
||||||
#endif
|
#endif
|
||||||
ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
|
ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
|
||||||
ADCSRA |= 1<<ADSC; // Start conversion
|
ADCSRA |= 1<<ADSC; // Start conversion
|
||||||
#endif
|
#endif
|
||||||
#ifdef ULTIPANEL
|
#ifdef ULTIPANEL
|
||||||
buttons_check();
|
buttons_check();
|
||||||
#endif
|
#endif
|
||||||
temp_state = 1;
|
temp_state = 1;
|
||||||
break;
|
break;
|
||||||
case 1: // Measure TEMP_0
|
case 1: // Measure TEMP_0
|
||||||
#if (TEMP_0_PIN > -1)
|
#if (TEMP_0_PIN > -1)
|
||||||
raw_temp_0_value += ADC;
|
raw_temp_0_value += ADC;
|
||||||
#endif
|
#endif
|
||||||
temp_state = 2;
|
temp_state = 2;
|
||||||
break;
|
break;
|
||||||
case 2: // Prepare TEMP_1
|
case 2: // Prepare TEMP_1
|
||||||
#if (TEMP_1_PIN > -1)
|
#if (TEMP_1_PIN > -1)
|
||||||
#if TEMP_1_PIN < 7
|
#if TEMP_1_PIN < 7
|
||||||
DIDR0 = 1<<TEMP_1_PIN;
|
DIDR0 = 1<<TEMP_1_PIN;
|
||||||
#else
|
#else
|
||||||
DIDR2 = 1<<(TEMP_1_PIN - 8);
|
DIDR2 = 1<<(TEMP_1_PIN - 8);
|
||||||
ADCSRB = 1<<MUX5;
|
ADCSRB = 1<<MUX5;
|
||||||
#endif
|
#endif
|
||||||
ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
|
ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
|
||||||
ADCSRA |= 1<<ADSC; // Start conversion
|
ADCSRA |= 1<<ADSC; // Start conversion
|
||||||
#endif
|
#endif
|
||||||
#ifdef ULTIPANEL
|
#ifdef ULTIPANEL
|
||||||
buttons_check();
|
buttons_check();
|
||||||
#endif
|
#endif
|
||||||
temp_state = 3;
|
temp_state = 3;
|
||||||
break;
|
break;
|
||||||
case 3: // Measure TEMP_1
|
case 3: // Measure TEMP_1
|
||||||
#if (TEMP_1_PIN > -1)
|
#if (TEMP_1_PIN > -1)
|
||||||
raw_temp_1_value += ADC;
|
raw_temp_1_value += ADC;
|
||||||
#endif
|
#endif
|
||||||
temp_state = 4;
|
temp_state = 4;
|
||||||
break;
|
break;
|
||||||
case 4: // Prepare TEMP_2
|
case 4: // Prepare TEMP_2
|
||||||
#if (TEMP_2_PIN > -1)
|
#if (TEMP_2_PIN > -1)
|
||||||
#if TEMP_2_PIN < 7
|
#if TEMP_2_PIN < 7
|
||||||
DIDR0 = 1 << TEMP_2_PIN;
|
DIDR0 = 1 << TEMP_2_PIN;
|
||||||
#else
|
#else
|
||||||
DIDR2 = 1<<(TEMP_2_PIN - 8);
|
DIDR2 = 1<<(TEMP_2_PIN - 8);
|
||||||
ADCSRB = 1<<MUX5;
|
ADCSRB = 1<<MUX5;
|
||||||
#endif
|
#endif
|
||||||
ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
|
ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
|
||||||
ADCSRA |= 1<<ADSC; // Start conversion
|
ADCSRA |= 1<<ADSC; // Start conversion
|
||||||
#endif
|
#endif
|
||||||
#ifdef ULTIPANEL
|
#ifdef ULTIPANEL
|
||||||
buttons_check();
|
buttons_check();
|
||||||
#endif
|
#endif
|
||||||
temp_state = 5;
|
temp_state = 5;
|
||||||
break;
|
break;
|
||||||
case 5: // Measure TEMP_2
|
case 5: // Measure TEMP_2
|
||||||
#if (TEMP_2_PIN > -1)
|
#if (TEMP_2_PIN > -1)
|
||||||
raw_temp_2_value += ADC;
|
raw_temp_2_value += ADC;
|
||||||
#endif
|
#endif
|
||||||
temp_state = 0;
|
temp_state = 0;
|
||||||
temp_count++;
|
temp_count++;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
SERIAL_ERRORLN("Temp measurement error!");
|
SERIAL_ERRORLN("Temp measurement error!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(temp_count >= 16) // 6 ms * 16 = 96ms.
|
if(temp_count >= 16) // 6 ms * 16 = 96ms.
|
||||||
|
@ -472,67 +473,71 @@ ISR(TIMER0_COMPB_vect)
|
||||||
raw_temp_0_value = 0;
|
raw_temp_0_value = 0;
|
||||||
raw_temp_1_value = 0;
|
raw_temp_1_value = 0;
|
||||||
raw_temp_2_value = 0;
|
raw_temp_2_value = 0;
|
||||||
#ifdef HEATER_0_MAXTEMP
|
#ifdef HEATER_0_MAXTEMP
|
||||||
#if (HEATER_0_PIN > -1)
|
#if (HEATER_0_PIN > -1)
|
||||||
if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
|
if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
|
||||||
target_raw[TEMPSENSOR_HOTEND_0] = 0;
|
target_raw[TEMPSENSOR_HOTEND_0] = 0;
|
||||||
analogWrite(HEATER_0_PIN, 0);
|
analogWrite(HEATER_0_PIN, 0);
|
||||||
SERIAL_ERRORLN("Temperature extruder 0 switched off. MAXTEMP triggered !!");
|
SERIAL_ERRORLN("Temperature extruder 0 switched off. MAXTEMP triggered !!");
|
||||||
kill();
|
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;
|
||||||
|
if(current_raw[2] >= maxttemp_1) {
|
||||||
|
analogWrite(HEATER_2_PIN, 0);
|
||||||
|
SERIAL_ERRORLN("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;
|
||||||
|
analogWrite(HEATER_0_PIN, 0);
|
||||||
|
SERIAL_ERRORLN("Temperature extruder 0 switched off. MINTEMP triggered !!");
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
#ifdef HEATER_1_MAXTEMP
|
#ifdef HEATER_1_MINTEMP
|
||||||
#if (HEATER_1_PIN > -1)
|
#if (HEATER_2_PIN > -1)
|
||||||
if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
|
if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
|
||||||
target_raw[TEMPSENSOR_HOTEND_1] = 0;
|
target_raw[TEMPSENSOR_HOTEND_1] = 0;
|
||||||
if(current_raw[2] >= maxttemp_1) {
|
analogWrite(HEATER_2_PIN, 0);
|
||||||
analogWrite(HEATER_2_PIN, 0);
|
SERIAL_ERRORLN("Temperature extruder 1 switched off. MINTEMP triggered !!");
|
||||||
SERIAL_ERRORLN("Temperature extruder 1 switched off. MAXTEMP triggered !!");
|
kill();
|
||||||
kill()
|
}
|
||||||
}
|
#endif
|
||||||
|
#endif //MAXTEMP
|
||||||
|
|
||||||
|
#ifdef BED_MINTEMP
|
||||||
|
#if (HEATER_1_PIN > -1)
|
||||||
|
if(current_raw[1] <= bed_minttemp) {
|
||||||
|
target_raw[1] = 0;
|
||||||
|
WRITE(HEATER_1_PIN, 0);
|
||||||
|
SERIAL_ERRORLN("Temperatur heated bed switched off. MINTEMP triggered !!");
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif //MAXTEMP
|
|
||||||
#ifdef HEATER_0_MINTEMP
|
#ifdef BED_MAXTEMP
|
||||||
#if (HEATER_0_PIN > -1)
|
#if (HEATER_1_PIN > -1)
|
||||||
if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
|
if(current_raw[1] >= bed_maxttemp) {
|
||||||
target_raw[TEMPSENSOR_HOTEND_0] = 0;
|
target_raw[1] = 0;
|
||||||
analogWrite(HEATER_0_PIN, 0);
|
WRITE(HEATER_1_PIN, 0);
|
||||||
SERIAL_ERRORLN("Temperature extruder 0 switched off. MINTEMP triggered !!");
|
SERIAL_ERRORLN("Temperature heated bed switched off. MAXTEMP triggered !!");
|
||||||
kill();
|
kill();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#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;
|
|
||||||
analogWrite(HEATER_2_PIN, 0);
|
|
||||||
SERIAL_ERRORLN("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;
|
|
||||||
WRITE(HEATER_1_PIN, 0);
|
|
||||||
SERIAL_ERRORLN("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;
|
|
||||||
WRITE(HEATER_1_PIN, 0);
|
|
||||||
SERIAL_ERRORLN("Temperature heated bed switched off. MAXTEMP triggered !!");
|
|
||||||
kill();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,11 @@
|
||||||
#include "stepper.h"
|
#include "stepper.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// public functions
|
||||||
void tp_init(); //initialise the heating
|
void tp_init(); //initialise the heating
|
||||||
void manage_heater(); //it is critical that this is called periodically.
|
void manage_heater(); //it is critical that this is called periodically.
|
||||||
|
|
||||||
|
|
||||||
enum TempSensor {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2};
|
enum TempSensor {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2};
|
||||||
|
|
||||||
//low leven conversion routines
|
//low leven conversion routines
|
||||||
|
@ -41,9 +43,11 @@ float analog2tempBed(int raw);
|
||||||
extern int target_raw[3];
|
extern int target_raw[3];
|
||||||
extern int current_raw[3];
|
extern int current_raw[3];
|
||||||
extern float Kp,Ki,Kd,Kc;
|
extern float Kp,Ki,Kd,Kc;
|
||||||
|
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
extern float pid_setpoint ;
|
extern float pid_setpoint ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WATCHPERIOD
|
#ifdef WATCHPERIOD
|
||||||
extern int watch_raw[3] ;
|
extern int watch_raw[3] ;
|
||||||
extern unsigned long watchmillis;
|
extern unsigned long watchmillis;
|
||||||
|
@ -63,15 +67,15 @@ inline float degTargetHotend0() { return analog2temp(target_raw[TEMPSENSOR_HOTE
|
||||||
inline float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);};
|
inline float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);};
|
||||||
inline float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);};
|
inline float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);};
|
||||||
|
|
||||||
inline void setTargetHotend0(float celsius)
|
inline void setTargetHotend0(const float &celsius)
|
||||||
{
|
{
|
||||||
target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius);
|
target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius);
|
||||||
#ifdef PIDTEMP
|
#ifdef PIDTEMP
|
||||||
pid_setpoint = celsius;
|
pid_setpoint = celsius;
|
||||||
#endif //PIDTEMP
|
#endif //PIDTEMP
|
||||||
};
|
};
|
||||||
inline void setTargetHotend1(float celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);};
|
inline void setTargetHotend1(const float &celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);};
|
||||||
inline void setTargetBed(float celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);};
|
inline void setTargetBed(const float &celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);};
|
||||||
|
|
||||||
inline bool isHeatingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];};
|
inline bool isHeatingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];};
|
||||||
inline bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];};
|
inline bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];};
|
||||||
|
@ -84,16 +88,5 @@ inline bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMP
|
||||||
void disable_heater();
|
void disable_heater();
|
||||||
void setWatch();
|
void setWatch();
|
||||||
|
|
||||||
#ifdef HEATER_0_USES_THERMISTOR
|
|
||||||
#define HEATERSOURCE 1
|
|
||||||
#endif
|
|
||||||
#ifdef BED_USES_THERMISTOR
|
|
||||||
#define BEDSOURCE 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -9,107 +9,48 @@
|
||||||
void lcd_status(const char* message);
|
void lcd_status(const char* message);
|
||||||
void beep();
|
void beep();
|
||||||
void buttons_check();
|
void buttons_check();
|
||||||
#define LCDSTATUSRIGHT
|
|
||||||
|
|
||||||
#define LCD_UPDATE_INTERVAL 100
|
#define LCD_UPDATE_INTERVAL 100
|
||||||
#define STATUSTIMEOUT 15000
|
#define STATUSTIMEOUT 15000
|
||||||
|
|
||||||
#include "Configuration.h"
|
|
||||||
|
|
||||||
#include <LiquidCrystal.h>
|
#include <LiquidCrystal.h>
|
||||||
extern LiquidCrystal lcd;
|
extern LiquidCrystal lcd;
|
||||||
|
|
||||||
//lcd display size
|
|
||||||
|
|
||||||
#ifdef NEWPANEL
|
#ifdef NEWPANEL
|
||||||
//arduino pin witch triggers an piezzo beeper
|
|
||||||
#define BEEPER 18
|
|
||||||
|
|
||||||
#define LCD_PINS_RS 20
|
|
||||||
#define LCD_PINS_ENABLE 17
|
|
||||||
#define LCD_PINS_D4 16
|
|
||||||
#define LCD_PINS_D5 21
|
|
||||||
#define LCD_PINS_D6 5
|
|
||||||
#define LCD_PINS_D7 6
|
|
||||||
|
|
||||||
//buttons are directly attached
|
|
||||||
#define BTN_EN1 40
|
|
||||||
#define BTN_EN2 42
|
|
||||||
#define BTN_ENC 19 //the click
|
|
||||||
|
|
||||||
#define BLEN_C 2
|
|
||||||
#define BLEN_B 1
|
|
||||||
#define BLEN_A 0
|
|
||||||
|
|
||||||
#define SDCARDDETECT 38
|
|
||||||
|
|
||||||
#define EN_C (1<<BLEN_C)
|
|
||||||
#define EN_B (1<<BLEN_B)
|
|
||||||
#define EN_A (1<<BLEN_A)
|
|
||||||
|
|
||||||
//encoder rotation values
|
|
||||||
#define encrot0 0
|
|
||||||
#define encrot1 2
|
|
||||||
#define encrot2 3
|
|
||||||
#define encrot3 1
|
|
||||||
|
|
||||||
|
|
||||||
#define CLICKED (buttons&EN_C)
|
#define EN_C (1<<BLEN_C)
|
||||||
#define BLOCK {blocking=millis()+blocktime;}
|
#define EN_B (1<<BLEN_B)
|
||||||
#define CARDINSERTED (READ(SDCARDDETECT)==0)
|
#define EN_A (1<<BLEN_A)
|
||||||
|
|
||||||
#else
|
#define CLICKED (buttons&EN_C)
|
||||||
//arduino pin witch triggers an piezzo beeper
|
#define BLOCK {blocking=millis()+blocktime;}
|
||||||
#define BEEPER 18
|
#define CARDINSERTED (READ(SDCARDDETECT)==0)
|
||||||
|
|
||||||
//buttons are attached to a shift register
|
#else
|
||||||
#define SHIFT_CLK 38
|
|
||||||
#define SHIFT_LD 42
|
|
||||||
#define SHIFT_OUT 40
|
|
||||||
#define SHIFT_EN 17
|
|
||||||
|
|
||||||
#define LCD_PINS_RS 16
|
//atomatic, do not change
|
||||||
#define LCD_PINS_ENABLE 5
|
#define B_LE (1<<BL_LE)
|
||||||
#define LCD_PINS_D4 6
|
#define B_UP (1<<BL_UP)
|
||||||
#define LCD_PINS_D5 21
|
#define B_MI (1<<BL_MI)
|
||||||
#define LCD_PINS_D6 20
|
#define B_DW (1<<BL_DW)
|
||||||
#define LCD_PINS_D7 19
|
#define B_RI (1<<BL_RI)
|
||||||
|
#define B_ST (1<<BL_ST)
|
||||||
|
#define EN_B (1<<BLEN_B)
|
||||||
|
#define EN_A (1<<BLEN_A)
|
||||||
|
|
||||||
//bits in the shift register that carry the buttons for:
|
#define CLICKED ((buttons&B_MI)||(buttons&B_ST))
|
||||||
// left up center down right red
|
#define BLOCK {blocking[BL_MI]=millis()+blocktime;blocking[BL_ST]=millis()+blocktime;}
|
||||||
#define BL_LE 7
|
|
||||||
#define BL_UP 6
|
|
||||||
#define BL_MI 5
|
|
||||||
#define BL_DW 4
|
|
||||||
#define BL_RI 3
|
|
||||||
#define BL_ST 2
|
|
||||||
|
|
||||||
#define BLEN_B 1
|
#endif
|
||||||
#define BLEN_A 0
|
|
||||||
|
|
||||||
//encoder rotation values
|
|
||||||
#define encrot0 0
|
|
||||||
#define encrot1 2
|
|
||||||
#define encrot2 3
|
|
||||||
#define encrot3 1
|
|
||||||
|
|
||||||
//atomatic, do not change
|
|
||||||
#define B_LE (1<<BL_LE)
|
|
||||||
#define B_UP (1<<BL_UP)
|
|
||||||
#define B_MI (1<<BL_MI)
|
|
||||||
#define B_DW (1<<BL_DW)
|
|
||||||
#define B_RI (1<<BL_RI)
|
|
||||||
#define B_ST (1<<BL_ST)
|
|
||||||
#define EN_B (1<<BLEN_B)
|
|
||||||
#define EN_A (1<<BLEN_A)
|
|
||||||
|
|
||||||
#define CLICKED ((buttons&B_MI)||(buttons&B_ST))
|
|
||||||
#define BLOCK {blocking[BL_MI]=millis()+blocktime;blocking[BL_ST]=millis()+blocktime;}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
// blocking time for recognizing a new keypress of one key, ms
|
// blocking time for recognizing a new keypress of one key, ms
|
||||||
#define blocktime 500
|
#define blocktime 500
|
||||||
#define lcdslow 5
|
#define lcdslow 5
|
||||||
|
|
||||||
enum MainStatus{Main_Status, Main_Menu, Main_Prepare, Main_Control, Main_SD};
|
enum MainStatus{Main_Status, Main_Menu, Main_Prepare, Main_Control, Main_SD};
|
||||||
|
|
||||||
class MainMenu{
|
class MainMenu{
|
||||||
|
@ -134,6 +75,7 @@
|
||||||
bool linechanging;
|
bool linechanging;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//conversion routines, could need some overworking
|
||||||
char *fillto(int8_t n,char *c);
|
char *fillto(int8_t n,char *c);
|
||||||
char *ftostr51(const float &x);
|
char *ftostr51(const float &x);
|
||||||
char *ftostr31(const float &x);
|
char *ftostr31(const float &x);
|
||||||
|
@ -146,11 +88,15 @@
|
||||||
#else //no lcd
|
#else //no lcd
|
||||||
#define LCD_STATUS
|
#define LCD_STATUS
|
||||||
#define LCD_MESSAGE(x)
|
#define LCD_MESSAGE(x)
|
||||||
|
inline void lcd_status() {};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef ULTIPANEL
|
#ifndef ULTIPANEL
|
||||||
#define CLICKED false
|
#define CLICKED false
|
||||||
#define BLOCK ;
|
#define BLOCK ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //ULTRALCD
|
#endif //ULTRALCD
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "ultralcd.h"
|
#include "ultralcd.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef ULTRA_LCD
|
#ifdef ULTRA_LCD
|
||||||
|
|
||||||
|
|
||||||
extern volatile int feedmultiply;
|
extern volatile int feedmultiply;
|
||||||
extern long position[4];
|
extern long position[4];
|
||||||
|
|
||||||
|
@ -122,58 +122,57 @@ void lcd_status()
|
||||||
menu.update();
|
menu.update();
|
||||||
}
|
}
|
||||||
#ifdef ULTIPANEL
|
#ifdef ULTIPANEL
|
||||||
|
|
||||||
|
|
||||||
void buttons_init()
|
void buttons_init()
|
||||||
{
|
{
|
||||||
#ifdef NEWPANEL
|
#ifdef NEWPANEL
|
||||||
pinMode(BTN_EN1,INPUT);
|
pinMode(BTN_EN1,INPUT);
|
||||||
pinMode(BTN_EN2,INPUT);
|
pinMode(BTN_EN2,INPUT);
|
||||||
pinMode(BTN_ENC,INPUT);
|
pinMode(BTN_ENC,INPUT);
|
||||||
pinMode(SDCARDDETECT,INPUT);
|
pinMode(SDCARDDETECT,INPUT);
|
||||||
WRITE(BTN_EN1,HIGH);
|
WRITE(BTN_EN1,HIGH);
|
||||||
WRITE(BTN_EN2,HIGH);
|
WRITE(BTN_EN2,HIGH);
|
||||||
WRITE(BTN_ENC,HIGH);
|
WRITE(BTN_ENC,HIGH);
|
||||||
WRITE(SDCARDDETECT,HIGH);
|
WRITE(SDCARDDETECT,HIGH);
|
||||||
#else
|
#else
|
||||||
pinMode(SHIFT_CLK,OUTPUT);
|
pinMode(SHIFT_CLK,OUTPUT);
|
||||||
pinMode(SHIFT_LD,OUTPUT);
|
pinMode(SHIFT_LD,OUTPUT);
|
||||||
pinMode(SHIFT_EN,OUTPUT);
|
pinMode(SHIFT_EN,OUTPUT);
|
||||||
pinMode(SHIFT_OUT,INPUT);
|
pinMode(SHIFT_OUT,INPUT);
|
||||||
WRITE(SHIFT_OUT,HIGH);
|
WRITE(SHIFT_OUT,HIGH);
|
||||||
WRITE(SHIFT_LD,HIGH);
|
WRITE(SHIFT_LD,HIGH);
|
||||||
WRITE(SHIFT_EN,LOW);
|
WRITE(SHIFT_EN,LOW);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void buttons_check()
|
void buttons_check()
|
||||||
{
|
{
|
||||||
// volatile static bool busy=false;
|
|
||||||
// if(busy)
|
|
||||||
// return;
|
|
||||||
// busy=true;
|
|
||||||
|
|
||||||
#ifdef NEWPANEL
|
#ifdef NEWPANEL
|
||||||
uint8_t newbutton=0;
|
uint8_t newbutton=0;
|
||||||
if(READ(BTN_EN1)==0) newbutton|=EN_A;
|
if(READ(BTN_EN1)==0) newbutton|=EN_A;
|
||||||
if(READ(BTN_EN2)==0) newbutton|=EN_B;
|
if(READ(BTN_EN2)==0) newbutton|=EN_B;
|
||||||
if((blocking<millis()) &&(READ(BTN_ENC)==0))
|
if((blocking<millis()) &&(READ(BTN_ENC)==0))
|
||||||
newbutton|=EN_C;
|
newbutton|=EN_C;
|
||||||
buttons=newbutton;
|
buttons=newbutton;
|
||||||
#else //read it from the shift register
|
#else //read it from the shift register
|
||||||
uint8_t newbutton=0;
|
uint8_t newbutton=0;
|
||||||
WRITE(SHIFT_LD,LOW);
|
WRITE(SHIFT_LD,LOW);
|
||||||
WRITE(SHIFT_LD,HIGH);
|
WRITE(SHIFT_LD,HIGH);
|
||||||
unsigned char tmp_buttons=0;
|
unsigned char tmp_buttons=0;
|
||||||
for(unsigned char i=0;i<8;i++)
|
for(unsigned char i=0;i<8;i++)
|
||||||
{
|
{
|
||||||
newbutton = newbutton>>1;
|
newbutton = newbutton>>1;
|
||||||
if(READ(SHIFT_OUT))
|
if(READ(SHIFT_OUT))
|
||||||
newbutton|=(1<<7);
|
newbutton|=(1<<7);
|
||||||
WRITE(SHIFT_CLK,HIGH);
|
WRITE(SHIFT_CLK,HIGH);
|
||||||
WRITE(SHIFT_CLK,LOW);
|
WRITE(SHIFT_CLK,LOW);
|
||||||
}
|
}
|
||||||
buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
|
buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char enc=0;
|
char enc=0;
|
||||||
if(buttons&EN_A)
|
if(buttons&EN_A)
|
||||||
enc|=(1<<0);
|
enc|=(1<<0);
|
||||||
|
@ -212,7 +211,6 @@ void buttons_check()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastenc=enc;
|
lastenc=enc;
|
||||||
// busy=false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -223,9 +221,9 @@ MainMenu::MainMenu()
|
||||||
displayStartingRow=0;
|
displayStartingRow=0;
|
||||||
activeline=0;
|
activeline=0;
|
||||||
force_lcd_update=true;
|
force_lcd_update=true;
|
||||||
#ifdef ULTIPANEL
|
#ifdef ULTIPANEL
|
||||||
buttons_init();
|
buttons_init();
|
||||||
#endif
|
#endif
|
||||||
lcd_init();
|
lcd_init();
|
||||||
linechanging=false;
|
linechanging=false;
|
||||||
}
|
}
|
||||||
|
@ -1154,12 +1152,13 @@ uint8_t getnrfilenames()
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
return cnt;
|
return cnt;
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::showSD()
|
void MainMenu::showSD()
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
uint8_t line=0;
|
uint8_t line=0;
|
||||||
|
|
||||||
|
@ -1205,11 +1204,11 @@ void MainMenu::showSD()
|
||||||
if(force_lcd_update)
|
if(force_lcd_update)
|
||||||
{
|
{
|
||||||
lcd.setCursor(0,line);
|
lcd.setCursor(0,line);
|
||||||
#ifdef CARDINSERTED
|
#ifdef CARDINSERTED
|
||||||
if(CARDINSERTED)
|
if(CARDINSERTED)
|
||||||
#else
|
#else
|
||||||
if(true)
|
if(true)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
lcd.print(" \004Refresh");
|
lcd.print(" \004Refresh");
|
||||||
}
|
}
|
||||||
|
@ -1306,9 +1305,9 @@ void MainMenu::showMainMenu()
|
||||||
{
|
{
|
||||||
//if(int(encoderpos/lcdslow)!=int(lastencoderpos/lcdslow))
|
//if(int(encoderpos/lcdslow)!=int(lastencoderpos/lcdslow))
|
||||||
// force_lcd_update=true;
|
// force_lcd_update=true;
|
||||||
#ifndef ULTIPANEL
|
#ifndef ULTIPANEL
|
||||||
force_lcd_update=false;
|
force_lcd_update=false;
|
||||||
#endif
|
#endif
|
||||||
//Serial.println((int)activeline);
|
//Serial.println((int)activeline);
|
||||||
if(force_lcd_update)
|
if(force_lcd_update)
|
||||||
clear();
|
clear();
|
||||||
|
@ -1347,17 +1346,17 @@ void MainMenu::showMainMenu()
|
||||||
beepshort();
|
beepshort();
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
case ItemM_file:
|
case ItemM_file:
|
||||||
{
|
{
|
||||||
if(force_lcd_update)
|
if(force_lcd_update)
|
||||||
{
|
{
|
||||||
lcd.setCursor(0,line);
|
lcd.setCursor(0,line);
|
||||||
#ifdef CARDINSERTED
|
#ifdef CARDINSERTED
|
||||||
if(CARDINSERTED)
|
if(CARDINSERTED)
|
||||||
#else
|
#else
|
||||||
if(true)
|
if(true)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if(sdmode)
|
if(sdmode)
|
||||||
lcd.print(" Stop Print \x7E");
|
lcd.print(" Stop Print \x7E");
|
||||||
|
@ -1370,7 +1369,7 @@ void MainMenu::showMainMenu()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef CARDINSERTED
|
#ifdef CARDINSERTED
|
||||||
if(CARDINSERTED)
|
if(CARDINSERTED)
|
||||||
#endif
|
#endif
|
||||||
if((activeline==line)&&CLICKED)
|
if((activeline==line)&&CLICKED)
|
||||||
{
|
{
|
||||||
|
@ -1380,28 +1379,30 @@ void MainMenu::showMainMenu()
|
||||||
beepshort();
|
beepshort();
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
SERIAL_ERRORLN("Something is wrong in the MenuStructure.");
|
SERIAL_ERRORLN("Something is wrong in the MenuStructure.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(activeline<0) activeline=0;
|
if(activeline<0)
|
||||||
if(activeline>=LCD_HEIGHT) activeline=LCD_HEIGHT-1;
|
activeline=0;
|
||||||
|
if(activeline>=LCD_HEIGHT)
|
||||||
|
activeline=LCD_HEIGHT-1;
|
||||||
if((encoderpos!=lastencoderpos)||force_lcd_update)
|
if((encoderpos!=lastencoderpos)||force_lcd_update)
|
||||||
{
|
{
|
||||||
lcd.setCursor(0,activeline);lcd.print(activeline?' ':' ');
|
lcd.setCursor(0,activeline);lcd.print(activeline?' ':' ');
|
||||||
if(encoderpos<0) encoderpos=0;
|
if(encoderpos<0) encoderpos=0;
|
||||||
if(encoderpos>3*lcdslow) encoderpos=3*lcdslow;
|
if(encoderpos>3*lcdslow)
|
||||||
|
encoderpos=3*lcdslow;
|
||||||
activeline=abs(encoderpos/lcdslow)%LCD_HEIGHT;
|
activeline=abs(encoderpos/lcdslow)%LCD_HEIGHT;
|
||||||
if(activeline<0) activeline=0;
|
if(activeline<0)
|
||||||
if(activeline>=LCD_HEIGHT) activeline=LCD_HEIGHT-1;
|
activeline=0;
|
||||||
|
if(activeline>=LCD_HEIGHT)
|
||||||
|
activeline=LCD_HEIGHT-1;
|
||||||
lastencoderpos=encoderpos;
|
lastencoderpos=encoderpos;
|
||||||
lcd.setCursor(0,activeline);lcd.print(activeline?'>':'\003');
|
lcd.setCursor(0,activeline);lcd.print(activeline?'>':'\003');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::update()
|
void MainMenu::update()
|
||||||
|
@ -1409,25 +1410,24 @@ void MainMenu::update()
|
||||||
static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
|
static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
|
||||||
static long timeoutToStatus=0;
|
static long timeoutToStatus=0;
|
||||||
static bool oldcardstatus=false;
|
static bool oldcardstatus=false;
|
||||||
#ifdef CARDINSERTED
|
#ifdef CARDINSERTED
|
||||||
if((CARDINSERTED != oldcardstatus))
|
if((CARDINSERTED != oldcardstatus))
|
||||||
{
|
|
||||||
force_lcd_update=true;
|
|
||||||
oldcardstatus=CARDINSERTED;
|
|
||||||
//Serial.println("echo: SD CHANGE");
|
|
||||||
if(CARDINSERTED)
|
|
||||||
{
|
{
|
||||||
initsd();
|
force_lcd_update=true;
|
||||||
lcd_status("Card inserted");
|
oldcardstatus=CARDINSERTED;
|
||||||
|
//Serial.println("echo: SD CHANGE");
|
||||||
|
if(CARDINSERTED)
|
||||||
|
{
|
||||||
|
initsd();
|
||||||
|
lcd_status("Card inserted");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sdactive=false;
|
||||||
|
lcd_status("Card removed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
#endif
|
||||||
{
|
|
||||||
sdactive=false;
|
|
||||||
lcd_status("Card removed");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(status!=oldstatus)
|
if(status!=oldstatus)
|
||||||
{
|
{
|
||||||
|
@ -1484,9 +1484,9 @@ void MainMenu::update()
|
||||||
|
|
||||||
|
|
||||||
//return for string conversion routines
|
//return for string conversion routines
|
||||||
char conv[8];
|
static char conv[8];
|
||||||
|
|
||||||
/// convert float to string with +123.4 format
|
// convert float to string with +123.4 format
|
||||||
char *ftostr3(const float &x)
|
char *ftostr3(const float &x)
|
||||||
{
|
{
|
||||||
//sprintf(conv,"%5.1f",x);
|
//sprintf(conv,"%5.1f",x);
|
||||||
|
@ -1497,6 +1497,7 @@ char *ftostr3(const float &x)
|
||||||
conv[3]=0;
|
conv[3]=0;
|
||||||
return conv;
|
return conv;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *itostr2(const uint8_t &x)
|
char *itostr2(const uint8_t &x)
|
||||||
{
|
{
|
||||||
//sprintf(conv,"%5.1f",x);
|
//sprintf(conv,"%5.1f",x);
|
||||||
|
@ -1506,10 +1507,10 @@ char *itostr2(const uint8_t &x)
|
||||||
conv[2]=0;
|
conv[2]=0;
|
||||||
return conv;
|
return conv;
|
||||||
}
|
}
|
||||||
/// convert float to string with +123.4 format
|
|
||||||
|
// convert float to string with +123.4 format
|
||||||
char *ftostr31(const float &x)
|
char *ftostr31(const float &x)
|
||||||
{
|
{
|
||||||
//sprintf(conv,"%5.1f",x);
|
|
||||||
int xx=x*10;
|
int xx=x*10;
|
||||||
conv[0]=(xx>=0)?'+':'-';
|
conv[0]=(xx>=0)?'+':'-';
|
||||||
xx=abs(xx);
|
xx=abs(xx);
|
||||||
|
@ -1524,7 +1525,6 @@ char *ftostr31(const float &x)
|
||||||
|
|
||||||
char *itostr31(const int &xx)
|
char *itostr31(const int &xx)
|
||||||
{
|
{
|
||||||
//sprintf(conv,"%5.1f",x);
|
|
||||||
conv[0]=(xx>=0)?'+':'-';
|
conv[0]=(xx>=0)?'+':'-';
|
||||||
conv[1]=(xx/1000)%10+'0';
|
conv[1]=(xx/1000)%10+'0';
|
||||||
conv[2]=(xx/100)%10+'0';
|
conv[2]=(xx/100)%10+'0';
|
||||||
|
@ -1534,6 +1534,7 @@ char *itostr31(const int &xx)
|
||||||
conv[6]=0;
|
conv[6]=0;
|
||||||
return conv;
|
return conv;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *itostr3(const int &xx)
|
char *itostr3(const int &xx)
|
||||||
{
|
{
|
||||||
conv[0]=(xx/100)%10+'0';
|
conv[0]=(xx/100)%10+'0';
|
||||||
|
@ -1553,7 +1554,7 @@ char *itostr4(const int &xx)
|
||||||
return conv;
|
return conv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// convert float to string with +1234.5 format
|
// convert float to string with +1234.5 format
|
||||||
char *ftostr51(const float &x)
|
char *ftostr51(const float &x)
|
||||||
{
|
{
|
||||||
int xx=x*10;
|
int xx=x*10;
|
||||||
|
@ -1587,11 +1588,9 @@ char *fillto(int8_t n,char *c)
|
||||||
}
|
}
|
||||||
ret[n]=0;
|
ret[n]=0;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
inline void lcd_status() {};
|
#endif //ULTRA_LCD
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
#ifndef __WATCHDOGH
|
#ifndef __WATCHDOGH
|
||||||
#define __WATCHDOGH
|
#define __WATCHDOGH
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
//#ifdef USE_WATCHDOG
|
#ifdef USE_WATCHDOG
|
||||||
|
|
||||||
/// intialise watch dog with a 1 sec interrupt time
|
// intialise watch dog with a 1 sec interrupt time
|
||||||
void wd_init();
|
void wd_init();
|
||||||
/// pad the dog/reset watchdog. MUST be called at least every second after the first wd_init or avr will go into emergency procedures..
|
// pad the dog/reset watchdog. MUST be called at least every second after the first wd_init or avr will go into emergency procedures..
|
||||||
void wd_reset();
|
void wd_reset();
|
||||||
|
|
||||||
//#endif
|
#else
|
||||||
|
inline void wd_init() {};
|
||||||
|
inline void wd_reset() {};
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <avr/wdt.h>
|
#include <avr/wdt.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
volatile uint8_t timeout_seconds=0;
|
static volatile uint8_t timeout_seconds=0;
|
||||||
|
|
||||||
void(* ctrlaltdelete) (void) = 0; //does not work on my atmega2560
|
void(* ctrlaltdelete) (void) = 0; //does not work on my atmega2560
|
||||||
|
|
||||||
|
|
Reference in a new issue