reformating and some minor bugs/things found on the way.

master
Bernhard Kubicek 13 years ago
parent 900e0c9bf2
commit 1d171e9e52

@ -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
/* #define PID_PI //no differentail term
//#define PID_PID //normal PID
#ifdef PID_PID
//PID according to Ziegler-Nichols method //PID according to Ziegler-Nichols method
float Kp = 0.6*PID_CRITIAL_GAIN; #define DEFAULT_Kp (0.6*PID_CRITIAL_GAIN)
float Ki =PIDIADD+2*Kp/PID_SWING_AT_CRITIAL*PID_dT; #define DEFAULT_Ki (2*Kp/PID_SWING_AT_CRITIAL*PID_dT)
float Kd = Kp*PID_SWING_AT_CRITIAL/8./PID_dT; #define DEFAULT_Kd (PID_SWING_AT_CRITIAL/8./PID_dT)
*/ #endif
#ifdef PID_PI
//PI according to Ziegler-Nichols method //PI according to Ziegler-Nichols method
#define DEFAULT_Kp (PID_CRITIAL_GAIN/2.2) #define DEFAULT_Kp (PID_CRITIAL_GAIN/2.2)
#define DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT) #define DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT)
#define DEFAULT_Kd (0) #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)
@ -237,13 +243,12 @@ const int dropsegments=5; //everything with this number of steps will be ignore
#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,12 +1,11 @@
#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;
@ -15,7 +14,7 @@ template <class T> int EEPROM_writeAnything(int &ee, const T& value)
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;
@ -28,12 +27,16 @@ template <class T> int EEPROM_readAnything(int &ee, T& value)
#define EEPROM_OFFSET 100 #define EEPROM_OFFSET 100
#define EEPROM_VERSION "V04" // IMPORTANT: Whenever there are changes made to the variables stored in EEPROM
// 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 // in the functions below, also increment the version number. This makes sure that
// the default values are used whenever there is a change to the data, to prevent // the default values are used whenever there is a change to the data, to prevent
// wrong data being written to the variables. // wrong data being written to the variables.
// ALSO: always make sure the variables in the Store and retrieve sections are in the same order. // ALSO: always make sure the variables in the Store and retrieve sections are in the same order.
void StoreSettings() { #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
@ -60,16 +63,17 @@ void StoreSettings() {
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))
{ // version number match
EEPROM_readAnything(i,axis_steps_per_unit); EEPROM_readAnything(i,axis_steps_per_unit);
EEPROM_readAnything(i,max_feedrate); EEPROM_readAnything(i,max_feedrate);
EEPROM_readAnything(i,max_acceleration_units_per_sq_second); EEPROM_readAnything(i,max_acceleration_units_per_sq_second);
@ -89,11 +93,13 @@ void RetrieveSettings(bool def=false){ // if def=true, the default values will
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];
@ -121,7 +127,6 @@ void RetrieveSettings(bool def=false){ // if def=true, the default values will
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

@ -24,6 +24,7 @@ void manage_inactivity(byte debug);
#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)
@ -31,6 +32,7 @@ void manage_inactivity(byte debug);
#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)
@ -40,19 +42,15 @@ void manage_inactivity(byte debug);
#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,14 +59,6 @@ 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.
@ -80,7 +70,4 @@ void enquecommand(const char *cmd); //put an ascii command at the end of the cur
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,9 +38,6 @@
#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";
@ -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;
@ -173,6 +166,9 @@ bool savetosd = false;
int16_t n; int16_t n;
unsigned long autostart_atmillis=0; unsigned long autostart_atmillis=0;
bool autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
void initsd() void initsd()
{ {
sdactive = false; sdactive = false;
@ -200,34 +196,39 @@ void initsd()
#endif //SDSS #endif //SDSS
} }
void quickinitsd(){ void quickinitsd()
{
sdactive=false; sdactive=false;
autostart_atmillis=millis()+5000; autostart_atmillis=millis()+5000;
} }
inline void write_command(char *buf){ inline void write_command(char *buf)
{
char* begin = buf; char* begin = buf;
char* npos = 0; char* npos = 0;
char* end = buf + strlen(buf) - 1; char* end = buf + strlen(buf) - 1;
file.writeError = false; file.writeError = false;
if((npos = strchr(buf, 'N')) != NULL){ if((npos = strchr(buf, 'N')) != NULL)
{
begin = strchr(npos, ' ') + 1; begin = strchr(npos, ' ') + 1;
end = strchr(npos, '*') - 1; end = strchr(npos, '*') - 1;
} }
end[1] = '\r'; end[1] = '\r';
end[2] = '\n'; end[2] = '\n';
end[3] = '\0'; end[3] = '\0';
//Serial.println(begin);
file.write(begin); file.write(begin);
if (file.writeError){ if (file.writeError)
{
SERIAL_ERRORLN("error writing to file"); 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,21 +243,18 @@ 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];
} }
@ -267,17 +265,14 @@ void setup()
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)
{ {
@ -304,8 +299,6 @@ void checkautostart(bool force)
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)
@ -328,20 +321,15 @@ void checkautostart(bool force)
enquecommand(cmd); enquecommand(cmd);
enquecommand("M24"); enquecommand("M24");
found=true; found=true;
} }
} }
if(!found) if(!found)
lastnr=-1; lastnr=-1;
else else
lastnr++; lastnr++;
}
#else
inline void checkautostart(bool x)
{
} }
#else //NO SD SUPORT
inline void checkautostart(bool x){}
#endif #endif
@ -353,19 +341,23 @@ void loop()
if(buflen) if(buflen)
{ {
#ifdef SDSUPPORT #ifdef SDSUPPORT
if(savetosd){ if(savetosd)
if(strstr(cmdbuffer[bufindr],"M29") == NULL){ {
if(strstr(cmdbuffer[bufindr],"M29") == NULL)
{
write_command(cmdbuffer[bufindr]); write_command(cmdbuffer[bufindr]);
Serial.println("ok"); Serial.println("ok");
} }
else{ else
{
file.sync(); file.sync();
file.close(); file.close();
savetosd = false; savetosd = false;
Serial.println("Done saving file."); Serial.println("Done saving file.");
} }
} }
else{ else
{
process_commands(); process_commands();
} }
#else #else
@ -497,7 +489,8 @@ inline void get_command()
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;
@ -518,15 +511,18 @@ inline void get_command()
} }
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;
@ -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,7 +792,6 @@ 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'))
{ {
@ -837,8 +834,6 @@ inline void process_commands()
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595) #if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
Serial.print("ok T:"); Serial.print("ok T:");
Serial.print(tt); Serial.print(tt);
// Serial.print(", raw:");
// Serial.print(current_raw);
#if TEMP_1_PIN > -1 #if TEMP_1_PIN > -1
#ifdef PIDTEMP #ifdef PIDTEMP
Serial.print(" B:"); Serial.print(" B:");
@ -847,18 +842,19 @@ inline void process_commands()
#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 #endif
return; return;
//break; break;
case 109: {// M109 - Wait for extruder heater to reach target. case 109:
{// M109 - Wait for extruder heater to reach target.
LCD_MESSAGE("Heating..."); LCD_MESSAGE("Heating...");
if (code_seen('S')) setTargetHotend0(code_value()); if (code_seen('S')) setTargetHotend0(code_value());
@ -878,7 +874,8 @@ inline void process_commands()
#else #else
while ( target_direction ? (isHeatingHotend0()) : (isCoolingHotend0()) ) { while ( target_direction ? (isHeatingHotend0()) : (isCoolingHotend0()) ) {
#endif //TEMP_RESIDENCY_TIME #endif //TEMP_RESIDENCY_TIME
if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down if( (millis() - codenum) > 1000 )
{ //Print Temp Reading every 1 second while heating up/cooling down
Serial.print("T:"); Serial.print("T:");
Serial.println( degHotend0() ); Serial.println( degHotend0() );
codenum = millis(); codenum = millis();
@ -890,7 +887,8 @@ inline void process_commands()
or when current temp falls outside the hysteresis after target temp was reached */ or when current temp falls outside the hysteresis after target temp was reached */
if ((residencyStart == -1 && target_direction && !isHeatingHotend0()) || if ((residencyStart == -1 && target_direction && !isHeatingHotend0()) ||
(residencyStart == -1 && !target_direction && !isCoolingHotend0()) || (residencyStart == -1 && !target_direction && !isCoolingHotend0()) ||
(residencyStart > -1 && labs(degHotend0() - degTargetHotend0()) > TEMP_HYSTERESIS) ) { (residencyStart > -1 && labs(degHotend0() - degTargetHotend0()) > TEMP_HYSTERESIS) )
{
residencyStart = millis(); residencyStart = millis();
} }
#endif //TEMP_RESIDENCY_TIME #endif //TEMP_RESIDENCY_TIME
@ -920,6 +918,7 @@ inline void process_commands()
} }
#endif #endif
break; break;
#if FAN_PIN > -1 #if FAN_PIN > -1
case 106: //M106 Fan On case 106: //M106 Fan On
if (code_seen('S')){ if (code_seen('S')){
@ -937,7 +936,8 @@ 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
@ -952,12 +952,13 @@ inline void process_commands()
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:");
@ -1026,7 +1028,8 @@ inline void process_commands()
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;
@ -1066,20 +1069,12 @@ inline void process_commands()
} }
} }
break; break;
#ifdef PIDTEMP #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; break;
#endif //PIDTEMP #endif //PIDTEMP
case 500: // Store settings in EEPROM case 500: // Store settings in EEPROM
@ -1100,7 +1095,8 @@ inline void process_commands()
} }
} }
else{ else
{
Serial.print("echo: Unknown command:\""); Serial.print("echo: Unknown command:\"");
Serial.print(cmdbuffer[bufindr]); Serial.print(cmdbuffer[bufindr]);
Serial.println("\""); Serial.println("\"");
@ -1276,9 +1272,14 @@ 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 )
if(max_inactive_time)
kill();
if( (millis()-previous_millis_cmd) > stepper_inactive_time )
if(stepper_inactive_time)
{
disable_x(); disable_x();
disable_y(); disable_y();
disable_z(); disable_z();

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

@ -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.
@ -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]);

@ -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},

@ -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
@ -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
@ -438,7 +441,6 @@ 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

@ -143,7 +143,6 @@ CRITICAL_SECTION_END;
#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
@ -350,12 +349,14 @@ void disable_heater()
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
@ -493,6 +494,7 @@ ISR(TIMER0_COMPB_vect)
} }
#endif #endif
#endif //MAXTEMP #endif //MAXTEMP
#ifdef HEATER_0_MINTEMP #ifdef HEATER_0_MINTEMP
#if (HEATER_0_PIN > -1) #if (HEATER_0_PIN > -1)
if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) { if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
@ -503,6 +505,7 @@ ISR(TIMER0_COMPB_vect)
} }
#endif #endif
#endif #endif
#ifdef HEATER_1_MINTEMP #ifdef HEATER_1_MINTEMP
#if (HEATER_2_PIN > -1) #if (HEATER_2_PIN > -1)
if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) { if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
@ -513,6 +516,7 @@ ISR(TIMER0_COMPB_vect)
} }
#endif #endif
#endif //MAXTEMP #endif //MAXTEMP
#ifdef BED_MINTEMP #ifdef BED_MINTEMP
#if (HEATER_1_PIN > -1) #if (HEATER_1_PIN > -1)
if(current_raw[1] <= bed_minttemp) { if(current_raw[1] <= bed_minttemp) {
@ -523,6 +527,7 @@ ISR(TIMER0_COMPB_vect)
} }
#endif #endif
#endif #endif
#ifdef BED_MAXTEMP #ifdef BED_MAXTEMP
#if (HEATER_1_PIN > -1) #if (HEATER_1_PIN > -1)
if(current_raw[1] >= bed_maxttemp) { if(current_raw[1] >= bed_maxttemp) {

@ -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,89 +9,28 @@
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_C (1<<BLEN_C)
#define EN_B (1<<BLEN_B) #define EN_B (1<<BLEN_B)
#define EN_A (1<<BLEN_A) #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 CLICKED (buttons&EN_C)
#define BLOCK {blocking=millis()+blocktime;} #define BLOCK {blocking=millis()+blocktime;}
#define CARDINSERTED (READ(SDCARDDETECT)==0) #define CARDINSERTED (READ(SDCARDDETECT)==0)
#else #else
//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
//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
//encoder rotation values
#define encrot0 0
#define encrot1 2
#define encrot2 3
#define encrot3 1
//atomatic, do not change //atomatic, do not change
#define B_LE (1<<BL_LE) #define B_LE (1<<BL_LE)
@ -107,9 +46,11 @@
#define BLOCK {blocking[BL_MI]=millis()+blocktime;blocking[BL_ST]=millis()+blocktime;} #define BLOCK {blocking[BL_MI]=millis()+blocktime;blocking[BL_ST]=millis()+blocktime;}
#endif #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,6 +122,8 @@ void lcd_status()
menu.update(); menu.update();
} }
#ifdef ULTIPANEL #ifdef ULTIPANEL
void buttons_init() void buttons_init()
{ {
#ifdef NEWPANEL #ifdef NEWPANEL
@ -147,10 +149,6 @@ void buttons_init()
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;
@ -174,6 +172,7 @@ void buttons_check()
} }
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
@ -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;
@ -1386,22 +1385,24 @@ void MainMenu::showMainMenu()
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()
@ -1424,7 +1425,6 @@ void MainMenu::update()
{ {
sdactive=false; sdactive=false;
lcd_status("Card removed"); lcd_status("Card removed");
} }
} }
#endif #endif
@ -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

Loading…
Cancel
Save