summaryrefslogtreecommitdiff
path: root/Sprinter
diff options
context:
space:
mode:
Diffstat (limited to 'Sprinter')
-rw-r--r--Sprinter/Sprinter.h71
-rw-r--r--Sprinter/Sprinter.pde315
2 files changed, 209 insertions, 177 deletions
diff --git a/Sprinter/Sprinter.h b/Sprinter/Sprinter.h
index 31d4b69..ad39c00 100644
--- a/Sprinter/Sprinter.h
+++ b/Sprinter/Sprinter.h
@@ -8,10 +8,59 @@ void process_commands();
void manage_inactivity(byte debug);
void manage_heater();
-float temp2analog(int celsius);
-float temp2analogBed(int celsius);
-float analog2temp(int raw);
-float analog2tempBed(int raw);
+int temp2analogu(int celsius, const short table[][2], int numtemps, int source);
+int analog2tempu(int raw, const short table[][2], int numtemps, int source);
+#ifdef HEATER_USES_THERMISTOR
+ #define HEATERSOURCE 1
+#endif
+#ifdef HEATER_USES_AD595
+ #define HEATERSOURCE 2
+#endif
+#ifdef HEATER_USES_MAX6675
+ #define HEATERSOURCE 3
+#endif
+#ifdef BED_USES_THERMISTOR
+ #define BEDSOURCE 1
+#endif
+#ifdef BED_USES_AD595
+ #define BEDSOURCE 2
+#endif
+#ifdef BED_USES_MAX6675
+ #define BEDSOURCE 3
+#endif
+
+#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS,HEATERSOURCE)
+#define temp2analogBed( c ) temp2analogu((c),bedtemptable,BNUMTEMPS,BEDSOURCE)
+#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS,HEATERSOURCE)
+#define analog2tempBed( c ) analog2tempu((c),bedtemptable,BNUMTEMPS,BEDSOURCE)
+#if X_ENABLE_PIN > -1
+#define enable_x() digitalWrite(X_ENABLE_PIN, X_ENABLE_ON)
+#define disable_x() digitalWrite(X_ENABLE_PIN,!X_ENABLE_ON)
+#else
+#define enable_x() ;
+#define disable_x() ;
+#endif
+#if Y_ENABLE_PIN > -1
+#define enable_y() digitalWrite(Y_ENABLE_PIN, Y_ENABLE_ON)
+#define disable_y() digitalWrite(Y_ENABLE_PIN,!Y_ENABLE_ON)
+#else
+#define enable_y() ;
+#define disable_y() ;
+#endif
+#if Z_ENABLE_PIN > -1
+#define enable_z() digitalWrite(Z_ENABLE_PIN, Z_ENABLE_ON)
+#define disable_z() digitalWrite(Z_ENABLE_PIN,!Z_ENABLE_ON)
+#else
+#define enable_z() ;
+#define disable_z() ;
+#endif
+#if E_ENABLE_PIN > -1
+#define enable_e() digitalWrite(E_ENABLE_PIN, E_ENABLE_ON)
+#define disable_e() digitalWrite(E_ENABLE_PIN,!E_ENABLE_ON)
+#else
+#define enable_e() ;
+#define disable_e() ;
+#endif
void FlushSerialRequestResend();
void ClearToSend();
@@ -20,18 +69,6 @@ void get_coordinates();
void prepare_move();
void linear_move(unsigned long steps_remaining[]);
void do_step_update_micros(int axis);
-void disable_x();
-void disable_y();
-void disable_z();
-void disable_e();
-void enable_x();
-void enable_y();
-void enable_z();
-void enable_e();
-void do_x_step();
-void do_y_step();
-void do_z_step();
-void do_e_step();
-
+void do_step(int axis);
void kill(byte debug);
diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde
index ea854cb..6b94c97 100644
--- a/Sprinter/Sprinter.pde
+++ b/Sprinter/Sprinter.pde
@@ -1,9 +1,9 @@
// Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
// Licence: GPL
-#include "Sprinter.h"
#include "Configuration.h"
#include "pins.h"
+#include "Sprinter.h"
#ifdef SDSUPPORT
#include "SdFat.h"
@@ -57,6 +57,7 @@
//Stepper Movement Variables
+
char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
bool move_direction[NUM_AXIS];
const int STEP_PIN[NUM_AXIS] = {X_STEP_PIN, Y_STEP_PIN, Z_STEP_PIN, E_STEP_PIN};
@@ -64,19 +65,11 @@ unsigned long axis_previous_micros[NUM_AXIS];
unsigned long previous_micros = 0, previous_millis_heater, previous_millis_bed_heater;
unsigned long move_steps_to_take[NUM_AXIS];
#ifdef RAMP_ACCELERATION
- unsigned long axis_max_interval[] = {100000000.0 / (max_start_speed_units_per_second[0] * axis_steps_per_unit[0]),
- 100000000.0 / (max_start_speed_units_per_second[1] * axis_steps_per_unit[1]),
- 100000000.0 / (max_start_speed_units_per_second[2] * axis_steps_per_unit[2]),
- 100000000.0 / (max_start_speed_units_per_second[3] * axis_steps_per_unit[3])}; //TODO: refactor all things like this in a function, or move to setup()
- // in a for loop
- unsigned long max_interval;
- unsigned long axis_steps_per_sqr_second[] = {max_acceleration_units_per_sq_second[0] * axis_steps_per_unit[0],
- max_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1], max_acceleration_units_per_sq_second[2] * axis_steps_per_unit[2],
- max_acceleration_units_per_sq_second[3] * axis_steps_per_unit[3]};
- unsigned long axis_travel_steps_per_sqr_second[] = {max_travel_acceleration_units_per_sq_second[0] * axis_steps_per_unit[0],
- max_travel_acceleration_units_per_sq_second[1] * axis_steps_per_unit[1], max_travel_acceleration_units_per_sq_second[2] * axis_steps_per_unit[2],
- max_travel_acceleration_units_per_sq_second[3] * axis_steps_per_unit[3]};
- unsigned long steps_per_sqr_second, plateau_steps;
+unsigned long axis_max_interval[NUM_AXIS];
+unsigned long axis_steps_per_sqr_second[NUM_AXIS];
+unsigned long axis_travel_steps_per_sqr_second[NUM_AXIS];
+unsigned long max_interval;
+unsigned long steps_per_sqr_second, plateau_steps;
#endif
boolean acceleration_enabled = false, accelerating = false;
unsigned long interval;
@@ -140,10 +133,10 @@ float tt = 0, bt = 0;
unsigned long watchmillis = 0;
#endif
#ifdef MINTEMP
- int minttemp = temp2analog(MINTEMP);
+ int minttemp = temp2analogh(MINTEMP);
#endif
#ifdef MAXTEMP
-int maxttemp = temp2analog(MAXTEMP);
+int maxttemp = temp2analogh(MAXTEMP);
#endif
//Inactivity shutdown variables
@@ -211,51 +204,116 @@ void setup()
fromsd[i] = false;
}
- //Initialize Step Pins
- for(int i=0; i < NUM_AXIS; i++) if(STEP_PIN[i] > -1) pinMode(STEP_PIN[i],OUTPUT);
//Initialize Dir Pins
- if(X_DIR_PIN > -1) pinMode(X_DIR_PIN,OUTPUT);
- if(Y_DIR_PIN > -1) pinMode(Y_DIR_PIN,OUTPUT);
- if(Z_DIR_PIN > -1) pinMode(Z_DIR_PIN,OUTPUT);
- if(E_DIR_PIN > -1) pinMode(E_DIR_PIN,OUTPUT);
-
- //Steppers default to disabled.
- if(X_ENABLE_PIN > -1) if(!X_ENABLE_ON) digitalWrite(X_ENABLE_PIN,HIGH);
- if(Y_ENABLE_PIN > -1) if(!Y_ENABLE_ON) digitalWrite(Y_ENABLE_PIN,HIGH);
- if(Z_ENABLE_PIN > -1) if(!Z_ENABLE_ON) digitalWrite(Z_ENABLE_PIN,HIGH);
- if(E_ENABLE_PIN > -1) if(!E_ENABLE_ON) digitalWrite(E_ENABLE_PIN,HIGH);
-
- //endstop pullups
+ #if X_DIR_PIN > -1
+ pinMode(X_DIR_PIN,OUTPUT);
+ #endif
+ #if Y_DIR_PIN > -1
+ pinMode(Y_DIR_PIN,OUTPUT);
+ #endif
+ #if Z_DIR_PIN > -1
+ pinMode(Z_DIR_PIN,OUTPUT);
+ #endif
+ #if E_DIR_PIN > -1
+ pinMode(E_DIR_PIN,OUTPUT);
+ #endif
+
+ //Initialize Enable Pins - steppers default to disabled.
+
+ #if (X_ENABLE_PIN > -1)
+ pinMode(X_ENABLE_PIN,OUTPUT);
+ if(!X_ENABLE_ON) digitalWrite(X_ENABLE_PIN,HIGH);
+ #endif
+ #if (Y_ENABLE_PIN > -1)
+ pinMode(Y_ENABLE_PIN,OUTPUT);
+ if(!Y_ENABLE_ON) digitalWrite(Y_ENABLE_PIN,HIGH);
+ #endif
+ #if (Z_ENABLE_PIN > -1)
+ pinMode(Z_ENABLE_PIN,OUTPUT);
+ if(!Z_ENABLE_ON) digitalWrite(Z_ENABLE_PIN,HIGH);
+ #endif
+ #if (E_ENABLE_PIN > -1)
+ pinMode(E_ENABLE_PIN,OUTPUT);
+ if(!E_ENABLE_ON) digitalWrite(E_ENABLE_PIN,HIGH);
+ #endif
+
+ //endstops and pullups
#ifdef ENDSTOPPULLUPS
- if(X_MIN_PIN > -1) { pinMode(X_MIN_PIN,INPUT); digitalWrite(X_MIN_PIN,HIGH);}
- if(Y_MIN_PIN > -1) { pinMode(Y_MIN_PIN,INPUT); digitalWrite(Y_MIN_PIN,HIGH);}
- if(Z_MIN_PIN > -1) { pinMode(Z_MIN_PIN,INPUT); digitalWrite(Z_MIN_PIN,HIGH);}
- if(X_MAX_PIN > -1) { pinMode(X_MAX_PIN,INPUT); digitalWrite(X_MAX_PIN,HIGH);}
- if(Y_MAX_PIN > -1) { pinMode(Y_MAX_PIN,INPUT); digitalWrite(Y_MAX_PIN,HIGH);}
- if(Z_MAX_PIN > -1) { pinMode(Z_MAX_PIN,INPUT); digitalWrite(Z_MAX_PIN,HIGH);}
+ #if X_MIN_PIN > -1
+ pinMode(X_MIN_PIN,INPUT);
+ digitalWrite(X_MIN_PIN,HIGH);
+ #endif
+ #if X_MAX_PIN > -1
+ pinMode(X_MAX_PIN,INPUT);
+ digitalWrite(X_MAX_PIN,HIGH);
+ #endif
+ #if Y_MIN_PIN > -1
+ pinMode(Y_MIN_PIN,INPUT);
+ digitalWrite(Y_MIN_PIN,HIGH);
+ #endif
+ #if Y_MAX_PIN > -1
+ pinMode(Y_MAX_PIN,INPUT);
+ digitalWrite(Y_MAX_PIN,HIGH);
+ #endif
+ #if Z_MIN_PIN > -1
+ pinMode(Z_MIN_PIN,INPUT);
+ digitalWrite(Z_MIN_PIN,HIGH);
+ #endif
+ #if Z_MAX_PIN > -1
+ pinMode(Z_MAX_PIN,INPUT);
+ digitalWrite(Z_MAX_PIN,HIGH);
+ #endif
+ #else
+ #if X_MIN_PIN > -1
+ pinMode(X_MIN_PIN,INPUT);
+ #endif
+ #if X_MAX_PIN > -1
+ pinMode(X_MAX_PIN,INPUT);
+ #endif
+ #if Y_MIN_PIN > -1
+ pinMode(Y_MIN_PIN,INPUT);
+ #endif
+ #if Y_MAX_PIN > -1
+ pinMode(Y_MAX_PIN,INPUT);
+ #endif
+ #if Z_MIN_PIN > -1
+ pinMode(Z_MIN_PIN,INPUT);
+ #endif
+ #if Z_MAX_PIN > -1
+ pinMode(Z_MAX_PIN,INPUT);
#endif
- //Initialize Enable Pins
- if(X_ENABLE_PIN > -1) pinMode(X_ENABLE_PIN,OUTPUT);
- if(Y_ENABLE_PIN > -1) pinMode(Y_ENABLE_PIN,OUTPUT);
- if(Z_ENABLE_PIN > -1) pinMode(Z_ENABLE_PIN,OUTPUT);
- if(E_ENABLE_PIN > -1) pinMode(E_ENABLE_PIN,OUTPUT);
-
- if(HEATER_0_PIN > -1) pinMode(HEATER_0_PIN,OUTPUT);
- if(HEATER_1_PIN > -1) pinMode(HEATER_1_PIN,OUTPUT);
+ #endif
+
+ #if (HEATER_0_PIN > -1)
+ pinMode(HEATER_0_PIN,OUTPUT);
+ #endif
+ #if (HEATER_1_PIN > -1)
+ pinMode(HEATER_1_PIN,OUTPUT);
+ #endif
+
+//Initialize Step Pins
+ for(int i=0; i < NUM_AXIS; i++){
+ if(STEP_PIN[i] > -1) pinMode(STEP_PIN[i],OUTPUT);
+ #ifdef RAMP_ACCELERATION
+ axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_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];
+ axis_travel_steps_per_sqr_second[i] = max_travel_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
+ #endif
+ }
#ifdef HEATER_USES_MAX6675
- digitalWrite(SCK_PIN,0);
pinMode(SCK_PIN,OUTPUT);
-
- digitalWrite(MOSI_PIN,1);
+ digitalWrite(SCK_PIN,0);
+
pinMode(MOSI_PIN,OUTPUT);
-
- digitalWrite(MISO_PIN,1);
+ digitalWrite(MOSI_PIN,1);
+
pinMode(MISO_PIN,INPUT);
-
- digitalWrite(MAX6675_SS,1);
+ digitalWrite(MISO_PIN,1);
+
pinMode(MAX6675_SS,OUTPUT);
+ digitalWrite(MAX6675_SS,1);
#endif
#ifdef SDSUPPORT
@@ -652,7 +710,7 @@ inline void process_commands()
break;
#endif
case 104: // M104
- if (code_seen('S')) target_raw = temp2analog(code_value());
+ if (code_seen('S')) target_raw = temp2analogh(code_value());
#ifdef WATCHPERIOD
if(target_raw > current_raw){
watchmillis = max(1,millis());
@@ -682,12 +740,12 @@ inline void process_commands()
Serial.println();
#endif
#else
- Serial.println("No thermistors - no temp");
+ #error No temperature source available
#endif
return;
//break;
case 109: // M109 - Wait for extruder heater to reach target.
- if (code_seen('S')) target_raw = temp2analog(code_value());
+ if (code_seen('S')) target_raw = temp2analogh(code_value());
#ifdef WATCHPERIOD
if(target_raw>current_raw){
watchmillis = max(1,millis());
@@ -709,7 +767,7 @@ inline void process_commands()
break;
case 190: // M190 - Wait bed for heater to reach target.
#if TEMP_1_PIN > -1
- if (code_seen('S')) target_bed_raw = temp2analog(code_value());
+ if (code_seen('S')) target_bed_raw = temp2analogh(code_value());
codenum = millis();
while(current_bed_raw < target_bed_raw) {
if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
@@ -1150,15 +1208,6 @@ inline void do_step(int axis) {
digitalWrite(STEP_PIN[axis], LOW);
}
-inline void disable_x() { if(X_ENABLE_PIN > -1) digitalWrite(X_ENABLE_PIN,!X_ENABLE_ON); }
-inline void disable_y() { if(Y_ENABLE_PIN > -1) digitalWrite(Y_ENABLE_PIN,!Y_ENABLE_ON); }
-inline void disable_z() { if(Z_ENABLE_PIN > -1) digitalWrite(Z_ENABLE_PIN,!Z_ENABLE_ON); }
-inline void disable_e() { if(E_ENABLE_PIN > -1) digitalWrite(E_ENABLE_PIN,!E_ENABLE_ON); }
-inline void enable_x() { if(X_ENABLE_PIN > -1) digitalWrite(X_ENABLE_PIN, X_ENABLE_ON); }
-inline void enable_y() { if(Y_ENABLE_PIN > -1) digitalWrite(Y_ENABLE_PIN, Y_ENABLE_ON); }
-inline void enable_z() { if(Z_ENABLE_PIN > -1) digitalWrite(Z_ENABLE_PIN, Z_ENABLE_ON); }
-inline void enable_e() { if(E_ENABLE_PIN > -1) digitalWrite(E_ENABLE_PIN, E_ENABLE_ON); }
-
#define HEAT_INTERVAL 250
#ifdef HEATER_USES_MAX6675
unsigned long max6675_previous_millis = 0;
@@ -1286,6 +1335,12 @@ inline void manage_heater()
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
return;
previous_millis_bed_heater = millis();
+ #ifndef TEMP_1_PIN
+ return;
+ #endif
+ #if TEMP_1_PIN == -1
+ return;
+ #endif
#ifdef BED_USES_THERMISTOR
@@ -1304,7 +1359,6 @@ inline void manage_heater()
#endif
- #if TEMP_1_PIN > -1
if(current_bed_raw >= target_bed_raw)
{
digitalWrite(HEATER_1_PIN,LOW);
@@ -1313,139 +1367,80 @@ inline void manage_heater()
{
digitalWrite(HEATER_1_PIN,HIGH);
}
- #endif
}
-// Takes hot end temperature value as input and returns corresponding raw value.
-// For a thermistor, it uses the RepRap thermistor temp table.
-// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
-// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
-float temp2analog(int celsius) {
- #ifdef HEATER_USES_THERMISTOR
- int raw = 0;
- byte i;
-
- for (i=1; i<NUMTEMPS; i++)
- {
- if (temptable[i][1] < celsius)
- {
- raw = temptable[i-1][0] +
- (celsius - temptable[i-1][1]) *
- (temptable[i][0] - temptable[i-1][0]) /
- (temptable[i][1] - temptable[i-1][1]);
-
- break;
- }
- }
-
- // Overflow: Set to last value in the table
- if (i == NUMTEMPS) raw = temptable[i-1][0];
-
- return 1023 - raw;
- #elif defined HEATER_USES_AD595
- return celsius * (1024.0 / (5.0 * 100.0) );
- #elif defined HEATER_USES_MAX6675
- return celsius * 4.0;
- #endif
-}
-
-// Takes bed temperature value as input and returns corresponding raw value.
-// For a thermistor, it uses the RepRap thermistor temp table.
-// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
-// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
-float temp2analogBed(int celsius) {
- #ifdef BED_USES_THERMISTOR
+int temp2analogu(int celsius, const short table[][2], int numtemps, int source) {
+ #if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
+ if(source==1){
int raw = 0;
byte i;
- for (i=1; i<BNUMTEMPS; i++)
+ for (i=1; i<numtemps; i++)
{
- if (bedtemptable[i][1] < celsius)
+ if (table[i][1] < celsius)
{
- raw = bedtemptable[i-1][0] +
- (celsius - bedtemptable[i-1][1]) *
- (bedtemptable[i][0] - bedtemptable[i-1][0]) /
- (bedtemptable[i][1] - bedtemptable[i-1][1]);
+ raw = table[i-1][0] +
+ (celsius - table[i-1][1]) *
+ (table[i][0] - table[i-1][0]) /
+ (table[i][1] - table[i-1][1]);
break;
}
}
// Overflow: Set to last value in the table
- if (i == BNUMTEMPS) raw = bedtemptable[i-1][0];
+ if (i == numtemps) raw = table[i-1][0];
return 1023 - raw;
- #elif defined BED_USES_AD595
- return celsius * (1024.0 / (5.0 * 100.0) );
+ }
+ #elif defined (HEATER_USES_AD595) || defined (BED_USES_AD595)
+ if(source==2)
+ return celsius * 1024 / (500);
+ #elif defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675)
+ if(source==3)
+ return celsius * 4;
#endif
+ return -1;
}
-// Derived from RepRap FiveD extruder::getTemperature()
-// For hot end temperature measurement.
-float analog2temp(int raw) {
- #ifdef HEATER_USES_THERMISTOR
+int analog2tempu(int raw,const short table[][2], int numtemps, int source) {
+ #if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
+ if(source==1){
int celsius = 0;
byte i;
raw = 1023 - raw;
- for (i=1; i<NUMTEMPS; i++)
+ for (i=1; i<numtemps; i++)
{
- if (temptable[i][0] > raw)
+ if (table[i][0] > raw)
{
- celsius = temptable[i-1][1] +
- (raw - temptable[i-1][0]) *
- (temptable[i][1] - temptable[i-1][1]) /
- (temptable[i][0] - temptable[i-1][0]);
+ celsius = table[i-1][1] +
+ (raw - table[i-1][0]) *
+ (table[i][1] - table[i-1][1]) /
+ (table[i][0] - table[i-1][0]);
break;
}
}
// Overflow: Set to last value in the table
- if (i == NUMTEMPS) celsius = temptable[i-1][1];
+ if (i == numtemps) celsius = table[i-1][1];
return celsius;
- #elif defined HEATER_USES_AD595
- return raw * ((5.0 * 100.0) / 1024.0);
- #elif defined HEATER_USES_MAX6675
- return raw * 0.25;
- #endif
-}
-
-// Derived from RepRap FiveD extruder::getTemperature()
-// For bed temperature measurement.
-float analog2tempBed(int raw) {
- #ifdef BED_USES_THERMISTOR
- int celsius = 0;
- byte i;
-
- raw = 1023 - raw;
-
- for (i=1; i<NUMTEMPS; i++)
- {
- if (bedtemptable[i][0] > raw)
- {
- celsius = bedtemptable[i-1][1] +
- (raw - bedtemptable[i-1][0]) *
- (bedtemptable[i][1] - bedtemptable[i-1][1]) /
- (bedtemptable[i][0] - bedtemptable[i-1][0]);
-
- break;
- }
}
-
- // Overflow: Set to last value in the table
- if (i == NUMTEMPS) celsius = bedtemptable[i-1][1];
-
- return celsius;
-
- #elif defined BED_USES_AD595
- return raw * ((5.0 * 100.0) / 1024.0);
+ #elif defined (HEATER_USES_AD595) || defined (BED_USES_AD595)
+ if(source==2)
+ return raw * 500 / 1024;
+ #elif defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675)
+ if(source==3)
+ return raw / 4;
#endif
+ return -1;
}
+
inline void kill()
{
#if TEMP_0_PIN > -1