summaryrefslogtreecommitdiff
path: root/Sprinter
diff options
context:
space:
mode:
authormidopple <mdoppler@gmx.at>2012-07-18 20:06:12 +0200
committermidopple <mdoppler@gmx.at>2012-07-18 20:06:12 +0200
commiteb9de32b3038a60445213bd18fce4bf33743bdf6 (patch)
tree286a9b2fa299b33fed5603bdac4ffedc3e5f65fd /Sprinter
parent9fe56bac47bb01f5412e12ed31a3d74b31b29040 (diff)
Version 1.3.21T
- M301 set PID Parameter, After PID values change use M500 to store to EEPROM - If no PID is used, deaktivate Variables for PID settings
Diffstat (limited to 'Sprinter')
-rw-r--r--Sprinter/Sprinter.pde30
-rw-r--r--Sprinter/heater.cpp18
-rw-r--r--Sprinter/heater.h6
-rw-r--r--Sprinter/store_eeprom.cpp54
-rw-r--r--Sprinter/store_eeprom.h1
5 files changed, 82 insertions, 27 deletions
diff --git a/Sprinter/Sprinter.pde b/Sprinter/Sprinter.pde
index 3620030..b3373a0 100644
--- a/Sprinter/Sprinter.pde
+++ b/Sprinter/Sprinter.pde
@@ -127,7 +127,16 @@
- Extra Parameter for Max Extruder Jerk
- New Parameter (max_e_jerk) in EEPROM --> Default settings after update !
+ Version 1.3.20T
+- fix a few typos and correct english usage
+- reimplement homing routine as an inline function
+- refactor eeprom routines to make it possible to modify the value of a single parameter
+- calculate eeprom parameter addresses based on previous param address plus sizeof(type)
+- add 0 C point in Thermistortable 7
+ Version 1.3.21T
+- M301 set PID Parameter, and Store to EEPROM
+- If no PID is used, deaktivate Variables for PID settings
*/
@@ -219,6 +228,7 @@ void __cxa_pure_virtual(){};
// M220 - set speed factor override percentage S=factor in percent
// M221 - set extruder multiply factor S100 --> original Extrude Speed
+// M301 - Set PID parameters P I and D
// M303 - PID relay autotune S<temperature> sets the target temperature. (default target temperature = 150C)
// M400 - Finish all moves
@@ -234,7 +244,7 @@ void __cxa_pure_virtual(){};
// M603 - Show Free Ram
-#define _VERSION_TEXT "1.3.19T / 11.06.2012"
+#define _VERSION_TEXT "1.3.21T / 17.07.2012"
//Stepper Movement Variables
char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
@@ -250,7 +260,9 @@ float max_xy_jerk = _MAX_XY_JERK;
float max_z_jerk = _MAX_Z_JERK;
float max_e_jerk = _MAX_E_JERK;
unsigned long min_seg_time = _MIN_SEG_TIME;
-unsigned int Kp = PID_PGAIN, Ki = PID_IGAIN, Kd = PID_DGAIN;
+#ifdef PIDTEMP
+ unsigned int PID_Kp = PID_PGAIN, PID_Ki = PID_IGAIN, PID_Kd = PID_DGAIN;
+#endif
long max_acceleration_units_per_sq_second[4] = _MAX_ACCELERATION_UNITS_PER_SQ_SECOND; // X, Y, Z and E max acceleration in mm/s^2 for printing moves or retracts
@@ -851,6 +863,10 @@ void setup()
//second value --> Print settings to UART
EEPROM_RetrieveSettings(false,false);
#endif
+
+ #ifdef PIDTEMP
+ updatePID();
+ #endif
//Free Ram
showString(PSTR("Free Ram: "));
@@ -1817,6 +1833,16 @@ FORCE_INLINE void process_commands()
}
}
break;
+#ifdef PIDTEMP
+ case 301: // M301
+ {
+ if(code_seen('P')) PID_Kp = code_value();
+ if(code_seen('I')) PID_Ki = code_value();
+ if(code_seen('D')) PID_Kd = code_value();
+ updatePID();
+ }
+ break;
+#endif //PIDTEMP
#ifdef PID_AUTOTUNE
case 303: // M303 PID autotune
{
diff --git a/Sprinter/heater.cpp b/Sprinter/heater.cpp
index 7682516..8283373 100644
--- a/Sprinter/heater.cpp
+++ b/Sprinter/heater.cpp
@@ -66,8 +66,8 @@ unsigned long previous_millis_heater, previous_millis_bed_heater, previous_milli
//int output;
int error;
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;
+ int temp_iState_min = 256L * -PID_INTEGRAL_DRIVE_MAX / PID_IGAIN;
+ int temp_iState_max = 256L * PID_INTEGRAL_DRIVE_MAX / PID_IGAIN;
#endif
@@ -496,6 +496,14 @@ void PID_autotune(int PIDAT_test_temp)
}
#endif
//---------------- END AUTOTUNE PID ------------------------------
+
+ void updatePID()
+ {
+ #ifdef PIDTEMP
+ temp_iState_min = (256L * -PID_INTEGRAL_DRIVE_MAX) / PID_Ki;
+ temp_iState_max = (256L * PID_INTEGRAL_DRIVE_MAX) / PID_Ki;
+ #endif
+ }
void manage_heater()
{
@@ -637,7 +645,7 @@ void PID_autotune(int PIDAT_test_temp)
int delta_temp = current_temp - prev_temp;
prev_temp = current_temp;
- pTerm = ((long)PID_PGAIN * error) / 256;
+ pTerm = ((long)PID_Kp * error) / 256;
const int H0 = min(HEATER_DUTY_FOR_SETPOINT(target_temp),HEATER_CURRENT);
heater_duty = H0 + pTerm;
@@ -645,7 +653,7 @@ void PID_autotune(int PIDAT_test_temp)
{
temp_iState += error;
temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
- iTerm = ((long)PID_IGAIN * temp_iState) / 256;
+ iTerm = ((long)PID_Ki * temp_iState) / 256;
heater_duty += iTerm;
}
@@ -656,7 +664,7 @@ void PID_autotune(int PIDAT_test_temp)
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);
+ dTerm = ((long)PID_Kd * delta_temp) / (256*log3);
heater_duty += dTerm;
heater_duty = constrain(heater_duty, 0, HEATER_CURRENT);
diff --git a/Sprinter/heater.h b/Sprinter/heater.h
index 87b6b4d..33252a1 100644
--- a/Sprinter/heater.h
+++ b/Sprinter/heater.h
@@ -88,6 +88,8 @@ extern unsigned char manage_monitor;
extern int dTerm;
extern int error;
extern int heater_duty;
+
+ extern unsigned int PID_Kp, PID_Ki, PID_Kd;
#endif
#if defined(FAN_SOFT_PWM) && (FAN_PIN > -1)
@@ -123,4 +125,8 @@ extern unsigned char manage_monitor;
void PID_autotune(int PIDAT_test_temp);
#endif
+#ifdef PIDTEMP
+ void updatePID();
+#endif
+
void manage_heater();
diff --git a/Sprinter/store_eeprom.cpp b/Sprinter/store_eeprom.cpp
index 5dc884a..694e2c5 100644
--- a/Sprinter/store_eeprom.cpp
+++ b/Sprinter/store_eeprom.cpp
@@ -23,6 +23,9 @@
#include "store_eeprom.h"
#include "Configuration.h"
+#ifdef PIDTEMP
+ extern unsigned int PID_Kp, PID_Ki, PID_Kd;
+#endif
#ifdef USE_EEPROM_SETTINGS
@@ -65,10 +68,17 @@ void EEPROM_StoreSettings()
EEPROM_write_setting(max_z_jerk_address, max_z_jerk);
EEPROM_write_setting(max_e_jerk_address, max_e_jerk);
- //PID Settings, not used yet --> placeholder
- EEPROM_write_setting(Kp_address, Kp); //Kp
- EEPROM_write_setting(Ki_address, Ki); //Ki
- EEPROM_write_setting(Kd_address, Kd); //Kd
+ //PID Settings
+ #ifdef PIDTEMP
+ EEPROM_write_setting(Kp_address, PID_Kp); //Kp
+ EEPROM_write_setting(Ki_address, PID_Ki); //Ki
+ EEPROM_write_setting(Kd_address, PID_Kd); //Kd
+ #else
+ EEPROM_write_setting(Kp_address, 2048); //Kp
+ EEPROM_write_setting(Ki_address, 32); //Ki
+ EEPROM_write_setting(Kd_address, 2048); //Kd
+ #endif
+
char ver2[4]=EEPROM_VERSION;
EEPROM_write_setting(EEPROM_OFFSET, ver2); // validate data
@@ -123,7 +133,7 @@ void EEPROM_printSettings()
showString(PSTR(" T" ));
Serial.print(mintravelfeedrate );
// showString(PSTR(" B"));
-// Serial.print(minsegmenttime );
+// Serial.print(min_seg_time );
showString(PSTR(" X"));
Serial.print(max_xy_jerk );
showString(PSTR(" Z"));
@@ -133,15 +143,15 @@ void EEPROM_printSettings()
#ifdef PIDTEMP
- /*
- showString(PSTR("PID settings:");
- showString(PSTR(" M301 P"));
- Serial.print(Kp);
+
+ showString(PSTR("PID settings:\r\n"));
+ showString(PSTR(" M301 P"));
+ Serial.print(PID_Kp);
showString(PSTR(" I"));
- Serial.print(Ki);
- SshowString(PSTR(" D"));
- Serial.print(Kd);
- */
+ Serial.print(PID_Ki);
+ showString(PSTR(" D"));
+ Serial.println(PID_Kd);
+
#endif
#endif
@@ -169,9 +179,12 @@ void EEPROM_RetrieveSettings(bool def, bool printout)
EEPROM_read_setting(max_xy_jerk_address, max_xy_jerk);
EEPROM_read_setting(max_z_jerk_address, max_z_jerk);
EEPROM_read_setting(max_e_jerk_address, max_e_jerk);
- EEPROM_read_setting(Kp_address, Kp);
- EEPROM_read_setting(Ki_address, Ki);
- EEPROM_read_setting(Kd_address, Kd);
+
+ #ifdef PIDTEMP
+ EEPROM_read_setting(Kp_address, PID_Kp);
+ EEPROM_read_setting(Ki_address, PID_Ki);
+ EEPROM_read_setting(Kd_address, PID_Kd);
+ #endif
showString(PSTR("Stored settings retreived\r\n"));
}
@@ -195,9 +208,12 @@ void EEPROM_RetrieveSettings(bool def, bool printout)
max_z_jerk=_MAX_Z_JERK;
max_e_jerk=_MAX_E_JERK;
min_seg_time=_MIN_SEG_TIME;
- Kp = PID_PGAIN;
- Ki = PID_IGAIN;
- Kd = PID_DGAIN;
+
+ #ifdef PIDTEMP
+ PID_Kp = PID_PGAIN;
+ PID_Ki = PID_IGAIN;
+ PID_Kd = PID_DGAIN;
+ #endif
showString(PSTR("Using Default settings\r\n"));
}
diff --git a/Sprinter/store_eeprom.h b/Sprinter/store_eeprom.h
index f275f3a..a9ddf7d 100644
--- a/Sprinter/store_eeprom.h
+++ b/Sprinter/store_eeprom.h
@@ -41,7 +41,6 @@ extern float max_xy_jerk;
extern float max_z_jerk;
extern float max_e_jerk;
extern unsigned long min_seg_time;
-extern unsigned int Kp, Ki, Kd;
#define axis_steps_per_unit_address (EEPROM_OFFSET + 4*sizeof(char))
#define max_feedrate_address (axis_steps_per_unit_address + 4*sizeof(float))