Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version 1.3.18T / 02.06.2012

  • Loading branch information...
commit 3c238bcf4d43cbcbd16cacb58429fce538c79ce8 1 parent a35fb05
midopple authored
2  Sprinter/Configuration.h
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
//-----------------------------------------------------------------------
15 Sprinter/Sprinter.ino
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]));
87 Sprinter/heater.cpp
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();
2  Sprinter/heater.h
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();
180 Sprinter/i2c_lcd_display.cpp
View
@@ -32,6 +32,14 @@
#include "i2c_lcd_display.h"
#include "heater.h"
+
+void show_main_page(void);
+
+unsigned char menu_level_ID = 0;
+volatile char buttons=0; //the last checked buttons in a bit array.
+int encoderpos=0;
+short lastenc=0;
+
extern int calc_plannerpuffer_fill(void);
extern float current_position[NUM_AXIS];
@@ -47,19 +55,122 @@ extern volatile int extrudemultiply;
LiquidCrystal_I2C lcd(0x20,20,4); // set the LCD address to 0x20 for a 20 chars and 4 line display
+void lcdProgMemprint(const char *str)
+{
+ char ch=pgm_read_byte(str);
+ while(ch)
+ {
+ lcd.print(ch);
+ ch=pgm_read_byte(++str);
+ }
+}
+
+#define lcdprintPGM(x) lcdProgMemprint(PSTR(x))
+
+//---------------------------------------------------------------------------
+//----------------------------- CHECK ENCODER ----------------------------
+//---------------------------------------------------------------------------
+#define EN_C (1<<2)
+#define EN_B (1<<1)
+#define EN_A (1<<0)
+
+void check_encoder_rotation(void)
+{
+ char enc=0;
+
+ if(buttons&EN_A)
+ enc|=(1<<0);
+ if(buttons&EN_B)
+ enc|=(1<<1);
+
+ if(enc!=lastenc)
+ {
+ switch(enc)
+ {
+ case 0:
+ if(lastenc==3)
+ encoderpos++;
+ else if(lastenc==1)
+ encoderpos--;
+ break;
+ case 1:
+ if(lastenc==0)
+ encoderpos++;
+ else if(lastenc==2)
+ encoderpos--;
+ break;
+ case 2:
+ if(lastenc==1)
+ encoderpos++;
+ else if(lastenc==3)
+ encoderpos--;
+ break;
+ case 3:
+ if(lastenc==2)
+ encoderpos++;
+ else if(lastenc==0)
+ encoderpos--;
+ break;
+ default:
+ break;
+ }
+ }
+ lastenc=enc;
+}
+//----------------------------- END CHECK ENCODER ------------------------
+//---------------------------------------------------------------------------
+
+
void init_I2C_LCD(void)
{
lcd.init(); // initialize the lcd
- // Print a message to the LCD.
+ //Backlight ON
lcd.backlight();
- //lcd.print("Sprinter with LCD");
}
+
+
void manage_display(void)
{
static unsigned long previous_millis_LCD = 0;
+ static unsigned long previous_millis_button = 0;
+
+ if((millis() - previous_millis_button) > 100 )
+ {
+ previous_millis_button = millis();
+
+ check_encoder_rotation();
+
+ }
+
+ if((millis() - previous_millis_LCD) > 250 )
+ {
+ previous_millis_LCD = millis();
+
+ switch(menu_level_ID)
+ {
+ case 0:
+ show_main_page();
+ break;
+ case 1:
+
+ break;
+ default:
+ menu_level_ID = 0;
+ break;
+ }
+ }
+
+
+
+}
+
+
+void show_main_page(void)
+{
+
static unsigned long start_millis_SD_card = 0;
static unsigned char state_cnt_LCD = 0;
int hotendtC_LCD,bedtempC_LCD,bed_tardet_temp;
@@ -69,10 +180,6 @@ void manage_display(void)
int help_int_calc = 0;
float help_float_calc = 0;
- if((millis() - previous_millis_LCD) > 250 )
- {
- previous_millis_LCD = millis();
-
switch(state_cnt_LCD)
{
@@ -86,32 +193,30 @@ void manage_display(void)
#endif
lcd.setCursor(0,0);
- lcd.print(" ");
+ lcdprintPGM(" ");
lcd.setCursor(0,0);
- lcd.print("H:");
+ lcdprintPGM("H:");
lcd.print(hotendtC_LCD);
- lcd.print("/");
+ lcdprintPGM("/");
lcd.print(target_temp);
- lcd.print(" B:");
+ lcdprintPGM(" B:");
lcd.print(bedtempC_LCD);
- lcd.print("/");
+ lcdprintPGM("/");
lcd.print(bed_tardet_temp);
state_cnt_LCD=1;
break;
case 1:
lcd.setCursor(0,1);
- lcd.print(" ");
+ lcdprintPGM(" ");
lcd.setCursor(0,1);
help_pos_calc = current_position[0];
- lcd.print("X:");
+ lcdprintPGM("X:");
lcd.print(help_pos_calc);
- lcd.print(" ");
help_pos_calc = current_position[1];
- lcd.print("Y:");
+ lcdprintPGM(" Y:");
lcd.print(help_pos_calc);
- lcd.print(" ");
- lcd.print("Z:");
+ lcdprintPGM(" Z:");
lcd.print(current_position[2]);
state_cnt_LCD=2;
@@ -119,29 +224,29 @@ void manage_display(void)
case 2:
state_cnt_LCD=3;
lcd.setCursor(0,2);
- lcd.print(" ");
+ lcdprintPGM(" ");
lcd.setCursor(0,2);
help_pos_calc = current_position[3];
- lcd.print("E:");
+ lcdprintPGM("E:");
lcd.print(help_pos_calc);
- lcd.print("mm ");
+ lcdprintPGM("mm ");
if(sdmode == true)
{
- lcd.print("SD:");
+ lcdprintPGM("SD:");
if(filesize > 0)
help_float_calc = ((float)sdpos*100) / (float)filesize;
else
help_float_calc = 0;
lcd.print(help_float_calc);
- lcd.print("%");
+ lcdprintPGM("%");
}
else
{
start_millis_SD_card = millis();
#ifdef PIDTEMP
- lcd.print(" PWM:");
+ lcdprintPGM(" PWM:");
lcd.print((unsigned char)g_heater_pwm_val*1);
#endif
}
@@ -150,17 +255,17 @@ void manage_display(void)
case 3:
state_cnt_LCD=0;
lcd.setCursor(0,3);
- lcd.print(" ");
+ lcdprintPGM(" ");
lcd.setCursor(0,3);
if(sdmode == true)
{
help_time_calc = (millis() - start_millis_SD_card)/1000;
lcd.print(help_time_calc/60);
- lcd.print(":");
+ lcdprintPGM(":");
if((help_time_calc%60 < 10))
- lcd.print("0");
+ lcdprintPGM("0");
lcd.print(help_time_calc%60);
- lcd.print(" / ");
+ lcdprintPGM(" / ");
if(filesize > 0)
{
help_float_calc = (float)sdpos / (float)filesize;
@@ -172,22 +277,22 @@ void manage_display(void)
help_time_calc = 0;
}
lcd.print(help_time_calc/60);
- lcd.print(":");
+ lcdprintPGM(":");
if((help_time_calc%60 < 10))
- lcd.print("0");
+ lcdprintPGM("0");
lcd.print(help_time_calc%60);
- lcd.print(" / ");
+ lcdprintPGM(" / ");
}
else
{
- lcd.print("FM/EM:");
+ lcdprintPGM("FM/EM:");
lcd.print(feedmultiply);
- lcd.print("/");
+ lcdprintPGM("/");
lcd.print(extrudemultiply);
- lcd.print(" P:");
+ lcdprintPGM(" P:");
}
@@ -198,12 +303,7 @@ void manage_display(void)
state_cnt_LCD=0;
break;
- }
-
-
- }
-
-
+ }
+
}
-
Please sign in to comment.
Something went wrong with that request. Please try again.