Cleanup temperature code

- Get rid of unused temp states in the ISR, resulting in more frequent
temperature reading with fewer sensors
- Shrink code slightly in min/max testing
This commit is contained in:
Scott Lahteine 2015-03-23 00:27:29 -07:00
parent f65f61fa72
commit 6bdee87be3

View File

@ -1240,16 +1240,26 @@ void disable_heater() {
enum TempState { enum TempState {
PrepareTemp_0, PrepareTemp_0,
MeasureTemp_0, MeasureTemp_0,
#if HAS_TEMP_BED
PrepareTemp_BED, PrepareTemp_BED,
MeasureTemp_BED, MeasureTemp_BED,
#endif
#if HAS_TEMP_1
PrepareTemp_1, PrepareTemp_1,
MeasureTemp_1, MeasureTemp_1,
#endif
#if HAS_TEMP_2
PrepareTemp_2, PrepareTemp_2,
MeasureTemp_2, MeasureTemp_2,
#endif
#if HAS_TEMP_3
PrepareTemp_3, PrepareTemp_3,
MeasureTemp_3, MeasureTemp_3,
#endif
#if HAS_FILAMENT_SENSOR
Prepare_FILWIDTH, Prepare_FILWIDTH,
Measure_FILWIDTH, Measure_FILWIDTH,
#endif
StartupDelay // Startup, delay initial temp reading a tiny bit so the hardware can settle StartupDelay // Startup, delay initial temp reading a tiny bit so the hardware can settle
}; };
@ -1473,78 +1483,124 @@ ISR(TIMER0_COMPB_vect) {
#if HAS_TEMP_0 #if HAS_TEMP_0
raw_temp_value[0] += ADC; raw_temp_value[0] += ADC;
#endif #endif
temp_state = PrepareTemp_BED; temp_state =
break;
case PrepareTemp_BED:
#if HAS_TEMP_BED #if HAS_TEMP_BED
START_ADC(TEMP_BED_PIN); PrepareTemp_BED
#elif HAS_TEMP_1
PrepareTemp_1
#elif HAS_TEMP_2
PrepareTemp_2
#elif HAS_TEMP_3
PrepareTemp_3
#elif HAS_FILAMENT_SENSOR
Prepare_FILWIDTH
#else
PrepareTemp_0
#endif #endif
;
break;
#if HAS_TEMP_BED
case PrepareTemp_BED:
START_ADC(TEMP_BED_PIN);
lcd_buttons_update(); lcd_buttons_update();
temp_state = MeasureTemp_BED; temp_state = MeasureTemp_BED;
break; break;
case MeasureTemp_BED: case MeasureTemp_BED:
#if HAS_TEMP_BED
raw_temp_bed_value += ADC; raw_temp_bed_value += ADC;
#endif temp_state =
temp_state = PrepareTemp_1;
break;
case PrepareTemp_1:
#if HAS_TEMP_1 #if HAS_TEMP_1
START_ADC(TEMP_1_PIN); PrepareTemp_1
#elif HAS_TEMP_2
PrepareTemp_2
#elif HAS_TEMP_3
PrepareTemp_3
#elif HAS_FILAMENT_SENSOR
Prepare_FILWIDTH
#else
PrepareTemp_0
#endif #endif
;
break;
#endif
#if HAS_TEMP_1
case PrepareTemp_1:
START_ADC(TEMP_1_PIN);
lcd_buttons_update(); lcd_buttons_update();
temp_state = MeasureTemp_1; temp_state = MeasureTemp_1;
break; break;
case MeasureTemp_1: case MeasureTemp_1:
#if HAS_TEMP_1
raw_temp_value[1] += ADC; raw_temp_value[1] += ADC;
#endif temp_state =
temp_state = PrepareTemp_2;
break;
case PrepareTemp_2:
#if HAS_TEMP_2 #if HAS_TEMP_2
START_ADC(TEMP_2_PIN); PrepareTemp_2
#elif HAS_TEMP_3
PrepareTemp_3
#elif HAS_FILAMENT_SENSOR
Prepare_FILWIDTH
#else
PrepareTemp_0
#endif #endif
;
break;
#endif
#if HAS_TEMP_2
case PrepareTemp_2:
START_ADC(TEMP_2_PIN);
lcd_buttons_update(); lcd_buttons_update();
temp_state = MeasureTemp_2; temp_state = MeasureTemp_2;
break; break;
case MeasureTemp_2: case MeasureTemp_2:
#if HAS_TEMP_2
raw_temp_value[2] += ADC; raw_temp_value[2] += ADC;
#endif temp_state =
temp_state = PrepareTemp_3;
break;
case PrepareTemp_3:
#if HAS_TEMP_3 #if HAS_TEMP_3
START_ADC(TEMP_3_PIN); PrepareTemp_3
#elif HAS_FILAMENT_SENSOR
Prepare_FILWIDTH
#else
PrepareTemp_0
#endif #endif
;
break;
#endif
#if HAS_TEMP_3
case PrepareTemp_3:
START_ADC(TEMP_3_PIN);
lcd_buttons_update(); lcd_buttons_update();
temp_state = MeasureTemp_3; temp_state = MeasureTemp_3;
break; break;
case MeasureTemp_3: case MeasureTemp_3:
#if HAS_TEMP_3
raw_temp_value[3] += ADC; raw_temp_value[3] += ADC;
#endif temp_state =
temp_state = Prepare_FILWIDTH;
break;
case Prepare_FILWIDTH:
#if HAS_FILAMENT_SENSOR #if HAS_FILAMENT_SENSOR
START_ADC(FILWIDTH_PIN); Prepare_FILWIDTH
#else
PrepareTemp_0
#endif #endif
;
break;
#endif
#if HAS_FILAMENT_SENSOR
case Prepare_FILWIDTH:
START_ADC(FILWIDTH_PIN);
lcd_buttons_update(); lcd_buttons_update();
temp_state = Measure_FILWIDTH; temp_state = Measure_FILWIDTH;
break; break;
case Measure_FILWIDTH: case Measure_FILWIDTH:
#if HAS_FILAMENT_SENSOR
// 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>>7); //multiply raw_filwidth_value by 127/128 raw_filwidth_value -= (raw_filwidth_value>>7); //multiply raw_filwidth_value by 127/128
raw_filwidth_value += ((unsigned long)ADC<<7); //add new ADC reading raw_filwidth_value += ((unsigned long)ADC<<7); //add new ADC reading
} }
#endif
temp_state = PrepareTemp_0; temp_state = PrepareTemp_0;
temp_count++; temp_count++;
break; break;
#endif
case StartupDelay: case StartupDelay:
temp_state = PrepareTemp_0; temp_state = PrepareTemp_0;
break; break;
@ -1587,44 +1643,39 @@ ISR(TIMER0_COMPB_vect) {
#if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
#define GE0 <= #define GE0 <=
#define LE0 >=
#else #else
#define GE0 >= #define GE0 >=
#define LE0 <=
#endif #endif
if (current_temperature_raw[0] GE0 maxttemp_raw[0]) max_temp_error(0); if (current_temperature_raw[0] GE0 maxttemp_raw[0]) max_temp_error(0);
if (current_temperature_raw[0] LE0 minttemp_raw[0]) min_temp_error(0); if (minttemp_raw[0] GE0 current_temperature_raw[0]) min_temp_error(0);
#if EXTRUDERS > 1 #if EXTRUDERS > 1
#if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP #if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
#define GE1 <= #define GE1 <=
#define LE1 >=
#else #else
#define GE1 >= #define GE1 >=
#define LE1 <=
#endif #endif
if (current_temperature_raw[1] GE1 maxttemp_raw[1]) max_temp_error(1); if (current_temperature_raw[1] GE1 maxttemp_raw[1]) max_temp_error(1);
if (current_temperature_raw[1] LE1 minttemp_raw[1]) min_temp_error(1); if (minttemp_raw[1] GE0 current_temperature_raw[1]) min_temp_error(1);
#if EXTRUDERS > 2 #if EXTRUDERS > 2
#if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP #if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
#define GE2 <= #define GE2 <=
#define LE2 >=
#else #else
#define GE2 >= #define GE2 >=
#define LE2 <=
#endif #endif
if (current_temperature_raw[2] GE2 maxttemp_raw[2]) max_temp_error(2); if (current_temperature_raw[2] GE2 maxttemp_raw[2]) max_temp_error(2);
if (current_temperature_raw[2] LE2 minttemp_raw[2]) min_temp_error(2); if (minttemp_raw[2] GE0 current_temperature_raw[2]) min_temp_error(2);
#if EXTRUDERS > 3 #if EXTRUDERS > 3
#if HEATER_3_RAW_LO_TEMP > HEATER_3_RAW_HI_TEMP #if HEATER_3_RAW_LO_TEMP > HEATER_3_RAW_HI_TEMP
#define GE3 <= #define GE3 <=
#define LE3 >=
#else #else
#define GE3 >= #define GE3 >=
#define LE3 <=
#endif #endif
if (current_temperature_raw[3] GE3 maxttemp_raw[3]) max_temp_error(3); if (current_temperature_raw[3] GE3 maxttemp_raw[3]) max_temp_error(3);
if (current_temperature_raw[3] LE3 minttemp_raw[3]) min_temp_error(3); if (minttemp_raw[3] GE0 current_temperature_raw[3]) min_temp_error(3);
#endif // EXTRUDERS > 3 #endif // EXTRUDERS > 3
#endif // EXTRUDERS > 2 #endif // EXTRUDERS > 2
#endif // EXTRUDERS > 1 #endif // EXTRUDERS > 1
@ -1632,10 +1683,8 @@ ISR(TIMER0_COMPB_vect) {
#if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0) #if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0)
#if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP #if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP
#define GEBED <= #define GEBED <=
#define LEBED >=
#else #else
#define GEBED >= #define GEBED >=
#define LEBED <=
#endif #endif
if (current_temperature_bed_raw GEBED bed_maxttemp_raw) { if (current_temperature_bed_raw GEBED bed_maxttemp_raw) {
target_temperature_bed = 0; target_temperature_bed = 0;