Permalink
Browse files

Version 1.3.18T / 02.06.2012

  • Loading branch information...
1 parent a35fb05 commit 3c238bcf4d43cbcbd16cacb58429fce538c79ce8 @midopple committed Jun 2, 2012
Showing with 194 additions and 92 deletions.
  1. +1 −1 Sprinter/Configuration.h
  2. +9 −6 Sprinter/Sprinter.ino
  3. +43 −44 Sprinter/heater.cpp
  4. +1 −1 Sprinter/heater.h
  5. +140 −40 Sprinter/i2c_lcd_display.cpp
View
@@ -174,7 +174,7 @@ const int NUM_AXIS = 4; // The axis order in all axis related arrays is X, Y, Z,
//#define RAPID_OSCILLATION_REDUCTION
#ifdef RAPID_OSCILLATION_REDUCTION
-long min_time_before_dir_change = 30; //milliseconds
+const long min_time_before_dir_change = 30; //milliseconds
#endif
//-----------------------------------------------------------------------
View
@@ -118,7 +118,8 @@
Version 1.3.17T
- M303 - PID relay autotune possible
-- G4 wait until last move is finished
+- G4 Wait until last move is done
+
*/
@@ -228,7 +229,7 @@ void __cxa_pure_virtual(){};
// M603 - Show Free Ram
-#define _VERSION_TEXT "1.3.17T / 30.04.2012"
+#define _VERSION_TEXT "1.3.18T / 02.06.2012"
//Stepper Movement Variables
char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
@@ -402,7 +403,7 @@ unsigned char manage_monitor = 255;
#ifdef SD_FAST_XFER_AKTIV
#ifdef PIDTEMP
- extern int g_heater_pwm_val;
+ extern volatile unsigned char g_heater_pwm_val;
#endif
void fast_xfer()
@@ -414,7 +415,9 @@ unsigned char manage_monitor = 255;
if(HEATER_0_PIN > -1) WRITE(HEATER_0_PIN,LOW);
if(HEATER_1_PIN > -1) WRITE(HEATER_1_PIN,LOW);
- g_heater_pwm_val = 0;
+ #ifdef PIDTEMP
+ g_heater_pwm_val = 0;
+ #endif
lastxferchar = 1;
xferbytes = 0;
@@ -2474,7 +2477,7 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate)
block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e)));
// Bail if this is a zero-length block
- if (block->step_event_count <=dropsegments) { return; };
+ if (block->step_event_count <=dropsegments) { /*Serial.println("drop seg");*/ return; };
// Compute direction bits for this block
block->direction_bits = 0;
@@ -2551,7 +2554,7 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate)
//delta_mm[E_AXIS] = (target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS];
delta_mm[E_AXIS] = ((target[E_AXIS]-position[E_AXIS])/axis_steps_per_unit[E_AXIS])*extrudemultiply/100.0;
- if ( block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0 ) {
+ if ( block->steps_x <= dropsegments && block->steps_y <= dropsegments && block->steps_z <= dropsegments ) {
block->millimeters = fabs(delta_mm[E_AXIS]);
} else {
block->millimeters = sqrt(square(delta_mm[X_AXIS]) + square(delta_mm[Y_AXIS]) + square(delta_mm[Z_AXIS]));
View
@@ -301,12 +301,19 @@ ISR(TIMER2_OVF_vect)
//--------------------END SOFT PWM---------------------------
//-------------------- START PID AUTOTUNE ---------------------------
+// Based on PID relay test
+// Thanks to Erik van der Zalm for this idea to use it for Marlin
+// Some information see:
+// http://brettbeauregard.com/blog/2012/01/arduino-pid-autotune-library/
+//------------------------------------------------------------------
#ifdef PID_AUTOTUNE
-void PID_autotune(float PIDAT_test_temp)
+void PID_autotune(int PIDAT_test_temp)
{
float PIDAT_input = 0;
- float PIDAT_input_help = 0;
+ int PIDAT_input_help = 0;
unsigned char PIDAT_count_input = 0;
+
+ float PIDAT_max, PIDAT_min;
unsigned char PIDAT_PWM_val = 255;
@@ -317,20 +324,21 @@ void PID_autotune(float PIDAT_test_temp)
unsigned long PIDAT_t1=PIDAT_temp_millis;
unsigned long PIDAT_t2=PIDAT_temp_millis;
unsigned long PIDAT_T_check_AI_val = PIDAT_temp_millis;
- unsigned long PIDAT_cycle_autotune = PIDAT_temp_millis;
+
+ unsigned char PIDAT_cycle_cnt = 0;
long PIDAT_t_high;
long PIDAT_t_low;
- long PIDAT_bias=127;
- long PIDAT_d = 127;
+ long PIDAT_bias= 127;
+ long PIDAT_d = 127;
+
float PIDAT_Ku, PIDAT_Tu;
float PIDAT_Kp, PIDAT_Ki, PIDAT_Kd;
- float PIDAT_max, PIDAT_min;
-
- showString(PSTR("PID Autotune start"));
- showString(PSTR("\r\n"));
+ #define PIDAT_TIME_FACTOR ((HEATER_CHECK_INTERVAL*256.0) / 1000.0)
+
+ showString(PSTR("PID Autotune start\r\n"));
target_temp = PIDAT_test_temp;
@@ -344,6 +352,7 @@ void PID_autotune(float PIDAT_test_temp)
if((millis() - PIDAT_T_check_AI_val) > 100 )
{
PIDAT_T_check_AI_val = millis();
+ PIDAT_cycle_cnt++;
#ifdef HEATER_USES_THERMISTOR
current_raw = analogRead(TEMP_0_PIN);
@@ -361,13 +370,14 @@ void PID_autotune(float PIDAT_test_temp)
#endif
}
- if((millis() - PIDAT_cycle_autotune) > 1000 )
+ if(PIDAT_cycle_cnt >= 10 )
{
- PIDAT_cycle_autotune = millis();
- PIDAT_input = PIDAT_input_help / PIDAT_count_input;
+ PIDAT_cycle_cnt = 0;
+
+ PIDAT_input = (float)PIDAT_input_help / (float)PIDAT_count_input;
PIDAT_input_help = 0;
- PIDAT_count_input=0;
+ PIDAT_count_input = 0;
PIDAT_max=max(PIDAT_max,PIDAT_input);
PIDAT_min=min(PIDAT_min,PIDAT_input);
@@ -388,9 +398,9 @@ void PID_autotune(float PIDAT_test_temp)
{
if(millis() - PIDAT_t1 > 5000)
{
- PIDAT_heating=true;
- PIDAT_t2=millis();
- PIDAT_t_low=PIDAT_t2 - PIDAT_t1;
+ PIDAT_heating = true;
+ PIDAT_t2 = millis();
+ PIDAT_t_low = PIDAT_t2 - PIDAT_t1;
if(PIDAT_cycles > 0)
{
@@ -408,50 +418,42 @@ void PID_autotune(float PIDAT_test_temp)
{
PIDAT_Ku = (4.0*PIDAT_d)/(3.14159*(PIDAT_max-PIDAT_min));
PIDAT_Tu = ((float)(PIDAT_t_low + PIDAT_t_high)/1000.0);
+
showString(PSTR(" Ku: ")); Serial.print(PIDAT_Ku);
showString(PSTR(" Tu: ")); Serial.println(PIDAT_Tu);
- PIDAT_Kp = 0.6*PIDAT_Ku;
+ PIDAT_Kp = 0.60*PIDAT_Ku;
PIDAT_Ki = 2*PIDAT_Kp/PIDAT_Tu;
PIDAT_Kd = PIDAT_Kp*PIDAT_Tu/8;
- showString(PSTR(" Clasic PID "));
- showString(PSTR("\r\n"));
+ showString(PSTR(" Clasic PID \r\n"));
//showString(PSTR(" Kp: ")); Serial.println(PIDAT_Kp);
//showString(PSTR(" Ki: ")); Serial.println(PIDAT_Ki);
//showString(PSTR(" Kd: ")); Serial.println(PIDAT_Kd);
showString(PSTR(" CFG Kp: ")); Serial.println((unsigned int)(PIDAT_Kp*256));
- showString(PSTR(" CFG Ki: ")); Serial.println((unsigned int)(PIDAT_Ki*128));
- showString(PSTR(" CFG Kd: ")); Serial.println((unsigned int)(PIDAT_Kd*128));
+ showString(PSTR(" CFG Ki: ")); Serial.println((unsigned int)(PIDAT_Ki*PIDAT_TIME_FACTOR));
+ showString(PSTR(" CFG Kd: ")); Serial.println((unsigned int)(PIDAT_Kd*PIDAT_TIME_FACTOR));
- PIDAT_Kp = 0.33*PIDAT_Ku;
+ PIDAT_Kp = 0.30*PIDAT_Ku;
PIDAT_Ki = PIDAT_Kp/PIDAT_Tu;
PIDAT_Kd = PIDAT_Kp*PIDAT_Tu/3;
- showString(PSTR(" Some overshoot "));
- showString(PSTR("\r\n"));
- //showString(PSTR(" Kp: ")); Serial.println(PIDAT_Kp);
- //showString(PSTR(" Ki: ")); Serial.println(PIDAT_Ki);
- //showString(PSTR(" Kd: ")); Serial.println(PIDAT_Kd);
+ showString(PSTR(" Some overshoot \r\n"));
showString(PSTR(" CFG Kp: ")); Serial.println((unsigned int)(PIDAT_Kp*256));
- showString(PSTR(" CFG Ki: ")); Serial.println((unsigned int)(PIDAT_Ki*128));
- showString(PSTR(" CFG Kd: ")); Serial.println((unsigned int)(PIDAT_Kd*128));
+ showString(PSTR(" CFG Ki: ")); Serial.println((unsigned int)(PIDAT_Ki*PIDAT_TIME_FACTOR));
+ showString(PSTR(" CFG Kd: ")); Serial.println((unsigned int)(PIDAT_Kd*PIDAT_TIME_FACTOR));
/*
- PIDAT_Kp = 0.2*PIDAT_Ku;
+ PIDAT_Kp = 0.20*PIDAT_Ku;
PIDAT_Ki = 2*PIDAT_Kp/PIDAT_Tu;
PIDAT_Kd = PIDAT_Kp*PIDAT_Tu/3;
- showString(PSTR(" No overshoot "));
- showString(PSTR("\r\n"));
- //showString(PSTR(" Kp: ")); Serial.println(PIDAT_Kp);
- //showString(PSTR(" Ki: ")); Serial.println(PIDAT_Ki);
- //showString(PSTR(" Kd: ")); Serial.println(PIDAT_Kd);
+ showString(PSTR(" No overshoot \r\n"));
showString(PSTR(" CFG Kp: ")); Serial.println((unsigned int)(PIDAT_Kp*256));
- showString(PSTR(" CFG Ki: ")); Serial.println((unsigned int)(PIDAT_Ki*128));
- showString(PSTR(" CFG Kd: ")); Serial.println((unsigned int)(PIDAT_Kd*128));
+ showString(PSTR(" CFG Ki: ")); Serial.println((unsigned int)(PIDAT_Ki*PIDAT_TIME_FACTOR));
+ showString(PSTR(" CFG Kd: ")); Serial.println((unsigned int)(PIDAT_Kd*PIDAT_TIME_FACTOR));
*/
}
}
PIDAT_PWM_val = (PIDAT_bias + PIDAT_d);
PIDAT_cycles++;
- PIDAT_min=PIDAT_test_temp;
+ PIDAT_min = PIDAT_test_temp;
}
}
@@ -467,8 +469,7 @@ void PID_autotune(float PIDAT_test_temp)
if(PIDAT_input > (PIDAT_test_temp + 20))
{
- showString(PSTR("PID Autotune failed! Temperature to high"));
- showString(PSTR("\r\n"));
+ showString(PSTR("PID Autotune failed! Temperature to high\r\n"));
return;
}
@@ -483,15 +484,13 @@ void PID_autotune(float PIDAT_test_temp)
if(((millis() - PIDAT_t1) + (millis() - PIDAT_t2)) > (10L*60L*1000L*2L))
{
- showString(PSTR("PID Autotune failed! timeout"));
- showString(PSTR("\r\n"));
+ showString(PSTR("PID Autotune failed! timeout\r\n"));
return;
}
if(PIDAT_cycles > 5)
{
- showString(PSTR("PID Autotune finished ! Place the Kp, Ki and Kd constants in the configuration.h"));
- showString(PSTR("\r\n"));
+ showString(PSTR("PID Autotune finished ! Place the Kp, Ki and Kd constants in the configuration.h\r\n"));
return;
}
manage_display();
View
@@ -120,7 +120,7 @@ extern unsigned char manage_monitor;
#endif
#ifdef PID_AUTOTUNE
- void PID_autotune(float PIDAT_test_temp);
+ void PID_autotune(int PIDAT_test_temp);
#endif
void manage_heater();
Oops, something went wrong.

0 comments on commit 3c238bc

Please sign in to comment.