|
@@ -219,7 +219,7 @@ void PID_autotune(float temp, int extruder, int ncycles)
|
219
|
219
|
|
220
|
220
|
SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START);
|
221
|
221
|
|
222
|
|
- disable_heater(); // switch off all heaters.
|
|
222
|
+ disable_all_heaters(); // switch off all heaters.
|
223
|
223
|
|
224
|
224
|
if (extruder < 0)
|
225
|
225
|
soft_pwm_bed = bias = d = MAX_BED_POWER / 2;
|
|
@@ -458,11 +458,11 @@ inline void _temp_error(int e, const char *msg1, const char *msg2) {
|
458
|
458
|
}
|
459
|
459
|
|
460
|
460
|
void max_temp_error(uint8_t e) {
|
461
|
|
- disable_heater();
|
|
461
|
+ disable_all_heaters();
|
462
|
462
|
_temp_error(e, PSTR(MSG_MAXTEMP_EXTRUDER_OFF), PSTR(MSG_ERR_MAXTEMP));
|
463
|
463
|
}
|
464
|
464
|
void min_temp_error(uint8_t e) {
|
465
|
|
- disable_heater();
|
|
465
|
+ disable_all_heaters();
|
466
|
466
|
_temp_error(e, PSTR(MSG_MINTEMP_EXTRUDER_OFF), PSTR(MSG_ERR_MINTEMP));
|
467
|
467
|
}
|
468
|
468
|
void bed_max_temp_error(void) {
|
|
@@ -579,6 +579,14 @@ float get_pid_output(int e) {
|
579
|
579
|
}
|
580
|
580
|
#endif
|
581
|
581
|
|
|
582
|
+/**
|
|
583
|
+ * Manage heating activities for extruder hot-ends and a heated bed
|
|
584
|
+ * - Acquire updated temperature readings
|
|
585
|
+ * - Invoke thermal runaway protection
|
|
586
|
+ * - Manage extruder auto-fan
|
|
587
|
+ * - Apply filament width to the extrusion rate (may move)
|
|
588
|
+ * - Update the heated bed PID output value
|
|
589
|
+ */
|
582
|
590
|
void manage_heater() {
|
583
|
591
|
|
584
|
592
|
if (!temp_meas_ready) return;
|
|
@@ -623,7 +631,7 @@ void manage_heater() {
|
623
|
631
|
|
624
|
632
|
#ifdef TEMP_SENSOR_1_AS_REDUNDANT
|
625
|
633
|
if (fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) {
|
626
|
|
- disable_heater();
|
|
634
|
+ disable_all_heaters();
|
627
|
635
|
_temp_error(0, PSTR(MSG_EXTRUDER_SWITCHED_OFF), PSTR(MSG_ERR_REDUNDANT_TEMP));
|
628
|
636
|
}
|
629
|
637
|
#endif // TEMP_SENSOR_1_AS_REDUNDANT
|
|
@@ -636,7 +644,22 @@ void manage_heater() {
|
636
|
644
|
next_auto_fan_check_ms = ms + 2500;
|
637
|
645
|
}
|
638
|
646
|
#endif
|
639
|
|
-
|
|
647
|
+
|
|
648
|
+ // Control the extruder rate based on the width sensor
|
|
649
|
+ #ifdef FILAMENT_SENSOR
|
|
650
|
+ if (filament_sensor) {
|
|
651
|
+ meas_shift_index = delay_index1 - meas_delay_cm;
|
|
652
|
+ if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1; //loop around buffer if needed
|
|
653
|
+
|
|
654
|
+ // Get the delayed info and add 100 to reconstitute to a percent of
|
|
655
|
+ // the nominal filament diameter then square it to get an area
|
|
656
|
+ meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
|
|
657
|
+ float vm = pow((measurement_delay[meas_shift_index] + 100.0) / 100.0, 2);
|
|
658
|
+ if (vm < 0.01) vm = 0.01;
|
|
659
|
+ volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vm;
|
|
660
|
+ }
|
|
661
|
+ #endif //FILAMENT_SENSOR
|
|
662
|
+
|
640
|
663
|
#ifndef PIDTEMPBED
|
641
|
664
|
if (ms < next_bed_check_ms) return;
|
642
|
665
|
next_bed_check_ms = ms + BED_CHECK_INTERVAL;
|
|
@@ -653,22 +676,22 @@ void manage_heater() {
|
653
|
676
|
|
654
|
677
|
soft_pwm_bed = current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP ? (int)pid_output >> 1 : 0;
|
655
|
678
|
|
656
|
|
- #elif !defined(BED_LIMIT_SWITCHING)
|
657
|
|
- // Check if temperature is within the correct range
|
|
679
|
+ #elif defined(BED_LIMIT_SWITCHING)
|
|
680
|
+ // Check if temperature is within the correct band
|
658
|
681
|
if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
|
659
|
|
- soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
|
|
682
|
+ if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
|
|
683
|
+ soft_pwm_bed = 0;
|
|
684
|
+ else if (current_temperature_bed <= target_temperature_bed - BED_HYSTERESIS)
|
|
685
|
+ soft_pwm_bed = MAX_BED_POWER >> 1;
|
660
|
686
|
}
|
661
|
687
|
else {
|
662
|
688
|
soft_pwm_bed = 0;
|
663
|
689
|
WRITE_HEATER_BED(LOW);
|
664
|
690
|
}
|
665
|
|
- #else //#ifdef BED_LIMIT_SWITCHING
|
666
|
|
- // Check if temperature is within the correct band
|
|
691
|
+ #else // BED_LIMIT_SWITCHING
|
|
692
|
+ // Check if temperature is within the correct range
|
667
|
693
|
if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
|
668
|
|
- if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
|
669
|
|
- soft_pwm_bed = 0;
|
670
|
|
- else if (current_temperature_bed <= target_temperature_bed - BED_HYSTERESIS)
|
671
|
|
- soft_pwm_bed = MAX_BED_POWER >> 1;
|
|
694
|
+ soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
|
672
|
695
|
}
|
673
|
696
|
else {
|
674
|
697
|
soft_pwm_bed = 0;
|
|
@@ -676,56 +699,36 @@ void manage_heater() {
|
676
|
699
|
}
|
677
|
700
|
#endif
|
678
|
701
|
#endif //TEMP_SENSOR_BED != 0
|
679
|
|
-
|
680
|
|
- // Control the extruder rate based on the width sensor
|
681
|
|
- #ifdef FILAMENT_SENSOR
|
682
|
|
- if (filament_sensor) {
|
683
|
|
- meas_shift_index = delay_index1 - meas_delay_cm;
|
684
|
|
- if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1; //loop around buffer if needed
|
685
|
|
-
|
686
|
|
- // Get the delayed info and add 100 to reconstitute to a percent of
|
687
|
|
- // the nominal filament diameter then square it to get an area
|
688
|
|
- meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
|
689
|
|
- float vm = pow((measurement_delay[meas_shift_index] + 100.0) / 100.0, 2);
|
690
|
|
- if (vm < 0.01) vm = 0.01;
|
691
|
|
- volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = vm;
|
692
|
|
- }
|
693
|
|
- #endif //FILAMENT_SENSOR
|
694
|
702
|
}
|
695
|
703
|
|
696
|
704
|
#define PGM_RD_W(x) (short)pgm_read_word(&x)
|
697
|
705
|
// Derived from RepRap FiveD extruder::getTemperature()
|
698
|
706
|
// For hot end temperature measurement.
|
699
|
707
|
static float analog2temp(int raw, uint8_t e) {
|
700
|
|
-#ifdef TEMP_SENSOR_1_AS_REDUNDANT
|
701
|
|
- if (e > EXTRUDERS)
|
702
|
|
-#else
|
703
|
|
- if (e >= EXTRUDERS)
|
704
|
|
-#endif
|
705
|
|
- {
|
|
708
|
+ #ifdef TEMP_SENSOR_1_AS_REDUNDANT
|
|
709
|
+ if (e > EXTRUDERS)
|
|
710
|
+ #else
|
|
711
|
+ if (e >= EXTRUDERS)
|
|
712
|
+ #endif
|
|
713
|
+ {
|
706
|
714
|
SERIAL_ERROR_START;
|
707
|
715
|
SERIAL_ERROR((int)e);
|
708
|
716
|
SERIAL_ERRORLNPGM(MSG_INVALID_EXTRUDER_NUM);
|
709
|
717
|
kill();
|
710
|
718
|
return 0.0;
|
711
|
|
- }
|
|
719
|
+ }
|
|
720
|
+
|
712
|
721
|
#ifdef HEATER_0_USES_MAX6675
|
713
|
|
- if (e == 0)
|
714
|
|
- {
|
715
|
|
- return 0.25 * raw;
|
716
|
|
- }
|
|
722
|
+ if (e == 0) return 0.25 * raw;
|
717
|
723
|
#endif
|
718
|
724
|
|
719
|
|
- if(heater_ttbl_map[e] != NULL)
|
720
|
|
- {
|
|
725
|
+ if (heater_ttbl_map[e] != NULL) {
|
721
|
726
|
float celsius = 0;
|
722
|
727
|
uint8_t i;
|
723
|
728
|
short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
|
724
|
729
|
|
725
|
|
- for (i=1; i<heater_ttbllen_map[e]; i++)
|
726
|
|
- {
|
727
|
|
- if (PGM_RD_W((*tt)[i][0]) > raw)
|
728
|
|
- {
|
|
730
|
+ for (i = 1; i < heater_ttbllen_map[e]; i++) {
|
|
731
|
+ if (PGM_RD_W((*tt)[i][0]) > raw) {
|
729
|
732
|
celsius = PGM_RD_W((*tt)[i-1][1]) +
|
730
|
733
|
(raw - PGM_RD_W((*tt)[i-1][0])) *
|
731
|
734
|
(float)(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1])) /
|
|
@@ -749,10 +752,8 @@ static float analog2tempBed(int raw) {
|
749
|
752
|
float celsius = 0;
|
750
|
753
|
byte i;
|
751
|
754
|
|
752
|
|
- for (i=1; i<BEDTEMPTABLE_LEN; i++)
|
753
|
|
- {
|
754
|
|
- if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw)
|
755
|
|
- {
|
|
755
|
+ for (i = 1; i < BEDTEMPTABLE_LEN; i++) {
|
|
756
|
+ if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw) {
|
756
|
757
|
celsius = PGM_RD_W(BEDTEMPTABLE[i-1][1]) +
|
757
|
758
|
(raw - PGM_RD_W(BEDTEMPTABLE[i-1][0])) *
|
758
|
759
|
(float)(PGM_RD_W(BEDTEMPTABLE[i][1]) - PGM_RD_W(BEDTEMPTABLE[i-1][1])) /
|
|
@@ -816,11 +817,11 @@ static void updateTemperaturesFromRawValues() {
|
816
|
817
|
#endif
|
817
|
818
|
|
818
|
819
|
|
819
|
|
-
|
820
|
|
-
|
821
|
|
-
|
822
|
|
-void tp_init()
|
823
|
|
-{
|
|
820
|
+/**
|
|
821
|
+ * Initialize the temperature manager
|
|
822
|
+ * The manager is implemented by periodic calls to manage_heater()
|
|
823
|
+ */
|
|
824
|
+void tp_init() {
|
824
|
825
|
#if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1))
|
825
|
826
|
//disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
|
826
|
827
|
MCUCR=BIT(JTD);
|
|
@@ -1059,7 +1060,7 @@ void setWatch() {
|
1059
|
1060
|
SERIAL_ERRORLNPGM(MSG_THERMAL_RUNAWAY_STOP);
|
1060
|
1061
|
if (heater_id < 0) SERIAL_ERRORLNPGM("bed"); else SERIAL_ERRORLN(heater_id);
|
1061
|
1062
|
LCD_ALERTMESSAGEPGM(MSG_THERMAL_RUNAWAY);
|
1062
|
|
- disable_heater();
|
|
1063
|
+ disable_all_heaters();
|
1063
|
1064
|
disable_all_steppers();
|
1064
|
1065
|
for (;;) {
|
1065
|
1066
|
manage_heater();
|
|
@@ -1070,7 +1071,7 @@ void setWatch() {
|
1070
|
1071
|
|
1071
|
1072
|
#endif // HAS_HEATER_THERMAL_PROTECTION || HAS_BED_THERMAL_PROTECTION
|
1072
|
1073
|
|
1073
|
|
-void disable_heater() {
|
|
1074
|
+void disable_all_heaters() {
|
1074
|
1075
|
for (int i=0; i<EXTRUDERS; i++) setTargetHotend(0, i);
|
1075
|
1076
|
setTargetBed(0);
|
1076
|
1077
|
|
|
@@ -1208,11 +1209,15 @@ static void set_current_temp_raw() {
|
1208
|
1209
|
temp_meas_ready = true;
|
1209
|
1210
|
}
|
1210
|
1211
|
|
1211
|
|
-//
|
1212
|
|
-// Timer 0 is shared with millies
|
1213
|
|
-//
|
|
1212
|
+/**
|
|
1213
|
+ * Timer 0 is shared with millies
|
|
1214
|
+ * - Manage PWM to all the heaters and fan
|
|
1215
|
+ * - Update the raw temperature values
|
|
1216
|
+ * - Check new temperature values for MIN/MAX errors
|
|
1217
|
+ * - Step the babysteps value for each axis towards 0
|
|
1218
|
+ */
|
1214
|
1219
|
ISR(TIMER0_COMPB_vect) {
|
1215
|
|
- //these variables are only accesible from the ISR, but static, so they don't lose their value
|
|
1220
|
+
|
1216
|
1221
|
static unsigned char temp_count = 0;
|
1217
|
1222
|
static TempState temp_state = StartupDelay;
|
1218
|
1223
|
static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
|
|
@@ -1414,6 +1419,7 @@ ISR(TIMER0_COMPB_vect) {
|
1414
|
1419
|
#define START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
|
1415
|
1420
|
#endif
|
1416
|
1421
|
|
|
1422
|
+ // Prepare or measure a sensor, each one every 12th frame
|
1417
|
1423
|
switch(temp_state) {
|
1418
|
1424
|
case PrepareTemp_0:
|
1419
|
1425
|
#if HAS_TEMP_0
|
|
@@ -1582,16 +1588,16 @@ ISR(TIMER0_COMPB_vect) {
|
1582
|
1588
|
} // temp_count >= OVERSAMPLENR
|
1583
|
1589
|
|
1584
|
1590
|
#ifdef BABYSTEPPING
|
1585
|
|
- for (uint8_t axis=X_AXIS; axis<=Z_AXIS; axis++) {
|
1586
|
|
- int curTodo=babystepsTodo[axis]; //get rid of volatile for performance
|
|
1591
|
+ for (uint8_t axis = X_AXIS; axis <= Z_AXIS; axis++) {
|
|
1592
|
+ int curTodo = babystepsTodo[axis]; //get rid of volatile for performance
|
1587
|
1593
|
|
1588
|
1594
|
if (curTodo > 0) {
|
1589
|
1595
|
babystep(axis,/*fwd*/true);
|
1590
|
|
- babystepsTodo[axis]--; //less to do next time
|
|
1596
|
+ babystepsTodo[axis]--; //fewer to do next time
|
1591
|
1597
|
}
|
1592
|
|
- else if(curTodo < 0) {
|
|
1598
|
+ else if (curTodo < 0) {
|
1593
|
1599
|
babystep(axis,/*fwd*/false);
|
1594
|
|
- babystepsTodo[axis]++; //less to do next time
|
|
1600
|
+ babystepsTodo[axis]++; //fewer to do next time
|
1595
|
1601
|
}
|
1596
|
1602
|
}
|
1597
|
1603
|
#endif //BABYSTEPPING
|