summaryrefslogtreecommitdiff
path: root/Sprinter
diff options
context:
space:
mode:
Diffstat (limited to 'Sprinter')
-rw-r--r--Sprinter/Configuration.h35
-rw-r--r--Sprinter/Sprinter.h52
-rw-r--r--Sprinter/Sprinter.pde296
-rw-r--r--Sprinter/pins.h84
4 files changed, 357 insertions, 110 deletions
diff --git a/Sprinter/Configuration.h b/Sprinter/Configuration.h
index f36183e..71e0b08 100644
--- a/Sprinter/Configuration.h
+++ b/Sprinter/Configuration.h
@@ -12,6 +12,7 @@
// Teensylu (at90usb) = 8
// Gen 3 Plus = 21
// gen 3 Monolithic Electronics = 22
+// Gen3 PLUS for TechZone Gen3 Remix Motherboard = 23
#define MOTHERBOARD 3
//// Thermistor settings:
@@ -37,9 +38,11 @@ float axis_steps_per_unit[] = {80, 80, 3200/1.25,700};
//// Endstop Settings
#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
-const bool ENDSTOPS_INVERTING = false; //set to true to invert the logic of the endstops
//If your axes are only moving in one direction, make sure the endstops are connected properly.
-//If your axes move in one direction ONLY when the endstops are triggered, set ENDSTOPS_INVERTING to true here
+//If your axes move in one direction ONLY when the endstops are triggered, set [XYZ]_ENDSTOP_INVERT to true here:
+const bool X_ENDSTOP_INVERT = false;
+const bool Y_ENDSTOP_INVERT = false;
+const bool Z_ENDSTOP_INVERT = false;
// This determines the communication speed of the printer
#define BAUDRATE 115200
@@ -117,15 +120,21 @@ char uuid[] = "00000000-0000-0000-0000-000000000000";
//// PID settings:
// Uncomment the following line to enable PID support. This is untested and could be disastrous. Be careful.
-//#define PIDTEMP
+//#define PIDTEMP 1
#ifdef PIDTEMP
-#define PID_MAX 255 // limits current to nozzle
-#define PID_INTEGRAL_DRIVE_MAX 220
-#define PID_PGAIN 180 //100 is 1.0
-#define PID_IGAIN 2 //100 is 1.0
-#define PID_DGAIN 100 //100 is 1.0
+#define PID_INTEGRAL_DRIVE_MAX 80 // too big, and heater will lag after changing temperature, too small and it might not compensate enough for long-term errors
+#define PID_PGAIN 1280 //256 is 1.0 // value of 5.0 means that error of 20C is changing it almost halfway of the PWM range
+#define PID_IGAIN 64 //256 is 1.0 // value of 0.25 means that each degree error over 1 sec (2 measurements) changes duty cycle by 0.5 units (verify?)
+#define PID_DGAIN 2048 //256 is 1.0 // value of 8.0 means that each degree change over one measurement (half second) adjusts PWM by 8 units to compensate
+// magic formula 1, to get approximate "zero error" PWM duty. It is most likely linear formula
+#define HEATER_DUTY_FOR_SETPOINT(setpoint) (22+1*setpoint)
+// magic formula 2, to make led brightness approximately linear
+#define LED_PWM_FOR_BRIGHTNESS(brightness) ((64*brightness-1384)/(300-brightness))
#endif
+// Change this value (range 1-255) to limit the current to the nozzle
+#define HEATER_CURRENT 255
+
// How often should the heater check for new temp readings, in milliseconds
#define HEATER_CHECK_INTERVAL 500
#define BED_CHECK_INTERVAL 5000
@@ -149,6 +158,10 @@ char uuid[] = "00000000-0000-0000-0000-000000000000";
// If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109
//#define WATCHPERIOD 5000 //5 seconds
+// Actual temperature must be close to target for this long before M109 returns success
+//#define TEMP_RESIDENCY_TIME 20 // (seconds)
+//#define TEMP_HYSTERESIS 5 // (C°) range of +/- temperatures considered "close" to the target one
+
//// The minimal temperature defines the temperature below which the heater will not be enabled
#define MINTEMP 5
@@ -167,6 +180,12 @@ char uuid[] = "00000000-0000-0000-0000-000000000000";
#define BED_USES_THERMISTOR
//#define BED_USES_AD595
+//This is for controlling a fan to cool down the stepper drivers
+//it will turn on when any driver is enabled
+//and turn off after the set amount of seconds from last driver being disabled again
+//#define CONTROLLERFAN_PIN 23 //Pin used for the fan to cool controller, comment out to disable this function
+#define CONTROLLERFAN_SEC 60 //How many seconds, after all motors were disabled, the fan should run
+
// Uncomment the following line to enable debugging. You can better control debugging below the following line
//#define DEBUG
#ifdef DEBUG
diff --git a/Sprinter/Sprinter.h b/Sprinter/Sprinter.h
index d612b5d..2ac9163 100644
--- a/Sprinter/Sprinter.h
+++ b/Sprinter/Sprinter.h
@@ -8,33 +8,47 @@ void get_command();
void process_commands();
void manage_inactivity(byte debug);
+void setup_acceleration();
void manage_heater();
-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
+
+#if defined HEATER_USES_THERMISTOR
+#define temp2analogh( c ) temp2analog_thermistor(c,temptable,NUMTEMPS)
+#define analog2temp( c ) analog2temp_thermistor(c,temptable,NUMTEMPS)
+#elif defined HEATER_USES_AD595
+#define temp2analogh( c ) temp2analog_ad595(c)
+#define analog2temp( c ) analog2temp_ad595(c)
+#elif defined HEATER_USES_MAX6675
+#define temp2analogh( c ) temp2analog_max6675(c)
+#define analog2temp( c ) analog2temp_max6675(c)
#endif
-#ifdef HEATER_USES_MAX6675
- #define HEATERSOURCE 3
+
+#if defined BED_USES_THERMISTOR
+#define temp2analogBed( c ) temp2analog_thermistor((c),bedtemptable,BNUMTEMPS)
+#define analog2tempBed( c ) analog2temp_thermistor((c),bedtemptable,BNUMTEMPS)
+#elif defined BED_USES_AD595
+#define temp2analogBed( c ) temp2analog_ad595(c)
+#define analog2tempBed( c ) analog2temp_ad595(c)
+#elif defined BED_USES_MAX6675
+#define temp2analogBed( c ) temp2analog_max6675(c)
+#define analog2tempBed( c ) analog2temp_max6675(c)
#endif
-#ifdef BED_USES_THERMISTOR
- #define BEDSOURCE 1
+
+#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
+int temp2analog_thermistor(int celsius, const short table[][2], int numtemps);
+int analog2temp_thermistor(int raw,const short table[][2], int numtemps);
#endif
-#ifdef BED_USES_AD595
- #define BEDSOURCE 2
+
+#if defined (HEATER_USES_AD595) || defined (BED_USES_AD595)
+int temp2analog_ad595(int celsius);
+int analog2temp_ad595(int raw);
#endif
-#ifdef BED_USES_MAX6675
- #define BEDSOURCE 3
+
+#if defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675)
+int temp2analog_max6675(int celsius);
+int analog2temp_max6675(int raw);
#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() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
#define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON)
diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde
index 2a36875..7a6bf5e 100644
--- a/Sprinter/Sprinter.pde
+++ b/Sprinter/Sprinter.pde
@@ -1,4 +1,4 @@
-// Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
+ // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
// Licence: GPL
#include "fastio.h"
@@ -43,6 +43,7 @@
// M27 - Report SD print status
// M28 - Start SD write (M28 filename.g)
// M29 - Stop SD write
+// M42 - Set output on free pins, on a non pwm pin (over pin 13 on an arduino mega) use S255 to turn it on and S0 to turn it off. Use P to decide the pin (M42 P23 S255) would turn pin 23 on
// M81 - Turn off Power Supply
// M82 - Set E codes absolute (default)
// M83 - Set E codes relative while in Absolute Coordinates (G90) mode
@@ -111,20 +112,25 @@ char *strchr_pointer; // just a pointer to find chars in the cmd string like X,
// degree increments (i.e. 100=25 deg).
int target_raw = 0;
+int target_temp = 0;
int current_raw = 0;
int target_bed_raw = 0;
int current_bed_raw = 0;
int tt = 0, bt = 0;
#ifdef PIDTEMP
int temp_iState = 0;
- int temp_dState = 0;
+ int prev_temp = 0;
int pTerm;
int iTerm;
int dTerm;
//int output;
int error;
- int temp_iState_min = 100 * -PID_INTEGRAL_DRIVE_MAX / PID_IGAIN;
- int temp_iState_max = 100 * PID_INTEGRAL_DRIVE_MAX / PID_IGAIN;
+ int heater_duty = 0;
+ const int temp_iState_min = 256L * -PID_INTEGRAL_DRIVE_MAX / PID_IGAIN;
+ const int temp_iState_max = 256L * PID_INTEGRAL_DRIVE_MAX / PID_IGAIN;
+#endif
+#ifndef HEATER_CURRENT
+ #define HEATER_CURRENT 255
#endif
#ifdef SMOOTHING
uint32_t nma = 0;
@@ -239,6 +245,10 @@ void setup()
if(!E_ENABLE_ON) WRITE(E_ENABLE_PIN,HIGH);
#endif
+ #ifdef CONTROLLERFAN_PIN
+ SET_OUTPUT(CONTROLLERFAN_PIN); //Set pin used for driver cooling fan
+ #endif
+
//endstops and pullups
#ifdef ENDSTOPPULLUPS
#if X_MIN_PIN > -1
@@ -288,9 +298,11 @@ void setup()
#if (HEATER_0_PIN > -1)
SET_OUTPUT(HEATER_0_PIN);
+ WRITE(HEATER_0_PIN,LOW);
#endif
#if (HEATER_1_PIN > -1)
SET_OUTPUT(HEATER_1_PIN);
+ WRITE(HEATER_1_PIN,LOW);
#endif
//Initialize Fan Pin
@@ -298,6 +310,18 @@ void setup()
SET_OUTPUT(FAN_PIN);
#endif
+ //Initialize Alarm Pin
+ #if (ALARM_PIN > -1)
+ SET_OUTPUT(ALARM_PIN);
+ WRITE(ALARM_PIN,LOW);
+ #endif
+
+ //Initialize LED Pin
+ #if (LED_PIN > -1)
+ SET_OUTPUT(LED_PIN);
+ WRITE(LED_PIN,LOW);
+ #endif
+
//Initialize Step Pins
#if (X_STEP_PIN > -1)
SET_OUTPUT(X_STEP_PIN);
@@ -312,11 +336,7 @@ void setup()
SET_OUTPUT(E_STEP_PIN);
#endif
#ifdef RAMP_ACCELERATION
- for(int i=0; i < NUM_AXIS; i++){
- 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];
- }
+ setup_acceleration();
#endif
#ifdef HEATER_USES_MAX6675
@@ -726,8 +746,33 @@ inline void process_commands()
//savetosd = false;
break;
#endif
+ case 42: //M42 -Change pin status via gcode
+ if (code_seen('S'))
+ {
+ int pin_status = code_value();
+ if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
+ {
+ int pin_number = code_value();
+ for(int i = 0; i < sizeof(sensitive_pins); i++)
+ {
+ if (sensitive_pins[i] == pin_number)
+ {
+ pin_number = -1;
+ break;
+ }
+ }
+
+ if (pin_number > -1)
+ {
+ pinMode(pin_number, OUTPUT);
+ digitalWrite(pin_number, pin_status);
+ analogWrite(pin_number, pin_status);
+ }
+ }
+ }
+ break;
case 104: // M104
- if (code_seen('S')) target_raw = temp2analogh(code_value());
+ if (code_seen('S')) target_raw = temp2analogh(target_temp = code_value());
#ifdef WATCHPERIOD
if(target_raw > current_raw){
watchmillis = max(1,millis());
@@ -752,6 +797,12 @@ inline void process_commands()
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX6675) || defined HEATER_USES_AD595
Serial.print("ok T:");
Serial.print(tt);
+ #ifdef PIDTEMP
+ Serial.print(" @:");
+ Serial.print(heater_duty);
+ Serial.print(",");
+ Serial.print(iTerm);
+ #endif
#if TEMP_1_PIN > -1 || defined BED_USES_AD595
Serial.print(" B:");
Serial.println(bt);
@@ -763,8 +814,8 @@ inline void process_commands()
#endif
return;
//break;
- case 109: // M109 - Wait for extruder heater to reach target.
- if (code_seen('S')) target_raw = temp2analogh(code_value());
+ case 109: { // M109 - Wait for extruder heater to reach target.
+ if (code_seen('S')) target_raw = temp2analogh(target_temp = code_value());
#ifdef WATCHPERIOD
if(target_raw>current_raw){
watchmillis = max(1,millis());
@@ -774,16 +825,39 @@ inline void process_commands()
}
#endif
codenum = millis();
- while(current_raw < target_raw) {
- if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
+
+ /* See if we are heating up or cooling down */
+ bool target_direction = (current_raw < target_raw); // 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 ? (current_raw < target_raw) : (current_raw > target_raw))
+ || (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
+ #else
+ while ( target_direction ? (current_raw < target_raw) : (current_raw > target_raw) ) {
+ #endif
+ if( (millis() - codenum) > 1000 ) //Print Temp Reading every 1 second while heating up/cooling down
{
Serial.print("T:");
- Serial.println( analog2temp(current_raw) );
- codenum = millis();
+ Serial.println( analog2temp(current_raw) );
+ codenum = millis();
}
manage_heater();
- }
- break;
+ #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 && current_raw >= target_raw)
+ || (residencyStart == -1 && !target_direction && current_raw <= target_raw)
+ || (residencyStart > -1 && labs(analog2temp(current_raw) - analog2temp(target_raw)) > TEMP_HYSTERESIS) ) {
+ residencyStart = millis();
+ }
+ #endif
+ }
+ }
+ break;
case 190: // M190 - Wait bed for heater to reach target.
#if TEMP_1_PIN > -1
if (code_seen('S')) target_bed_raw = temp2analogh(code_value());
@@ -845,15 +919,10 @@ inline void process_commands()
if(code_seen(axis_codes[i])) axis_steps_per_unit[i] = code_value();
}
- //Update start speed intervals and axis order. TODO: refactor axis_max_interval[] calculation into a function, as it
- // should also be used in setup() as well
#ifdef RAMP_ACCELERATION
- long temp_max_intervals[NUM_AXIS];
- for(int i=0; i < NUM_AXIS; i++) {
- axis_max_interval[i] = 100000000.0 / (max_start_speed_units_per_second[i] * axis_steps_per_unit[i]);//TODO: do this for
- // all steps_per_unit related variables
- }
+ setup_acceleration();
#endif
+
break;
case 115: // M115
Serial.print("FIRMWARE_NAME:Sprinter FIRMWARE_URL:http%%3A/github.com/kliment/Sprinter/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 UUID:");
@@ -872,27 +941,27 @@ inline void process_commands()
case 119: // M119
#if (X_MIN_PIN > -1)
Serial.print("x_min:");
- Serial.print((READ(X_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
+ Serial.print((READ(X_MIN_PIN)^X_ENDSTOP_INVERT)?"H ":"L ");
#endif
#if (X_MAX_PIN > -1)
Serial.print("x_max:");
- Serial.print((READ(X_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
+ Serial.print((READ(X_MAX_PIN)^X_ENDSTOP_INVERT)?"H ":"L ");
#endif
#if (Y_MIN_PIN > -1)
Serial.print("y_min:");
- Serial.print((READ(Y_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
+ Serial.print((READ(Y_MIN_PIN)^Y_ENDSTOP_INVERT)?"H ":"L ");
#endif
#if (Y_MAX_PIN > -1)
Serial.print("y_max:");
- Serial.print((READ(Y_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
+ Serial.print((READ(Y_MAX_PIN)^Y_ENDSTOP_INVERT)?"H ":"L ");
#endif
#if (Z_MIN_PIN > -1)
Serial.print("z_min:");
- Serial.print((READ(Z_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
+ Serial.print((READ(Z_MIN_PIN)^Z_ENDSTOP_INVERT)?"H ":"L ");
#endif
#if (Z_MAX_PIN > -1)
Serial.print("z_max:");
- Serial.print((READ(Z_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
+ Serial.print((READ(Z_MAX_PIN)^Z_ENDSTOP_INVERT)?"H ":"L ");
#endif
Serial.println("");
break;
@@ -1047,22 +1116,22 @@ inline void linear_move(unsigned long axis_steps_remaining[]) // make linear mov
else WRITE(E_DIR_PIN,INVERT_E_DIR);
movereset:
#if (X_MIN_PIN > -1)
- if(!move_direction[0]) if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[0]=0;
+ if(!move_direction[0]) if(READ(X_MIN_PIN) != X_ENDSTOP_INVERT) axis_steps_remaining[0]=0;
#endif
#if (Y_MIN_PIN > -1)
- if(!move_direction[1]) if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[1]=0;
+ if(!move_direction[1]) if(READ(Y_MIN_PIN) != Y_ENDSTOP_INVERT) axis_steps_remaining[1]=0;
#endif
#if (Z_MIN_PIN > -1)
- if(!move_direction[2]) if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[2]=0;
+ if(!move_direction[2]) if(READ(Z_MIN_PIN) != Z_ENDSTOP_INVERT) axis_steps_remaining[2]=0;
#endif
#if (X_MAX_PIN > -1)
- if(move_direction[0]) if(READ(X_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[0]=0;
+ if(move_direction[0]) if(READ(X_MAX_PIN) != X_ENDSTOP_INVERT) axis_steps_remaining[0]=0;
#endif
#if (Y_MAX_PIN > -1)
- if(move_direction[1]) if(READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[1]=0;
+ if(move_direction[1]) if(READ(Y_MAX_PIN) != Y_ENDSTOP_INVERT) axis_steps_remaining[1]=0;
#endif
# if(Z_MAX_PIN > -1)
- if(move_direction[2]) if(READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) axis_steps_remaining[2]=0;
+ if(move_direction[2]) if(READ(Z_MAX_PIN) != Z_ENDSTOP_INVERT) axis_steps_remaining[2]=0;
#endif
@@ -1238,22 +1307,22 @@ inline void linear_move(unsigned long axis_steps_remaining[]) // make linear mov
//If there are x or y steps remaining, perform Bresenham algorithm
if(axis_steps_remaining[primary_axis]) {
#if (X_MIN_PIN > -1)
- if(!move_direction[0]) if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) if(primary_axis==0) break; else if(axis_steps_remaining[0]) axis_steps_remaining[0]=0;
+ if(!move_direction[0]) if(READ(X_MIN_PIN) != X_ENDSTOP_INVERT) if(primary_axis==0) break; else if(axis_steps_remaining[0]) axis_steps_remaining[0]=0;
#endif
#if (Y_MIN_PIN > -1)
- if(!move_direction[1]) if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) if(primary_axis==1) break; else if(axis_steps_remaining[1]) axis_steps_remaining[1]=0;
+ if(!move_direction[1]) if(READ(Y_MIN_PIN) != Y_ENDSTOP_INVERT) if(primary_axis==1) break; else if(axis_steps_remaining[1]) axis_steps_remaining[1]=0;
#endif
#if (X_MAX_PIN > -1)
- if(move_direction[0]) if(READ(X_MAX_PIN) != ENDSTOPS_INVERTING) if(primary_axis==0) break; else if(axis_steps_remaining[0]) axis_steps_remaining[0]=0;
+ if(move_direction[0]) if(READ(X_MAX_PIN) != X_ENDSTOP_INVERT) if(primary_axis==0) break; else if(axis_steps_remaining[0]) axis_steps_remaining[0]=0;
#endif
#if (Y_MAX_PIN > -1)
- if(move_direction[1]) if(READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) if(primary_axis==1) break; else if(axis_steps_remaining[1]) axis_steps_remaining[1]=0;
+ if(move_direction[1]) if(READ(Y_MAX_PIN) != Y_ENDSTOP_INVERT) if(primary_axis==1) break; else if(axis_steps_remaining[1]) axis_steps_remaining[1]=0;
#endif
#if (Z_MIN_PIN > -1)
- if(!move_direction[2]) if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) if(primary_axis==2) break; else if(axis_steps_remaining[2]) axis_steps_remaining[2]=0;
+ if(!move_direction[2]) if(READ(Z_MIN_PIN) != Z_ENDSTOP_INVERT) if(primary_axis==2) break; else if(axis_steps_remaining[2]) axis_steps_remaining[2]=0;
#endif
#if (Z_MAX_PIN > -1)
- if(move_direction[2]) if(READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) if(primary_axis==2) break; else if(axis_steps_remaining[2]) axis_steps_remaining[2]=0;
+ if(move_direction[2]) if(READ(Z_MAX_PIN) != Z_ENDSTOP_INVERT) if(primary_axis==2) break; else if(axis_steps_remaining[2]) axis_steps_remaining[2]=0;
#endif
timediff = micros() * 100 - axis_previous_micros[primary_axis];
if(timediff<0){//check for overflow
@@ -1376,6 +1445,32 @@ int read_max6675()
}
#endif
+#ifdef CONTROLLERFAN_PIN
+unsigned long lastMotor = 0; //Save the time for when a motor was turned on last
+unsigned long lastMotorCheck = 0;
+
+void controllerFan()
+{
+ if ((millis() - lastMotorCheck) >= 2500) //Not a time critical function, so we only check every 2500ms
+ {
+ lastMotorCheck = millis();
+
+ if(!READ(X_ENABLE_PIN) || !READ(Y_ENABLE_PIN) || !READ(Z_ENABLE_PIN) || !READ(E_ENABLE_PIN)) //If any of the drivers are enabled...
+ {
+ lastMotor = millis(); //... set time to NOW so the fan will turn on
+ }
+
+ if ((millis() - lastMotor) >= (CONTROLLERFAN_SEC*1000UL) || lastMotor == 0) //If the last time any driver was enabled, is longer since than CONTROLLERSEC...
+ {
+ WRITE(CONTROLLERFAN_PIN, LOW); //... turn the fan off
+ }
+ else
+ {
+ WRITE(CONTROLLERFAN_PIN, HIGH); //... turn the fan on
+ }
+ }
+}
+#endif
void manage_heater()
{
@@ -1404,8 +1499,9 @@ void manage_heater()
#ifdef WATCHPERIOD
if(watchmillis && millis() - watchmillis > WATCHPERIOD){
if(watch_raw + 1 >= current_raw){
- target_raw = 0;
+ target_temp = target_raw = 0;
WRITE(HEATER_0_PIN,LOW);
+ analogWrite(HEATER_0_PIN, 0);
#if LED_PIN>-1
WRITE(LED_PIN,LOW);
#endif
@@ -1416,27 +1512,48 @@ void manage_heater()
#endif
#ifdef MINTEMP
if(current_raw <= minttemp)
- target_raw = 0;
+ target_temp = target_raw = 0;
#endif
#ifdef MAXTEMP
if(current_raw >= maxttemp) {
- target_raw = 0;
+ target_temp = target_raw = 0;
+ #if (ALARM_PIN > -1)
+ WRITE(ALARM_PIN,HIGH);
+ #endif
}
#endif
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_MAX6675) || defined (HEATER_USES_AD595)
#ifdef PIDTEMP
- error = target_raw - current_raw;
- pTerm = (PID_PGAIN * error) / 100;
- temp_iState += error;
- temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
- iTerm = (PID_IGAIN * temp_iState) / 100;
- dTerm = (PID_DGAIN * (current_raw - temp_dState)) / 100;
- temp_dState = current_raw;
- analogWrite(HEATER_0_PIN, constrain(pTerm + iTerm - dTerm, 0, PID_MAX));
+ int current_temp = analog2temp(current_raw);
+ error = target_temp - current_temp;
+ int delta_temp = current_temp - prev_temp;
+ prev_temp = current_temp;
+ pTerm = ((long)PID_PGAIN * error) / 256;
+ const int H0 = min(HEATER_DUTY_FOR_SETPOINT(target_temp),HEATER_CURRENT);
+ heater_duty = H0 + pTerm;
+ if(error < 20){
+ temp_iState += error;
+ temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
+ iTerm = ((long)PID_IGAIN * temp_iState) / 256;
+ heater_duty += iTerm;
+ }
+ int prev_error = abs(target_temp - prev_temp);
+ int log3 = 1; // discrete logarithm base 3, plus 1
+ if(prev_error > 81){ prev_error /= 81; log3 += 4; }
+ if(prev_error > 9){ prev_error /= 9; log3 += 2; }
+ if(prev_error > 3){ prev_error /= 3; log3 ++; }
+ dTerm = ((long)PID_DGAIN * delta_temp) / (256*log3);
+ heater_duty += dTerm;
+ heater_duty = constrain(heater_duty, 0, HEATER_CURRENT);
+ analogWrite(HEATER_0_PIN, heater_duty);
+ #if LED_PIN>-1
+ analogWrite(LED_PIN, constrain(LED_PWM_FOR_BRIGHTNESS(heater_duty),0,255));
+ #endif
#else
if(current_raw >= target_raw)
{
WRITE(HEATER_0_PIN,LOW);
+ analogWrite(HEATER_0_PIN, 0);
#if LED_PIN>-1
WRITE(LED_PIN,LOW);
#endif
@@ -1444,6 +1561,7 @@ void manage_heater()
else
{
WRITE(HEATER_0_PIN,HIGH);
+ analogWrite(HEATER_0_PIN, HEATER_CURRENT);
#if LED_PIN > -1
WRITE(LED_PIN,HIGH);
#endif
@@ -1478,7 +1596,11 @@ void manage_heater()
#endif
+ #ifdef MINTEMP
+ if(current_bed_raw >= target_bed_raw || current_bed_raw < minttemp)
+ #else
if(current_bed_raw >= target_bed_raw)
+ #endif
{
WRITE(HEATER_1_PIN,LOW);
}
@@ -1487,12 +1609,14 @@ void manage_heater()
WRITE(HEATER_1_PIN,HIGH);
}
#endif
+
+#ifdef CONTROLLERFAN_PIN
+ controllerFan(); //Check if fan should be turned on to cool stepper drivers down
+#endif
}
-
-int temp2analogu(int celsius, const short table[][2], int numtemps, int source) {
- #if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
- if(source==1){
+#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
+int temp2analog_thermistor(int celsius, const short table[][2], int numtemps) {
int raw = 0;
byte i;
@@ -1513,20 +1637,23 @@ int temp2analogu(int celsius, const short table[][2], int numtemps, int source)
if (i == numtemps) raw = table[i-1][0];
return 1023 - raw;
- }
- #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;
}
+#endif
+
+#if defined (HEATER_USES_AD595) || defined (BED_USES_AD595)
+int temp2analog_ad595(int celsius) {
+ return celsius * 1024 / (500);
+}
+#endif
+
+#if defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675)
+int temp2analog_max6675(int celsius) {
+ return celsius * 4;
+}
+#endif
-int analog2tempu(int raw,const short table[][2], int numtemps, int source) {
- #if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
- if(source==1){
+#if defined (HEATER_USES_THERMISTOR) || defined (BED_USES_THERMISTOR)
+int analog2temp_thermistor(int raw,const short table[][2], int numtemps) {
int celsius = 0;
byte i;
@@ -1549,17 +1676,20 @@ int analog2tempu(int raw,const short table[][2], int numtemps, int source) {
if (i == numtemps) celsius = table[i-1][1];
return celsius;
- }
- #elif defined (HEATER_USES_AD595) || defined (BED_USES_AD595)
- if(source==2)
+}
+#endif
+
+#if defined (HEATER_USES_AD595) || defined (BED_USES_AD595)
+int analog2temp_ad595(int raw) {
return raw * 500 / 1024;
- #elif defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675)
- if(source==3)
- return raw / 4;
- #endif
- return -1;
}
+#endif
+#if defined (HEATER_USES_MAX6675) || defined (BED_USES_MAX6675)
+int analog2temp_max6675(int raw) {
+ return raw / 4;
+}
+#endif
inline void kill()
{
@@ -1585,6 +1715,16 @@ if( (millis()-previous_millis_cmd) > max_inactive_time ) if(max_inactive_time)
if( (millis()-previous_millis_cmd) > stepper_inactive_time ) if(stepper_inactive_time) { disable_x(); disable_y(); disable_z(); disable_e(); }
}
+#ifdef RAMP_ACCELERATION
+void setup_acceleration() {
+ for (int i=0; i < NUM_AXIS; i++) {
+ 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 DEBUG
void log_message(char* message) {
Serial.print("DEBUG"); Serial.println(message);
diff --git a/Sprinter/pins.h b/Sprinter/pins.h
index d9111ce..2160335 100644
--- a/Sprinter/pins.h
+++ b/Sprinter/pins.h
@@ -57,6 +57,7 @@
#define FAN_PIN -1
#define PS_ON_PIN 15
#define KILL_PIN -1
+#define ALARM_PIN -1
#define HEATER_0_PIN 6
#define TEMP_0_PIN 0 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
@@ -130,6 +131,7 @@
#define FAN_PIN -1
#define PS_ON_PIN -1
#define KILL_PIN -1
+#define ALARM_PIN -1
#define HEATER_0_PIN 14
#define TEMP_0_PIN 4 //D27 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
@@ -191,6 +193,7 @@
#define FAN_PIN -1
#define KILL_PIN -1
+#define ALARM_PIN -1
#define HEATER_0_PIN -1
#define TEMP_0_PIN -1 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
@@ -201,7 +204,7 @@
#endif
/****************************************************************************************
-* Gen3 PLUS
+* Gen3 PLUS for RepRap Motherboard V1.2
*
****************************************************************************************/
#if MOTHERBOARD == 21
@@ -243,7 +246,7 @@
#define HEATER_0_PIN 12
//Pin for heated bed heater
-#define HEATER_1_PIN 5
+#define HEATER_1_PIN 16
//pin for debugging.
@@ -265,7 +268,7 @@
#endif
/****************************************************************************************
-* Gen3 Monolithic Electronics
+* Gen3 Monolithic Electronics
*
****************************************************************************************/
#if MOTHERBOARD == 22
@@ -324,6 +327,71 @@
/****************************************************************************************
+* Gen3 PLUS for TechZone Gen3 Remix Motherboard
+*
+****************************************************************************************/
+#if MOTHERBOARD == 23
+#define KNOWN_BOARD 1
+
+#ifndef __AVR_ATmega644P__
+ #error Oops! Make sure you have 'Sanguino' selected from the 'Tools -> Boards' menu.
+#endif
+
+
+//x axis pins
+#define X_STEP_PIN 15
+#define X_DIR_PIN 18
+#define X_ENABLE_PIN 24 //same as E/Y_enable_pin
+#define X_MIN_PIN 20
+#define X_MAX_PIN -1
+
+//y axis pins
+#define Y_STEP_PIN 23
+#define Y_DIR_PIN 22
+#define Y_ENABLE_PIN 24 //same as E/X_enable_pin
+#define Y_MIN_PIN 25
+#define Y_MAX_PIN -1
+
+//z axis pins
+#define Z_STEP_PIN 27
+#define Z_DIR_PIN 28
+#define Z_ENABLE_PIN 29
+#define Z_MIN_PIN 30
+#define Z_MAX_PIN -1
+
+#define E_DIR_PIN 21
+#define E_STEP_PIN 19
+#define E_ENABLE_PIN 24 //same as X/Y_enable_pin
+
+//heaters
+
+//pin for hot end heater
+#define HEATER_0_PIN 16
+
+//Pin for heated bed heater
+#define HEATER_1_PIN 17
+
+
+//pin for debugging.
+#define DEBUG_PIN -1
+
+//SD card pin
+
+#define SDSS 4
+
+#define SDPOWER -1
+#define FAN_PIN -1
+#define TEMP_0_PIN 0
+#define TEMP_1_PIN 5
+#define LED_PIN -1
+
+//pin for controlling the PSU.
+#define PS_ON_PIN 14
+
+#endif
+
+
+/****************************************************************************************
* Arduino Mega pin assignment
*
****************************************************************************************/
@@ -379,12 +447,13 @@
#define FAN_PIN 9
#define PS_ON_PIN 12
#define KILL_PIN -1
+#define ALARM_PIN -1
#define HEATER_0_PIN 10
#define HEATER_1_PIN 8
#define TEMP_0_PIN 13 // ANALOG NUMBERING
#define TEMP_1_PIN 14 // ANALOG NUMBERING
-
+#define TEMP_2_PIN 15 // ANALOG NUMBERING
#else // RAMPS_V_1_1 or RAMPS_V_1_2 as default
@@ -415,7 +484,7 @@
#define LED_PIN 13
#define PS_ON_PIN -1
#define KILL_PIN -1
-
+#define ALARM_PIN -1
#ifdef RAMPS_V_1_0 // RAMPS_V_1_0
@@ -486,6 +555,7 @@
#define FAN_PIN 5
#define PS_ON_PIN -1
#define KILL_PIN -1
+#define ALARM_PIN -1
#define HEATER_0_PIN 6
#define TEMP_0_PIN 0 // MUST USE ANALOG INPUT NUMBERING NOT DIGITAL OUTPUT NUMBERING!!!!!!!!!
@@ -587,6 +657,7 @@
#define PS_ON_PIN -1
#define KILL_PIN -1
+#define ALARM_PIN -1
#define HEATER_0_PIN 13 // (extruder)
@@ -619,6 +690,9 @@
#endif
+//List of pins which to ignore when asked to change by gcode, 0 and 1 are RX and TX, do not mess with those!
+const int sensitive_pins[] = {0, 1, X_STEP_PIN, X_DIR_PIN, X_ENABLE_PIN, X_MIN_PIN, X_MAX_PIN, Y_STEP_PIN, Y_DIR_PIN, Y_ENABLE_PIN, Y_MIN_PIN, Y_MAX_PIN, Z_STEP_PIN, Z_DIR_PIN, Z_ENABLE_PIN, Z_MIN_PIN, Z_MAX_PIN, E_STEP_PIN, E_DIR_PIN, E_ENABLE_PIN, LED_PIN, PS_ON_PIN, HEATER_0_PIN, HEATER_1_PIN, FAN_PIN, TEMP_0_PIN, TEMP_1_PIN};
+
#endif
/****************************************************************************************