![]() |
Repetier-Firmware
0.91
|
00001 #ifndef EXTRUDER_H_INCLUDED 00002 #define EXTRUDER_H_INCLUDED 00003 00004 #define CELSIUS_EXTRA_BITS 3 00005 00006 //#ifdef TEMP_PID 00007 //extern uint8_t current_extruder_out; 00008 //#endif 00009 00010 // Updates the temperature of all extruders and heated bed if it's time. 00011 // Toggels the heater power if necessary. 00012 extern bool reportTempsensorError(); 00013 extern uint8_t manageMonitor; 00014 00015 #define TEMPERATURE_CONTROLLER_FLAG_ALARM 1 00016 00020 class TemperatureController 00021 { 00022 public: 00023 uint8_t pwmIndex; 00024 uint8_t sensorType; 00025 uint8_t sensorPin; 00026 int16_t currentTemperature; 00027 int16_t targetTemperature; 00028 float currentTemperatureC; 00029 float targetTemperatureC; 00030 uint32_t lastTemperatureUpdate; 00031 int8_t heatManager; 00032 #ifdef TEMP_PID 00033 float tempIState; 00034 uint8_t pidDriveMax; 00035 uint8_t pidDriveMin; 00036 float pidPGain; 00037 float pidIGain; 00038 float pidDGain; 00039 uint8_t pidMax; 00040 float tempIStateLimitMax; 00041 float tempIStateLimitMin; 00042 uint8_t tempPointer; 00043 float tempArray[4]; 00044 #endif 00045 uint8_t flags; 00046 00047 void setTargetTemperature(float target); 00048 void updateCurrentTemperature(); 00049 void updateTempControlVars(); 00050 inline bool isAlarm() {return flags & TEMPERATURE_CONTROLLER_FLAG_ALARM;} 00051 inline void setAlarm(bool on) {if(on) flags |= TEMPERATURE_CONTROLLER_FLAG_ALARM; else flags &= ~TEMPERATURE_CONTROLLER_FLAG_ALARM;} 00052 #ifdef TEMP_PID 00053 void autotunePID(float temp,uint8_t controllerId,bool storeResult); 00054 #endif 00055 }; 00056 00057 class Extruder; 00058 extern Extruder extruder[]; 00059 00065 class Extruder // Size: 12*1 Byte+12*4 Byte+4*2Byte = 68 Byte 00066 { 00067 public: 00068 static Extruder *current; 00069 #if FEATURE_DITTO_PRINTING 00070 static uint8_t dittoMode; 00071 #endif 00072 uint8_t id; 00073 int32_t xOffset; 00074 int32_t yOffset; 00075 float stepsPerMM; 00076 uint8_t enablePin; 00077 // uint8_t directionPin; ///< Pin number to assign the direction. 00078 // uint8_t stepPin; ///< Pin number for a step. 00079 uint8_t enableOn; 00080 // uint8_t invertDir; ///< 1 if the direction of the extruder should be inverted. 00081 float maxFeedrate; 00082 float maxAcceleration; 00083 float maxStartFeedrate; 00084 int32_t extrudePosition; 00085 int16_t watchPeriod; 00086 int16_t waitRetractTemperature; 00087 int16_t waitRetractUnits; 00088 #ifdef USE_ADVANCE 00089 #ifdef ENABLE_QUADRATIC_ADVANCE 00090 float advanceK; 00091 #endif 00092 float advanceL; 00093 int16_t advanceBacklash; 00094 #endif 00095 TemperatureController tempControl; 00096 const char * PROGMEM selectCommands; 00097 const char * PROGMEM deselectCommands; 00098 uint8_t coolerSpeed; 00099 uint8_t coolerPWM; 00100 00104 static inline void step() 00105 { 00106 #if NUM_EXTRUDER==1 00107 WRITE(EXT0_STEP_PIN,HIGH); 00108 #else 00109 switch(Extruder::current->id) 00110 { 00111 case 0: 00112 #if NUM_EXTRUDER>0 00113 WRITE(EXT0_STEP_PIN,HIGH); 00114 #if FEATURE_DITTO_PRINTING 00115 if(Extruder::dittoMode) { 00116 WRITE(EXT1_STEP_PIN,HIGH); 00117 } 00118 #endif 00119 #endif 00120 break; 00121 #if defined(EXT1_STEP_PIN) && NUM_EXTRUDER>1 00122 case 1: 00123 WRITE(EXT1_STEP_PIN,HIGH); 00124 break; 00125 #endif 00126 #if defined(EXT2_STEP_PIN) && NUM_EXTRUDER>2 00127 case 2: 00128 WRITE(EXT2_STEP_PIN,HIGH); 00129 break; 00130 #endif 00131 #if defined(EXT3_STEP_PIN) && NUM_EXTRUDER>3 00132 case 3: 00133 WRITE(EXT3_STEP_PIN,HIGH); 00134 break; 00135 #endif 00136 #if defined(EXT4_STEP_PIN) && NUM_EXTRUDER>4 00137 case 4: 00138 WRITE(EXT4_STEP_PIN,HIGH); 00139 break; 00140 #endif 00141 #if defined(EXT5_STEP_PIN) && NUM_EXTRUDER>5 00142 case 5: 00143 WRITE(EXT5_STEP_PIN,HIGH); 00144 break; 00145 #endif 00146 } 00147 #endif 00148 } 00153 static inline void unstep() 00154 { 00155 #if NUM_EXTRUDER==1 00156 WRITE(EXT0_STEP_PIN,LOW); 00157 #else 00158 switch(Extruder::current->id) 00159 { 00160 case 0: 00161 #if NUM_EXTRUDER>0 00162 WRITE(EXT0_STEP_PIN,LOW); 00163 #if FEATURE_DITTO_PRINTING 00164 if(Extruder::dittoMode) { 00165 WRITE(EXT1_STEP_PIN,LOW); 00166 } 00167 #endif 00168 #endif 00169 break; 00170 #if defined(EXT1_STEP_PIN) && NUM_EXTRUDER>1 00171 case 1: 00172 WRITE(EXT1_STEP_PIN,LOW); 00173 break; 00174 #endif 00175 #if defined(EXT2_STEP_PIN) && NUM_EXTRUDER>2 00176 case 2: 00177 WRITE(EXT2_STEP_PIN,LOW); 00178 break; 00179 #endif 00180 #if defined(EXT3_STEP_PIN) && NUM_EXTRUDER>3 00181 case 3: 00182 WRITE(EXT3_STEP_PIN,LOW); 00183 break; 00184 #endif 00185 #if defined(EXT4_STEP_PIN) && NUM_EXTRUDER>4 00186 case 4: 00187 WRITE(EXT4_STEP_PIN,LOW); 00188 break; 00189 #endif 00190 #if defined(EXT5_STEP_PIN) && NUM_EXTRUDER>5 00191 case 5: 00192 WRITE(EXT5_STEP_PIN,LOW); 00193 break; 00194 #endif 00195 } 00196 #endif 00197 } 00199 static inline void setDirection(uint8_t dir) 00200 { 00201 #if NUM_EXTRUDER==1 00202 if(dir) 00203 WRITE(EXT0_DIR_PIN,!EXT0_INVERSE); 00204 else 00205 WRITE(EXT0_DIR_PIN,EXT0_INVERSE); 00206 #else 00207 switch(Extruder::current->id) 00208 { 00209 #if NUM_EXTRUDER>0 00210 case 0: 00211 if(dir) 00212 WRITE(EXT0_DIR_PIN,!EXT0_INVERSE); 00213 else 00214 WRITE(EXT0_DIR_PIN,EXT0_INVERSE); 00215 #if FEATURE_DITTO_PRINTING 00216 if(Extruder::dittoMode) { 00217 if(dir) 00218 WRITE(EXT1_DIR_PIN,!EXT1_INVERSE); 00219 else 00220 WRITE(EXT1_DIR_PIN,EXT1_INVERSE); 00221 } 00222 #endif 00223 break; 00224 #endif 00225 #if defined(EXT1_DIR_PIN) && NUM_EXTRUDER>1 00226 case 1: 00227 if(dir) 00228 WRITE(EXT1_DIR_PIN,!EXT1_INVERSE); 00229 else 00230 WRITE(EXT1_DIR_PIN,EXT1_INVERSE); 00231 break; 00232 #endif 00233 #if defined(EXT2_DIR_PIN) && NUM_EXTRUDER>2 00234 case 2: 00235 if(dir) 00236 WRITE(EXT2_DIR_PIN,!EXT2_INVERSE); 00237 else 00238 WRITE(EXT2_DIR_PIN,EXT2_INVERSE); 00239 break; 00240 #endif 00241 #if defined(EXT3_DIR_PIN) && NUM_EXTRUDER>3 00242 case 3: 00243 if(dir) 00244 WRITE(EXT3_DIR_PIN,!EXT3_INVERSE); 00245 else 00246 WRITE(EXT3_DIR_PIN,EXT3_INVERSE); 00247 break; 00248 #endif 00249 #if defined(EXT4_DIR_PIN) && NUM_EXTRUDER>4 00250 case 4: 00251 if(dir) 00252 WRITE(EXT4_DIR_PIN,!EXT4_INVERSE); 00253 else 00254 WRITE(EXT4_DIR_PIN,EXT4_INVERSE); 00255 break; 00256 #endif 00257 #if defined(EXT5_DIR_PIN) && NUM_EXTRUDER>5 00258 case 5: 00259 if(dir) 00260 WRITE(EXT5_DIR_PIN,!EXT5_INVERSE); 00261 else 00262 WRITE(EXT5_DIR_PIN,EXT5_INVERSE); 00263 break; 00264 #endif 00265 } 00266 #endif 00267 } 00268 static inline void enable() 00269 { 00270 #if NUM_EXTRUDER==1 00271 #if EXT0_ENABLE_PIN>-1 00272 WRITE(EXT0_ENABLE_PIN,EXT0_ENABLE_ON ); 00273 #endif 00274 #else 00275 if(Extruder::current->enablePin > -1) 00276 digitalWrite(Extruder::current->enablePin,Extruder::current->enableOn); 00277 #if FEATURE_DITTO_PRINTING 00278 if(Extruder::dittoMode) { 00279 if(extruder[1].enablePin > -1) 00280 digitalWrite(extruder[1].enablePin,extruder[1].enableOn); 00281 } 00282 #endif 00283 #endif 00284 } 00285 static void manageTemperatures(); 00286 static void disableCurrentExtruderMotor(); 00287 static void selectExtruderById(uint8_t extruderId); 00288 static void disableAllHeater(); 00289 static void initExtruder(); 00290 static void initHeatedBed(); 00291 static void setHeatedBedTemperature(float temp_celsius,bool beep = false); 00292 static float getHeatedBedTemperature(); 00293 static void setTemperatureForExtruder(float temp_celsius,uint8_t extr,bool beep = false); 00294 }; 00295 00296 #if HAVE_HEATED_BED 00297 #define NUM_TEMPERATURE_LOOPS NUM_EXTRUDER+1 00298 extern TemperatureController heatedBedController; 00299 #else 00300 #define NUM_TEMPERATURE_LOOPS NUM_EXTRUDER 00301 #endif 00302 #define TEMP_INT_TO_FLOAT(temp) ((float)(temp)/(float)(1<<CELSIUS_EXTRA_BITS)) 00303 #define TEMP_FLOAT_TO_INT(temp) ((int)((temp)*(1<<CELSIUS_EXTRA_BITS))) 00304 00305 //extern Extruder *Extruder::current; 00306 extern TemperatureController *tempController[NUM_TEMPERATURE_LOOPS]; 00307 extern uint8_t autotuneIndex; 00308 00309 00310 #endif // EXTRUDER_H_INCLUDED