From 0ac452e2524df00d4dd97d4dfecd6d346592e4d7 Mon Sep 17 00:00:00 2001 From: Erik vd Zalm Date: Sun, 6 Jan 2013 13:37:01 +0100 Subject: [PATCH 1/7] Disable is now multi extruder compatible. M84 got a T option. --- Marlin/Configuration.h | 2 +- Marlin/Configuration_adv.h | 2 +- Marlin/Marlin_main.cpp | 22 ++++++++++++++++++---- Marlin/planner.cpp | 25 +++++++++++++++---------- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index d7d35d2400..080462d25e 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -46,7 +46,7 @@ // 301 = Rambo #ifndef MOTHERBOARD -#define MOTHERBOARD 7 +#define MOTHERBOARD 34 #endif diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index b74f74ad81..7c770cfc1d 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -71,7 +71,7 @@ //=========================================================================== // This defines the number of extruders -#define EXTRUDERS 1 +#define EXTRUDERS 2 #define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 1dc4c2103d..e387de8d24 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1181,10 +1181,24 @@ void process_commands() if(code_seen('Z')) disable_z(); #if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS if(code_seen('E')) { - disable_e0(); - disable_e1(); - disable_e2(); - } + if(code_seen('T')) { + tmp_extruder = code_value(); + if(tmp_extruder >= EXTRUDERS) { + SERIAL_ECHO_START; + SERIAL_ECHOLN(MSG_INVALID_EXTRUDER); + } + else { + if(tmp_extruder == 0) disable_e0(); + else if(tmp_extruder == 1) disable_e1(); + else if(tmp_extruder == 2) disable_e2(); + } + } + else { + disable_e0(); + disable_e1(); + disable_e2(); + } + } #endif } } diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 66809a10af..18256fc75d 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -437,7 +437,9 @@ void check_axes_activity() unsigned char x_active = 0; unsigned char y_active = 0; unsigned char z_active = 0; - unsigned char e_active = 0; + unsigned char e0_active = 0; + unsigned char e1_active = 0; + unsigned char e2_active = 0; unsigned char fan_speed = 0; unsigned char tail_fan_speed = 0; block_t *block; @@ -452,7 +454,11 @@ void check_axes_activity() if(block->steps_x != 0) x_active++; if(block->steps_y != 0) y_active++; if(block->steps_z != 0) z_active++; - if(block->steps_e != 0) e_active++; + if(block->steps_e != 0) { + if(block->active_extruder == 0) e0_active++; + if(block->active_extruder == 1) e1_active++; + if(block->active_extruder == 2) e2_active++; + } if(block->fan_speed != 0) fan_speed++; block_index = (block_index+1) & (BLOCK_BUFFER_SIZE - 1); } @@ -470,11 +476,10 @@ void check_axes_activity() if((DISABLE_X) && (x_active == 0)) disable_x(); if((DISABLE_Y) && (y_active == 0)) disable_y(); if((DISABLE_Z) && (z_active == 0)) disable_z(); - if((DISABLE_E) && (e_active == 0)) - { - disable_e0(); - disable_e1(); - disable_e2(); + if(DISABLE_E) { + if(e0_active == 0) disable_e0(); + if(e1_active == 0) disable_e1(); + if(e2_active == 0) disable_e2(); } #if FAN_PIN > -1 #ifndef FAN_SOFT_PWM @@ -597,9 +602,9 @@ void plan_buffer_line(const float &x, const float &y, const float &z, const floa // Enable all if(block->steps_e != 0) { - enable_e0(); - enable_e1(); - enable_e2(); + if(extruder == 0) enable_e0(); + if(extruder == 1) enable_e1(); + if(extruder == 2) enable_e2(); } if (block->steps_e == 0) From 6752cb2d9ce085ed1df760475adac46a959009c4 Mon Sep 17 00:00:00 2001 From: Erik vd Zalm Date: Sun, 6 Jan 2013 14:26:23 +0100 Subject: [PATCH 2/7] PID now per extruder. Fixed typo --- Marlin/Configuration.h | 11 ++++ Marlin/ConfigurationStore.cpp | 110 +++++++++++++++++++++------------- Marlin/Marlin_main.cpp | 18 ++++-- Marlin/language.h | 11 +++- Marlin/planner.cpp | 4 +- Marlin/temperature.cpp | 38 ++++++------ Marlin/temperature.h | 5 +- 7 files changed, 125 insertions(+), 72 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 080462d25e..94bacabc39 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -136,6 +136,17 @@ // #define DEFAULT_Kd 440 #endif // PIDTEMP +// PID parameters for 2nd extruder + #define DEFAULT_Kp_E1 22.2 + #define DEFAULT_Ki_E1 1.08 + #define DEFAULT_Kd_E1 114 + + +// PID parameters for 3th extruder +// #define DEFAULT_Kp_E2 22.2 +// #define DEFAULT_Ki_E2 1.08 +// #define DEFAULT_Kd_E2 114 + // Bed Temperature Control // Select PID or bang-bang with PIDTEMPBED. If bang-bang, BED_LIMIT_SWITCHING will enable hysteresis // diff --git a/Marlin/ConfigurationStore.cpp b/Marlin/ConfigurationStore.cpp index 6d4777701f..2c11244d73 100644 --- a/Marlin/ConfigurationStore.cpp +++ b/Marlin/ConfigurationStore.cpp @@ -3,26 +3,26 @@ #include "temperature.h" #include "ultralcd.h" #include "ConfigurationStore.h" - -void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) -{ - do - { - eeprom_write_byte((unsigned char*)pos, *value); - pos++; - value++; + +void _EEPROM_writeData(int &pos, uint8_t* value, uint8_t size) +{ + do + { + eeprom_write_byte((unsigned char*)pos, *value); + pos++; + value++; }while(--size); -} +} #define EEPROM_WRITE_VAR(pos, value) _EEPROM_writeData(pos, (uint8_t*)&value, sizeof(value)) -void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) -{ - do - { - *value = eeprom_read_byte((unsigned char*)pos); - pos++; - value++; +void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) +{ + do + { + *value = eeprom_read_byte((unsigned char*)pos); + pos++; + value++; }while(--size); -} +} #define EEPROM_READ_VAR(pos, value) _EEPROM_readData(pos, (uint8_t*)&value, sizeof(value)) //====================================================================================== @@ -43,7 +43,7 @@ void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) void Config_StoreSettings() { char ver[4]= "000"; - int i=EEPROM_OFFSET; + int i=EEPROM_OFFSET; EEPROM_WRITE_VAR(i,ver); // invalidate data first EEPROM_WRITE_VAR(i,axis_steps_per_unit); EEPROM_WRITE_VAR(i,max_feedrate); @@ -58,8 +58,8 @@ void Config_StoreSettings() EEPROM_WRITE_VAR(i,max_e_jerk); EEPROM_WRITE_VAR(i,add_homeing); #ifndef ULTIPANEL - int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED; - int absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED; + int plaPreheatHotendTemp = PLA_PREHEAT_HOTEND_TEMP, plaPreheatHPBTemp = PLA_PREHEAT_HPB_TEMP, plaPreheatFanSpeed = PLA_PREHEAT_FAN_SPEED; + int absPreheatHotendTemp = ABS_PREHEAT_HOTEND_TEMP, absPreheatHPBTemp = ABS_PREHEAT_HPB_TEMP, absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED; #endif EEPROM_WRITE_VAR(i,plaPreheatHotendTemp); EEPROM_WRITE_VAR(i,plaPreheatHPBTemp); @@ -75,7 +75,7 @@ void Config_StoreSettings() EEPROM_WRITE_VAR(i,3000); EEPROM_WRITE_VAR(i,0); EEPROM_WRITE_VAR(i,0); - #endif + #endif char ver2[4]=EEPROM_VERSION; i=EEPROM_OFFSET; EEPROM_WRITE_VAR(i,ver2); // validate data @@ -105,7 +105,7 @@ void Config_PrintSettings() SERIAL_ECHOPAIR(" Z", max_feedrate[2] ); SERIAL_ECHOPAIR(" E", max_feedrate[3]); SERIAL_ECHOLN(""); - + SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Maximum Acceleration (mm/s2):"); SERIAL_ECHO_START; @@ -120,7 +120,7 @@ void Config_PrintSettings() SERIAL_ECHOPAIR(" M204 S",acceleration ); SERIAL_ECHOPAIR(" T" ,retract_acceleration); SERIAL_ECHOLN(""); - + SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Advanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum xY jerk (mm/s), Z=maximum Z jerk (mm/s)"); SERIAL_ECHO_START; @@ -131,7 +131,7 @@ void Config_PrintSettings() SERIAL_ECHOPAIR(" Z" ,max_z_jerk); SERIAL_ECHOPAIR(" E" ,max_e_jerk); SERIAL_ECHOLN(""); - + SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Home offset (mm):"); SERIAL_ECHO_START; @@ -143,11 +143,25 @@ void Config_PrintSettings() SERIAL_ECHO_START; SERIAL_ECHOLNPGM("PID settings:"); SERIAL_ECHO_START; - SERIAL_ECHOPAIR(" M301 P",Kp); - SERIAL_ECHOPAIR(" I" ,Ki/PID_dT); - SERIAL_ECHOPAIR(" D" ,Kd*PID_dT); + SERIAL_ECHOPAIR(" M301 P",Kp[0]); + SERIAL_ECHOPAIR(" I" ,Ki[0]/PID_dT); + SERIAL_ECHOPAIR(" D" ,Kd[0]*PID_dT); + SERIAL_ECHOLN(""); +#if EXTRUDERS > 1 + SERIAL_ECHOPAIR(" M301 P",Kp[1]); + SERIAL_ECHOPAIR(" I" ,Ki[1]/PID_dT); + SERIAL_ECHOPAIR(" D" ,Kd[1]*PID_dT); + SERIAL_ECHOPGM(" T1"); + SERIAL_ECHOLN(""); +#endif +#if EXTRUDERS > 2 + SERIAL_ECHOPAIR(" M301 P",Kp[2]); + SERIAL_ECHOPAIR(" I" ,Ki[2]/PID_dT); + SERIAL_ECHOPAIR(" D" ,Kd[2]*PID_dT); + SERIAL_ECHOPGM(" T2"); SERIAL_ECHOLN(""); #endif +#endif } #endif @@ -161,7 +175,7 @@ void Config_RetrieveSettings() EEPROM_READ_VAR(i,stored_ver); //read stored version // SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]"); if (strncmp(ver,stored_ver,3) == 0) - { + { // version number match EEPROM_READ_VAR(i,axis_steps_per_unit); EEPROM_READ_VAR(i,max_feedrate); @@ -176,15 +190,15 @@ void Config_RetrieveSettings() EEPROM_READ_VAR(i,max_e_jerk); EEPROM_READ_VAR(i,add_homeing); #ifndef ULTIPANEL - int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed; - int absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed; + int plaPreheatHotendTemp, plaPreheatHPBTemp, plaPreheatFanSpeed; + int absPreheatHotendTemp, absPreheatHPBTemp, absPreheatFanSpeed; #endif EEPROM_READ_VAR(i,plaPreheatHotendTemp); EEPROM_READ_VAR(i,plaPreheatHPBTemp); EEPROM_READ_VAR(i,plaPreheatFanSpeed); EEPROM_READ_VAR(i,absPreheatHotendTemp); EEPROM_READ_VAR(i,absPreheatHPBTemp); - EEPROM_READ_VAR(i,absPreheatFanSpeed); + EEPROM_READ_VAR(i,absPreheatFanSpeed); #ifndef PIDTEMP float Kp,Ki,Kd; #endif @@ -195,17 +209,17 @@ void Config_RetrieveSettings() SERIAL_ECHO_START; SERIAL_ECHOLNPGM("Stored settings retreived:"); } - else - { - Config_ResetDefault(); - SERIAL_ECHO_START; - SERIAL_ECHOLN("Using Default settings:"); - } + else + { + Config_ResetDefault(); + SERIAL_ECHO_START; + SERIAL_ECHOLN("Using Default settings:"); + } Config_PrintSettings(); } -#endif - -void Config_ResetDefault() +#endif + +void Config_ResetDefault() { float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT; float tmp2[]=DEFAULT_MAX_FEEDRATE; @@ -234,9 +248,19 @@ void Config_ResetDefault() absPreheatFanSpeed = ABS_PREHEAT_FAN_SPEED; #endif #ifdef PIDTEMP - Kp = DEFAULT_Kp; - Ki = (DEFAULT_Ki*PID_dT); - Kd = (DEFAULT_Kd/PID_dT); + Kp[0] = DEFAULT_Kp; + Ki[0] = (DEFAULT_Ki*PID_dT); + Kd[0] = (DEFAULT_Kd/PID_dT); + #if EXTRUDERS > 1 + Kp[1] = DEFAULT_Kp_E1; + Ki[1] = (DEFAULT_Ki_E1*PID_dT); + Kd[1] = (DEFAULT_Kd_E1/PID_dT); + #endif + #if EXTRUDERS > 2 + Kp[2] = DEFAULT_Kp_E2; + Ki[2] = (DEFAULT_Ki_E2*PID_dT); + Kd[2] = (DEFAULT_Kd_E2/PID_dT); + #endif #ifdef PID_ADD_EXTRUSION_RATE Kc = DEFAULT_Kc; #endif//PID_ADD_EXTRUSION_RATE diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index e387de8d24..a64156c28f 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1401,20 +1401,23 @@ void process_commands() #ifdef PIDTEMP case 301: // M301 { - if(code_seen('P')) Kp = code_value(); - if(code_seen('I')) Ki = code_value()*PID_dT; - if(code_seen('D')) Kd = code_value()/PID_dT; + if(setTargetedHotend(301)){ + break; + } + if(code_seen('P')) Kp[tmp_extruder] = code_value(); + if(code_seen('I')) Ki[tmp_extruder] = code_value()*PID_dT; + if(code_seen('D')) Kd[tmp_extruder] = code_value()/PID_dT; #ifdef PID_ADD_EXTRUSION_RATE if(code_seen('C')) Kc = code_value(); #endif updatePID(); SERIAL_PROTOCOL(MSG_OK); SERIAL_PROTOCOL(" p:"); - SERIAL_PROTOCOL(Kp); + SERIAL_PROTOCOL(Kp[tmp_extruder]); SERIAL_PROTOCOL(" i:"); - SERIAL_PROTOCOL(Ki/PID_dT); + SERIAL_PROTOCOL(Ki[tmp_extruder]/PID_dT); SERIAL_PROTOCOL(" d:"); - SERIAL_PROTOCOL(Kd*PID_dT); + SERIAL_PROTOCOL(Kd[tmp_extruder]*PID_dT); #ifdef PID_ADD_EXTRUSION_RATE SERIAL_PROTOCOL(" c:"); SERIAL_PROTOCOL(Kc*PID_dT); @@ -1936,6 +1939,9 @@ bool setTargetedHotend(int code){ case 109: SERIAL_ECHO(MSG_M109_INVALID_EXTRUDER); break; + case 301: + SERIAL_ECHO(MSG_M301_INVALID_EXTRUDER); + break; } SERIAL_ECHOLN(tmp_extruder); return true; diff --git a/Marlin/language.h b/Marlin/language.h index 97e8f9d839..575c78d39b 100644 --- a/Marlin/language.h +++ b/Marlin/language.h @@ -139,6 +139,7 @@ #define MSG_M105_INVALID_EXTRUDER "M105 Invalid extruder " #define MSG_ERR_NO_THERMISTORS "No thermistors - no temperature" #define MSG_M109_INVALID_EXTRUDER "M109 Invalid extruder " + #define MSG_M301_INVALID_EXTRUDER "M301 Invalid extruder " #define MSG_HEATING "Heating..." #define MSG_HEATING_COMPLETE "Heating done." #define MSG_BED_HEATING "Bed Heating." @@ -293,6 +294,7 @@ #define MSG_M105_INVALID_EXTRUDER "M105 Niepoprawny ekstruder " #define MSG_ERR_NO_THERMISTORS "Brak termistorow - brak temperatury :(" #define MSG_M109_INVALID_EXTRUDER "M109 Niepoprawny ekstruder " + #define MSG_M301_INVALID_EXTRUDER "M301 Niepoprawny ekstruder " #define MSG_HEATING "Nagrzewanie ekstrudera..." #define MSG_HEATING_COMPLETE "Nagrzewanie ekstrudera zakonczone." #define MSG_BED_HEATING "Nagrzewanie loza..." @@ -452,6 +454,7 @@ #define MSG_M105_INVALID_EXTRUDER "M105 Extruder invalide" #define MSG_ERR_NO_THERMISTORS "Pas de thermistor, pas de temperature" #define MSG_M109_INVALID_EXTRUDER "M109 Extruder invalide " +#define MSG_M301_INVALID_EXTRUDER "M301 Extruder invalide " #define MSG_HEATING "En chauffe..." #define MSG_HEATING_COMPLETE "Chauffe terminee." #define MSG_BED_HEATING "Chauffe du lit." @@ -570,7 +573,7 @@ #define MSG_NO_CARD "Keine SDKarte" #define MSG_DWELL "Warten..." #define MSG_USERWAIT "Warte auf Nutzer..." - #define MSG_RESUMING "Druck fortsetzung" + #define MSG_RESUMING "Druck fortsetzung" #define MSG_NO_MOVE "Kein Zug." #define MSG_PART_RELEASE "Stepper tlw frei" #define MSG_KILLED "KILLED" @@ -609,6 +612,7 @@ #define MSG_M105_INVALID_EXTRUDER "M105 Invalid extruder " #define MSG_ERR_NO_THERMISTORS "No thermistors - no temp" #define MSG_M109_INVALID_EXTRUDER "M109 Invalid extruder " + #define MSG_M301_INVALID_EXTRUDER "M301 Invalid extruder " #define MSG_HEATING "Heating..." #define MSG_HEATING_COMPLETE "Heating done." #define MSG_BED_HEATING "Bed Heating." @@ -767,6 +771,7 @@ #define MSG_M105_INVALID_EXTRUDER "M105 Extrusor Invalido " #define MSG_ERR_NO_THERMISTORS "No hay termistores - no temp" #define MSG_M109_INVALID_EXTRUDER "M109 Extrusor Invalido " +#define MSG_M301_INVALID_EXTRUDER "M301 Extrusor Invalido " #define MSG_HEATING "Calentando..." #define MSG_HEATING_COMPLETE "Calentamiento Hecho." #define MSG_BED_HEATING "Calentando la base." @@ -916,7 +921,8 @@ #define MSG_M104_INVALID_EXTRUDER "M104 ошибка экструдера " #define MSG_M105_INVALID_EXTRUDER "M105 ошибка экструдера " #define MSG_ERR_NO_THERMISTORS "Нет термистра - нет температуры" -#define MSG_M109_INVALID_EXTRUDER "M109 ошибка экструдера " +#define MSG_M109_INVALID_EXTRUDER "M109 ошибка экструдера " +#define MSG_M301_INVALID_EXTRUDER "M301 ошибка экструдера " #define MSG_HEATING "Нагрев... " #define MSG_HEATING_COMPLETE "Наргето. " #define MSG_BED_HEATING "Нагрев стола... " @@ -1235,6 +1241,7 @@ #define MSG_M105_INVALID_EXTRUDER "M105 Extrusor inválido " #define MSG_ERR_NO_THERMISTORS "Nao ha termistor - no temp" #define MSG_M109_INVALID_EXTRUDER "M109 Extrusor inválido " + #define MSG_M301_INVALID_EXTRUDER "M301 Extrusor inválido " #define MSG_HEATING "Aquecendo..." #define MSG_HEATING_COMPLETE "Aquecido." #define MSG_BED_HEATING "Aquecendo a Base." diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index 18256fc75d..4fd37b1871 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -478,8 +478,8 @@ void check_axes_activity() if((DISABLE_Z) && (z_active == 0)) disable_z(); if(DISABLE_E) { if(e0_active == 0) disable_e0(); - if(e1_active == 0) disable_e1(); - if(e2_active == 0) disable_e2(); + if(e1_active == 1) disable_e1(); + if(e2_active == 2) disable_e2(); } #if FAN_PIN > -1 #ifndef FAN_SOFT_PWM diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 6093c99346..178ce2b265 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -34,6 +34,16 @@ #include "temperature.h" #include "watchdog.h" +#if EXTRUDERS > 3 +# error Unsupported number of extruders +#elif EXTRUDERS > 2 +# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2, v3 } +#elif EXTRUDERS > 1 +# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2 } +#else +# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1 } +#endif + //=========================================================================== //=============================public variables============================ //=========================================================================== @@ -44,10 +54,10 @@ float current_temperature[EXTRUDERS] = { 0 }; int current_temperature_bed_raw = 0; float current_temperature_bed = 0; -#ifdef PIDTEMP - float Kp=DEFAULT_Kp; - float Ki=(DEFAULT_Ki*PID_dT); - float Kd=(DEFAULT_Kd/PID_dT); +#ifdef PIDTEMP + float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kp, DEFAULT_Kp_E1, DEFAULT_Kp_E2); + float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Ki*PID_dT, DEFAULT_Ki_E1*PID_dT, DEFAULT_Ki_E2*PID_dT); + float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kd/PID_dT, DEFAULT_Kd_E1/PID_dT, DEFAULT_Kd_E2/PID_dT); #ifdef PID_ADD_EXTRUSION_RATE float Kc=DEFAULT_Kc; #endif @@ -102,15 +112,7 @@ static volatile bool temp_meas_ready = false; -#if EXTRUDERS > 3 -# error Unsupported number of extruders -#elif EXTRUDERS > 2 -# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2, v3 } -#elif EXTRUDERS > 1 -# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2 } -#else -# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1 } -#endif + // Init min and max temp with extreme values to prevent false errors during startup static int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP ); @@ -292,7 +294,7 @@ void updatePID() { #ifdef PIDTEMP for(int e = 0; e < EXTRUDERS; e++) { - temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki; + temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki[e]; } #endif #ifdef PIDTEMPBED @@ -337,14 +339,14 @@ void manage_heater() temp_iState[e] = 0.0; pid_reset[e] = false; } - pTerm[e] = Kp * pid_error[e]; + pTerm[e] = Kp[e] * pid_error[e]; temp_iState[e] += pid_error[e]; temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]); - iTerm[e] = Ki * temp_iState[e]; + iTerm[e] = Ki[e] * temp_iState[e]; //K1 defined in Configuration.h in the PID settings #define K2 (1.0-K1) - dTerm[e] = (Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); + dTerm[e] = (Kd[e] * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); temp_dState[e] = pid_input; pid_output = constrain(pTerm[e] + iTerm[e] - dTerm[e], 0, PID_MAX); @@ -577,7 +579,7 @@ void tp_init() maxttemp[e] = maxttemp[0]; #ifdef PIDTEMP temp_iState_min[e] = 0.0; - temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki; + temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki[e]; #endif //PIDTEMP #ifdef PIDTEMPBED temp_iState_min_bed = 0.0; diff --git a/Marlin/temperature.h b/Marlin/temperature.h index feffcbd414..3311916872 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -39,7 +39,10 @@ extern int target_temperature_bed; extern float current_temperature_bed; #ifdef PIDTEMP - extern float Kp,Ki,Kd,Kc; + extern float Kp[EXTRUDERS]; + extern float Ki[EXTRUDERS]; + extern float Kd[EXTRUDERS]; + extern float Kc; #endif #ifdef PIDTEMPBED extern float bedKp,bedKi,bedKd; From b27a59f41ecdad900bcdffa955a4f55814bec13e Mon Sep 17 00:00:00 2001 From: kiyoshigawa Date: Mon, 6 May 2013 08:44:38 -0600 Subject: [PATCH 3/7] Added support for Elefu RA Board and Elefu Control Panel --- Marlin/Configuration.h | 25 +++- Marlin/Marlin.pde | 16 ++- Marlin/pins.h | 129 ++++++++++++++++++ .../ultralcd_implementation_hitachi_HD44780.h | 23 +++- 4 files changed, 180 insertions(+), 13 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index eed4abc81f..9f91b4d38f 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -46,9 +46,10 @@ // 90 = Alpha OMCA board // 91 = Final OMCA board // 301 = Rambo +// 21 = Elefu Ra Board (v3) #ifndef MOTHERBOARD -#define MOTHERBOARD 7 +#define MOTHERBOARD 21 #endif //// The following define selects which power supply you have. Please choose the one that matches your setup @@ -84,10 +85,10 @@ // 52 is 200k thermistor - ATC Semitec 204GT-2 (1k pullup) // 55 is 100k thermistor - ATC Semitec 104GT-2 (Used in ParCan) (1k pullup) -#define TEMP_SENSOR_0 -1 +#define TEMP_SENSOR_0 1 #define TEMP_SENSOR_1 0 #define TEMP_SENSOR_2 0 -#define TEMP_SENSOR_BED 0 +#define TEMP_SENSOR_BED 1 // Actual temperature must be close to target for this long before M109 returns success #define TEMP_RESIDENCY_TIME 10 // (seconds) @@ -338,6 +339,15 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // ==> REMEMBER TO INSTALL U8glib to your ARDUINO library folder: http://code.google.com/p/u8glib/wiki/u8glib //#define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER +// The Elefu RA Board Control Panel +// http://www.elefu.com/index.php?route=product/product&product_id=53 +// REMEMBER TO INSTALL LiquidCrystal_I2C.h in your ARUDINO library folder: http://hmario.home.xs4all.nl/arduino/LiquidCrystal_I2C/LiquidCrystal_I2C.zip +#define RA_CONTROL_PANEL + +// The Elefu TLC5947 RGB Lighting Module +// Uncomment to enable TLC5947 Lighting Modules. +//#define RA_DISCO + //automatic expansion #if defined (REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) #define DOGLCD @@ -348,7 +358,14 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th #if defined(ULTIMAKERCONTROLLER) || defined(REPRAP_DISCOUNT_SMART_CONTROLLER) || defined(G3D_PANEL) #define ULTIPANEL #define NEWPANEL -#endif +#endif + +#if defined(RA_CONTROL_PANEL) + #define ULTIPANEL + #define NEWPANEL + #define LCD_I2C_TYPE_PCA8574 + #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander +#endif // Preheat Constants #define PLA_PREHEAT_HOTEND_TEMP 180 diff --git a/Marlin/Marlin.pde b/Marlin/Marlin.pde index 4d7d0a2fd7..2f845fedb3 100644 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@ -34,11 +34,17 @@ #include "pins.h" #ifdef ULTRA_LCD - #ifdef DOGLCD - #include // library for graphics LCD by Oli Kraus (https://code.google.com/p/u8glib/) - #else - #include // library for character LCD - #endif + #if defined(LCD_I2C_TYPE_PCF8575) + #include + #include + #elif defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008) + #include + #include + #elif defined DOGLCD + #include // library for graphics LCD by Oli Kraus (https://code.google.com/p/u8glib/) + #else + #include // library for character LCD + #endif #endif #if DIGIPOTSS_PIN > -1 diff --git a/Marlin/pins.h b/Marlin/pins.h index 2424010aa5..d845ce1b4e 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -53,6 +53,7 @@ #endif /* 99 */ + /**************************************************************************************** * Gen7 v1.1, v1.2, v1.3 pin assignment * @@ -575,6 +576,131 @@ #endif +/**************************************************************************************** +* Elefu RA Board Pin Assignments +* +****************************************************************************************/ +#if MOTHERBOARD == 21 +#define KNOWN_BOARD 1 + +#ifndef __AVR_ATmega2560__ + #error Oops! Make sure you have 'Arduino Mega' selected from the 'Tools -> Boards' menu. +#endif + + +#define X_STEP_PIN 49 +#define X_DIR_PIN 13 +#define X_ENABLE_PIN 48 +#define X_MIN_PIN 35 +#define X_MAX_PIN -1 //34 + +#define Y_STEP_PIN 11 +#define Y_DIR_PIN 9 +#define Y_ENABLE_PIN 12 +#define Y_MIN_PIN 33 +#define Y_MAX_PIN -1 //32 + +#define Z_STEP_PIN 7 +#define Z_DIR_PIN 6 +#define Z_ENABLE_PIN 8 +#define Z_MIN_PIN 31 +#define Z_MAX_PIN -1 //30 + +#define E2_STEP_PIN 43 +#define E2_DIR_PIN 47 +#define E2_ENABLE_PIN 42 + +#define E1_STEP_PIN 18 +#define E1_DIR_PIN 19 +#define E1_ENABLE_PIN 38 + +#define E0_STEP_PIN 40 +#define E0_DIR_PIN 41 +#define E0_ENABLE_PIN 37 + +#define SDPOWER -1 +#define LED_PIN -1 //Use +12V Aux port for LED Ring + +#define FAN_PIN 16 //5V PWM + +#define PS_ON_PIN 10 //Set to -1 if using a manual switch on the PWRSW Connector +#define SLEEP_WAKE_PIN 26 //This feature still needs work + +#define HEATER_0_PIN 45 //12V PWM1 +#define HEATER_1_PIN 46 //12V PWM2 +#define HEATER_2_PIN 17 //12V PWM3 +#define HEATER_BED_PIN 44 //DOUBLE 12V PWM +#define TEMP_0_PIN 3 //ANALOG NUMBERING +#define TEMP_1_PIN 2 //ANALOG NUMBERING +#define TEMP_2_PIN 1 //ANALOG NUMBERING +#define TEMP_BED_PIN 0 //ANALOG NUMBERING + +#define BEEPER 36 + +#define KILL_PIN -1 + +// M240 Triggers a camera by emulating a Canon RC-1 Remote +// Data from: http://www.doc-diy.net/photo/rc-1_hacked/ +#define PHOTOGRAPH_PIN 29 + +#ifdef RA_CONTROL_PANEL + + #define SDSS 53 + #define SDCARDDETECT 28 + + #define BTN_EN1 14 + #define BTN_EN2 39 + #define BTN_ENC 15 //the click + + #define BLEN_C 2 + #define BLEN_B 1 + #define BLEN_A 0 + + //encoder rotation values + #define encrot0 0 + #define encrot1 2 + #define encrot2 3 + #define encrot3 1 + +#endif //RA_CONTROL_PANEL + +#ifdef RA_DISCO + //variables for which pins the TLC5947 is using + #define TLC_CLOCK_PIN 25 + #define TLC_BLANK_PIN 23 + #define TLC_XLAT_PIN 22 + #define TLC_DATA_PIN 24 + + //We also need to define pin to port number mapping for the 2560 to match the pins listed above. If you change the TLC pins, update this as well per the 2560 datasheet! + //This currently only works with the RA Board. + #define TLC_CLOCK_BIT 3 //bit 3 on port A + #define TLC_CLOCK_PORT &PORTA //bit 3 on port A + + #define TLC_BLANK_BIT 1 //bit 1 on port A + #define TLC_BLANK_PORT &PORTA //bit 1 on port A + + #define TLC_DATA_BIT 2 //bit 2 on port A + #define TLC_DATA_PORT &PORTA //bit 2 on port A + + #define TLC_XLAT_BIT 0 //bit 0 on port A + #define TLC_XLAT_PORT &PORTA //bit 0 on port A + + //change this to match your situation. Lots of TLCs takes up the arduino SRAM very quickly, so be careful + //Leave it at at least 1 if you have enabled RA_LIGHTING + //The number of TLC5947 boards chained together for use with the animation, additional ones will repeat the animation on them, but are not individually addressable and mimic those before them. You can leave the default at 2 even if you only have 1 TLC5947 module. + #define NUM_TLCS 2 + + //These TRANS_ARRAY values let you change the order the LEDs on the lighting modules will animate for chase functions. + //Modify them according to your specific situation. + //NOTE: the array should be 8 long for every TLC you have. These defaults assume (2) TLCs. + #define TRANS_ARRAY {0, 1, 2, 3, 4, 5, 6, 7, 15, 14, 13, 12, 11, 10, 9, 8} //forwards + //#define TRANS_ARRAY {7, 6, 5, 4, 3, 2, 1, 0, 8, 9, 10, 11, 12, 13, 14, 15} //backwards +#endif //RA_LIGHTING + + +#endif /* Ra Board */ + + /**************************************************************************************** * Gen6 pin assignment * @@ -1645,3 +1771,6 @@ _E0_PINS _E1_PINS _E2_PINS \ analogInputToDigitalPin(TEMP_0_PIN), analogInputToDigitalPin(TEMP_1_PIN), analogInputToDigitalPin(TEMP_2_PIN), analogInputToDigitalPin(TEMP_BED_PIN) } #endif + + + diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index 88dea492b3..074dafd82b 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -10,8 +10,13 @@ #include "LiquidCrystalRus.h" #define LCD_CLASS LiquidCrystalRus #else -#include -#define LCD_CLASS LiquidCrystal + #ifdef LCD_I2C_TYPE_PCA8574 + #include + #define LCD_CLASS LiquidCrystal_I2C + #else + #include + #define LCD_CLASS LiquidCrystal + #endif #endif /* Custom characters defined in the first 8 characters of the LCD */ @@ -25,7 +30,12 @@ #define LCD_STR_CLOCK "\x07" #define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */ -LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 +#ifdef LCD_I2C_TYPE_PCA8574 + LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT); +#else + LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 +#endif + static void lcd_implementation_init() { byte bedTemp[8] = @@ -111,7 +121,12 @@ static void lcd_implementation_init() B00000, B00000 }; //thanks Sonny Mounicou - lcd.begin(LCD_WIDTH, LCD_HEIGHT); + #ifdef LCD_I2C_TYPE_PCA8574 + lcd.init(); + lcd.backlight(); + #else + lcd.begin(LCD_WIDTH, LCD_HEIGHT); + #endif lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp); lcd.createChar(LCD_STR_DEGREE[0], degree); lcd.createChar(LCD_STR_THERMOMETER[0], thermometer); From 1fa61c297ef340c08a87dbcb5dd2abfc52ab747a Mon Sep 17 00:00:00 2001 From: Tim Anderson Date: Mon, 6 May 2013 23:23:54 -0600 Subject: [PATCH 4/7] Turning off Control Panel by Default and Updating the link to the LiquidCrystal_I2C library to avoid confusion. --- Marlin/Configuration.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 9f91b4d38f..aeb9ef16ec 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -341,12 +341,8 @@ const bool Z_ENDSTOPS_INVERTING = true; // set to true to invert the logic of th // The Elefu RA Board Control Panel // http://www.elefu.com/index.php?route=product/product&product_id=53 -// REMEMBER TO INSTALL LiquidCrystal_I2C.h in your ARUDINO library folder: http://hmario.home.xs4all.nl/arduino/LiquidCrystal_I2C/LiquidCrystal_I2C.zip -#define RA_CONTROL_PANEL - -// The Elefu TLC5947 RGB Lighting Module -// Uncomment to enable TLC5947 Lighting Modules. -//#define RA_DISCO +// REMEMBER TO INSTALL LiquidCrystal_I2C.h in your ARUDINO library folder: https://github.com/kiyoshigawa/LiquidCrystal_I2C +//#define RA_CONTROL_PANEL //automatic expansion #if defined (REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) From 2ca6c5fbd75e35b026de24c57e7bab138df4e192 Mon Sep 17 00:00:00 2001 From: kiyoshigawa Date: Sat, 8 Jun 2013 09:00:34 -0600 Subject: [PATCH 5/7] Fixed small error in lcd define statements. --- Marlin/ultralcd_implementation_hitachi_HD44780.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index 768c4ce1bc..b4c58696ce 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -303,14 +303,9 @@ static void lcd_implementation_init() B00000, B00000 }; //thanks Sonny Mounicou - #ifdef LCD_I2C_TYPE_PCA8574 - lcd.init(); - lcd.backlight(); - #else - if defined(LCDI2C_TYPE_PCF8575) - lcd.begin(LCD_WIDTH, LCD_HEIGHT); - #endif - #ifdef LCD_I2C_PIN_BL +#if defined(LCDI2C_TYPE_PCF8575) + lcd.begin(LCD_WIDTH, LCD_HEIGHT); + #ifdef LCD_I2C_PIN_BL lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE); lcd.setBacklight(HIGH); #endif @@ -323,6 +318,10 @@ static void lcd_implementation_init() #elif defined(LCD_I2C_TYPE_MCP23008) lcd.setMCPType(LTI_TYPE_MCP23008); lcd.begin(LCD_WIDTH, LCD_HEIGHT); + +#elif defined(LCD_I2C_TYPE_PCA8574) + lcd.init(); + lcd.backlight(); #else lcd.begin(LCD_WIDTH, LCD_HEIGHT); From 69b02031caadb3207ea0e5de8edc648025f7f566 Mon Sep 17 00:00:00 2001 From: kiyoshigawa Date: Sat, 8 Jun 2013 09:00:34 -0600 Subject: [PATCH 6/7] Fixed small error in lcd define statements. --- .../ultralcd_implementation_hitachi_HD44780.h | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index 768c4ce1bc..a624541e63 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -10,14 +10,6 @@ extern volatile uint8_t buttons; //the last checked buttons in a bit array. #else extern volatile uint16_t buttons; //an extended version of the last checked buttons in a bit array. - - #ifdef LCD_I2C_TYPE_PCA8574 - #include - #define LCD_CLASS LiquidCrystal_I2C - #else - #include - #define LCD_CLASS LiquidCrystal - #endif #endif //////////////////////////////////// @@ -188,6 +180,11 @@ extern volatile uint16_t buttons; //an extended version of the last checked but #include #define LCD_CLASS LiquidTWI2 LCD_CLASS lcd(LCD_I2C_ADDRESS); + +#elif defined(LCD_I2C_TYPE_PCA8574) + #include + #define LCD_CLASS LiquidCrystal_I2C + LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT); #else // Standard directly connected LCD implementations @@ -212,12 +209,6 @@ extern volatile uint16_t buttons; //an extended version of the last checked but #define LCD_STR_CLOCK "\x07" #define LCD_STR_ARROW_RIGHT "\x7E" /* from the default character set */ -#ifdef LCD_I2C_TYPE_PCA8574 - LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT); -#else - LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 -#endif - static void lcd_implementation_init() { byte bedTemp[8] = @@ -303,14 +294,9 @@ static void lcd_implementation_init() B00000, B00000 }; //thanks Sonny Mounicou - #ifdef LCD_I2C_TYPE_PCA8574 - lcd.init(); - lcd.backlight(); - #else - if defined(LCDI2C_TYPE_PCF8575) - lcd.begin(LCD_WIDTH, LCD_HEIGHT); - #endif - #ifdef LCD_I2C_PIN_BL +#if defined(LCDI2C_TYPE_PCF8575) + lcd.begin(LCD_WIDTH, LCD_HEIGHT); + #ifdef LCD_I2C_PIN_BL lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE); lcd.setBacklight(HIGH); #endif @@ -323,6 +309,10 @@ static void lcd_implementation_init() #elif defined(LCD_I2C_TYPE_MCP23008) lcd.setMCPType(LTI_TYPE_MCP23008); lcd.begin(LCD_WIDTH, LCD_HEIGHT); + +#elif defined(LCD_I2C_TYPE_PCA8574) + lcd.init(); + lcd.backlight(); #else lcd.begin(LCD_WIDTH, LCD_HEIGHT); From f295712008385970334f64006b1a39b9efbb103e Mon Sep 17 00:00:00 2001 From: kiyoshigawa Date: Sat, 8 Jun 2013 09:27:56 -0600 Subject: [PATCH 7/7] Trying to fix weird diff on ultralcd_implementation_hitachi_HD44780.h --- Marlin/ultralcd_implementation_hitachi_HD44780.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index a624541e63..a025244876 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -184,7 +184,7 @@ extern volatile uint16_t buttons; //an extended version of the last checked but #elif defined(LCD_I2C_TYPE_PCA8574) #include #define LCD_CLASS LiquidCrystal_I2C - LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT); + LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT); #else // Standard directly connected LCD implementations @@ -294,9 +294,10 @@ static void lcd_implementation_init() B00000, B00000 }; //thanks Sonny Mounicou + #if defined(LCDI2C_TYPE_PCF8575) lcd.begin(LCD_WIDTH, LCD_HEIGHT); - #ifdef LCD_I2C_PIN_BL + #ifdef LCD_I2C_PIN_BL lcd.setBacklightPin(LCD_I2C_PIN_BL,POSITIVE); lcd.setBacklight(HIGH); #endif