|
@@ -141,7 +141,7 @@ static volatile bool temp_meas_ready = false;
|
141
|
141
|
// Init min and max temp with extreme values to prevent false errors during startup
|
142
|
142
|
static int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP, HEATER_3_RAW_LO_TEMP);
|
143
|
143
|
static int maxttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_HI_TEMP , HEATER_1_RAW_HI_TEMP , HEATER_2_RAW_HI_TEMP, HEATER_3_RAW_HI_TEMP);
|
144
|
|
-static int minttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 0, 0, 0, 0 );
|
|
144
|
+static int minttemp[EXTRUDERS] = { 0 };
|
145
|
145
|
static int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 16383, 16383, 16383, 16383 );
|
146
|
146
|
//static int bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP; /* No bed mintemp error implemented?!? */
|
147
|
147
|
#ifdef BED_MAXTEMP
|
|
@@ -161,8 +161,8 @@ static float analog2tempBed(int raw);
|
161
|
161
|
static void updateTemperaturesFromRawValues();
|
162
|
162
|
|
163
|
163
|
#ifdef WATCH_TEMP_PERIOD
|
164
|
|
- int watch_start_temp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0,0);
|
165
|
|
- unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0,0);
|
|
164
|
+ int watch_start_temp[EXTRUDERS] = { 0 };
|
|
165
|
+ unsigned long watchmillis[EXTRUDERS] = { 0 };
|
166
|
166
|
#endif //WATCH_TEMP_PERIOD
|
167
|
167
|
|
168
|
168
|
#ifndef SOFT_PWM_SCALE
|
|
@@ -576,12 +576,6 @@ void manage_heater() {
|
576
|
576
|
|
577
|
577
|
updateTemperaturesFromRawValues();
|
578
|
578
|
|
579
|
|
- #ifdef HEATER_0_USES_MAX6675
|
580
|
|
- float ct = current_temperature[0];
|
581
|
|
- if (ct > min(HEATER_0_MAXTEMP, 1023)) max_temp_error(0);
|
582
|
|
- if (ct < max(HEATER_0_MINTEMP, 0.01)) min_temp_error(0);
|
583
|
|
- #endif //HEATER_0_USES_MAX6675
|
584
|
|
-
|
585
|
579
|
unsigned long ms = millis();
|
586
|
580
|
|
587
|
581
|
// Loop through all extruders
|
|
@@ -1060,28 +1054,28 @@ void disable_heater() {
|
1060
|
1054
|
for (int i=0; i<EXTRUDERS; i++) setTargetHotend(0, i);
|
1061
|
1055
|
setTargetBed(0);
|
1062
|
1056
|
|
|
1057
|
+ #define DISABLE_HEATER(NR) { \
|
|
1058
|
+ target_temperature[NR] = 0; \
|
|
1059
|
+ soft_pwm[NR] = 0; \
|
|
1060
|
+ WRITE_HEATER_ ## NR (LOW); \
|
|
1061
|
+ }
|
|
1062
|
+
|
1063
|
1063
|
#if HAS_TEMP_0
|
1064
|
1064
|
target_temperature[0] = 0;
|
1065
|
1065
|
soft_pwm[0] = 0;
|
1066
|
|
- WRITE_HEATER_0P(LOW); // If HEATERS_PARALLEL should apply, change to WRITE_HEATER_0
|
|
1066
|
+ WRITE_HEATER_0P(LOW); // Should HEATERS_PARALLEL apply here? Then change to DISABLE_HEATER(0)
|
1067
|
1067
|
#endif
|
1068
|
1068
|
|
1069
|
1069
|
#if EXTRUDERS > 1 && HAS_TEMP_1
|
1070
|
|
- target_temperature[1] = 0;
|
1071
|
|
- soft_pwm[1] = 0;
|
1072
|
|
- WRITE_HEATER_1(LOW);
|
|
1070
|
+ DISABLE_HEATER(1);
|
1073
|
1071
|
#endif
|
1074
|
1072
|
|
1075
|
1073
|
#if EXTRUDERS > 2 && HAS_TEMP_2
|
1076
|
|
- target_temperature[2] = 0;
|
1077
|
|
- soft_pwm[2] = 0;
|
1078
|
|
- WRITE_HEATER_2(LOW);
|
|
1074
|
+ DISABLE_HEATER(2);
|
1079
|
1075
|
#endif
|
1080
|
1076
|
|
1081
|
1077
|
#if EXTRUDERS > 3 && HAS_TEMP_3
|
1082
|
|
- target_temperature[3] = 0;
|
1083
|
|
- soft_pwm[3] = 0;
|
1084
|
|
- WRITE_HEATER_3(LOW);
|
|
1078
|
+ DISABLE_HEATER(3);
|
1085
|
1079
|
#endif
|
1086
|
1080
|
|
1087
|
1081
|
#if HAS_TEMP_BED
|
|
@@ -1172,9 +1166,15 @@ enum TempState {
|
1172
|
1166
|
// Timer 0 is shared with millies
|
1173
|
1167
|
//
|
1174
|
1168
|
ISR(TIMER0_COMPB_vect) {
|
|
1169
|
+ #ifdef TEMP_SENSOR_1_AS_REDUNDANT
|
|
1170
|
+ #define TEMP_SENSOR_COUNT 2
|
|
1171
|
+ #else
|
|
1172
|
+ #define TEMP_SENSOR_COUNT EXTRUDERS
|
|
1173
|
+ #endif
|
|
1174
|
+
|
1175
|
1175
|
//these variables are only accesible from the ISR, but static, so they don't lose their value
|
1176
|
1176
|
static unsigned char temp_count = 0;
|
1177
|
|
- static unsigned long raw_temp_value[EXTRUDERS] = { 0 };
|
|
1177
|
+ static unsigned long raw_temp_value[TEMP_SENSOR_COUNT] = { 0 };
|
1178
|
1178
|
static unsigned long raw_temp_bed_value = 0;
|
1179
|
1179
|
static TempState temp_state = StartupDelay;
|
1180
|
1180
|
static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
|
|
@@ -1390,6 +1390,7 @@ ISR(TIMER0_COMPB_vect) {
|
1390
|
1390
|
#endif
|
1391
|
1391
|
temp_state = PrepareTemp_BED;
|
1392
|
1392
|
break;
|
|
1393
|
+
|
1393
|
1394
|
case PrepareTemp_BED:
|
1394
|
1395
|
#if HAS_TEMP_BED
|
1395
|
1396
|
START_ADC(TEMP_BED_PIN);
|
|
@@ -1403,6 +1404,7 @@ ISR(TIMER0_COMPB_vect) {
|
1403
|
1404
|
#endif
|
1404
|
1405
|
temp_state = PrepareTemp_1;
|
1405
|
1406
|
break;
|
|
1407
|
+
|
1406
|
1408
|
case PrepareTemp_1:
|
1407
|
1409
|
#if HAS_TEMP_1
|
1408
|
1410
|
START_ADC(TEMP_1_PIN);
|
|
@@ -1416,6 +1418,7 @@ ISR(TIMER0_COMPB_vect) {
|
1416
|
1418
|
#endif
|
1417
|
1419
|
temp_state = PrepareTemp_2;
|
1418
|
1420
|
break;
|
|
1421
|
+
|
1419
|
1422
|
case PrepareTemp_2:
|
1420
|
1423
|
#if HAS_TEMP_2
|
1421
|
1424
|
START_ADC(TEMP_2_PIN);
|
|
@@ -1429,6 +1432,7 @@ ISR(TIMER0_COMPB_vect) {
|
1429
|
1432
|
#endif
|
1430
|
1433
|
temp_state = PrepareTemp_3;
|
1431
|
1434
|
break;
|
|
1435
|
+
|
1432
|
1436
|
case PrepareTemp_3:
|
1433
|
1437
|
#if HAS_TEMP_3
|
1434
|
1438
|
START_ADC(TEMP_3_PIN);
|
|
@@ -1442,6 +1446,7 @@ ISR(TIMER0_COMPB_vect) {
|
1442
|
1446
|
#endif
|
1443
|
1447
|
temp_state = Prepare_FILWIDTH;
|
1444
|
1448
|
break;
|
|
1449
|
+
|
1445
|
1450
|
case Prepare_FILWIDTH:
|
1446
|
1451
|
#if HAS_FILAMENT_SENSOR
|
1447
|
1452
|
START_ADC(FILWIDTH_PIN);
|
|
@@ -1460,6 +1465,7 @@ ISR(TIMER0_COMPB_vect) {
|
1460
|
1465
|
temp_state = PrepareTemp_0;
|
1461
|
1466
|
temp_count++;
|
1462
|
1467
|
break;
|
|
1468
|
+
|
1463
|
1469
|
case StartupDelay:
|
1464
|
1470
|
temp_state = PrepareTemp_0;
|
1465
|
1471
|
break;
|
|
@@ -1469,7 +1475,7 @@ ISR(TIMER0_COMPB_vect) {
|
1469
|
1475
|
// SERIAL_ERRORLNPGM("Temp measurement error!");
|
1470
|
1476
|
// break;
|
1471
|
1477
|
} // switch(temp_state)
|
1472
|
|
-
|
|
1478
|
+
|
1473
|
1479
|
if (temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256) = 164ms.
|
1474
|
1480
|
if (!temp_meas_ready) { //Only update the raw values if they have been read. Else we could be updating them during reading.
|
1475
|
1481
|
#ifndef HEATER_0_USES_MAX6675
|
|
@@ -1494,52 +1500,53 @@ ISR(TIMER0_COMPB_vect) {
|
1494
|
1500
|
#if HAS_FILAMENT_SENSOR
|
1495
|
1501
|
current_raw_filwidth = raw_filwidth_value >> 10; // Divide to get to 0-16384 range since we used 1/128 IIR filter approach
|
1496
|
1502
|
#endif
|
1497
|
|
-
|
|
1503
|
+
|
1498
|
1504
|
temp_meas_ready = true;
|
1499
|
1505
|
temp_count = 0;
|
1500
|
|
- for (int i = 0; i < EXTRUDERS; i++) raw_temp_value[i] = 0;
|
|
1506
|
+ for (int i = 0; i < TEMP_SENSOR_COUNT; i++) raw_temp_value[i] = 0;
|
1501
|
1507
|
raw_temp_bed_value = 0;
|
1502
|
1508
|
|
1503
|
|
- #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
|
1504
|
|
- #define GE0 <=
|
1505
|
|
- #define LE0 >=
|
|
1509
|
+ #ifdef HEATER_0_USES_MAX6675
|
|
1510
|
+ float ct = current_temperature[0];
|
|
1511
|
+ if (ct > min(HEATER_0_MAXTEMP, 1023)) max_temp_error(0);
|
|
1512
|
+ if (ct < max(HEATER_0_MINTEMP, 0.01)) min_temp_error(0);
|
1506
|
1513
|
#else
|
1507
|
|
- #define GE0 >=
|
1508
|
|
- #define LE0 <=
|
|
1514
|
+ #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
|
|
1515
|
+ #define GE0 <=
|
|
1516
|
+ #else
|
|
1517
|
+ #define GE0 >=
|
|
1518
|
+ #endif
|
|
1519
|
+ if (current_temperature_raw[0] GE0 maxttemp_raw[0]) max_temp_error(0);
|
|
1520
|
+ if (minttemp_raw[0] GE0 current_temperature_raw[0]) min_temp_error(0);
|
1509
|
1521
|
#endif
|
1510
|
|
- if (current_temperature_raw[0] GE0 maxttemp_raw[0]) max_temp_error(0);
|
1511
|
|
- if (current_temperature_raw[0] LE0 minttemp_raw[0]) min_temp_error(0);
|
1512
|
1522
|
|
1513
|
1523
|
#if EXTRUDERS > 1
|
1514
|
1524
|
#if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
|
1515
|
1525
|
#define GE1 <=
|
1516
|
|
- #define LE1 >=
|
1517
|
1526
|
#else
|
1518
|
1527
|
#define GE1 >=
|
1519
|
|
- #define LE1 <=
|
1520
|
1528
|
#endif
|
1521
|
1529
|
if (current_temperature_raw[1] GE1 maxttemp_raw[1]) max_temp_error(1);
|
1522
|
|
- if (current_temperature_raw[1] LE1 minttemp_raw[1]) min_temp_error(1);
|
|
1530
|
+ if (minttemp_raw[1] GE0 current_temperature_raw[1]) min_temp_error(1);
|
|
1531
|
+
|
1523
|
1532
|
#if EXTRUDERS > 2
|
1524
|
1533
|
#if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
|
1525
|
1534
|
#define GE2 <=
|
1526
|
|
- #define LE2 >=
|
1527
|
1535
|
#else
|
1528
|
1536
|
#define GE2 >=
|
1529
|
|
- #define LE2 <=
|
1530
|
1537
|
#endif
|
1531
|
1538
|
if (current_temperature_raw[2] GE2 maxttemp_raw[2]) max_temp_error(2);
|
1532
|
|
- if (current_temperature_raw[2] LE2 minttemp_raw[2]) min_temp_error(2);
|
|
1539
|
+ if (minttemp_raw[2] GE0 current_temperature_raw[2]) min_temp_error(2);
|
|
1540
|
+
|
1533
|
1541
|
#if EXTRUDERS > 3
|
1534
|
1542
|
#if HEATER_3_RAW_LO_TEMP > HEATER_3_RAW_HI_TEMP
|
1535
|
1543
|
#define GE3 <=
|
1536
|
|
- #define LE3 >=
|
1537
|
1544
|
#else
|
1538
|
1545
|
#define GE3 >=
|
1539
|
|
- #define LE3 <=
|
1540
|
1546
|
#endif
|
1541
|
1547
|
if (current_temperature_raw[3] GE3 maxttemp_raw[3]) max_temp_error(3);
|
1542
|
|
- if (current_temperature_raw[3] LE3 minttemp_raw[3]) min_temp_error(3);
|
|
1548
|
+ if (minttemp_raw[3] GE0 current_temperature_raw[3]) min_temp_error(3);
|
|
1549
|
+
|
1543
|
1550
|
#endif // EXTRUDERS > 3
|
1544
|
1551
|
#endif // EXTRUDERS > 2
|
1545
|
1552
|
#endif // EXTRUDERS > 1
|
|
@@ -1547,10 +1554,8 @@ ISR(TIMER0_COMPB_vect) {
|
1547
|
1554
|
#if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0)
|
1548
|
1555
|
#if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP
|
1549
|
1556
|
#define GEBED <=
|
1550
|
|
- #define LEBED >=
|
1551
|
1557
|
#else
|
1552
|
1558
|
#define GEBED >=
|
1553
|
|
- #define LEBED <=
|
1554
|
1559
|
#endif
|
1555
|
1560
|
if (current_temperature_bed_raw GEBED bed_maxttemp_raw) {
|
1556
|
1561
|
target_temperature_bed = 0;
|