Revert "Testing Fix for Arduino 1.6+ compiler issue #1523"

This reverts commit fb75a9272d.
This commit is contained in:
chrono 2015-03-02 13:47:35 +00:00
parent fb75a9272d
commit 7f060d7caf
2 changed files with 355 additions and 349 deletions

View file

@ -215,7 +215,7 @@ Here are some standard links for getting your machine calibrated:
// If your configuration is significantly different than this and you don't understand the issues involved, you probably // If your configuration is significantly different than this and you don't understand the issues involved, you probably
// shouldn't use bed PID until someone else verifies your hardware works. // shouldn't use bed PID until someone else verifies your hardware works.
// If this is enabled, find your own PID constants below. // If this is enabled, find your own PID constants below.
#define PIDTEMPBED //#define PIDTEMPBED
// //
//#define BED_LIMIT_SWITCHING //#define BED_LIMIT_SWITCHING
@ -226,10 +226,17 @@ Here are some standard links for getting your machine calibrated:
#define MAX_BED_POWER 255 // limits duty cycle to bed; 255=full current #define MAX_BED_POWER 255 // limits duty cycle to bed; 255=full current
#ifdef PIDTEMPBED #ifdef PIDTEMPBED
// Felix Foil Heater //120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
#define DEFAULT_bedKp 103.37 //from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10)
#define DEFAULT_bedKi 2.79 #define DEFAULT_bedKp 10.00
#define DEFAULT_bedKd 956.94 #define DEFAULT_bedKi .023
#define DEFAULT_bedKd 305.4
//120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
//from pidautotune
// #define DEFAULT_bedKp 97.1
// #define DEFAULT_bedKi 1.41
// #define DEFAULT_bedKd 1675.16
// FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles. // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
#endif // PIDTEMPBED #endif // PIDTEMPBED
@ -273,15 +280,15 @@ your extruder heater takes 2 minutes to hit the target on heating.
// uncomment the 2 defines below: // uncomment the 2 defines below:
// Parameters for all extruder heaters // Parameters for all extruder heaters
#define THERMAL_RUNAWAY_PROTECTION_PERIOD 60 //in seconds //#define THERMAL_RUNAWAY_PROTECTION_PERIOD 40 //in seconds
#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 5 // in degree Celsius //#define THERMAL_RUNAWAY_PROTECTION_HYSTERESIS 4 // in degree Celsius
// If you want to enable this feature for your bed heater, // If you want to enable this feature for your bed heater,
// uncomment the 2 defines below: // uncomment the 2 defines below:
// Parameters for the bed heater // Parameters for the bed heater
#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 30 //in seconds //#define THERMAL_RUNAWAY_PROTECTION_BED_PERIOD 20 //in seconds
#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 5// in degree Celsius //#define THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS 2 // in degree Celsius
//=========================================================================== //===========================================================================

View file

@ -109,7 +109,7 @@ static volatile bool temp_meas_ready = false;
static float temp_iState_min_bed; static float temp_iState_min_bed;
static float temp_iState_max_bed; static float temp_iState_max_bed;
#else //PIDTEMPBED #else //PIDTEMPBED
static unsigned long previous_millis_bed_heater; static unsigned long previous_millis_bed_heater;
#endif //PIDTEMPBED #endif //PIDTEMPBED
static unsigned char soft_pwm[EXTRUDERS]; static unsigned char soft_pwm[EXTRUDERS];
@ -377,8 +377,8 @@ void updatePID()
} }
int getHeaterPower(int heater) { int getHeaterPower(int heater) {
if (heater<0) if (heater<0)
return soft_pwm_bed; return soft_pwm_bed;
return soft_pwm[heater]; return soft_pwm[heater];
} }
@ -527,13 +527,12 @@ void manage_heater()
dTerm[e] = (PID_PARAM(Kd,e) * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); dTerm[e] = (PID_PARAM(Kd,e) * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
pid_output = pTerm[e] + iTerm[e] - dTerm[e]; pid_output = pTerm[e] + iTerm[e] - dTerm[e];
if (pid_output > PID_MAX) { if (pid_output > PID_MAX) {
if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
pid_output=PID_MAX; pid_output=PID_MAX;
} else if (pid_output < 0){ } else if (pid_output < 0){
if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
pid_output=0; pid_output=0;
} }
} }
temp_dState[e] = pid_input; temp_dState[e] = pid_input;
#else #else
@ -625,18 +624,18 @@ void manage_heater()
pid_input = current_temperature_bed; pid_input = current_temperature_bed;
#ifndef PID_OPENLOOP #ifndef PID_OPENLOOP
pid_error_bed = target_temperature_bed - pid_input; pid_error_bed = target_temperature_bed - pid_input;
pTerm_bed = bedKp * pid_error_bed; pTerm_bed = bedKp * pid_error_bed;
temp_iState_bed += pid_error_bed; temp_iState_bed += pid_error_bed;
temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed); temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed);
iTerm_bed = bedKi * temp_iState_bed; iTerm_bed = bedKi * temp_iState_bed;
//K1 defined in Configuration.h in the PID settings //K1 defined in Configuration.h in the PID settings
#define K2 (1.0-K1) #define K2 (1.0-K1)
dTerm_bed= (bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed); dTerm_bed= (bedKd * (pid_input - temp_dState_bed))*K2 + (K1 * dTerm_bed);
temp_dState_bed = pid_input; temp_dState_bed = pid_input;
pid_output = pTerm_bed + iTerm_bed - dTerm_bed; pid_output = pTerm_bed + iTerm_bed - dTerm_bed;
if (pid_output > MAX_BED_POWER) { if (pid_output > MAX_BED_POWER) {
if (pid_error_bed > 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration if (pid_error_bed > 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration
pid_output=MAX_BED_POWER; pid_output=MAX_BED_POWER;
@ -649,13 +648,13 @@ void manage_heater()
pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER); pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
#endif //PID_OPENLOOP #endif //PID_OPENLOOP
if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP))
{ {
soft_pwm_bed = (int)pid_output >> 1; soft_pwm_bed = (int)pid_output >> 1;
} }
else { else {
soft_pwm_bed = 0; soft_pwm_bed = 0;
} }
#elif !defined(BED_LIMIT_SWITCHING) #elif !defined(BED_LIMIT_SWITCHING)
// Check if temperature is within the correct range // Check if temperature is within the correct range
@ -699,23 +698,23 @@ void manage_heater()
//code for controlling the extruder rate based on the width sensor //code for controlling the extruder rate based on the width sensor
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
if(filament_sensor) if(filament_sensor)
{ {
meas_shift_index=delay_index1-meas_delay_cm; meas_shift_index=delay_index1-meas_delay_cm;
if(meas_shift_index<0) if(meas_shift_index<0)
meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed
//get the delayed info and add 100 to reconstitute to a percent of the nominal filament diameter //get the delayed info and add 100 to reconstitute to a percent of the nominal filament diameter
//then square it to get an area //then square it to get an area
if(meas_shift_index<0) if(meas_shift_index<0)
meas_shift_index=0; meas_shift_index=0;
else if (meas_shift_index>MAX_MEASUREMENT_DELAY) else if (meas_shift_index>MAX_MEASUREMENT_DELAY)
meas_shift_index=MAX_MEASUREMENT_DELAY; meas_shift_index=MAX_MEASUREMENT_DELAY;
volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = pow((float)(100+measurement_delay[meas_shift_index])/100.0,2); volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = pow((float)(100+measurement_delay[meas_shift_index])/100.0,2);
if (volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] <0.01) if (volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] <0.01)
volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]=0.01; volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]=0.01;
} }
#endif #endif
} }
@ -839,9 +838,9 @@ float temp;
temp=filament_width_meas; temp=filament_width_meas;
if(filament_width_meas<MEASURED_LOWER_LIMIT) if(filament_width_meas<MEASURED_LOWER_LIMIT)
temp=filament_width_nominal; //assume sensor cut out temp=filament_width_nominal; //assume sensor cut out
else if (filament_width_meas>MEASURED_UPPER_LIMIT) else if (filament_width_meas>MEASURED_UPPER_LIMIT)
temp= MEASURED_UPPER_LIMIT; temp= MEASURED_UPPER_LIMIT;
return(filament_width_nominal/temp*100); return(filament_width_nominal/temp*100);
@ -939,7 +938,7 @@ void tp_init()
#if TEMP_1_PIN < 8 #if TEMP_1_PIN < 8
DIDR0 |= 1<<TEMP_1_PIN; DIDR0 |= 1<<TEMP_1_PIN;
#else #else
DIDR2 |= 1<<(TEMP_1_PIN - 8); DIDR2 |= 1<<(TEMP_1_PIN - 8);
#endif #endif
#endif #endif
#if defined(TEMP_2_PIN) && (TEMP_2_PIN > -1) #if defined(TEMP_2_PIN) && (TEMP_2_PIN > -1)
@ -1442,27 +1441,27 @@ ISR(TIMER0_COMPB_vect)
if (soft_pwm_0 > 0) { if (soft_pwm_0 > 0) {
// turn ON heather only if the minimum time is up // turn ON heather only if the minimum time is up
if (state_timer_heater_0 == 0) { if (state_timer_heater_0 == 0) {
// if change state set timer // if change state set timer
if (state_heater_0 == 0) { if (state_heater_0 == 0) {
state_timer_heater_0 = MIN_STATE_TIME; state_timer_heater_0 = MIN_STATE_TIME;
} }
state_heater_0 = 1; state_heater_0 = 1;
WRITE(HEATER_0_PIN, 1); WRITE(HEATER_0_PIN, 1);
#ifdef HEATERS_PARALLEL #ifdef HEATERS_PARALLEL
WRITE(HEATER_1_PIN, 1); WRITE(HEATER_1_PIN, 1);
#endif #endif
} }
} else { } else {
// turn OFF heather only if the minimum time is up // turn OFF heather only if the minimum time is up
if (state_timer_heater_0 == 0) { if (state_timer_heater_0 == 0) {
// if change state set timer // if change state set timer
if (state_heater_0 == 1) { if (state_heater_0 == 1) {
state_timer_heater_0 = MIN_STATE_TIME; state_timer_heater_0 = MIN_STATE_TIME;
} }
state_heater_0 = 0; state_heater_0 = 0;
WRITE(HEATER_0_PIN, 0); WRITE(HEATER_0_PIN, 0);
#ifdef HEATERS_PARALLEL #ifdef HEATERS_PARALLEL
WRITE(HEATER_1_PIN, 0); WRITE(HEATER_1_PIN, 0);
#endif #endif
} }
} }
@ -1473,22 +1472,22 @@ ISR(TIMER0_COMPB_vect)
if (soft_pwm_1 > 0) { if (soft_pwm_1 > 0) {
// turn ON heather only if the minimum time is up // turn ON heather only if the minimum time is up
if (state_timer_heater_1 == 0) { if (state_timer_heater_1 == 0) {
// if change state set timer // if change state set timer
if (state_heater_1 == 0) { if (state_heater_1 == 0) {
state_timer_heater_1 = MIN_STATE_TIME; state_timer_heater_1 = MIN_STATE_TIME;
} }
state_heater_1 = 1; state_heater_1 = 1;
WRITE(HEATER_1_PIN, 1); WRITE(HEATER_1_PIN, 1);
} }
} else { } else {
// turn OFF heather only if the minimum time is up // turn OFF heather only if the minimum time is up
if (state_timer_heater_1 == 0) { if (state_timer_heater_1 == 0) {
// if change state set timer // if change state set timer
if (state_heater_1 == 1) { if (state_heater_1 == 1) {
state_timer_heater_1 = MIN_STATE_TIME; state_timer_heater_1 = MIN_STATE_TIME;
} }
state_heater_1 = 0; state_heater_1 = 0;
WRITE(HEATER_1_PIN, 0); WRITE(HEATER_1_PIN, 0);
} }
} }
#endif #endif
@ -1499,22 +1498,22 @@ ISR(TIMER0_COMPB_vect)
if (soft_pwm_2 > 0) { if (soft_pwm_2 > 0) {
// turn ON heather only if the minimum time is up // turn ON heather only if the minimum time is up
if (state_timer_heater_2 == 0) { if (state_timer_heater_2 == 0) {
// if change state set timer // if change state set timer
if (state_heater_2 == 0) { if (state_heater_2 == 0) {
state_timer_heater_2 = MIN_STATE_TIME; state_timer_heater_2 = MIN_STATE_TIME;
} }
state_heater_2 = 1; state_heater_2 = 1;
WRITE(HEATER_2_PIN, 1); WRITE(HEATER_2_PIN, 1);
} }
} else { } else {
// turn OFF heather only if the minimum time is up // turn OFF heather only if the minimum time is up
if (state_timer_heater_2 == 0) { if (state_timer_heater_2 == 0) {
// if change state set timer // if change state set timer
if (state_heater_2 == 1) { if (state_heater_2 == 1) {
state_timer_heater_2 = MIN_STATE_TIME; state_timer_heater_2 = MIN_STATE_TIME;
} }
state_heater_2 = 0; state_heater_2 = 0;
WRITE(HEATER_2_PIN, 0); WRITE(HEATER_2_PIN, 0);
} }
} }
#endif #endif
@ -1525,22 +1524,22 @@ ISR(TIMER0_COMPB_vect)
if (soft_pwm_3 > 0) { if (soft_pwm_3 > 0) {
// turn ON heather only if the minimum time is up // turn ON heather only if the minimum time is up
if (state_timer_heater_3 == 0) { if (state_timer_heater_3 == 0) {
// if change state set timer // if change state set timer
if (state_heater_3 == 0) { if (state_heater_3 == 0) {
state_timer_heater_3 = MIN_STATE_TIME; state_timer_heater_3 = MIN_STATE_TIME;
} }
state_heater_3 = 1; state_heater_3 = 1;
WRITE(HEATER_3_PIN, 1); WRITE(HEATER_3_PIN, 1);
} }
} else { } else {
// turn OFF heather only if the minimum time is up // turn OFF heather only if the minimum time is up
if (state_timer_heater_3 == 0) { if (state_timer_heater_3 == 0) {
// if change state set timer // if change state set timer
if (state_heater_3 == 1) { if (state_heater_3 == 1) {
state_timer_heater_3 = MIN_STATE_TIME; state_timer_heater_3 = MIN_STATE_TIME;
} }
state_heater_3 = 0; state_heater_3 = 0;
WRITE(HEATER_3_PIN, 0); WRITE(HEATER_3_PIN, 0);
} }
} }
#endif #endif
@ -1551,22 +1550,22 @@ ISR(TIMER0_COMPB_vect)
if (soft_pwm_b > 0) { if (soft_pwm_b > 0) {
// turn ON heather only if the minimum time is up // turn ON heather only if the minimum time is up
if (state_timer_heater_b == 0) { if (state_timer_heater_b == 0) {
// if change state set timer // if change state set timer
if (state_heater_b == 0) { if (state_heater_b == 0) {
state_timer_heater_b = MIN_STATE_TIME; state_timer_heater_b = MIN_STATE_TIME;
} }
state_heater_b = 1; state_heater_b = 1;
WRITE(HEATER_BED_PIN, 1); WRITE(HEATER_BED_PIN, 1);
} }
} else { } else {
// turn OFF heather only if the minimum time is up // turn OFF heather only if the minimum time is up
if (state_timer_heater_b == 0) { if (state_timer_heater_b == 0) {
// if change state set timer // if change state set timer
if (state_heater_b == 1) { if (state_heater_b == 1) {
state_timer_heater_b = MIN_STATE_TIME; state_timer_heater_b = MIN_STATE_TIME;
} }
state_heater_b = 0; state_heater_b = 0;
WRITE(HEATER_BED_PIN, 0); WRITE(HEATER_BED_PIN, 0);
} }
} }
#endif #endif
@ -1578,7 +1577,7 @@ ISR(TIMER0_COMPB_vect)
if (state_timer_heater_0 == 0) { if (state_timer_heater_0 == 0) {
// if change state set timer // if change state set timer
if (state_heater_0 == 1) { if (state_heater_0 == 1) {
state_timer_heater_0 = MIN_STATE_TIME; state_timer_heater_0 = MIN_STATE_TIME;
} }
state_heater_0 = 0; state_heater_0 = 0;
WRITE(HEATER_0_PIN, 0); WRITE(HEATER_0_PIN, 0);
@ -1595,7 +1594,7 @@ ISR(TIMER0_COMPB_vect)
if (state_timer_heater_1 == 0) { if (state_timer_heater_1 == 0) {
// if change state set timer // if change state set timer
if (state_heater_1 == 1) { if (state_heater_1 == 1) {
state_timer_heater_1 = MIN_STATE_TIME; state_timer_heater_1 = MIN_STATE_TIME;
} }
state_heater_1 = 0; state_heater_1 = 0;
WRITE(HEATER_1_PIN, 0); WRITE(HEATER_1_PIN, 0);
@ -1610,7 +1609,7 @@ ISR(TIMER0_COMPB_vect)
if (state_timer_heater_2 == 0) { if (state_timer_heater_2 == 0) {
// if change state set timer // if change state set timer
if (state_heater_2 == 1) { if (state_heater_2 == 1) {
state_timer_heater_2 = MIN_STATE_TIME; state_timer_heater_2 = MIN_STATE_TIME;
} }
state_heater_2 = 0; state_heater_2 = 0;
WRITE(HEATER_2_PIN, 0); WRITE(HEATER_2_PIN, 0);
@ -1625,7 +1624,7 @@ ISR(TIMER0_COMPB_vect)
if (state_timer_heater_3 == 0) { if (state_timer_heater_3 == 0) {
// if change state set timer // if change state set timer
if (state_heater_3 == 1) { if (state_heater_3 == 1) {
state_timer_heater_3 = MIN_STATE_TIME; state_timer_heater_3 = MIN_STATE_TIME;
} }
state_heater_3 = 0; state_heater_3 = 0;
WRITE(HEATER_3_PIN, 0); WRITE(HEATER_3_PIN, 0);
@ -1640,7 +1639,7 @@ ISR(TIMER0_COMPB_vect)
if (state_timer_heater_b == 0) { if (state_timer_heater_b == 0) {
// if change state set timer // if change state set timer
if (state_heater_b == 1) { if (state_heater_b == 1) {
state_timer_heater_b = MIN_STATE_TIME; state_timer_heater_b = MIN_STATE_TIME;
} }
state_heater_b = 0; state_heater_b = 0;
WRITE(HEATER_BED_PIN, 0); WRITE(HEATER_BED_PIN, 0);
@ -1810,7 +1809,7 @@ ISR(TIMER0_COMPB_vect)
//raw_filwidth_value += ADC; //remove to use an IIR filter approach //raw_filwidth_value += ADC; //remove to use an IIR filter approach
if(ADC>102) //check that ADC is reading a voltage > 0.5 volts, otherwise don't take in the data. if(ADC>102) //check that ADC is reading a voltage > 0.5 volts, otherwise don't take in the data.
{ {
raw_filwidth_value= raw_filwidth_value-(raw_filwidth_value>>7); //multipliy raw_filwidth_value by 127/128 raw_filwidth_value= raw_filwidth_value-(raw_filwidth_value>>7); //multipliy raw_filwidth_value by 127/128
raw_filwidth_value= raw_filwidth_value + ((unsigned long)ADC<<7); //add new ADC reading raw_filwidth_value= raw_filwidth_value + ((unsigned long)ADC<<7); //add new ADC reading
} }
@ -1975,12 +1974,12 @@ ISR(TIMER0_COMPB_vect)
float scalePID_i(float i) float scalePID_i(float i)
{ {
return i*PID_dT; return i*PID_dT;
} }
float unscalePID_i(float i) float unscalePID_i(float i)
{ {
return i/PID_dT; return i/PID_dT;
} }
float scalePID_d(float d) float scalePID_d(float d)
@ -1990,7 +1989,7 @@ float scalePID_d(float d)
float unscalePID_d(float d) float unscalePID_d(float d)
{ {
return d*PID_dT; return d*PID_dT;
} }
#endif //PIDTEMP #endif //PIDTEMP