|
@@ -1240,16 +1240,26 @@ void disable_heater() {
|
1240
|
1240
|
enum TempState {
|
1241
|
1241
|
PrepareTemp_0,
|
1242
|
1242
|
MeasureTemp_0,
|
1243
|
|
- PrepareTemp_BED,
|
1244
|
|
- MeasureTemp_BED,
|
1245
|
|
- PrepareTemp_1,
|
1246
|
|
- MeasureTemp_1,
|
1247
|
|
- PrepareTemp_2,
|
1248
|
|
- MeasureTemp_2,
|
1249
|
|
- PrepareTemp_3,
|
1250
|
|
- MeasureTemp_3,
|
1251
|
|
- Prepare_FILWIDTH,
|
1252
|
|
- Measure_FILWIDTH,
|
|
1243
|
+ #if HAS_TEMP_BED
|
|
1244
|
+ PrepareTemp_BED,
|
|
1245
|
+ MeasureTemp_BED,
|
|
1246
|
+ #endif
|
|
1247
|
+ #if HAS_TEMP_1
|
|
1248
|
+ PrepareTemp_1,
|
|
1249
|
+ MeasureTemp_1,
|
|
1250
|
+ #endif
|
|
1251
|
+ #if HAS_TEMP_2
|
|
1252
|
+ PrepareTemp_2,
|
|
1253
|
+ MeasureTemp_2,
|
|
1254
|
+ #endif
|
|
1255
|
+ #if HAS_TEMP_3
|
|
1256
|
+ PrepareTemp_3,
|
|
1257
|
+ MeasureTemp_3,
|
|
1258
|
+ #endif
|
|
1259
|
+ #if HAS_FILAMENT_SENSOR
|
|
1260
|
+ Prepare_FILWIDTH,
|
|
1261
|
+ Measure_FILWIDTH,
|
|
1262
|
+ #endif
|
1253
|
1263
|
StartupDelay // Startup, delay initial temp reading a tiny bit so the hardware can settle
|
1254
|
1264
|
};
|
1255
|
1265
|
|
|
@@ -1473,78 +1483,124 @@ ISR(TIMER0_COMPB_vect) {
|
1473
|
1483
|
#if HAS_TEMP_0
|
1474
|
1484
|
raw_temp_value[0] += ADC;
|
1475
|
1485
|
#endif
|
1476
|
|
- temp_state = PrepareTemp_BED;
|
|
1486
|
+ temp_state =
|
|
1487
|
+ #if HAS_TEMP_BED
|
|
1488
|
+ PrepareTemp_BED
|
|
1489
|
+ #elif HAS_TEMP_1
|
|
1490
|
+ PrepareTemp_1
|
|
1491
|
+ #elif HAS_TEMP_2
|
|
1492
|
+ PrepareTemp_2
|
|
1493
|
+ #elif HAS_TEMP_3
|
|
1494
|
+ PrepareTemp_3
|
|
1495
|
+ #elif HAS_FILAMENT_SENSOR
|
|
1496
|
+ Prepare_FILWIDTH
|
|
1497
|
+ #else
|
|
1498
|
+ PrepareTemp_0
|
|
1499
|
+ #endif
|
|
1500
|
+ ;
|
1477
|
1501
|
break;
|
1478
|
|
- case PrepareTemp_BED:
|
1479
|
|
- #if HAS_TEMP_BED
|
|
1502
|
+
|
|
1503
|
+ #if HAS_TEMP_BED
|
|
1504
|
+ case PrepareTemp_BED:
|
1480
|
1505
|
START_ADC(TEMP_BED_PIN);
|
1481
|
|
- #endif
|
1482
|
|
- lcd_buttons_update();
|
1483
|
|
- temp_state = MeasureTemp_BED;
|
1484
|
|
- break;
|
1485
|
|
- case MeasureTemp_BED:
|
1486
|
|
- #if HAS_TEMP_BED
|
|
1506
|
+ lcd_buttons_update();
|
|
1507
|
+ temp_state = MeasureTemp_BED;
|
|
1508
|
+ break;
|
|
1509
|
+ case MeasureTemp_BED:
|
1487
|
1510
|
raw_temp_bed_value += ADC;
|
1488
|
|
- #endif
|
1489
|
|
- temp_state = PrepareTemp_1;
|
1490
|
|
- break;
|
1491
|
|
- case PrepareTemp_1:
|
1492
|
|
- #if HAS_TEMP_1
|
|
1511
|
+ temp_state =
|
|
1512
|
+ #if HAS_TEMP_1
|
|
1513
|
+ PrepareTemp_1
|
|
1514
|
+ #elif HAS_TEMP_2
|
|
1515
|
+ PrepareTemp_2
|
|
1516
|
+ #elif HAS_TEMP_3
|
|
1517
|
+ PrepareTemp_3
|
|
1518
|
+ #elif HAS_FILAMENT_SENSOR
|
|
1519
|
+ Prepare_FILWIDTH
|
|
1520
|
+ #else
|
|
1521
|
+ PrepareTemp_0
|
|
1522
|
+ #endif
|
|
1523
|
+ ;
|
|
1524
|
+ break;
|
|
1525
|
+ #endif
|
|
1526
|
+
|
|
1527
|
+ #if HAS_TEMP_1
|
|
1528
|
+ case PrepareTemp_1:
|
1493
|
1529
|
START_ADC(TEMP_1_PIN);
|
1494
|
|
- #endif
|
1495
|
|
- lcd_buttons_update();
|
1496
|
|
- temp_state = MeasureTemp_1;
|
1497
|
|
- break;
|
1498
|
|
- case MeasureTemp_1:
|
1499
|
|
- #if HAS_TEMP_1
|
|
1530
|
+ lcd_buttons_update();
|
|
1531
|
+ temp_state = MeasureTemp_1;
|
|
1532
|
+ break;
|
|
1533
|
+ case MeasureTemp_1:
|
1500
|
1534
|
raw_temp_value[1] += ADC;
|
1501
|
|
- #endif
|
1502
|
|
- temp_state = PrepareTemp_2;
|
1503
|
|
- break;
|
1504
|
|
- case PrepareTemp_2:
|
1505
|
|
- #if HAS_TEMP_2
|
|
1535
|
+ temp_state =
|
|
1536
|
+ #if HAS_TEMP_2
|
|
1537
|
+ PrepareTemp_2
|
|
1538
|
+ #elif HAS_TEMP_3
|
|
1539
|
+ PrepareTemp_3
|
|
1540
|
+ #elif HAS_FILAMENT_SENSOR
|
|
1541
|
+ Prepare_FILWIDTH
|
|
1542
|
+ #else
|
|
1543
|
+ PrepareTemp_0
|
|
1544
|
+ #endif
|
|
1545
|
+ ;
|
|
1546
|
+ break;
|
|
1547
|
+ #endif
|
|
1548
|
+
|
|
1549
|
+ #if HAS_TEMP_2
|
|
1550
|
+ case PrepareTemp_2:
|
1506
|
1551
|
START_ADC(TEMP_2_PIN);
|
1507
|
|
- #endif
|
1508
|
|
- lcd_buttons_update();
|
1509
|
|
- temp_state = MeasureTemp_2;
|
1510
|
|
- break;
|
1511
|
|
- case MeasureTemp_2:
|
1512
|
|
- #if HAS_TEMP_2
|
|
1552
|
+ lcd_buttons_update();
|
|
1553
|
+ temp_state = MeasureTemp_2;
|
|
1554
|
+ break;
|
|
1555
|
+ case MeasureTemp_2:
|
1513
|
1556
|
raw_temp_value[2] += ADC;
|
1514
|
|
- #endif
|
1515
|
|
- temp_state = PrepareTemp_3;
|
1516
|
|
- break;
|
1517
|
|
- case PrepareTemp_3:
|
1518
|
|
- #if HAS_TEMP_3
|
|
1557
|
+ temp_state =
|
|
1558
|
+ #if HAS_TEMP_3
|
|
1559
|
+ PrepareTemp_3
|
|
1560
|
+ #elif HAS_FILAMENT_SENSOR
|
|
1561
|
+ Prepare_FILWIDTH
|
|
1562
|
+ #else
|
|
1563
|
+ PrepareTemp_0
|
|
1564
|
+ #endif
|
|
1565
|
+ ;
|
|
1566
|
+ break;
|
|
1567
|
+ #endif
|
|
1568
|
+
|
|
1569
|
+ #if HAS_TEMP_3
|
|
1570
|
+ case PrepareTemp_3:
|
1519
|
1571
|
START_ADC(TEMP_3_PIN);
|
1520
|
|
- #endif
|
1521
|
|
- lcd_buttons_update();
|
1522
|
|
- temp_state = MeasureTemp_3;
|
1523
|
|
- break;
|
1524
|
|
- case MeasureTemp_3:
|
1525
|
|
- #if HAS_TEMP_3
|
|
1572
|
+ lcd_buttons_update();
|
|
1573
|
+ temp_state = MeasureTemp_3;
|
|
1574
|
+ break;
|
|
1575
|
+ case MeasureTemp_3:
|
1526
|
1576
|
raw_temp_value[3] += ADC;
|
1527
|
|
- #endif
|
1528
|
|
- temp_state = Prepare_FILWIDTH;
|
1529
|
|
- break;
|
1530
|
|
- case Prepare_FILWIDTH:
|
1531
|
|
- #if HAS_FILAMENT_SENSOR
|
|
1577
|
+ temp_state =
|
|
1578
|
+ #if HAS_FILAMENT_SENSOR
|
|
1579
|
+ Prepare_FILWIDTH
|
|
1580
|
+ #else
|
|
1581
|
+ PrepareTemp_0
|
|
1582
|
+ #endif
|
|
1583
|
+ ;
|
|
1584
|
+ break;
|
|
1585
|
+ #endif
|
|
1586
|
+
|
|
1587
|
+ #if HAS_FILAMENT_SENSOR
|
|
1588
|
+ case Prepare_FILWIDTH:
|
1532
|
1589
|
START_ADC(FILWIDTH_PIN);
|
1533
|
|
- #endif
|
1534
|
|
- lcd_buttons_update();
|
1535
|
|
- temp_state = Measure_FILWIDTH;
|
1536
|
|
- break;
|
1537
|
|
- case Measure_FILWIDTH:
|
1538
|
|
- #if HAS_FILAMENT_SENSOR
|
|
1590
|
+ lcd_buttons_update();
|
|
1591
|
+ temp_state = Measure_FILWIDTH;
|
|
1592
|
+ break;
|
|
1593
|
+ case Measure_FILWIDTH:
|
1539
|
1594
|
// raw_filwidth_value += ADC; //remove to use an IIR filter approach
|
1540
|
1595
|
if (ADC > 102) { //check that ADC is reading a voltage > 0.5 volts, otherwise don't take in the data.
|
1541
|
1596
|
raw_filwidth_value -= (raw_filwidth_value>>7); //multiply raw_filwidth_value by 127/128
|
1542
|
1597
|
raw_filwidth_value += ((unsigned long)ADC<<7); //add new ADC reading
|
1543
|
1598
|
}
|
1544
|
|
- #endif
|
1545
|
|
- temp_state = PrepareTemp_0;
|
1546
|
|
- temp_count++;
|
1547
|
|
- break;
|
|
1599
|
+ temp_state = PrepareTemp_0;
|
|
1600
|
+ temp_count++;
|
|
1601
|
+ break;
|
|
1602
|
+ #endif
|
|
1603
|
+
|
1548
|
1604
|
case StartupDelay:
|
1549
|
1605
|
temp_state = PrepareTemp_0;
|
1550
|
1606
|
break;
|
|
@@ -1554,7 +1610,7 @@ ISR(TIMER0_COMPB_vect) {
|
1554
|
1610
|
// SERIAL_ERRORLNPGM("Temp measurement error!");
|
1555
|
1611
|
// break;
|
1556
|
1612
|
} // switch(temp_state)
|
1557
|
|
-
|
|
1613
|
+
|
1558
|
1614
|
if (temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256) = 164ms.
|
1559
|
1615
|
if (!temp_meas_ready) { //Only update the raw values if they have been read. Else we could be updating them during reading.
|
1560
|
1616
|
#ifndef HEATER_0_USES_MAX6675
|
|
@@ -1579,7 +1635,7 @@ ISR(TIMER0_COMPB_vect) {
|
1579
|
1635
|
#if HAS_FILAMENT_SENSOR
|
1580
|
1636
|
current_raw_filwidth = raw_filwidth_value >> 10; // Divide to get to 0-16384 range since we used 1/128 IIR filter approach
|
1581
|
1637
|
#endif
|
1582
|
|
-
|
|
1638
|
+
|
1583
|
1639
|
temp_meas_ready = true;
|
1584
|
1640
|
temp_count = 0;
|
1585
|
1641
|
for (int i = 0; i < EXTRUDERS; i++) raw_temp_value[i] = 0;
|
|
@@ -1587,44 +1643,39 @@ ISR(TIMER0_COMPB_vect) {
|
1587
|
1643
|
|
1588
|
1644
|
#if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
|
1589
|
1645
|
#define GE0 <=
|
1590
|
|
- #define LE0 >=
|
1591
|
1646
|
#else
|
1592
|
1647
|
#define GE0 >=
|
1593
|
|
- #define LE0 <=
|
1594
|
1648
|
#endif
|
1595
|
1649
|
if (current_temperature_raw[0] GE0 maxttemp_raw[0]) max_temp_error(0);
|
1596
|
|
- if (current_temperature_raw[0] LE0 minttemp_raw[0]) min_temp_error(0);
|
|
1650
|
+ if (minttemp_raw[0] GE0 current_temperature_raw[0]) min_temp_error(0);
|
1597
|
1651
|
|
1598
|
1652
|
#if EXTRUDERS > 1
|
1599
|
1653
|
#if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
|
1600
|
1654
|
#define GE1 <=
|
1601
|
|
- #define LE1 >=
|
1602
|
1655
|
#else
|
1603
|
1656
|
#define GE1 >=
|
1604
|
|
- #define LE1 <=
|
1605
|
1657
|
#endif
|
1606
|
1658
|
if (current_temperature_raw[1] GE1 maxttemp_raw[1]) max_temp_error(1);
|
1607
|
|
- if (current_temperature_raw[1] LE1 minttemp_raw[1]) min_temp_error(1);
|
|
1659
|
+ if (minttemp_raw[1] GE0 current_temperature_raw[1]) min_temp_error(1);
|
|
1660
|
+
|
1608
|
1661
|
#if EXTRUDERS > 2
|
1609
|
1662
|
#if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
|
1610
|
1663
|
#define GE2 <=
|
1611
|
|
- #define LE2 >=
|
1612
|
1664
|
#else
|
1613
|
1665
|
#define GE2 >=
|
1614
|
|
- #define LE2 <=
|
1615
|
1666
|
#endif
|
1616
|
1667
|
if (current_temperature_raw[2] GE2 maxttemp_raw[2]) max_temp_error(2);
|
1617
|
|
- if (current_temperature_raw[2] LE2 minttemp_raw[2]) min_temp_error(2);
|
|
1668
|
+ if (minttemp_raw[2] GE0 current_temperature_raw[2]) min_temp_error(2);
|
|
1669
|
+
|
1618
|
1670
|
#if EXTRUDERS > 3
|
1619
|
1671
|
#if HEATER_3_RAW_LO_TEMP > HEATER_3_RAW_HI_TEMP
|
1620
|
1672
|
#define GE3 <=
|
1621
|
|
- #define LE3 >=
|
1622
|
1673
|
#else
|
1623
|
1674
|
#define GE3 >=
|
1624
|
|
- #define LE3 <=
|
1625
|
1675
|
#endif
|
1626
|
1676
|
if (current_temperature_raw[3] GE3 maxttemp_raw[3]) max_temp_error(3);
|
1627
|
|
- if (current_temperature_raw[3] LE3 minttemp_raw[3]) min_temp_error(3);
|
|
1677
|
+ if (minttemp_raw[3] GE0 current_temperature_raw[3]) min_temp_error(3);
|
|
1678
|
+
|
1628
|
1679
|
#endif // EXTRUDERS > 3
|
1629
|
1680
|
#endif // EXTRUDERS > 2
|
1630
|
1681
|
#endif // EXTRUDERS > 1
|
|
@@ -1632,10 +1683,8 @@ ISR(TIMER0_COMPB_vect) {
|
1632
|
1683
|
#if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0)
|
1633
|
1684
|
#if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP
|
1634
|
1685
|
#define GEBED <=
|
1635
|
|
- #define LEBED >=
|
1636
|
1686
|
#else
|
1637
|
1687
|
#define GEBED >=
|
1638
|
|
- #define LEBED <=
|
1639
|
1688
|
#endif
|
1640
|
1689
|
if (current_temperature_bed_raw GEBED bed_maxttemp_raw) {
|
1641
|
1690
|
target_temperature_bed = 0;
|