reformating and some minor bugs/things found on the way.
This commit is contained in:
		| @@ -1,5 +1,5 @@ | ||||
| #ifndef CONFIGURATION_H | ||||
| #define CONFIGURATION_H | ||||
| #ifndef __CONFIGURATION_H | ||||
| #define __CONFIGURATION_H | ||||
|  | ||||
| //#define DEBUG_STEPS | ||||
|  | ||||
| @@ -118,10 +118,7 @@ const int dropsegments=5; //everything with this number of steps  will be ignore | ||||
| #define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E | ||||
| //note: on bernhards ultimaker 200 200 12 are working well. | ||||
| #define HOMING_FEEDRATE {50*60, 50*60, 12*60, 0}  // set the homing speeds | ||||
| //the followint checks if an extrusion is existent in the move. if _not_, the speed of the move is set to the maximum speed.  | ||||
| //!!!!!!Use only if you know that your printer works at the maximum declared speeds. | ||||
| // works around the skeinforge cool-bug. There all moves are slowed to have a minimum layer time. However slow travel moves= ooze | ||||
| #define TRAVELING_AT_MAXSPEED   | ||||
|  | ||||
| #define AXIS_RELATIVE_MODES {false, false, false, false} | ||||
|  | ||||
| #define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step) | ||||
| @@ -177,41 +174,50 @@ const int dropsegments=5; //everything with this number of steps  will be ignore | ||||
| //#define_HEATER_1_MAXTEMP 275 | ||||
| //#define BED_MAXTEMP 150 | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| /// PID settings: | ||||
| // Uncomment the following line to enable PID support. | ||||
|    | ||||
| #define PIDTEMP | ||||
| #ifdef PIDTEMP | ||||
|   /// PID settings: | ||||
|   // Uncomment the following line to enable PID support. | ||||
|   //#define SMOOTHING | ||||
|   //#define SMOOTHFACTOR 5.0 | ||||
|   //float current_raw_average=0; | ||||
|     #define K1 0.95 //smoothing of the PID | ||||
|   //#define PID_DEBUG // Sends debug data to the serial port.  | ||||
|   //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in % | ||||
|   #define PID_MAX 255 // limits current to nozzle | ||||
|   #define PID_INTEGRAL_DRIVE_MAX 255 | ||||
|   #define PID_dT 0.1 | ||||
|  //machine with red silicon: 1950:45 second ; with fan fully blowin 3000:47 | ||||
|    | ||||
|   #define PID_MAX 255 // limits current to nozzle; 255=full current | ||||
|   #define PID_INTEGRAL_DRIVE_MAX 255  //limit for the integral term | ||||
|   #define K1 0.95 //smoothing factor withing the PID | ||||
|   #define PID_dT 0.1 //sampling period of the PID | ||||
|  | ||||
|   //To develop some PID settings for your machine, you can initiall follow  | ||||
|   // the Ziegler-Nichols method. | ||||
|   // set Ki and Kd to zero.  | ||||
|   // heat with a defined Kp and see if the temperature stabilizes | ||||
|   // ideally you do this graphically with repg. | ||||
|   // the PID_CRITIAL_GAIN should be the Kp at which temperature oscillatins are not dampned out/decreas in amplitutde | ||||
|   // PID_SWING_AT_CRITIAL is the time for a full period of the oscillations at the critical Gain | ||||
|   // usually further manual tunine is necessary. | ||||
|  | ||||
|   #define PID_CRITIAL_GAIN 3000 | ||||
|   #define PID_SWING_AT_CRITIAL 45 //seconds | ||||
|   #define PIDIADD 5 | ||||
|   /* | ||||
|   //PID according to Ziegler-Nichols method | ||||
|   float Kp = 0.6*PID_CRITIAL_GAIN;  | ||||
|   float Ki =PIDIADD+2*Kp/PID_SWING_AT_CRITIAL*PID_dT;   | ||||
|   float Kd = Kp*PID_SWING_AT_CRITIAL/8./PID_dT;   | ||||
|   */ | ||||
|   //PI according to Ziegler-Nichols method | ||||
|   #define  DEFAULT_Kp (PID_CRITIAL_GAIN/2.2)  | ||||
|   #define  DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT) | ||||
|   #define  DEFAULT_Kd (0) | ||||
|    | ||||
|   #define PID_PI    //no differentail term | ||||
|   //#define PID_PID //normal PID | ||||
|  | ||||
|   #ifdef PID_PID | ||||
|     //PID according to Ziegler-Nichols method | ||||
|     #define  DEFAULT_Kp  (0.6*PID_CRITIAL_GAIN) | ||||
|     #define  DEFAULT_Ki (2*Kp/PID_SWING_AT_CRITIAL*PID_dT)   | ||||
|     #define  DEFAULT_Kd (PID_SWING_AT_CRITIAL/8./PID_dT)   | ||||
|   #endif | ||||
|   | ||||
|   #ifdef PID_PI | ||||
|     //PI according to Ziegler-Nichols method | ||||
|     #define  DEFAULT_Kp (PID_CRITIAL_GAIN/2.2)  | ||||
|     #define  DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT) | ||||
|     #define  DEFAULT_Kd (0) | ||||
|   #endif | ||||
|    | ||||
|   // this adds an experimental additional term to the heatingpower, proportional to the extrusion speed. | ||||
|   // if Kc is choosen well, the additional required power due to increased melting should be compensated. | ||||
|   #define PID_ADD_EXTRUSION_RATE   | ||||
|   #ifdef PID_ADD_EXTRUSION_RATE | ||||
|     #define  DEFAULT_Kc (5) //heatingpower=Kc*(e_speed) | ||||
| @@ -228,22 +234,21 @@ const int dropsegments=5; //everything with this number of steps  will be ignore | ||||
| //#define ADVANCE | ||||
|  | ||||
| #ifdef ADVANCE | ||||
| #define EXTRUDER_ADVANCE_K .3 | ||||
|   #define EXTRUDER_ADVANCE_K .3 | ||||
|  | ||||
| #define D_FILAMENT 1.7 | ||||
| #define STEPS_MM_E 65 | ||||
| #define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159) | ||||
| #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA) | ||||
|   #define D_FILAMENT 1.7 | ||||
|   #define STEPS_MM_E 65 | ||||
|   #define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159) | ||||
|   #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA) | ||||
|  | ||||
| #endif // ADVANCE | ||||
|  | ||||
| // THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, e.g. 8,16,32  | ||||
| #if defined SDSUPPORT | ||||
| // The number of linear motions that can be in the plan at any give time.   | ||||
| // THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, i.g. 8,16,32 because shifts and ors are used to do the ringbuffering. | ||||
| #if defined SDSUPPORT | ||||
|   #define BLOCK_BUFFER_SIZE 16   // SD,LCD,Buttons take more memory, block buffer needs to be smaller | ||||
| #else | ||||
|   #define BLOCK_BUFFER_SIZE 16 // maximize block buffer | ||||
| #endif | ||||
|  | ||||
|  | ||||
| #endif | ||||
| #endif //__CONFIGURATION_H | ||||
|   | ||||
| @@ -1,39 +1,42 @@ | ||||
| #ifndef __EEPROMH | ||||
| #define __EEPROMH | ||||
|  | ||||
| #include "Marlin.h" | ||||
| #include "planner.h" | ||||
| #include "temperature.h" | ||||
| #include <EEPROM.h> | ||||
| #include "Marlin.h" | ||||
| #include "streaming.h" | ||||
|  | ||||
| //====================================================================================== | ||||
| template <class T> int EEPROM_writeAnything(int &ee, const T& value) | ||||
| { | ||||
|     const byte* p = (const byte*)(const void*)&value; | ||||
|     int i; | ||||
|     for (i = 0; i < (int)sizeof(value); i++) | ||||
| 	  EEPROM.write(ee++, *p++); | ||||
|     return i; | ||||
|   const byte* p = (const byte*)(const void*)&value; | ||||
|   int i; | ||||
|   for (i = 0; i < (int)sizeof(value); i++) | ||||
|     EEPROM.write(ee++, *p++); | ||||
|   return i; | ||||
| } | ||||
| //====================================================================================== | ||||
|  | ||||
| template <class T> int EEPROM_readAnything(int &ee, T& value) | ||||
| { | ||||
|     byte* p = (byte*)(void*)&value; | ||||
|     int i; | ||||
|     for (i = 0; i < (int)sizeof(value); i++) | ||||
| 	  *p++ = EEPROM.read(ee++); | ||||
|     return i; | ||||
|   byte* p = (byte*)(void*)&value; | ||||
|   int i; | ||||
|   for (i = 0; i < (int)sizeof(value); i++) | ||||
|     *p++ = EEPROM.read(ee++); | ||||
|   return i; | ||||
| } | ||||
| //====================================================================================== | ||||
|  | ||||
| #define EEPROM_OFFSET 100 | ||||
|  | ||||
| #define EEPROM_VERSION "V04"  // IMPORTANT:  Whenever there are changes made to the variables stored in EEPROM | ||||
|                               // in the functions below, also increment the version number. This makes sure that | ||||
|                               // the default values are used whenever there is a change to the data, to prevent | ||||
|                               // wrong data being written to the variables. | ||||
|                               // ALSO:  always make sure the variables in the Store and retrieve sections are in the same order. | ||||
| void StoreSettings() { | ||||
|  | ||||
| // IMPORTANT:  Whenever there are changes made to the variables stored in EEPROM | ||||
| // in the functions below, also increment the version number. This makes sure that | ||||
| // the default values are used whenever there is a change to the data, to prevent | ||||
| // wrong data being written to the variables. | ||||
| // ALSO:  always make sure the variables in the Store and retrieve sections are in the same order. | ||||
| #define EEPROM_VERSION "V04"   | ||||
|  | ||||
| void StoreSettings()  | ||||
| { | ||||
|   char ver[4]= "000"; | ||||
|   int i=EEPROM_OFFSET; | ||||
|   EEPROM_writeAnything(i,ver); // invalidate data first  | ||||
| @@ -48,52 +51,55 @@ void StoreSettings() { | ||||
|   EEPROM_writeAnything(i,max_xy_jerk); | ||||
|   EEPROM_writeAnything(i,max_z_jerk); | ||||
|   #ifdef PIDTEMP | ||||
|   EEPROM_writeAnything(i,Kp); | ||||
|   EEPROM_writeAnything(i,Ki); | ||||
|   EEPROM_writeAnything(i,Kd); | ||||
| #else | ||||
|   EEPROM_writeAnything(i,3000); | ||||
|   EEPROM_writeAnything(i,0); | ||||
|   EEPROM_writeAnything(i,0); | ||||
| #endif | ||||
|     EEPROM_writeAnything(i,Kp); | ||||
|     EEPROM_writeAnything(i,Ki); | ||||
|     EEPROM_writeAnything(i,Kd); | ||||
|   #else | ||||
|     EEPROM_writeAnything(i,3000); | ||||
|     EEPROM_writeAnything(i,0); | ||||
|     EEPROM_writeAnything(i,0); | ||||
|   #endif | ||||
|   char ver2[4]=EEPROM_VERSION; | ||||
|   i=EEPROM_OFFSET; | ||||
|   EEPROM_writeAnything(i,ver2); // validate data | ||||
|    SERIAL_ECHOLN("Settings Stored"); | ||||
|  | ||||
|   SERIAL_ECHOLN("Settings Stored"); | ||||
| } | ||||
|  | ||||
| void RetrieveSettings(bool def=false){  // if def=true, the default values will be used | ||||
| void RetrieveSettings(bool def=false) | ||||
| {  // if def=true, the default values will be used | ||||
|   int i=EEPROM_OFFSET; | ||||
|   char stored_ver[4]; | ||||
|   char ver[4]=EEPROM_VERSION; | ||||
|   EEPROM_readAnything(i,stored_ver); //read stored version | ||||
| //  SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]"); | ||||
|   if ((!def)&&(strncmp(ver,stored_ver,3)==0)) {   // version number match | ||||
|       EEPROM_readAnything(i,axis_steps_per_unit);   | ||||
|       EEPROM_readAnything(i,max_feedrate);   | ||||
|       EEPROM_readAnything(i,max_acceleration_units_per_sq_second); | ||||
|       EEPROM_readAnything(i,acceleration); | ||||
|       EEPROM_readAnything(i,retract_acceleration); | ||||
|       EEPROM_readAnything(i,minimumfeedrate); | ||||
|       EEPROM_readAnything(i,mintravelfeedrate); | ||||
|       EEPROM_readAnything(i,minsegmenttime); | ||||
|       EEPROM_readAnything(i,max_xy_jerk); | ||||
|       EEPROM_readAnything(i,max_z_jerk); | ||||
| #ifndef PIDTEMP | ||||
|   //  SERIAL_ECHOLN("Version: [" << ver << "] Stored version: [" << stored_ver << "]"); | ||||
|   if ((!def)&&(strncmp(ver,stored_ver,3)==0))  | ||||
|   {   // version number match | ||||
|     EEPROM_readAnything(i,axis_steps_per_unit);   | ||||
|     EEPROM_readAnything(i,max_feedrate);   | ||||
|     EEPROM_readAnything(i,max_acceleration_units_per_sq_second); | ||||
|     EEPROM_readAnything(i,acceleration); | ||||
|     EEPROM_readAnything(i,retract_acceleration); | ||||
|     EEPROM_readAnything(i,minimumfeedrate); | ||||
|     EEPROM_readAnything(i,mintravelfeedrate); | ||||
|     EEPROM_readAnything(i,minsegmenttime); | ||||
|     EEPROM_readAnything(i,max_xy_jerk); | ||||
|     EEPROM_readAnything(i,max_z_jerk); | ||||
|     #ifndef PIDTEMP | ||||
|       float Kp,Ki,Kd; | ||||
| #endif | ||||
|       EEPROM_readAnything(i,Kp); | ||||
|       EEPROM_readAnything(i,Ki); | ||||
|       EEPROM_readAnything(i,Kd); | ||||
|     #endif | ||||
|     EEPROM_readAnything(i,Kp); | ||||
|     EEPROM_readAnything(i,Ki); | ||||
|     EEPROM_readAnything(i,Kd); | ||||
|  | ||||
|       SERIAL_ECHOLN("Stored settings retreived:"); | ||||
|     SERIAL_ECHOLN("Stored settings retreived:"); | ||||
|   } | ||||
|   else { | ||||
|   else  | ||||
|   { | ||||
|     float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT; | ||||
|     float tmp2[]=DEFAULT_MAX_FEEDRATE; | ||||
|     long tmp3[]=DEFAULT_MAX_ACCELERATION; | ||||
|     for (int i=0;i<4;i++) { | ||||
|     for (short i=0;i<4;i++)  | ||||
|     { | ||||
|       axis_steps_per_unit[i]=tmp1[i];   | ||||
|       max_feedrate[i]=tmp2[i];   | ||||
|       max_acceleration_units_per_sq_second[i]=tmp3[i]; | ||||
| @@ -117,11 +123,10 @@ void RetrieveSettings(bool def=false){  // if def=true, the default values will | ||||
|   SERIAL_ECHOLN("   M204 S"  <<_FLOAT(acceleration,2) << " T" << _FLOAT(retract_acceleration,2)); | ||||
|   SERIAL_ECHOLN("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_ECHOLN("   M205 S"  <<_FLOAT(minimumfeedrate/60,2) << " T" << _FLOAT(mintravelfeedrate/60,2) << " B" << _FLOAT(minsegmenttime,2) << " X" << _FLOAT(max_xy_jerk/60,2) << " Z" << _FLOAT(max_z_jerk/60,2)); | ||||
| #ifdef PIDTEMP | ||||
|   SERIAL_ECHOLN("PID settings:"); | ||||
|   SERIAL_ECHOLN("   M301 P"  << _FLOAT(Kp,3) << " I" << _FLOAT(Ki,3) << " D" << _FLOAT(Kd,3));   | ||||
| #endif | ||||
|    | ||||
|   #ifdef PIDTEMP | ||||
|     SERIAL_ECHOLN("PID settings:"); | ||||
|     SERIAL_ECHOLN("   M301 P"  << _FLOAT(Kp,3) << " I" << _FLOAT(Ki,3) << " D" << _FLOAT(Kd,3));   | ||||
|   #endif | ||||
| }   | ||||
|  | ||||
| #endif | ||||
|   | ||||
| @@ -18,41 +18,39 @@ void process_commands(); | ||||
| void manage_inactivity(byte debug); | ||||
|  | ||||
| #if X_ENABLE_PIN > -1 | ||||
| #define  enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON) | ||||
| #define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON) | ||||
|   #define  enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON) | ||||
|   #define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON) | ||||
| #else | ||||
| #define enable_x() ; | ||||
| #define disable_x() ; | ||||
|   #define enable_x() ; | ||||
|   #define disable_x() ; | ||||
| #endif | ||||
|  | ||||
| #if Y_ENABLE_PIN > -1 | ||||
| #define  enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON) | ||||
| #define disable_y() WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON) | ||||
|   #define  enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON) | ||||
|   #define disable_y() WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON) | ||||
| #else | ||||
| #define enable_y() ; | ||||
| #define disable_y() ; | ||||
|   #define enable_y() ; | ||||
|   #define disable_y() ; | ||||
| #endif | ||||
|  | ||||
| #if Z_ENABLE_PIN > -1 | ||||
| #define  enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON) | ||||
| #define disable_z() WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON) | ||||
|   #define  enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON) | ||||
|   #define disable_z() WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON) | ||||
| #else | ||||
| #define enable_z() ; | ||||
| #define disable_z() ; | ||||
|   #define enable_z() ; | ||||
|   #define disable_z() ; | ||||
| #endif | ||||
|  | ||||
| #if E_ENABLE_PIN > -1 | ||||
|  | ||||
| 	#define  enable_e() WRITE(E_ENABLE_PIN, E_ENABLE_ON) | ||||
| 	#define disable_e() WRITE(E_ENABLE_PIN,!E_ENABLE_ON) | ||||
|  | ||||
|   #define  enable_e() WRITE(E_ENABLE_PIN, E_ENABLE_ON) | ||||
|   #define disable_e() WRITE(E_ENABLE_PIN,!E_ENABLE_ON) | ||||
| #else | ||||
| #define enable_e() ; | ||||
| #define disable_e() ; | ||||
|   #define enable_e() ; | ||||
|   #define disable_e() ; | ||||
| #endif | ||||
|  | ||||
| #define X_AXIS 0 | ||||
| #define Y_AXIS 1 | ||||
| #define Z_AXIS 2 | ||||
| #define E_AXIS 3 | ||||
| enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3}; | ||||
|  | ||||
|  | ||||
| void FlushSerialRequestResend(); | ||||
| void ClearToSend(); | ||||
| @@ -61,26 +59,15 @@ void get_coordinates(); | ||||
| void prepare_move(); | ||||
| void kill(); | ||||
|  | ||||
| //void check_axes_activity(); | ||||
| //void plan_init(); | ||||
| //void st_init(); | ||||
| //void tp_init(); | ||||
| //void plan_buffer_line(float x, float y, float z, float e, float feed_rate); | ||||
| //void plan_set_position(float x, float y, float z, float e); | ||||
| //void st_wake_up(); | ||||
| //void st_synchronize(); | ||||
| void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer. | ||||
|  | ||||
|  | ||||
| #ifndef CRITICAL_SECTION_START | ||||
| #define CRITICAL_SECTION_START  unsigned char _sreg = SREG; cli(); | ||||
| #define CRITICAL_SECTION_END    SREG = _sreg; | ||||
|   #define CRITICAL_SECTION_START  unsigned char _sreg = SREG; cli(); | ||||
|   #define CRITICAL_SECTION_END    SREG = _sreg; | ||||
| #endif //CRITICAL_SECTION_START | ||||
|  | ||||
| extern float homing_feedrate[]; | ||||
| extern bool axis_relative_modes[]; | ||||
|  | ||||
|  | ||||
| void kill(); | ||||
|  | ||||
| #endif | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -33,8 +33,8 @@ | ||||
| void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8_t axis_1,  | ||||
|   uint8_t axis_linear, float feed_rate, float radius, uint8_t isclockwise) | ||||
| {       | ||||
| //   int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled(); | ||||
| //   plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc | ||||
|   //   int acceleration_manager_was_enabled = plan_is_acceleration_manager_enabled(); | ||||
|   //   plan_set_acceleration_manager_enabled(false); // disable acceleration management for the duration of the arc | ||||
|   SERIAL_ECHOLN("mc_arc."); | ||||
|   float center_axis0 = position[axis_0] + offset[axis_0]; | ||||
|   float center_axis1 = position[axis_1] + offset[axis_1]; | ||||
| @@ -52,12 +52,12 @@ void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8 | ||||
|   float millimeters_of_travel = hypot(angular_travel*radius, fabs(linear_travel)); | ||||
|   if (millimeters_of_travel == 0.0) { return; } | ||||
|   uint16_t segments = floor(millimeters_of_travel/MM_PER_ARC_SEGMENT); | ||||
| /*   | ||||
|   // Multiply inverse feed_rate to compensate for the fact that this movement is approximated | ||||
|   // by a number of discrete segments. The inverse feed_rate should be correct for the sum of  | ||||
|   // all segments. | ||||
|   if (invert_feed_rate) { feed_rate *= segments; } | ||||
| */ | ||||
|   /*   | ||||
|     // Multiply inverse feed_rate to compensate for the fact that this movement is approximated | ||||
|     // by a number of discrete segments. The inverse feed_rate should be correct for the sum of  | ||||
|     // all segments. | ||||
|     if (invert_feed_rate) { feed_rate *= segments; } | ||||
|   */ | ||||
|   float theta_per_segment = angular_travel/segments; | ||||
|   float linear_per_segment = linear_travel/segments; | ||||
|    | ||||
| @@ -128,6 +128,6 @@ void mc_arc(float *position, float *target, float *offset, uint8_t axis_0, uint8 | ||||
|   // Ensure last segment arrives at target location. | ||||
|   plan_buffer_line(target[X_AXIS], target[Y_AXIS], target[Z_AXIS], target[E_AXIS], feed_rate); | ||||
|  | ||||
| //   plan_set_acceleration_manager_enabled(acceleration_manager_was_enabled); | ||||
|   //   plan_set_acceleration_manager_enabled(acceleration_manager_was_enabled); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -557,6 +557,74 @@ | ||||
| #define FAN_PIN            7 | ||||
| #define PS_ON_PIN          12 | ||||
| #define KILL_PIN           -1 | ||||
|  | ||||
| #ifdef ULTRA_LCD | ||||
|  | ||||
|   #ifdef NEWPANEL | ||||
|   //arduino pin witch triggers an piezzo beeper | ||||
|     #define BEEPER 18 | ||||
|  | ||||
|     #define LCD_PINS_RS 20  | ||||
|     #define LCD_PINS_ENABLE 17 | ||||
|     #define LCD_PINS_D4 16 | ||||
|     #define LCD_PINS_D5 21  | ||||
|     #define LCD_PINS_D6 5 | ||||
|     #define LCD_PINS_D7 6 | ||||
|      | ||||
|     //buttons are directly attached | ||||
|     #define BTN_EN1 40 | ||||
|     #define BTN_EN2 42 | ||||
|     #define BTN_ENC 19  //the click | ||||
|      | ||||
|     #define BLEN_C 2 | ||||
|     #define BLEN_B 1 | ||||
|     #define BLEN_A 0 | ||||
|      | ||||
|     #define SDCARDDETECT 38 | ||||
|      | ||||
|       //encoder rotation values | ||||
|     #define encrot0 0 | ||||
|     #define encrot1 2 | ||||
|     #define encrot2 3 | ||||
|     #define encrot3 1 | ||||
|   #else //old style panel with shift register | ||||
|     //arduino pin witch triggers an piezzo beeper | ||||
|     #define BEEPER 18 | ||||
|  | ||||
|     //buttons are attached to a shift register | ||||
|     #define SHIFT_CLK 38 | ||||
|     #define SHIFT_LD 42 | ||||
|     #define SHIFT_OUT 40 | ||||
|     #define SHIFT_EN 17 | ||||
|      | ||||
|     #define LCD_PINS_RS 16  | ||||
|     #define LCD_PINS_ENABLE 5 | ||||
|     #define LCD_PINS_D4 6 | ||||
|     #define LCD_PINS_D5 21  | ||||
|     #define LCD_PINS_D6 20 | ||||
|     #define LCD_PINS_D7 19 | ||||
|      | ||||
|     //encoder rotation values | ||||
|     #define encrot0 0 | ||||
|     #define encrot1 2 | ||||
|     #define encrot2 3 | ||||
|     #define encrot3 1 | ||||
|  | ||||
|      | ||||
|     //bits in the shift register that carry the buttons for: | ||||
|     // left up center down right red | ||||
|     #define BL_LE 7 | ||||
|     #define BL_UP 6 | ||||
|     #define BL_MI 5 | ||||
|     #define BL_DW 4 | ||||
|     #define BL_RI 3 | ||||
|     #define BL_ST 2 | ||||
|  | ||||
|     #define BLEN_B 1 | ||||
|     #define BLEN_A 0 | ||||
|   #endif  | ||||
| #endif //ULTRA_LCD | ||||
|  | ||||
| #endif | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -83,7 +83,7 @@ static volatile unsigned char block_buffer_head;           // Index of the next | ||||
| static volatile unsigned char block_buffer_tail;           // Index of the block to process now | ||||
|  | ||||
| // The current position of the tool in absolute steps | ||||
|  long position[4];    | ||||
| long position[4];    | ||||
|  | ||||
| #define ONE_MINUTE_OF_MICROSECONDS 60000000.0 | ||||
|  | ||||
| @@ -123,10 +123,10 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit | ||||
|   long initial_rate = ceil(block->nominal_rate*entry_factor); | ||||
|   long final_rate = ceil(block->nominal_rate*exit_factor); | ||||
|    | ||||
| #ifdef ADVANCE | ||||
|   long initial_advance = block->advance*entry_factor*entry_factor; | ||||
|   long final_advance = block->advance*exit_factor*exit_factor; | ||||
| #endif // ADVANCE | ||||
|   #ifdef ADVANCE | ||||
|     long initial_advance = block->advance*entry_factor*entry_factor; | ||||
|     long final_advance = block->advance*exit_factor*exit_factor; | ||||
|   #endif // ADVANCE | ||||
|  | ||||
|   // Limit minimal step rate (Otherwise the timer will overflow.) | ||||
|   if(initial_rate <120) initial_rate=120; | ||||
| @@ -155,10 +155,10 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit | ||||
|     block->decelerate_after = decelerate_after; | ||||
|     block->initial_rate = initial_rate; | ||||
|     block->final_rate = final_rate; | ||||
| #ifdef ADVANCE | ||||
|     block->initial_advance = initial_advance; | ||||
|     block->final_advance = final_advance; | ||||
| #endif //ADVANCE | ||||
|   #ifdef ADVANCE | ||||
|       block->initial_advance = initial_advance; | ||||
|       block->final_advance = final_advance; | ||||
|   #endif //ADVANCE | ||||
|   } | ||||
|   CRITICAL_SECTION_END; | ||||
| }                     | ||||
| @@ -166,18 +166,15 @@ void calculate_trapezoid_for_block(block_t *block, float entry_speed, float exit | ||||
| // Calculates the maximum allowable speed at this point when you must be able to reach target_velocity using the  | ||||
| // acceleration within the allotted distance. | ||||
| inline float max_allowable_speed(float acceleration, float target_velocity, float distance) { | ||||
|   return( | ||||
|   sqrt(target_velocity*target_velocity-2*acceleration*60*60*distance) | ||||
|     ); | ||||
|   return  sqrt(target_velocity*target_velocity-2*acceleration*60*60*distance); | ||||
| } | ||||
|  | ||||
| // "Junction jerk" in this context is the immediate change in speed at the junction of two blocks. | ||||
| // This method will calculate the junction jerk as the euclidean distance between the nominal  | ||||
| // velocities of the respective blocks. | ||||
| inline float junction_jerk(block_t *before, block_t *after) { | ||||
|   return(sqrt( | ||||
|     pow((before->speed_x-after->speed_x), 2)+ | ||||
|     pow((before->speed_y-after->speed_y), 2))); | ||||
|   return sqrt( | ||||
|     pow((before->speed_x-after->speed_x), 2)+pow((before->speed_y-after->speed_y), 2)); | ||||
| } | ||||
|  | ||||
| // Return the safe speed which is max_jerk/2, e.g. the  | ||||
| @@ -185,8 +182,10 @@ inline float junction_jerk(block_t *before, block_t *after) { | ||||
| float safe_speed(block_t *block) { | ||||
|   float safe_speed; | ||||
|   safe_speed = max_xy_jerk/2;   | ||||
|   if(abs(block->speed_z) > max_z_jerk/2) safe_speed = max_z_jerk/2; | ||||
|   if (safe_speed > block->nominal_speed) safe_speed = block->nominal_speed; | ||||
|   if(abs(block->speed_z) > max_z_jerk/2)  | ||||
|     safe_speed = max_z_jerk/2; | ||||
|   if (safe_speed > block->nominal_speed)  | ||||
|     safe_speed = block->nominal_speed; | ||||
|   return safe_speed;   | ||||
| } | ||||
|  | ||||
| @@ -379,9 +378,8 @@ void check_axes_activity() { | ||||
| // Add a new linear movement to the buffer. steps_x, _y and _z is the absolute position in  | ||||
| // mm. Microseconds specify how many microseconds the move should take to perform. To aid acceleration | ||||
| // calculation the caller must also provide the physical length of the line in millimeters. | ||||
| void plan_buffer_line(float x, float y, float z, float e, float feed_rate) { | ||||
|  | ||||
|  | ||||
| void plan_buffer_line(const float &x, const float &y, const float &z, const float &e,  float feed_rate) | ||||
| { | ||||
|   // Calculate the buffer head after we push this byte | ||||
|   int next_buffer_head = (block_buffer_head + 1) & (BLOCK_BUFFER_SIZE - 1); | ||||
|  | ||||
| @@ -469,11 +467,8 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) { | ||||
|   // Limit speed per axis | ||||
|   float speed_factor = 1; //factor <=1 do decrease speed | ||||
|   if(abs(block->speed_x) > max_feedrate[X_AXIS]) { | ||||
|     //// [ErikDeBruijn] IS THIS THE BUG WE'RE LOOING FOR???? | ||||
|     //// [bernhard] No its not, according to Zalm. | ||||
| 		//// the if would always be true, since tmp_speedfactor <=0 due the inial if, so its safe to set. the next lines actually compare. | ||||
|     speed_factor = max_feedrate[X_AXIS] / abs(block->speed_x); | ||||
|     //if(speed_factor > tmp_speed_factor) speed_factor = tmp_speed_factor; | ||||
|     //if(speed_factor > tmp_speed_factor) speed_factor = tmp_speed_factor; /is not need here because auf the init above | ||||
|   } | ||||
|   if(abs(block->speed_y) > max_feedrate[Y_AXIS]){ | ||||
|     float tmp_speed_factor = max_feedrate[Y_AXIS] / abs(block->speed_y); | ||||
| @@ -495,7 +490,8 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) { | ||||
|   block->nominal_speed = block->millimeters * multiplier; | ||||
|   block->nominal_rate = ceil(block->step_event_count * multiplier / 60);   | ||||
|  | ||||
|   if(block->nominal_rate < 120) block->nominal_rate = 120; | ||||
|   if(block->nominal_rate < 120)  | ||||
|     block->nominal_rate = 120; | ||||
|   block->entry_speed = safe_speed(block); | ||||
|  | ||||
|   // Compute the acceleration rate for the trapezoid generator.  | ||||
| @@ -527,25 +523,25 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) { | ||||
|   block->acceleration = block->acceleration_st * travel_per_step; | ||||
|   block->acceleration_rate = (long)((float)block->acceleration_st * 8.388608); | ||||
|  | ||||
| #ifdef ADVANCE | ||||
|   // Calculate advance rate | ||||
|   if((block->steps_e == 0) || (block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0)) { | ||||
|     block->advance_rate = 0; | ||||
|     block->advance = 0; | ||||
|   } | ||||
|   else { | ||||
|     long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_st); | ||||
|     float advance = (STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K) *  | ||||
|       (block->speed_e * block->speed_e * EXTRUTION_AREA * EXTRUTION_AREA / 3600.0)*65536; | ||||
|     block->advance = advance; | ||||
|     if(acc_dist == 0) { | ||||
|   #ifdef ADVANCE | ||||
|     // Calculate advance rate | ||||
|     if((block->steps_e == 0) || (block->steps_x == 0 && block->steps_y == 0 && block->steps_z == 0)) { | ||||
|       block->advance_rate = 0; | ||||
|     }  | ||||
|     else { | ||||
|       block->advance_rate = advance / (float)acc_dist; | ||||
|       block->advance = 0; | ||||
|     } | ||||
|   } | ||||
| #endif // ADVANCE | ||||
|     else { | ||||
|       long acc_dist = estimate_acceleration_distance(0, block->nominal_rate, block->acceleration_st); | ||||
|       float advance = (STEPS_PER_CUBIC_MM_E * EXTRUDER_ADVANCE_K) *  | ||||
|         (block->speed_e * block->speed_e * EXTRUTION_AREA * EXTRUTION_AREA / 3600.0)*65536; | ||||
|       block->advance = advance; | ||||
|       if(acc_dist == 0) { | ||||
|         block->advance_rate = 0; | ||||
|       }  | ||||
|       else { | ||||
|         block->advance_rate = advance / (float)acc_dist; | ||||
|       } | ||||
|     } | ||||
|   #endif // ADVANCE | ||||
|  | ||||
|   // compute a preliminary conservative acceleration trapezoid | ||||
|   float safespeed = safe_speed(block); | ||||
| @@ -576,7 +572,7 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) { | ||||
|   st_wake_up(); | ||||
| } | ||||
|  | ||||
| void plan_set_position(float x, float y, float z, float e) | ||||
| void plan_set_position(const float &x, const float &y, const float &z, const float &e) | ||||
| { | ||||
|   position[X_AXIS] = lround(x*axis_steps_per_unit[X_AXIS]); | ||||
|   position[Y_AXIS] = lround(y*axis_steps_per_unit[Y_AXIS]); | ||||
|   | ||||
| @@ -32,16 +32,16 @@ typedef struct { | ||||
|   // Fields used by the bresenham algorithm for tracing the line | ||||
|   long steps_x, steps_y, steps_z, steps_e;  // Step count along each axis | ||||
|   long step_event_count;                    // The number of step events required to complete this block | ||||
|   volatile long accelerate_until;                    // The index of the step event on which to stop acceleration | ||||
|   volatile long decelerate_after;                    // The index of the step event on which to start decelerating | ||||
|   volatile long acceleration_rate;                   // The acceleration rate used for acceleration calculation | ||||
|   volatile long accelerate_until;           // The index of the step event on which to stop acceleration | ||||
|   volatile long decelerate_after;           // The index of the step event on which to start decelerating | ||||
|   volatile long acceleration_rate;          // The acceleration rate used for acceleration calculation | ||||
|   unsigned char direction_bits;             // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h) | ||||
| #ifdef ADVANCE | ||||
|   long advance_rate; | ||||
|   volatile long initial_advance; | ||||
|   volatile long final_advance; | ||||
|   float advance; | ||||
| #endif | ||||
|   #ifdef ADVANCE | ||||
|     long advance_rate; | ||||
|     volatile long initial_advance; | ||||
|     volatile long final_advance; | ||||
|     float advance; | ||||
|   #endif | ||||
|  | ||||
|   // Fields used by the motion planner to manage acceleration | ||||
|   float speed_x, speed_y, speed_z, speed_e;          // Nominal mm/minute for each axis | ||||
| @@ -57,16 +57,17 @@ typedef struct { | ||||
|   long acceleration_st;                              // acceleration steps/sec^2 | ||||
|   volatile char busy; | ||||
| } block_t; | ||||
|        | ||||
|  | ||||
| // Initialize the motion plan subsystem       | ||||
| void plan_init(); | ||||
|  | ||||
| // Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in  | ||||
| // millimaters. Feed rate specifies the speed of the motion. | ||||
| void plan_buffer_line(float x, float y, float z, float e, float feed_rate); | ||||
| void plan_buffer_line(const float &x, const float &y, const float &z, const float &e, float feed_rate); | ||||
|  | ||||
| // Set position. Used for G92 instructions. | ||||
| void plan_set_position(float x, float y, float z, float e); | ||||
| void plan_set_position(const float &x, const float &y, const float &z, const float &e); | ||||
|  | ||||
|  | ||||
| // Called when the current block is no longer needed. Discards the block and makes the memory | ||||
| // availible for new blocks. | ||||
|   | ||||
| @@ -37,6 +37,7 @@ uint16_t speed_lookuptable_fast[256][2] PROGMEM = {\ | ||||
| { 32, 0}, { 32, 0}, { 32, 0}, { 32, 0}, { 32, 1}, { 31, 0}, { 31, 0}, { 31, 0},  | ||||
| { 31, 0}, { 31, 0}, { 31, 0}, { 31, 1}, { 30, 0}, { 30, 0}, { 30, 0}, { 30, 0} | ||||
| }; | ||||
|  | ||||
| uint16_t speed_lookuptable_slow[256][2] PROGMEM = {\ | ||||
| { 62500, 12500}, { 50000, 8334}, { 41666, 5952}, { 35714, 4464}, { 31250, 3473}, { 27777, 2777}, { 25000, 2273}, { 22727, 1894},  | ||||
| { 20833, 1603}, { 19230, 1373}, { 17857, 1191}, { 16666, 1041}, { 15625, 920}, { 14705, 817}, { 13888, 731}, { 13157, 657},  | ||||
|   | ||||
| @@ -35,8 +35,8 @@ | ||||
| // if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer. | ||||
| // for debugging purposes only, should be disabled by default | ||||
| #ifdef DEBUG_STEPS | ||||
| volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0}; | ||||
| volatile int count_direction[NUM_AXIS] = { 1, 1, 1, 1}; | ||||
|   volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0}; | ||||
|   volatile int count_direction[NUM_AXIS] = { 1, 1, 1, 1}; | ||||
| #endif | ||||
|  | ||||
|  | ||||
| @@ -117,6 +117,8 @@ asm volatile ( \ | ||||
|  | ||||
| block_t *current_block;  // A pointer to the block currently being traced | ||||
|  | ||||
| //static makes it inpossible to be called from outside of this file by extern.! | ||||
|  | ||||
| // Variables used by The Stepper Driver Interrupt | ||||
| static unsigned char out_bits;        // The next stepping-bits to be output | ||||
| static long counter_x,       // Counter variables for the bresenham line tracer | ||||
| @@ -125,9 +127,9 @@ static long counter_x,       // Counter variables for the bresenham line tracer | ||||
|             counter_e; | ||||
| static unsigned long step_events_completed; // The number of step events executed in the current block | ||||
| #ifdef ADVANCE | ||||
| static long advance_rate, advance, final_advance = 0; | ||||
| static short old_advance = 0; | ||||
| static short e_steps; | ||||
|   static long advance_rate, advance, final_advance = 0; | ||||
|   static short old_advance = 0; | ||||
|   static short e_steps; | ||||
| #endif | ||||
| static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler. | ||||
| static long acceleration_time, deceleration_time; | ||||
| @@ -195,10 +197,10 @@ inline unsigned short calc_timer(unsigned short step_rate) { | ||||
| // Initializes the trapezoid generator from the current block. Called whenever a new  | ||||
| // block begins. | ||||
| inline void trapezoid_generator_reset() { | ||||
| #ifdef ADVANCE | ||||
|   advance = current_block->initial_advance; | ||||
|   final_advance = current_block->final_advance; | ||||
| #endif | ||||
|   #ifdef ADVANCE | ||||
|     advance = current_block->initial_advance; | ||||
|     final_advance = current_block->final_advance; | ||||
|   #endif | ||||
|   deceleration_time = 0; | ||||
|   // advance_rate = current_block->advance_rate; | ||||
|   // step_rate to timer interval | ||||
| @@ -211,7 +213,8 @@ inline void trapezoid_generator_reset() { | ||||
| // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.  | ||||
| ISR(TIMER1_COMPA_vect) | ||||
| {         | ||||
|   if(busy){ SERIAL_ERRORLN(*(unsigned short *)OCR1A<< " ISR overtaking itself."); | ||||
|   if(busy){  | ||||
|     SERIAL_ERRORLN(*(unsigned short *)OCR1A<< " ISR overtaking itself."); | ||||
|     return;  | ||||
|   } // The busy-flag is used to avoid reentering this interrupt | ||||
|  | ||||
| @@ -242,74 +245,74 @@ ISR(TIMER1_COMPA_vect) | ||||
|     // Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt | ||||
|     out_bits = current_block->direction_bits; | ||||
|  | ||||
| #ifdef ADVANCE | ||||
|     // Calculate E early. | ||||
|     counter_e += current_block->steps_e; | ||||
|     if (counter_e > 0) { | ||||
|       counter_e -= current_block->step_event_count; | ||||
|       if ((out_bits & (1<<E_AXIS)) != 0) { // - direction | ||||
|     #ifdef ADVANCE | ||||
|         // Calculate E early. | ||||
|         counter_e += current_block->steps_e; | ||||
|         if (counter_e > 0) { | ||||
|           counter_e -= current_block->step_event_count; | ||||
|           if ((out_bits & (1<<E_AXIS)) != 0) { // - direction | ||||
|             CRITICAL_SECTION_START; | ||||
|             e_steps--; | ||||
|             CRITICAL_SECTION_END; | ||||
|           } | ||||
|           else { | ||||
|             CRITICAL_SECTION_START; | ||||
|             e_steps++; | ||||
|             CRITICAL_SECTION_END; | ||||
|           } | ||||
|         }     | ||||
|         // Do E steps + advance steps | ||||
|         CRITICAL_SECTION_START; | ||||
|         e_steps--; | ||||
|         e_steps += ((advance >> 16) - old_advance); | ||||
|         CRITICAL_SECTION_END; | ||||
|       } | ||||
|       else { | ||||
|         CRITICAL_SECTION_START; | ||||
|         e_steps++; | ||||
|         CRITICAL_SECTION_END; | ||||
|       } | ||||
|     }     | ||||
|     // Do E steps + advance steps | ||||
|     CRITICAL_SECTION_START; | ||||
|     e_steps += ((advance >> 16) - old_advance); | ||||
|     CRITICAL_SECTION_END; | ||||
|     old_advance = advance >> 16;   | ||||
| #endif //ADVANCE | ||||
|         old_advance = advance >> 16;   | ||||
|     #endif //ADVANCE | ||||
|  | ||||
|     // Set direction en check limit switches | ||||
| if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction | ||||
|     if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction | ||||
|       WRITE(X_DIR_PIN, INVERT_X_DIR); | ||||
|       #ifdef DEBUG_STEPS | ||||
|       count_direction[X_AXIS]=-1; | ||||
|         count_direction[X_AXIS]=-1; | ||||
|       #endif | ||||
|       #if X_MIN_PIN > -1 | ||||
|             if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) { | ||||
|               step_events_completed = current_block->step_event_count; | ||||
|             } | ||||
|       #endif | ||||
| #if X_MIN_PIN > -1 | ||||
|       if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) { | ||||
|         step_events_completed = current_block->step_event_count; | ||||
|       } | ||||
| #endif | ||||
|     } | ||||
|     else { // +direction  | ||||
|         WRITE(X_DIR_PIN,!INVERT_X_DIR); | ||||
|         #ifdef DEBUG_STEPS | ||||
|       WRITE(X_DIR_PIN,!INVERT_X_DIR); | ||||
|       #ifdef DEBUG_STEPS | ||||
|         count_direction[X_AXIS]=1; | ||||
|         #endif | ||||
| #if X_MAX_PIN > -1 | ||||
|       #endif | ||||
|       #if X_MAX_PIN > -1 | ||||
|         if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_x >0)){ | ||||
|           step_events_completed = current_block->step_event_count; | ||||
|         } | ||||
| #endif | ||||
|         #endif | ||||
|     } | ||||
|  | ||||
|     if ((out_bits & (1<<Y_AXIS)) != 0) {   // -direction | ||||
|       WRITE(Y_DIR_PIN,INVERT_Y_DIR); | ||||
|       #ifdef DEBUG_STEPS | ||||
|       count_direction[Y_AXIS]=-1; | ||||
|         count_direction[Y_AXIS]=-1; | ||||
|       #endif | ||||
|       #if Y_MIN_PIN > -1 | ||||
|         if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) { | ||||
|           step_events_completed = current_block->step_event_count; | ||||
|         } | ||||
|       #endif | ||||
| #if Y_MIN_PIN > -1 | ||||
|       if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) { | ||||
|         step_events_completed = current_block->step_event_count; | ||||
|       } | ||||
| #endif | ||||
|     } | ||||
|     else { // +direction | ||||
|     WRITE(Y_DIR_PIN,!INVERT_Y_DIR); | ||||
|       #ifdef DEBUG_STEPS | ||||
|       count_direction[Y_AXIS]=1; | ||||
|         count_direction[Y_AXIS]=1; | ||||
|       #endif | ||||
|       #if Y_MAX_PIN > -1 | ||||
|       if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){ | ||||
|           step_events_completed = current_block->step_event_count; | ||||
|         } | ||||
|       #endif | ||||
| #if Y_MAX_PIN > -1 | ||||
|     if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){ | ||||
|         step_events_completed = current_block->step_event_count; | ||||
|       } | ||||
| #endif | ||||
|     } | ||||
|  | ||||
|     if ((out_bits & (1<<Z_AXIS)) != 0) {   // -direction | ||||
| @@ -317,30 +320,30 @@ if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction | ||||
|       #ifdef DEBUG_STEPS | ||||
|       count_direction[Z_AXIS]=-1; | ||||
|       #endif | ||||
| #if Z_MIN_PIN > -1 | ||||
|       if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) { | ||||
|         step_events_completed = current_block->step_event_count; | ||||
|       } | ||||
| #endif | ||||
|       #if Z_MIN_PIN > -1 | ||||
|         if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) { | ||||
|           step_events_completed = current_block->step_event_count; | ||||
|         } | ||||
|       #endif | ||||
|     } | ||||
|     else { // +direction | ||||
|         WRITE(Z_DIR_PIN,!INVERT_Z_DIR); | ||||
|         #ifdef DEBUG_STEPS | ||||
|       WRITE(Z_DIR_PIN,!INVERT_Z_DIR); | ||||
|       #ifdef DEBUG_STEPS | ||||
|         count_direction[Z_AXIS]=1; | ||||
|         #endif | ||||
| #if Z_MAX_PIN > -1 | ||||
|       #endif | ||||
|       #if Z_MAX_PIN > -1 | ||||
|         if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING)  && (current_block->steps_z >0)){ | ||||
|           step_events_completed = current_block->step_event_count; | ||||
|         } | ||||
| #endif | ||||
|       #endif | ||||
|     } | ||||
|  | ||||
| #ifndef ADVANCE | ||||
|     if ((out_bits & (1<<E_AXIS)) != 0)   // -direction | ||||
|       WRITE(E_DIR_PIN,INVERT_E_DIR); | ||||
|     else // +direction | ||||
|       WRITE(E_DIR_PIN,!INVERT_E_DIR); | ||||
| #endif //!ADVANCE | ||||
|     #ifndef ADVANCE | ||||
|       if ((out_bits & (1<<E_AXIS)) != 0)   // -direction | ||||
|         WRITE(E_DIR_PIN,INVERT_E_DIR); | ||||
|       else // +direction | ||||
|         WRITE(E_DIR_PIN,!INVERT_E_DIR); | ||||
|     #endif //!ADVANCE | ||||
|  | ||||
|     for(char i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)  | ||||
|       counter_x += current_block->steps_x; | ||||
| @@ -349,7 +352,7 @@ if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction | ||||
|         counter_x -= current_block->step_event_count; | ||||
|         WRITE(X_STEP_PIN, LOW); | ||||
|         #ifdef DEBUG_STEPS | ||||
|         count_position[X_AXIS]+=count_direction[X_AXIS];    | ||||
|           count_position[X_AXIS]+=count_direction[X_AXIS];    | ||||
|         #endif | ||||
|       } | ||||
|  | ||||
| @@ -359,7 +362,7 @@ if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction | ||||
|         counter_y -= current_block->step_event_count; | ||||
|         WRITE(Y_STEP_PIN, LOW); | ||||
|         #ifdef DEBUG_STEPS | ||||
|         count_position[Y_AXIS]+=count_direction[Y_AXIS]; | ||||
|           count_position[Y_AXIS]+=count_direction[Y_AXIS]; | ||||
|         #endif | ||||
|       } | ||||
|  | ||||
| @@ -369,18 +372,18 @@ if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction | ||||
|         counter_z -= current_block->step_event_count; | ||||
|         WRITE(Z_STEP_PIN, LOW); | ||||
|         #ifdef DEBUG_STEPS | ||||
|         count_position[Z_AXIS]+=count_direction[Z_AXIS]; | ||||
|           count_position[Z_AXIS]+=count_direction[Z_AXIS]; | ||||
|         #endif | ||||
|       } | ||||
|  | ||||
| #ifndef ADVANCE | ||||
|       counter_e += current_block->steps_e; | ||||
|       if (counter_e > 0) { | ||||
|         WRITE(E_STEP_PIN, HIGH); | ||||
|         counter_e -= current_block->step_event_count; | ||||
|         WRITE(E_STEP_PIN, LOW); | ||||
|       } | ||||
| #endif //!ADVANCE | ||||
|       #ifndef ADVANCE | ||||
|         counter_e += current_block->steps_e; | ||||
|         if (counter_e > 0) { | ||||
|           WRITE(E_STEP_PIN, HIGH); | ||||
|           counter_e -= current_block->step_event_count; | ||||
|           WRITE(E_STEP_PIN, LOW); | ||||
|         } | ||||
|       #endif //!ADVANCE | ||||
|       step_events_completed += 1;   | ||||
|       if(step_events_completed >= current_block->step_event_count) break; | ||||
|     } | ||||
| @@ -397,9 +400,9 @@ if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction | ||||
|  | ||||
|       // step_rate to timer interval | ||||
|       timer = calc_timer(acc_step_rate); | ||||
| #ifdef ADVANCE | ||||
|       advance += advance_rate; | ||||
| #endif | ||||
|       #ifdef ADVANCE | ||||
|         advance += advance_rate; | ||||
|       #endif | ||||
|       acceleration_time += timer; | ||||
|       OCR1A = timer; | ||||
|     }  | ||||
| @@ -419,11 +422,11 @@ if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction | ||||
|  | ||||
|       // step_rate to timer interval | ||||
|       timer = calc_timer(step_rate); | ||||
| #ifdef ADVANCE | ||||
|       advance -= advance_rate; | ||||
|       if(advance < final_advance) | ||||
|         advance = final_advance; | ||||
| #endif //ADVANCE | ||||
|       #ifdef ADVANCE | ||||
|         advance -= advance_rate; | ||||
|         if(advance < final_advance) | ||||
|           advance = final_advance; | ||||
|       #endif //ADVANCE | ||||
|       deceleration_time += timer; | ||||
|       OCR1A = timer; | ||||
|     }        | ||||
| @@ -438,127 +441,126 @@ if ((out_bits & (1<<X_AXIS)) != 0) {   // -direction | ||||
| } | ||||
|  | ||||
| #ifdef ADVANCE | ||||
|  | ||||
| unsigned char old_OCR0A; | ||||
| // Timer interrupt for E. e_steps is set in the main routine; | ||||
| // Timer 0 is shared with millies | ||||
| ISR(TIMER0_COMPA_vect) | ||||
| { | ||||
|   // Critical section needed because Timer 1 interrupt has higher priority.  | ||||
|   // The pin set functions are placed on trategic position to comply with the stepper driver timing. | ||||
|   WRITE(E_STEP_PIN, LOW); | ||||
|   // Set E direction (Depends on E direction + advance) | ||||
|   if (e_steps < 0) { | ||||
|     WRITE(E_DIR_PIN,INVERT_E_DIR);     | ||||
|     e_steps++; | ||||
|     WRITE(E_STEP_PIN, HIGH); | ||||
|   }  | ||||
|   if (e_steps > 0) { | ||||
|     WRITE(E_DIR_PIN,!INVERT_E_DIR); | ||||
|     e_steps--; | ||||
|     WRITE(E_STEP_PIN, HIGH); | ||||
|   unsigned char old_OCR0A; | ||||
|   // Timer interrupt for E. e_steps is set in the main routine; | ||||
|   // Timer 0 is shared with millies | ||||
|   ISR(TIMER0_COMPA_vect) | ||||
|   { | ||||
|     // Critical section needed because Timer 1 interrupt has higher priority.  | ||||
|     // The pin set functions are placed on trategic position to comply with the stepper driver timing. | ||||
|     WRITE(E_STEP_PIN, LOW); | ||||
|     // Set E direction (Depends on E direction + advance) | ||||
|     if (e_steps < 0) { | ||||
|       WRITE(E_DIR_PIN,INVERT_E_DIR);     | ||||
|       e_steps++; | ||||
|       WRITE(E_STEP_PIN, HIGH); | ||||
|     }  | ||||
|     if (e_steps > 0) { | ||||
|       WRITE(E_DIR_PIN,!INVERT_E_DIR); | ||||
|       e_steps--; | ||||
|       WRITE(E_STEP_PIN, HIGH); | ||||
|     } | ||||
|     old_OCR0A += 25; // 10kHz interrupt | ||||
|     OCR0A = old_OCR0A; | ||||
|   } | ||||
|   old_OCR0A += 25; // 10kHz interrupt | ||||
|   OCR0A = old_OCR0A; | ||||
| } | ||||
| #endif // ADVANCE | ||||
|  | ||||
| void st_init() | ||||
| { | ||||
|     //Initialize Dir Pins | ||||
| #if X_DIR_PIN > -1 | ||||
|   SET_OUTPUT(X_DIR_PIN); | ||||
| #endif | ||||
| #if Y_DIR_PIN > -1  | ||||
|   SET_OUTPUT(Y_DIR_PIN); | ||||
| #endif | ||||
| #if Z_DIR_PIN > -1  | ||||
|   SET_OUTPUT(Z_DIR_PIN); | ||||
| #endif | ||||
| #if E_DIR_PIN > -1  | ||||
|   SET_OUTPUT(E_DIR_PIN); | ||||
| #endif | ||||
|   #if X_DIR_PIN > -1 | ||||
|     SET_OUTPUT(X_DIR_PIN); | ||||
|   #endif | ||||
|   #if Y_DIR_PIN > -1  | ||||
|     SET_OUTPUT(Y_DIR_PIN); | ||||
|   #endif | ||||
|   #if Z_DIR_PIN > -1  | ||||
|     SET_OUTPUT(Z_DIR_PIN); | ||||
|   #endif | ||||
|   #if E_DIR_PIN > -1  | ||||
|     SET_OUTPUT(E_DIR_PIN); | ||||
|   #endif | ||||
|  | ||||
|   //Initialize Enable Pins - steppers default to disabled. | ||||
|  | ||||
| #if (X_ENABLE_PIN > -1) | ||||
|   SET_OUTPUT(X_ENABLE_PIN); | ||||
|   if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH); | ||||
| #endif | ||||
| #if (Y_ENABLE_PIN > -1) | ||||
|   SET_OUTPUT(Y_ENABLE_PIN); | ||||
|   if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH); | ||||
| #endif | ||||
| #if (Z_ENABLE_PIN > -1) | ||||
|   SET_OUTPUT(Z_ENABLE_PIN); | ||||
|   if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH); | ||||
| #endif | ||||
| #if (E_ENABLE_PIN > -1) | ||||
|   SET_OUTPUT(E_ENABLE_PIN); | ||||
|   if(!E_ENABLE_ON) WRITE(E_ENABLE_PIN,HIGH); | ||||
| #endif | ||||
|   #if (X_ENABLE_PIN > -1) | ||||
|     SET_OUTPUT(X_ENABLE_PIN); | ||||
|     if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH); | ||||
|   #endif | ||||
|   #if (Y_ENABLE_PIN > -1) | ||||
|     SET_OUTPUT(Y_ENABLE_PIN); | ||||
|     if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH); | ||||
|   #endif | ||||
|   #if (Z_ENABLE_PIN > -1) | ||||
|     SET_OUTPUT(Z_ENABLE_PIN); | ||||
|     if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH); | ||||
|   #endif | ||||
|   #if (E_ENABLE_PIN > -1) | ||||
|     SET_OUTPUT(E_ENABLE_PIN); | ||||
|     if(!E_ENABLE_ON) WRITE(E_ENABLE_PIN,HIGH); | ||||
|   #endif | ||||
|  | ||||
|   //endstops and pullups | ||||
| #ifdef ENDSTOPPULLUPS | ||||
| #if X_MIN_PIN > -1 | ||||
|   SET_INPUT(X_MIN_PIN);  | ||||
|   WRITE(X_MIN_PIN,HIGH); | ||||
| #endif | ||||
| #if X_MAX_PIN > -1 | ||||
|   SET_INPUT(X_MAX_PIN);  | ||||
|   WRITE(X_MAX_PIN,HIGH); | ||||
| #endif | ||||
| #if Y_MIN_PIN > -1 | ||||
|   SET_INPUT(Y_MIN_PIN);  | ||||
|   WRITE(Y_MIN_PIN,HIGH); | ||||
| #endif | ||||
| #if Y_MAX_PIN > -1 | ||||
|   SET_INPUT(Y_MAX_PIN);  | ||||
|   WRITE(Y_MAX_PIN,HIGH); | ||||
| #endif | ||||
| #if Z_MIN_PIN > -1 | ||||
|   SET_INPUT(Z_MIN_PIN);  | ||||
|   WRITE(Z_MIN_PIN,HIGH); | ||||
| #endif | ||||
| #if Z_MAX_PIN > -1 | ||||
|   SET_INPUT(Z_MAX_PIN);  | ||||
|   WRITE(Z_MAX_PIN,HIGH); | ||||
| #endif | ||||
| #else //ENDSTOPPULLUPS | ||||
| #if X_MIN_PIN > -1 | ||||
|   SET_INPUT(X_MIN_PIN);  | ||||
| #endif | ||||
| #if X_MAX_PIN > -1 | ||||
|   SET_INPUT(X_MAX_PIN);  | ||||
| #endif | ||||
| #if Y_MIN_PIN > -1 | ||||
|   SET_INPUT(Y_MIN_PIN);  | ||||
| #endif | ||||
| #if Y_MAX_PIN > -1 | ||||
|   SET_INPUT(Y_MAX_PIN);  | ||||
| #endif | ||||
| #if Z_MIN_PIN > -1 | ||||
|   SET_INPUT(Z_MIN_PIN);  | ||||
| #endif | ||||
| #if Z_MAX_PIN > -1 | ||||
|   SET_INPUT(Z_MAX_PIN);  | ||||
| #endif | ||||
| #endif //ENDSTOPPULLUPS | ||||
|   #ifdef ENDSTOPPULLUPS | ||||
|     #if X_MIN_PIN > -1 | ||||
|       SET_INPUT(X_MIN_PIN);  | ||||
|       WRITE(X_MIN_PIN,HIGH); | ||||
|     #endif | ||||
|     #if X_MAX_PIN > -1 | ||||
|       SET_INPUT(X_MAX_PIN);  | ||||
|       WRITE(X_MAX_PIN,HIGH); | ||||
|     #endif | ||||
|     #if Y_MIN_PIN > -1 | ||||
|       SET_INPUT(Y_MIN_PIN);  | ||||
|       WRITE(Y_MIN_PIN,HIGH); | ||||
|     #endif | ||||
|     #if Y_MAX_PIN > -1 | ||||
|       SET_INPUT(Y_MAX_PIN);  | ||||
|       WRITE(Y_MAX_PIN,HIGH); | ||||
|     #endif | ||||
|     #if Z_MIN_PIN > -1 | ||||
|       SET_INPUT(Z_MIN_PIN);  | ||||
|       WRITE(Z_MIN_PIN,HIGH); | ||||
|     #endif | ||||
|     #if Z_MAX_PIN > -1 | ||||
|       SET_INPUT(Z_MAX_PIN);  | ||||
|       WRITE(Z_MAX_PIN,HIGH); | ||||
|     #endif | ||||
|   #else //ENDSTOPPULLUPS | ||||
|     #if X_MIN_PIN > -1 | ||||
|       SET_INPUT(X_MIN_PIN);  | ||||
|     #endif | ||||
|     #if X_MAX_PIN > -1 | ||||
|       SET_INPUT(X_MAX_PIN);  | ||||
|     #endif | ||||
|     #if Y_MIN_PIN > -1 | ||||
|       SET_INPUT(Y_MIN_PIN);  | ||||
|     #endif | ||||
|     #if Y_MAX_PIN > -1 | ||||
|       SET_INPUT(Y_MAX_PIN);  | ||||
|     #endif | ||||
|     #if Z_MIN_PIN > -1 | ||||
|       SET_INPUT(Z_MIN_PIN);  | ||||
|     #endif | ||||
|     #if Z_MAX_PIN > -1 | ||||
|       SET_INPUT(Z_MAX_PIN);  | ||||
|     #endif | ||||
|   #endif //ENDSTOPPULLUPS | ||||
|   | ||||
|  | ||||
|   //Initialize Step Pins | ||||
| #if (X_STEP_PIN > -1)  | ||||
|   SET_OUTPUT(X_STEP_PIN); | ||||
| #endif   | ||||
| #if (Y_STEP_PIN > -1)  | ||||
|   SET_OUTPUT(Y_STEP_PIN); | ||||
| #endif   | ||||
| #if (Z_STEP_PIN > -1)  | ||||
|   SET_OUTPUT(Z_STEP_PIN); | ||||
| #endif   | ||||
| #if (E_STEP_PIN > -1)  | ||||
|   SET_OUTPUT(E_STEP_PIN); | ||||
| #endif   | ||||
|   #if (X_STEP_PIN > -1)  | ||||
|     SET_OUTPUT(X_STEP_PIN); | ||||
|   #endif   | ||||
|   #if (Y_STEP_PIN > -1)  | ||||
|     SET_OUTPUT(Y_STEP_PIN); | ||||
|   #endif   | ||||
|   #if (Z_STEP_PIN > -1)  | ||||
|     SET_OUTPUT(Z_STEP_PIN); | ||||
|   #endif   | ||||
|   #if (E_STEP_PIN > -1)  | ||||
|     SET_OUTPUT(E_STEP_PIN); | ||||
|   #endif   | ||||
|  | ||||
|   // waveform generation = 0100 = CTC | ||||
|   TCCR1B &= ~(1<<WGM13); | ||||
| @@ -574,10 +576,10 @@ void st_init() | ||||
|   OCR1A = 0x4000; | ||||
|   DISABLE_STEPPER_DRIVER_INTERRUPT();   | ||||
|  | ||||
| #ifdef ADVANCE | ||||
|   e_steps = 0; | ||||
|   TIMSK0 |= (1<<OCIE0A); | ||||
| #endif //ADVANCE | ||||
|   #ifdef ADVANCE | ||||
|     e_steps = 0; | ||||
|     TIMSK0 |= (1<<OCIE0A); | ||||
|   #endif //ADVANCE | ||||
|   sei(); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -36,8 +36,8 @@ void st_wake_up(); | ||||
| // if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer. | ||||
| // for debugging purposes only, should be disabled by default | ||||
| #ifdef DEBUG_STEPS | ||||
| extern volatile long count_position[NUM_AXIS]; | ||||
| extern volatile int count_direction[NUM_AXIS]; | ||||
|   extern volatile long count_position[NUM_AXIS]; | ||||
|   extern volatile int count_direction[NUM_AXIS]; | ||||
| #endif | ||||
|  | ||||
| extern block_t *current_block;  // A pointer to the block currently being traced | ||||
|   | ||||
| @@ -74,24 +74,24 @@ unsigned long previous_millis_heater, previous_millis_bed_heater; | ||||
| #endif //WATCHPERIOD | ||||
|  | ||||
| #ifdef HEATER_0_MINTEMP | ||||
| int minttemp_0 = temp2analog(HEATER_0_MINTEMP); | ||||
|   int minttemp_0 = temp2analog(HEATER_0_MINTEMP); | ||||
| #endif //MINTEMP | ||||
| #ifdef HEATER_0_MAXTEMP | ||||
| int maxttemp_0 = temp2analog(HEATER_0_MAXTEMP); | ||||
|   int maxttemp_0 = temp2analog(HEATER_0_MAXTEMP); | ||||
| #endif //MAXTEMP | ||||
|  | ||||
| #ifdef HEATER_1_MINTEMP | ||||
| int minttemp_1 = temp2analog(HEATER_1_MINTEMP); | ||||
|   int minttemp_1 = temp2analog(HEATER_1_MINTEMP); | ||||
| #endif //MINTEMP | ||||
| #ifdef HEATER_1_MAXTEMP | ||||
| int maxttemp_1 = temp2analog(HEATER_1_MAXTEMP); | ||||
|   int maxttemp_1 = temp2analog(HEATER_1_MAXTEMP); | ||||
| #endif //MAXTEMP | ||||
|  | ||||
| #ifdef BED_MINTEMP | ||||
| int bed_minttemp = temp2analog(BED_MINTEMP); | ||||
|   int bed_minttemp = temp2analog(BED_MINTEMP); | ||||
| #endif //BED_MINTEMP | ||||
| #ifdef BED_MAXTEMP | ||||
| int bed_maxttemp = temp2analog(BED_MAXTEMP); | ||||
|   int bed_maxttemp = temp2analog(BED_MAXTEMP); | ||||
| #endif //BED_MAXTEMP | ||||
|  | ||||
| void manage_heater() | ||||
| @@ -105,50 +105,49 @@ void manage_heater() | ||||
|   if(temp_meas_ready != true)   //better readability | ||||
|     return;  | ||||
|  | ||||
| CRITICAL_SECTION_START; | ||||
|   CRITICAL_SECTION_START; | ||||
|     temp_meas_ready = false; | ||||
| CRITICAL_SECTION_END; | ||||
|   CRITICAL_SECTION_END; | ||||
|  | ||||
| #ifdef PIDTEMP | ||||
|   #ifdef PIDTEMP | ||||
|     pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND_0]); | ||||
|  | ||||
| #ifndef PID_OPENLOOP | ||||
|     pid_error = pid_setpoint - pid_input; | ||||
|     if(pid_error > 10){ | ||||
|       pid_output = PID_MAX; | ||||
|       pid_reset = true; | ||||
|     } | ||||
|     else if(pid_error < -10) { | ||||
|       pid_output = 0; | ||||
|       pid_reset = true; | ||||
|     } | ||||
|     else { | ||||
|       if(pid_reset == true) { | ||||
|         temp_iState = 0.0; | ||||
|         pid_reset = false; | ||||
|       } | ||||
|       pTerm = Kp * pid_error; | ||||
|       temp_iState += pid_error; | ||||
|       temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max); | ||||
|       iTerm = Ki * temp_iState; | ||||
|       //K1 defined in Configuration.h in the PID settings | ||||
|       #define K2 (1.0-K1) | ||||
|       dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm); | ||||
|       temp_dState = pid_input; | ||||
|       #ifdef PID_ADD_EXTRUSION_RATE | ||||
|         pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high | ||||
|       #endif | ||||
|       pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX); | ||||
|     } | ||||
| #endif //PID_OPENLOOP | ||||
| #ifdef PID_DEBUG | ||||
|      SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);  | ||||
|       | ||||
| #endif //PID_DEBUG | ||||
|     #ifndef PID_OPENLOOP | ||||
|         pid_error = pid_setpoint - pid_input; | ||||
|         if(pid_error > 10){ | ||||
|           pid_output = PID_MAX; | ||||
|           pid_reset = true; | ||||
|         } | ||||
|         else if(pid_error < -10) { | ||||
|           pid_output = 0; | ||||
|           pid_reset = true; | ||||
|         } | ||||
|         else { | ||||
|           if(pid_reset == true) { | ||||
|             temp_iState = 0.0; | ||||
|             pid_reset = false; | ||||
|           } | ||||
|           pTerm = Kp * pid_error; | ||||
|           temp_iState += pid_error; | ||||
|           temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max); | ||||
|           iTerm = Ki * temp_iState; | ||||
|           //K1 defined in Configuration.h in the PID settings | ||||
|           #define K2 (1.0-K1) | ||||
|           dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm); | ||||
|           temp_dState = pid_input; | ||||
|           #ifdef PID_ADD_EXTRUSION_RATE | ||||
|             pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high | ||||
|           #endif | ||||
|           pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX); | ||||
|         } | ||||
|     #endif //PID_OPENLOOP | ||||
|     #ifdef PID_DEBUG | ||||
|      SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);   | ||||
|     #endif //PID_DEBUG | ||||
|     analogWrite(HEATER_0_PIN, pid_output); | ||||
| #endif //PIDTEMP | ||||
|   #endif //PIDTEMP | ||||
|  | ||||
| #ifndef PIDTEMP | ||||
|   #ifndef PIDTEMP | ||||
|     if(current_raw[0] >= target_raw[0]) | ||||
|     { | ||||
|       WRITE(HEATER_0_PIN,LOW); | ||||
| @@ -157,7 +156,7 @@ CRITICAL_SECTION_END; | ||||
|     { | ||||
|       WRITE(HEATER_0_PIN,HIGH); | ||||
|     } | ||||
| #endif | ||||
|   #endif | ||||
|      | ||||
|   if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) | ||||
|     return; | ||||
| @@ -173,7 +172,7 @@ CRITICAL_SECTION_END; | ||||
|       WRITE(HEATER_1_PIN,HIGH); | ||||
|     } | ||||
|   #endif | ||||
|   } | ||||
| } | ||||
|  | ||||
| // Takes hot end temperature value as input and returns corresponding raw value.  | ||||
| // For a thermistor, it uses the RepRap thermistor temp table. | ||||
| @@ -300,26 +299,26 @@ float analog2tempBed(int raw) { | ||||
|  | ||||
| void tp_init() | ||||
| { | ||||
| #if (HEATER_0_PIN > -1)  | ||||
|   SET_OUTPUT(HEATER_0_PIN); | ||||
| #endif   | ||||
| #if (HEATER_1_PIN > -1)  | ||||
|   SET_OUTPUT(HEATER_1_PIN); | ||||
| #endif   | ||||
| #if (HEATER_2_PIN > -1)  | ||||
|   SET_OUTPUT(HEATER_2_PIN); | ||||
| #endif   | ||||
|   #if (HEATER_0_PIN > -1)  | ||||
|     SET_OUTPUT(HEATER_0_PIN); | ||||
|   #endif   | ||||
|   #if (HEATER_1_PIN > -1)  | ||||
|     SET_OUTPUT(HEATER_1_PIN); | ||||
|   #endif   | ||||
|   #if (HEATER_2_PIN > -1)  | ||||
|     SET_OUTPUT(HEATER_2_PIN); | ||||
|   #endif   | ||||
|  | ||||
| #ifdef PIDTEMP | ||||
|   temp_iState_min = 0.0; | ||||
|   temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki; | ||||
| #endif //PIDTEMP | ||||
|   #ifdef PIDTEMP | ||||
|     temp_iState_min = 0.0; | ||||
|     temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki; | ||||
|   #endif //PIDTEMP | ||||
|  | ||||
| // Set analog inputs | ||||
|   // Set analog inputs | ||||
|   ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07; | ||||
|    | ||||
| // Use timer0 for temperature measurement | ||||
| // Interleave temperature interrupt with millies interrupt | ||||
|   // Use timer0 for temperature measurement | ||||
|   // Interleave temperature interrupt with millies interrupt | ||||
|   OCR0B = 128; | ||||
|   TIMSK0 |= (1<<OCIE0B);   | ||||
| } | ||||
| @@ -344,23 +343,25 @@ void setWatch() | ||||
|  | ||||
| void disable_heater() | ||||
| { | ||||
|    #if TEMP_0_PIN > -1 | ||||
|   #if TEMP_0_PIN > -1 | ||||
|   target_raw[0]=0; | ||||
|    #if HEATER_0_PIN > -1   | ||||
|      WRITE(HEATER_0_PIN,LOW); | ||||
|    #endif | ||||
|   #endif | ||||
|       | ||||
|   #if TEMP_1_PIN > -1 | ||||
|   target_raw[1]=0; | ||||
|   #if HEATER_1_PIN > -1  | ||||
|     WRITE(HEATER_1_PIN,LOW); | ||||
|   #endif | ||||
|     target_raw[1]=0; | ||||
|     #if HEATER_1_PIN > -1  | ||||
|       WRITE(HEATER_1_PIN,LOW); | ||||
|     #endif | ||||
|   #endif | ||||
|        | ||||
|   #if TEMP_2_PIN > -1 | ||||
|   target_raw[2]=0; | ||||
|   #if HEATER_2_PIN > -1   | ||||
|     WRITE(HEATER_2_PIN,LOW); | ||||
|   #endif | ||||
|     target_raw[2]=0; | ||||
|     #if HEATER_2_PIN > -1   | ||||
|       WRITE(HEATER_2_PIN,LOW); | ||||
|     #endif | ||||
|   #endif  | ||||
| } | ||||
|  | ||||
| @@ -376,75 +377,75 @@ ISR(TIMER0_COMPB_vect) | ||||
|    | ||||
|   switch(temp_state) { | ||||
|     case 0: // Prepare TEMP_0 | ||||
|             #if (TEMP_0_PIN > -1) | ||||
|               #if TEMP_0_PIN < 8 | ||||
|                 DIDR0 = 1 << TEMP_0_PIN;  | ||||
|               #else | ||||
|                 DIDR2 = 1<<(TEMP_0_PIN - 8);  | ||||
|                 ADCSRB = 1<<MUX5; | ||||
|               #endif | ||||
|               ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07)); | ||||
|               ADCSRA |= 1<<ADSC; // Start conversion | ||||
|             #endif | ||||
|             #ifdef ULTIPANEL | ||||
|               buttons_check(); | ||||
|             #endif | ||||
|             temp_state = 1; | ||||
|             break; | ||||
|       #if (TEMP_0_PIN > -1) | ||||
|         #if TEMP_0_PIN < 8 | ||||
|           DIDR0 = 1 << TEMP_0_PIN;  | ||||
|         #else | ||||
|           DIDR2 = 1<<(TEMP_0_PIN - 8);  | ||||
|           ADCSRB = 1<<MUX5; | ||||
|         #endif | ||||
|         ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07)); | ||||
|         ADCSRA |= 1<<ADSC; // Start conversion | ||||
|       #endif | ||||
|       #ifdef ULTIPANEL | ||||
|         buttons_check(); | ||||
|       #endif | ||||
|       temp_state = 1; | ||||
|       break; | ||||
|     case 1: // Measure TEMP_0 | ||||
|             #if (TEMP_0_PIN > -1) | ||||
|               raw_temp_0_value += ADC; | ||||
|             #endif | ||||
|             temp_state = 2; | ||||
|             break; | ||||
|       #if (TEMP_0_PIN > -1) | ||||
|         raw_temp_0_value += ADC; | ||||
|       #endif | ||||
|       temp_state = 2; | ||||
|       break; | ||||
|     case 2: // Prepare TEMP_1 | ||||
|             #if (TEMP_1_PIN > -1) | ||||
|               #if TEMP_1_PIN < 7 | ||||
|                 DIDR0 = 1<<TEMP_1_PIN;  | ||||
|               #else | ||||
|                 DIDR2 = 1<<(TEMP_1_PIN - 8);  | ||||
|                 ADCSRB = 1<<MUX5; | ||||
|               #endif | ||||
|               ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07)); | ||||
|               ADCSRA |= 1<<ADSC; // Start conversion | ||||
|             #endif | ||||
|             #ifdef ULTIPANEL | ||||
|               buttons_check(); | ||||
|             #endif | ||||
|             temp_state = 3; | ||||
|             break; | ||||
|       #if (TEMP_1_PIN > -1) | ||||
|         #if TEMP_1_PIN < 7 | ||||
|           DIDR0 = 1<<TEMP_1_PIN;  | ||||
|         #else | ||||
|           DIDR2 = 1<<(TEMP_1_PIN - 8);  | ||||
|           ADCSRB = 1<<MUX5; | ||||
|         #endif | ||||
|         ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07)); | ||||
|         ADCSRA |= 1<<ADSC; // Start conversion | ||||
|       #endif | ||||
|       #ifdef ULTIPANEL | ||||
|         buttons_check(); | ||||
|       #endif | ||||
|       temp_state = 3; | ||||
|       break; | ||||
|     case 3: // Measure TEMP_1 | ||||
|             #if (TEMP_1_PIN > -1) | ||||
|               raw_temp_1_value += ADC; | ||||
|             #endif | ||||
|             temp_state = 4; | ||||
|             break; | ||||
|       #if (TEMP_1_PIN > -1) | ||||
|         raw_temp_1_value += ADC; | ||||
|       #endif | ||||
|       temp_state = 4; | ||||
|       break; | ||||
|     case 4: // Prepare TEMP_2 | ||||
|             #if (TEMP_2_PIN > -1) | ||||
|               #if TEMP_2_PIN < 7 | ||||
|                 DIDR0 = 1 << TEMP_2_PIN;  | ||||
|               #else | ||||
|                 DIDR2 = 1<<(TEMP_2_PIN - 8);  | ||||
|                 ADCSRB = 1<<MUX5; | ||||
|               #endif | ||||
|               ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07)); | ||||
|               ADCSRA |= 1<<ADSC; // Start conversion | ||||
|             #endif | ||||
|             #ifdef ULTIPANEL | ||||
|               buttons_check(); | ||||
|             #endif | ||||
|             temp_state = 5; | ||||
|             break; | ||||
|       #if (TEMP_2_PIN > -1) | ||||
|         #if TEMP_2_PIN < 7 | ||||
|           DIDR0 = 1 << TEMP_2_PIN;  | ||||
|         #else | ||||
|           DIDR2 = 1<<(TEMP_2_PIN - 8);  | ||||
|           ADCSRB = 1<<MUX5; | ||||
|         #endif | ||||
|         ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07)); | ||||
|         ADCSRA |= 1<<ADSC; // Start conversion | ||||
|       #endif | ||||
|       #ifdef ULTIPANEL | ||||
|         buttons_check(); | ||||
|       #endif | ||||
|       temp_state = 5; | ||||
|       break; | ||||
|     case 5: // Measure TEMP_2 | ||||
|             #if (TEMP_2_PIN > -1) | ||||
|               raw_temp_2_value += ADC; | ||||
|             #endif | ||||
|             temp_state = 0; | ||||
|             temp_count++; | ||||
|             break; | ||||
|       #if (TEMP_2_PIN > -1) | ||||
|         raw_temp_2_value += ADC; | ||||
|       #endif | ||||
|       temp_state = 0; | ||||
|       temp_count++; | ||||
|       break; | ||||
|     default: | ||||
|             SERIAL_ERRORLN("Temp measurement error!"); | ||||
|             break; | ||||
|       SERIAL_ERRORLN("Temp measurement error!"); | ||||
|       break; | ||||
|   } | ||||
|      | ||||
|   if(temp_count >= 16) // 6 ms * 16 = 96ms. | ||||
| @@ -472,67 +473,71 @@ ISR(TIMER0_COMPB_vect) | ||||
|     raw_temp_0_value = 0; | ||||
|     raw_temp_1_value = 0; | ||||
|     raw_temp_2_value = 0; | ||||
| #ifdef HEATER_0_MAXTEMP | ||||
|   #if (HEATER_0_PIN > -1) | ||||
|     if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) { | ||||
|       target_raw[TEMPSENSOR_HOTEND_0] = 0; | ||||
|       analogWrite(HEATER_0_PIN, 0); | ||||
|       SERIAL_ERRORLN("Temperature extruder 0 switched off. MAXTEMP triggered !!"); | ||||
|       kill(); | ||||
|     } | ||||
|     #ifdef HEATER_0_MAXTEMP | ||||
|       #if (HEATER_0_PIN > -1) | ||||
|         if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) { | ||||
|           target_raw[TEMPSENSOR_HOTEND_0] = 0; | ||||
|           analogWrite(HEATER_0_PIN, 0); | ||||
|           SERIAL_ERRORLN("Temperature extruder 0 switched off. MAXTEMP triggered !!"); | ||||
|           kill(); | ||||
|         } | ||||
|       #endif | ||||
|     #endif | ||||
|   #ifdef HEATER_1_MAXTEMP | ||||
|     #if (HEATER_1_PIN > -1) | ||||
|       if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) { | ||||
|         target_raw[TEMPSENSOR_HOTEND_1] = 0; | ||||
|       if(current_raw[2] >= maxttemp_1) { | ||||
|         analogWrite(HEATER_2_PIN, 0); | ||||
|         SERIAL_ERRORLN("Temperature extruder 1 switched off. MAXTEMP triggered !!"); | ||||
|         kill() | ||||
|       } | ||||
|     #endif | ||||
|   #endif //MAXTEMP | ||||
|    | ||||
|   #ifdef HEATER_0_MINTEMP | ||||
|     #if (HEATER_0_PIN > -1) | ||||
|       if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) { | ||||
|         target_raw[TEMPSENSOR_HOTEND_0] = 0; | ||||
|         analogWrite(HEATER_0_PIN, 0); | ||||
|         SERIAL_ERRORLN("Temperature extruder 0 switched off. MINTEMP triggered !!"); | ||||
|         kill(); | ||||
|       } | ||||
|     #endif | ||||
|   #endif | ||||
| #endif | ||||
| #ifdef HEATER_1_MAXTEMP | ||||
|   #if (HEATER_1_PIN > -1) | ||||
|     if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) { | ||||
|       target_raw[TEMPSENSOR_HOTEND_1] = 0; | ||||
|     if(current_raw[2] >= maxttemp_1) { | ||||
|       analogWrite(HEATER_2_PIN, 0); | ||||
|       SERIAL_ERRORLN("Temperature extruder 1 switched off. MAXTEMP triggered !!"); | ||||
|       kill() | ||||
|     } | ||||
|    | ||||
|   #ifdef HEATER_1_MINTEMP | ||||
|     #if (HEATER_2_PIN > -1) | ||||
|       if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) { | ||||
|         target_raw[TEMPSENSOR_HOTEND_1] = 0; | ||||
|         analogWrite(HEATER_2_PIN, 0); | ||||
|         SERIAL_ERRORLN("Temperature extruder 1 switched off. MINTEMP triggered !!"); | ||||
|         kill(); | ||||
|       } | ||||
|     #endif | ||||
|   #endif //MAXTEMP | ||||
|    | ||||
|   #ifdef BED_MINTEMP | ||||
|     #if (HEATER_1_PIN > -1) | ||||
|       if(current_raw[1] <= bed_minttemp) { | ||||
|         target_raw[1] = 0; | ||||
|         WRITE(HEATER_1_PIN, 0); | ||||
|         SERIAL_ERRORLN("Temperatur heated bed switched off. MINTEMP triggered !!"); | ||||
|         kill(); | ||||
|       } | ||||
|     #endif | ||||
|   #endif | ||||
| #endif //MAXTEMP | ||||
| #ifdef HEATER_0_MINTEMP | ||||
|   #if (HEATER_0_PIN > -1) | ||||
|     if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) { | ||||
|       target_raw[TEMPSENSOR_HOTEND_0] = 0; | ||||
|       analogWrite(HEATER_0_PIN, 0); | ||||
|       SERIAL_ERRORLN("Temperature extruder 0 switched off. MINTEMP triggered !!"); | ||||
|       kill(); | ||||
|     } | ||||
|    | ||||
|   #ifdef BED_MAXTEMP | ||||
|     #if (HEATER_1_PIN > -1) | ||||
|       if(current_raw[1] >= bed_maxttemp) { | ||||
|         target_raw[1] = 0; | ||||
|         WRITE(HEATER_1_PIN, 0); | ||||
|         SERIAL_ERRORLN("Temperature heated bed switched off. MAXTEMP triggered !!"); | ||||
|         kill(); | ||||
|       } | ||||
|     #endif | ||||
|   #endif | ||||
| #endif | ||||
| #ifdef HEATER_1_MINTEMP | ||||
|   #if (HEATER_2_PIN > -1) | ||||
|     if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) { | ||||
|       target_raw[TEMPSENSOR_HOTEND_1] = 0; | ||||
|       analogWrite(HEATER_2_PIN, 0); | ||||
|       SERIAL_ERRORLN("Temperature extruder 1 switched off. MINTEMP triggered !!"); | ||||
|       kill(); | ||||
|     } | ||||
|   #endif | ||||
| #endif //MAXTEMP | ||||
| #ifdef BED_MINTEMP | ||||
|   #if (HEATER_1_PIN > -1) | ||||
|     if(current_raw[1] <= bed_minttemp) { | ||||
|       target_raw[1] = 0; | ||||
|       WRITE(HEATER_1_PIN, 0); | ||||
|       SERIAL_ERRORLN("Temperatur heated bed switched off. MINTEMP triggered !!"); | ||||
|       kill(); | ||||
|     } | ||||
|   #endif | ||||
| #endif | ||||
| #ifdef BED_MAXTEMP | ||||
|   #if (HEATER_1_PIN > -1) | ||||
|     if(current_raw[1] >= bed_maxttemp) { | ||||
|       target_raw[1] = 0; | ||||
|       WRITE(HEATER_1_PIN, 0); | ||||
|       SERIAL_ERRORLN("Temperature heated bed switched off. MAXTEMP triggered !!"); | ||||
|       kill(); | ||||
|     } | ||||
|   #endif | ||||
| #endif | ||||
|   } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -27,9 +27,11 @@ | ||||
|   #include "stepper.h" | ||||
| #endif | ||||
|  | ||||
| // public functions | ||||
| void tp_init();  //initialise the heating | ||||
| void manage_heater(); //it is critical that this is called periodically. | ||||
|  | ||||
|  | ||||
| enum TempSensor {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2}; | ||||
|  | ||||
| //low leven conversion routines | ||||
| @@ -41,9 +43,11 @@ float analog2tempBed(int raw); | ||||
| extern int target_raw[3];   | ||||
| extern int current_raw[3]; | ||||
| extern float Kp,Ki,Kd,Kc; | ||||
|  | ||||
| #ifdef PIDTEMP | ||||
|   extern float pid_setpoint ; | ||||
| #endif | ||||
|    | ||||
| #ifdef WATCHPERIOD | ||||
|   extern int watch_raw[3] ; | ||||
|   extern unsigned long watchmillis; | ||||
| @@ -63,15 +67,15 @@ inline float degTargetHotend0() {  return analog2temp(target_raw[TEMPSENSOR_HOTE | ||||
| inline float degTargetHotend1() {  return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);}; | ||||
| inline float degTargetBed() {   return analog2tempBed(target_raw[TEMPSENSOR_BED]);}; | ||||
|  | ||||
| inline void setTargetHotend0(float celsius)  | ||||
| inline void setTargetHotend0(const float &celsius)  | ||||
| {   | ||||
|   target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius); | ||||
|   #ifdef PIDTEMP | ||||
|     pid_setpoint = celsius; | ||||
|   #endif //PIDTEMP | ||||
| }; | ||||
| inline void setTargetHotend1(float celsius) {  target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);}; | ||||
| inline void setTargetBed(float celsius)     {  target_raw[TEMPSENSOR_BED     ]=temp2analogBed(celsius);}; | ||||
| inline void setTargetHotend1(const float &celsius) {  target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);}; | ||||
| inline void setTargetBed(const float &celsius)     {  target_raw[TEMPSENSOR_BED     ]=temp2analogBed(celsius);}; | ||||
|  | ||||
| inline bool isHeatingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];}; | ||||
| inline bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];}; | ||||
| @@ -84,16 +88,5 @@ inline bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMP | ||||
| void disable_heater(); | ||||
| void setWatch(); | ||||
|  | ||||
| #ifdef HEATER_0_USES_THERMISTOR | ||||
|     #define HEATERSOURCE 1 | ||||
| #endif | ||||
| #ifdef BED_USES_THERMISTOR | ||||
|     #define BEDSOURCE 1 | ||||
| #endif | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| #endif | ||||
|  | ||||
|   | ||||
| @@ -9,107 +9,48 @@ | ||||
|   void lcd_status(const char* message); | ||||
|   void beep(); | ||||
|   void buttons_check(); | ||||
|   #define LCDSTATUSRIGHT | ||||
|  | ||||
|  | ||||
|   #define LCD_UPDATE_INTERVAL 100 | ||||
|   #define STATUSTIMEOUT 15000 | ||||
|  | ||||
|   #include "Configuration.h" | ||||
|  | ||||
|   #include <LiquidCrystal.h> | ||||
|   extern LiquidCrystal lcd; | ||||
|  | ||||
|   //lcd display size | ||||
|  | ||||
| #ifdef NEWPANEL | ||||
|  //arduino pin witch triggers an piezzo beeper | ||||
|   #define BEEPER 18 | ||||
|   #ifdef NEWPANEL | ||||
|  | ||||
|   #define LCD_PINS_RS 20  | ||||
|   #define LCD_PINS_ENABLE 17 | ||||
|   #define LCD_PINS_D4 16 | ||||
|   #define LCD_PINS_D5 21  | ||||
|   #define LCD_PINS_D6 5 | ||||
|   #define LCD_PINS_D7 6 | ||||
|    | ||||
|   //buttons are directly attached | ||||
|   #define BTN_EN1 40 | ||||
|   #define BTN_EN2 42 | ||||
|   #define BTN_ENC 19  //the click | ||||
|    | ||||
|   #define BLEN_C 2 | ||||
|   #define BLEN_B 1 | ||||
|   #define BLEN_A 0 | ||||
|    | ||||
|   #define SDCARDDETECT 38 | ||||
|    | ||||
|   #define EN_C (1<<BLEN_C) | ||||
|   #define EN_B (1<<BLEN_B) | ||||
|   #define EN_A (1<<BLEN_A) | ||||
|    | ||||
|    //encoder rotation values | ||||
|   #define encrot0 0 | ||||
|   #define encrot1 2 | ||||
|   #define encrot2 3 | ||||
|   #define encrot3 1 | ||||
|      | ||||
|     #define EN_C (1<<BLEN_C) | ||||
|     #define EN_B (1<<BLEN_B) | ||||
|     #define EN_A (1<<BLEN_A) | ||||
|      | ||||
|     #define CLICKED (buttons&EN_C) | ||||
|     #define BLOCK {blocking=millis()+blocktime;} | ||||
|     #define CARDINSERTED (READ(SDCARDDETECT)==0) | ||||
|      | ||||
|   #else | ||||
|  | ||||
|    | ||||
|   #define CLICKED (buttons&EN_C) | ||||
|   #define BLOCK {blocking=millis()+blocktime;} | ||||
|   #define CARDINSERTED (READ(SDCARDDETECT)==0) | ||||
|    | ||||
| #else | ||||
|   //arduino pin witch triggers an piezzo beeper | ||||
|   #define BEEPER 18 | ||||
|  | ||||
|   //buttons are attached to a shift register | ||||
|   #define SHIFT_CLK 38 | ||||
|   #define SHIFT_LD 42 | ||||
|   #define SHIFT_OUT 40 | ||||
|   #define SHIFT_EN 17 | ||||
|    | ||||
|   #define LCD_PINS_RS 16  | ||||
|   #define LCD_PINS_ENABLE 5 | ||||
|   #define LCD_PINS_D4 6 | ||||
|   #define LCD_PINS_D5 21  | ||||
|   #define LCD_PINS_D6 20 | ||||
|   #define LCD_PINS_D7 19 | ||||
|    | ||||
|    //bits in the shift register that carry the buttons for: | ||||
|   // left up center down right red | ||||
|   #define BL_LE 7 | ||||
|   #define BL_UP 6 | ||||
|   #define BL_MI 5 | ||||
|   #define BL_DW 4 | ||||
|   #define BL_RI 3 | ||||
|   #define BL_ST 2 | ||||
|  | ||||
|   #define BLEN_B 1 | ||||
|   #define BLEN_A 0 | ||||
|  | ||||
|   //encoder rotation values | ||||
|   #define encrot0 0 | ||||
|   #define encrot1 2 | ||||
|   #define encrot2 3 | ||||
|   #define encrot3 1 | ||||
|  | ||||
|   //atomatic, do not change | ||||
|   #define B_LE (1<<BL_LE) | ||||
|   #define B_UP (1<<BL_UP) | ||||
|   #define B_MI (1<<BL_MI) | ||||
|   #define B_DW (1<<BL_DW) | ||||
|   #define B_RI (1<<BL_RI) | ||||
|   #define B_ST (1<<BL_ST) | ||||
|   #define EN_B (1<<BLEN_B) | ||||
|   #define EN_A (1<<BLEN_A) | ||||
|    | ||||
|   #define CLICKED ((buttons&B_MI)||(buttons&B_ST)) | ||||
|   #define BLOCK {blocking[BL_MI]=millis()+blocktime;blocking[BL_ST]=millis()+blocktime;} | ||||
|    | ||||
| #endif | ||||
|     //atomatic, do not change | ||||
|     #define B_LE (1<<BL_LE) | ||||
|     #define B_UP (1<<BL_UP) | ||||
|     #define B_MI (1<<BL_MI) | ||||
|     #define B_DW (1<<BL_DW) | ||||
|     #define B_RI (1<<BL_RI) | ||||
|     #define B_ST (1<<BL_ST) | ||||
|     #define EN_B (1<<BLEN_B) | ||||
|     #define EN_A (1<<BLEN_A) | ||||
|      | ||||
|     #define CLICKED ((buttons&B_MI)||(buttons&B_ST)) | ||||
|     #define BLOCK {blocking[BL_MI]=millis()+blocktime;blocking[BL_ST]=millis()+blocktime;} | ||||
|      | ||||
|   #endif | ||||
|      | ||||
|   // blocking time for recognizing a new keypress of one key, ms | ||||
| #define blocktime 500 | ||||
| #define lcdslow 5 | ||||
|   #define blocktime 500 | ||||
|   #define lcdslow 5 | ||||
|      | ||||
|   enum MainStatus{Main_Status, Main_Menu, Main_Prepare, Main_Control, Main_SD}; | ||||
|  | ||||
|   class MainMenu{ | ||||
| @@ -134,6 +75,7 @@ | ||||
|     bool linechanging; | ||||
|   }; | ||||
|  | ||||
|   //conversion routines, could need some overworking | ||||
|   char *fillto(int8_t n,char *c); | ||||
|   char *ftostr51(const float &x); | ||||
|   char *ftostr31(const float &x); | ||||
| @@ -146,11 +88,15 @@ | ||||
| #else //no lcd | ||||
|   #define LCD_STATUS | ||||
|   #define LCD_MESSAGE(x) | ||||
|   inline void lcd_status() {}; | ||||
| #endif | ||||
|    | ||||
| #ifndef ULTIPANEL   | ||||
|  #define CLICKED false | ||||
| #define BLOCK ; | ||||
|   #define BLOCK ; | ||||
| #endif  | ||||
|    | ||||
|    | ||||
|    | ||||
| #endif //ULTRALCD | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| #include "ultralcd.h" | ||||
|  | ||||
|  | ||||
| #ifdef ULTRA_LCD | ||||
|  | ||||
|  | ||||
| extern volatile int feedmultiply; | ||||
| extern long position[4];    | ||||
|  | ||||
| @@ -122,58 +122,57 @@ void lcd_status() | ||||
|   menu.update(); | ||||
| } | ||||
| #ifdef ULTIPANEL   | ||||
|  | ||||
|  | ||||
| void buttons_init() | ||||
| { | ||||
| #ifdef NEWPANEL | ||||
|   pinMode(BTN_EN1,INPUT); | ||||
|   pinMode(BTN_EN2,INPUT);  | ||||
|   pinMode(BTN_ENC,INPUT);  | ||||
|   pinMode(SDCARDDETECT,INPUT); | ||||
|   WRITE(BTN_EN1,HIGH); | ||||
|   WRITE(BTN_EN2,HIGH); | ||||
|   WRITE(BTN_ENC,HIGH); | ||||
|   WRITE(SDCARDDETECT,HIGH); | ||||
| #else | ||||
|   pinMode(SHIFT_CLK,OUTPUT); | ||||
|   pinMode(SHIFT_LD,OUTPUT); | ||||
|   pinMode(SHIFT_EN,OUTPUT); | ||||
|   pinMode(SHIFT_OUT,INPUT); | ||||
|   WRITE(SHIFT_OUT,HIGH); | ||||
|   WRITE(SHIFT_LD,HIGH);  | ||||
|   WRITE(SHIFT_EN,LOW);  | ||||
| #endif | ||||
|   #ifdef NEWPANEL | ||||
|     pinMode(BTN_EN1,INPUT); | ||||
|     pinMode(BTN_EN2,INPUT);  | ||||
|     pinMode(BTN_ENC,INPUT);  | ||||
|     pinMode(SDCARDDETECT,INPUT); | ||||
|     WRITE(BTN_EN1,HIGH); | ||||
|     WRITE(BTN_EN2,HIGH); | ||||
|     WRITE(BTN_ENC,HIGH); | ||||
|     WRITE(SDCARDDETECT,HIGH); | ||||
|   #else | ||||
|     pinMode(SHIFT_CLK,OUTPUT); | ||||
|     pinMode(SHIFT_LD,OUTPUT); | ||||
|     pinMode(SHIFT_EN,OUTPUT); | ||||
|     pinMode(SHIFT_OUT,INPUT); | ||||
|     WRITE(SHIFT_OUT,HIGH); | ||||
|     WRITE(SHIFT_LD,HIGH);  | ||||
|     WRITE(SHIFT_EN,LOW);  | ||||
|   #endif | ||||
| } | ||||
|  | ||||
|  | ||||
| void buttons_check() | ||||
| { | ||||
| //  volatile static bool busy=false; | ||||
| //  if(busy)  | ||||
| //    return; | ||||
| //  busy=true; | ||||
|    | ||||
| #ifdef NEWPANEL | ||||
|   uint8_t newbutton=0; | ||||
|   if(READ(BTN_EN1)==0)  newbutton|=EN_A; | ||||
|   if(READ(BTN_EN2)==0)  newbutton|=EN_B; | ||||
|   if((blocking<millis()) &&(READ(BTN_ENC)==0)) | ||||
|     newbutton|=EN_C; | ||||
|   buttons=newbutton; | ||||
| #else   //read it from the shift register | ||||
|   uint8_t newbutton=0; | ||||
|   WRITE(SHIFT_LD,LOW); | ||||
|   WRITE(SHIFT_LD,HIGH); | ||||
|   unsigned char tmp_buttons=0; | ||||
|   for(unsigned char i=0;i<8;i++) | ||||
|   {  | ||||
|     newbutton = newbutton>>1; | ||||
|     if(READ(SHIFT_OUT)) | ||||
|       newbutton|=(1<<7); | ||||
|     WRITE(SHIFT_CLK,HIGH); | ||||
|     WRITE(SHIFT_CLK,LOW); | ||||
|   } | ||||
|   buttons=~newbutton; //invert it, because a pressed switch produces a logical 0 | ||||
| #endif | ||||
|   #ifdef NEWPANEL | ||||
|     uint8_t newbutton=0; | ||||
|     if(READ(BTN_EN1)==0)  newbutton|=EN_A; | ||||
|     if(READ(BTN_EN2)==0)  newbutton|=EN_B; | ||||
|     if((blocking<millis()) &&(READ(BTN_ENC)==0)) | ||||
|       newbutton|=EN_C; | ||||
|     buttons=newbutton; | ||||
|   #else   //read it from the shift register | ||||
|     uint8_t newbutton=0; | ||||
|     WRITE(SHIFT_LD,LOW); | ||||
|     WRITE(SHIFT_LD,HIGH); | ||||
|     unsigned char tmp_buttons=0; | ||||
|     for(unsigned char i=0;i<8;i++) | ||||
|     {  | ||||
|       newbutton = newbutton>>1; | ||||
|       if(READ(SHIFT_OUT)) | ||||
|         newbutton|=(1<<7); | ||||
|       WRITE(SHIFT_CLK,HIGH); | ||||
|       WRITE(SHIFT_CLK,LOW); | ||||
|     } | ||||
|     buttons=~newbutton; //invert it, because a pressed switch produces a logical 0 | ||||
|   #endif | ||||
|    | ||||
|   char enc=0; | ||||
|   if(buttons&EN_A) | ||||
|     enc|=(1<<0); | ||||
| @@ -212,7 +211,6 @@ void buttons_check() | ||||
|     } | ||||
|   } | ||||
|   lastenc=enc; | ||||
| //  busy=false; | ||||
| } | ||||
|  | ||||
| #endif | ||||
| @@ -223,9 +221,9 @@ MainMenu::MainMenu() | ||||
|   displayStartingRow=0; | ||||
|   activeline=0; | ||||
|   force_lcd_update=true; | ||||
| #ifdef ULTIPANEL | ||||
|   buttons_init(); | ||||
| #endif | ||||
|   #ifdef ULTIPANEL | ||||
|     buttons_init(); | ||||
|   #endif | ||||
|   lcd_init(); | ||||
|   linechanging=false; | ||||
| } | ||||
| @@ -1154,12 +1152,13 @@ uint8_t getnrfilenames() | ||||
|     cnt++; | ||||
|   } | ||||
|   return cnt; | ||||
| #else | ||||
|   return 0; | ||||
| #endif | ||||
| } | ||||
|  | ||||
| void MainMenu::showSD() | ||||
| { | ||||
|  | ||||
| #ifdef SDSUPPORT | ||||
|  uint8_t line=0; | ||||
|  | ||||
| @@ -1205,11 +1204,11 @@ void MainMenu::showSD() | ||||
|         if(force_lcd_update) | ||||
|         { | ||||
|           lcd.setCursor(0,line); | ||||
| #ifdef CARDINSERTED | ||||
|            #ifdef CARDINSERTED | ||||
|           if(CARDINSERTED) | ||||
| #else | ||||
|           #else | ||||
|           if(true) | ||||
| #endif | ||||
|           #endif | ||||
|           { | ||||
|             lcd.print(" \004Refresh"); | ||||
|           } | ||||
| @@ -1306,9 +1305,9 @@ void MainMenu::showMainMenu() | ||||
| { | ||||
|    //if(int(encoderpos/lcdslow)!=int(lastencoderpos/lcdslow)) | ||||
|    //  force_lcd_update=true; | ||||
| #ifndef ULTIPANEL | ||||
|    force_lcd_update=false; | ||||
| #endif | ||||
|   #ifndef ULTIPANEL | ||||
|     force_lcd_update=false; | ||||
|   #endif | ||||
|    //Serial.println((int)activeline); | ||||
|    if(force_lcd_update) | ||||
|      clear(); | ||||
| @@ -1347,17 +1346,17 @@ void MainMenu::showMainMenu() | ||||
|           beepshort(); | ||||
|         } | ||||
|       }break; | ||||
| #ifdef SDSUPPORT | ||||
|       #ifdef SDSUPPORT | ||||
|       case ItemM_file:     | ||||
|       { | ||||
|         if(force_lcd_update)  | ||||
|         { | ||||
|           lcd.setCursor(0,line); | ||||
| #ifdef CARDINSERTED | ||||
|           if(CARDINSERTED) | ||||
| #else | ||||
|           if(true) | ||||
| #endif | ||||
|           #ifdef CARDINSERTED | ||||
|             if(CARDINSERTED) | ||||
|           #else | ||||
|             if(true) | ||||
|           #endif | ||||
|           { | ||||
|             if(sdmode) | ||||
|               lcd.print(" Stop Print   \x7E"); | ||||
| @@ -1370,7 +1369,7 @@ void MainMenu::showMainMenu() | ||||
|           } | ||||
|         } | ||||
|         #ifdef CARDINSERTED | ||||
|         if(CARDINSERTED) | ||||
|           if(CARDINSERTED) | ||||
|         #endif | ||||
|         if((activeline==line)&&CLICKED) | ||||
|         { | ||||
| @@ -1380,28 +1379,30 @@ void MainMenu::showMainMenu() | ||||
|           beepshort(); | ||||
|         } | ||||
|       }break; | ||||
| #endif | ||||
|       #endif | ||||
|       default:  | ||||
|         SERIAL_ERRORLN("Something is wrong in the MenuStructure."); | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
|   if(activeline<0) activeline=0; | ||||
|   if(activeline>=LCD_HEIGHT) activeline=LCD_HEIGHT-1; | ||||
|   if(activeline<0)  | ||||
|     activeline=0; | ||||
|   if(activeline>=LCD_HEIGHT)  | ||||
|     activeline=LCD_HEIGHT-1; | ||||
|   if((encoderpos!=lastencoderpos)||force_lcd_update) | ||||
|   { | ||||
|     lcd.setCursor(0,activeline);lcd.print(activeline?' ':' '); | ||||
|     if(encoderpos<0) encoderpos=0; | ||||
|     if(encoderpos>3*lcdslow) encoderpos=3*lcdslow; | ||||
|     if(encoderpos>3*lcdslow)  | ||||
|       encoderpos=3*lcdslow; | ||||
|     activeline=abs(encoderpos/lcdslow)%LCD_HEIGHT; | ||||
|      if(activeline<0) activeline=0; | ||||
|   if(activeline>=LCD_HEIGHT) activeline=LCD_HEIGHT-1; | ||||
|     if(activeline<0)  | ||||
|       activeline=0; | ||||
|     if(activeline>=LCD_HEIGHT)  | ||||
|       activeline=LCD_HEIGHT-1; | ||||
|     lastencoderpos=encoderpos; | ||||
|     lcd.setCursor(0,activeline);lcd.print(activeline?'>':'\003'); | ||||
|   } | ||||
|  | ||||
|    | ||||
|    | ||||
| } | ||||
|  | ||||
| void MainMenu::update() | ||||
| @@ -1409,25 +1410,24 @@ void MainMenu::update() | ||||
|   static MainStatus oldstatus=Main_Menu;  //init automatically causes foce_lcd_update=true | ||||
|   static long timeoutToStatus=0; | ||||
|   static bool oldcardstatus=false; | ||||
| #ifdef CARDINSERTED | ||||
|   if((CARDINSERTED != oldcardstatus)) | ||||
|   { | ||||
|     force_lcd_update=true; | ||||
|     oldcardstatus=CARDINSERTED; | ||||
|     //Serial.println("echo: SD CHANGE"); | ||||
|     if(CARDINSERTED) | ||||
|   #ifdef CARDINSERTED | ||||
|     if((CARDINSERTED != oldcardstatus)) | ||||
|     { | ||||
|       initsd(); | ||||
|       lcd_status("Card inserted"); | ||||
|       force_lcd_update=true; | ||||
|       oldcardstatus=CARDINSERTED; | ||||
|       //Serial.println("echo: SD CHANGE"); | ||||
|       if(CARDINSERTED) | ||||
|       { | ||||
|         initsd(); | ||||
|         lcd_status("Card inserted"); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|         sdactive=false; | ||||
|         lcd_status("Card removed"); | ||||
|       } | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|       sdactive=false; | ||||
|       lcd_status("Card removed"); | ||||
|        | ||||
|     } | ||||
|   } | ||||
| #endif | ||||
|   #endif | ||||
|   | ||||
|   if(status!=oldstatus) | ||||
|   { | ||||
| @@ -1484,9 +1484,9 @@ void MainMenu::update() | ||||
|  | ||||
|  | ||||
| //return for string conversion routines | ||||
| char conv[8]; | ||||
| static char conv[8]; | ||||
|  | ||||
| ///  convert float to string with +123.4 format | ||||
| //  convert float to string with +123.4 format | ||||
| char *ftostr3(const float &x) | ||||
| { | ||||
|   //sprintf(conv,"%5.1f",x); | ||||
| @@ -1497,6 +1497,7 @@ char *ftostr3(const float &x) | ||||
|   conv[3]=0; | ||||
|   return conv; | ||||
| } | ||||
|  | ||||
| char *itostr2(const uint8_t &x) | ||||
| { | ||||
|   //sprintf(conv,"%5.1f",x); | ||||
| @@ -1506,10 +1507,10 @@ char *itostr2(const uint8_t &x) | ||||
|   conv[2]=0; | ||||
|   return conv; | ||||
| } | ||||
| ///  convert float to string with +123.4 format | ||||
|  | ||||
| //  convert float to string with +123.4 format | ||||
| char *ftostr31(const float &x) | ||||
| { | ||||
|   //sprintf(conv,"%5.1f",x); | ||||
|   int xx=x*10; | ||||
|   conv[0]=(xx>=0)?'+':'-'; | ||||
|   xx=abs(xx); | ||||
| @@ -1524,7 +1525,6 @@ char *ftostr31(const float &x) | ||||
|  | ||||
| char *itostr31(const int &xx) | ||||
| { | ||||
|   //sprintf(conv,"%5.1f",x); | ||||
|   conv[0]=(xx>=0)?'+':'-'; | ||||
|   conv[1]=(xx/1000)%10+'0'; | ||||
|   conv[2]=(xx/100)%10+'0'; | ||||
| @@ -1534,6 +1534,7 @@ char *itostr31(const int &xx) | ||||
|   conv[6]=0; | ||||
|   return conv; | ||||
| } | ||||
|  | ||||
| char *itostr3(const int &xx) | ||||
| { | ||||
|   conv[0]=(xx/100)%10+'0'; | ||||
| @@ -1553,7 +1554,7 @@ char *itostr4(const int &xx) | ||||
|   return conv; | ||||
| } | ||||
|  | ||||
| ///  convert float to string with +1234.5 format | ||||
| //  convert float to string with +1234.5 format | ||||
| char *ftostr51(const float &x) | ||||
| { | ||||
|   int xx=x*10; | ||||
| @@ -1587,11 +1588,9 @@ char *fillto(int8_t n,char *c) | ||||
|   } | ||||
|   ret[n]=0; | ||||
|   return ret; | ||||
|    | ||||
| } | ||||
|  | ||||
| #else | ||||
| inline void lcd_status() {}; | ||||
| #endif | ||||
|  | ||||
| #endif //ULTRA_LCD | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -1,13 +1,16 @@ | ||||
| #ifndef __WATCHDOGH | ||||
| #define __WATCHDOGH | ||||
| #include "Configuration.h" | ||||
| //#ifdef USE_WATCHDOG | ||||
| #ifdef USE_WATCHDOG | ||||
|  | ||||
| /// intialise watch dog with a 1 sec interrupt time | ||||
| void wd_init(); | ||||
| /// pad the dog/reset watchdog. MUST be called at least every second after the first wd_init or avr will go into emergency procedures.. | ||||
| void wd_reset(); | ||||
|   // intialise watch dog with a 1 sec interrupt time | ||||
|   void wd_init(); | ||||
|   // pad the dog/reset watchdog. MUST be called at least every second after the first wd_init or avr will go into emergency procedures.. | ||||
|   void wd_reset(); | ||||
|  | ||||
| //#endif | ||||
| #else | ||||
|   inline void wd_init() {}; | ||||
|   inline void wd_reset() {}; | ||||
| #endif | ||||
|  | ||||
| #endif | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
| #include  <avr/wdt.h> | ||||
| #include  <avr/interrupt.h> | ||||
|  | ||||
| volatile uint8_t timeout_seconds=0; | ||||
| static volatile uint8_t timeout_seconds=0; | ||||
|  | ||||
| void(* ctrlaltdelete) (void) = 0; //does not work on my atmega2560 | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user