|
@@ -775,8 +775,13 @@ void Temperature::manage_heater() {
|
775
|
775
|
updateTemperaturesFromRawValues(); // also resets the watchdog
|
776
|
776
|
|
777
|
777
|
#if ENABLED(HEATER_0_USES_MAX6675)
|
778
|
|
- if (current_temperature[0] > MIN(HEATER_0_MAXTEMP, MAX6675_TMAX - 1.0)) max_temp_error(0);
|
779
|
|
- if (current_temperature[0] < MAX(HEATER_0_MINTEMP, MAX6675_TMIN + .01)) min_temp_error(0);
|
|
778
|
+ if (current_temperature[0] > MIN(HEATER_0_MAXTEMP, HEATER_0_MAX6675_TMAX - 1.0)) max_temp_error(0);
|
|
779
|
+ if (current_temperature[0] < MAX(HEATER_0_MINTEMP, HEATER_0_MAX6675_TMIN + .01)) min_temp_error(0);
|
|
780
|
+ #endif
|
|
781
|
+
|
|
782
|
+ #if ENABLED(HEATER_1_USES_MAX6675)
|
|
783
|
+ if (current_temperature[1] > MIN(HEATER_1_MAXTEMP, HEATER_1_MAX6675_TMAX - 1.0)) max_temp_error(1);
|
|
784
|
+ if (current_temperature[1] < MAX(HEATER_1_MINTEMP, HEATER_1_MAX6675_TMIN + .01)) min_temp_error(1);
|
780
|
785
|
#endif
|
781
|
786
|
|
782
|
787
|
#if WATCH_HOTENDS || WATCH_THE_BED || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN || HEATER_IDLE_HANDLER
|
|
@@ -953,7 +958,9 @@ float Temperature::analog_to_celsius_hotend(const int raw, const uint8_t e) {
|
953
|
958
|
break;
|
954
|
959
|
#endif
|
955
|
960
|
case 1:
|
956
|
|
- #if ENABLED(HEATER_1_USES_AD595)
|
|
961
|
+ #if ENABLED(HEATER_1_USES_MAX6675)
|
|
962
|
+ return raw * 0.25;
|
|
963
|
+ #elif ENABLED(HEATER_1_USES_AD595)
|
957
|
964
|
return TEMP_AD595(raw);
|
958
|
965
|
#elif ENABLED(HEATER_1_USES_AD8495)
|
959
|
966
|
return TEMP_AD8495(raw);
|
|
@@ -1036,7 +1043,10 @@ float Temperature::analog_to_celsius_hotend(const int raw, const uint8_t e) {
|
1036
|
1043
|
*/
|
1037
|
1044
|
void Temperature::updateTemperaturesFromRawValues() {
|
1038
|
1045
|
#if ENABLED(HEATER_0_USES_MAX6675)
|
1039
|
|
- current_temperature_raw[0] = read_max6675();
|
|
1046
|
+ current_temperature_raw[0] = READ_MAX6675(0);
|
|
1047
|
+ #endif
|
|
1048
|
+ #if ENABLED(HEATER_1_USES_MAX6675)
|
|
1049
|
+ current_temperature_raw[1] = READ_MAX6675(1);
|
1040
|
1050
|
#endif
|
1041
|
1051
|
HOTEND_LOOP() current_temperature[e] = analog_to_celsius_hotend(current_temperature_raw[e], e);
|
1042
|
1052
|
#if HAS_HEATED_BED
|
|
@@ -1170,10 +1180,14 @@ void Temperature::init() {
|
1170
|
1180
|
max6675_spi.init();
|
1171
|
1181
|
|
1172
|
1182
|
OUT_WRITE(SS_PIN, HIGH);
|
1173
|
|
- OUT_WRITE(MAX6675_SS, HIGH);
|
|
1183
|
+ OUT_WRITE(MAX6675_SS_PIN, HIGH);
|
1174
|
1184
|
|
1175
|
1185
|
#endif // HEATER_0_USES_MAX6675
|
1176
|
1186
|
|
|
1187
|
+ #if ENABLED(HEATER_1_USES_MAX6675)
|
|
1188
|
+ OUT_WRITE(MAX6675_SS2_PIN, HIGH);
|
|
1189
|
+ #endif
|
|
1190
|
+
|
1177
|
1191
|
HAL_adc_init();
|
1178
|
1192
|
|
1179
|
1193
|
#if HAS_TEMP_ADC_0
|
|
@@ -1595,47 +1609,71 @@ void Temperature::disable_all_heaters() {
|
1595
|
1609
|
|
1596
|
1610
|
#endif // PROBING_HEATERS_OFF
|
1597
|
1611
|
|
1598
|
|
-#if ENABLED(HEATER_0_USES_MAX6675)
|
1599
|
|
-
|
1600
|
|
- #define MAX6675_HEAT_INTERVAL 250u
|
|
1612
|
+#if HAS_MAX6675
|
1601
|
1613
|
|
1602
|
|
- #if ENABLED(MAX6675_IS_MAX31855)
|
1603
|
|
- uint32_t max6675_temp = 2000;
|
1604
|
|
- #define MAX6675_ERROR_MASK 7
|
1605
|
|
- #define MAX6675_DISCARD_BITS 18
|
1606
|
|
- #define MAX6675_SPEED_BITS 3 // (_BV(SPR1)) // clock ÷ 64
|
1607
|
|
- #else
|
1608
|
|
- uint16_t max6675_temp = 2000;
|
1609
|
|
- #define MAX6675_ERROR_MASK 4
|
1610
|
|
- #define MAX6675_DISCARD_BITS 3
|
1611
|
|
- #define MAX6675_SPEED_BITS 2 // (_BV(SPR0)) // clock ÷ 16
|
1612
|
|
- #endif
|
|
1614
|
+ int Temperature::read_max6675(
|
|
1615
|
+ #if COUNT_6675 > 1
|
|
1616
|
+ const uint8_t hindex
|
|
1617
|
+ #endif
|
|
1618
|
+ ) {
|
|
1619
|
+ #if COUNT_6675 == 1
|
|
1620
|
+ constexpr uint8_t hindex = 0;
|
|
1621
|
+ #endif
|
1613
|
1622
|
|
1614
|
|
- int Temperature::read_max6675() {
|
|
1623
|
+ #define MAX6675_HEAT_INTERVAL 250UL
|
1615
|
1624
|
|
1616
|
|
- static millis_t next_max6675_ms = 0;
|
|
1625
|
+ #if ENABLED(MAX6675_IS_MAX31855)
|
|
1626
|
+ static uint32_t max6675_temp = 2000;
|
|
1627
|
+ #define MAX6675_ERROR_MASK 7
|
|
1628
|
+ #define MAX6675_DISCARD_BITS 18
|
|
1629
|
+ #define MAX6675_SPEED_BITS 3 // (_BV(SPR1)) // clock ÷ 64
|
|
1630
|
+ #else
|
|
1631
|
+ static uint16_t max6675_temp = 2000;
|
|
1632
|
+ #define MAX6675_ERROR_MASK 4
|
|
1633
|
+ #define MAX6675_DISCARD_BITS 3
|
|
1634
|
+ #define MAX6675_SPEED_BITS 2 // (_BV(SPR0)) // clock ÷ 16
|
|
1635
|
+ #endif
|
1617
|
1636
|
|
|
1637
|
+ // Return last-read value between readings
|
|
1638
|
+ static millis_t next_max6675_ms[COUNT_6675] = { 0 };
|
1618
|
1639
|
millis_t ms = millis();
|
|
1640
|
+ if (PENDING(ms, next_max6675_ms[hindex])) return int(max6675_temp);
|
|
1641
|
+ next_max6675_ms[hindex] = ms + MAX6675_HEAT_INTERVAL;
|
1619
|
1642
|
|
1620
|
|
- if (PENDING(ms, next_max6675_ms)) return (int)max6675_temp;
|
1621
|
|
-
|
1622
|
|
- next_max6675_ms = ms + MAX6675_HEAT_INTERVAL;
|
|
1643
|
+ //
|
|
1644
|
+ // TODO: spiBegin, spiRec and spiInit doesn't work when soft spi is used.
|
|
1645
|
+ //
|
|
1646
|
+ #if MB(MIGHTYBOARD_REVE)
|
|
1647
|
+ spiBegin();
|
|
1648
|
+ spiInit(MAX6675_SPEED_BITS);
|
|
1649
|
+ #endif
|
1623
|
1650
|
|
1624
|
|
- spiBegin();
|
1625
|
|
- spiInit(MAX6675_SPEED_BITS);
|
|
1651
|
+ #if COUNT_6675 > 1
|
|
1652
|
+ #define WRITE_MAX6675(V) do{ switch (hindex) { case 1: WRITE(MAX6675_SS2_PIN, V); break; default: WRITE(MAX6675_SS_PIN, V); } }while(0)
|
|
1653
|
+ #elif ENABLED(HEATER_1_USES_MAX6675)
|
|
1654
|
+ #define WRITE_MAX6675(V) WRITE(MAX6675_SS2_PIN, V)
|
|
1655
|
+ #else
|
|
1656
|
+ #define WRITE_MAX6675(V) WRITE(MAX6675_SS_PIN, V)
|
|
1657
|
+ #endif
|
1626
|
1658
|
|
1627
|
|
- WRITE(MAX6675_SS, 0); // enable TT_MAX6675
|
|
1659
|
+ WRITE_MAX6675(LOW); // enable TT_MAX6675
|
1628
|
1660
|
|
1629
|
1661
|
DELAY_NS(100); // Ensure 100ns delay
|
1630
|
1662
|
|
1631
|
1663
|
// Read a big-endian temperature value
|
1632
|
1664
|
max6675_temp = 0;
|
1633
|
1665
|
for (uint8_t i = sizeof(max6675_temp); i--;) {
|
1634
|
|
- max6675_temp |= spiRec();
|
|
1666
|
+ max6675_temp |= (
|
|
1667
|
+ #if MB(MIGHTYBOARD_REVE)
|
|
1668
|
+ max6675_spi.receive()
|
|
1669
|
+ #else
|
|
1670
|
+ spiRec()
|
|
1671
|
+ #endif
|
|
1672
|
+ );
|
1635
|
1673
|
if (i > 0) max6675_temp <<= 8; // shift left if not the last byte
|
1636
|
1674
|
}
|
1637
|
1675
|
|
1638
|
|
- WRITE(MAX6675_SS, 1); // disable TT_MAX6675
|
|
1676
|
+ WRITE_MAX6675(HIGH); // disable TT_MAX6675
|
1639
|
1677
|
|
1640
|
1678
|
if (max6675_temp & MAX6675_ERROR_MASK) {
|
1641
|
1679
|
SERIAL_ERROR_START();
|
|
@@ -1651,7 +1689,17 @@ void Temperature::disable_all_heaters() {
|
1651
|
1689
|
#else
|
1652
|
1690
|
SERIAL_ERRORLNPGM("MAX6675");
|
1653
|
1691
|
#endif
|
1654
|
|
- max6675_temp = MAX6675_TMAX * 4; // thermocouple open
|
|
1692
|
+
|
|
1693
|
+ // Thermocouple open
|
|
1694
|
+ max6675_temp = 4 * (
|
|
1695
|
+ #if COUNT_6675 > 1
|
|
1696
|
+ hindex ? HEATER_1_MAX6675_TMAX : HEATER_0_MAX6675_TMAX
|
|
1697
|
+ #elif ENABLED(HEATER_1_USES_MAX6675)
|
|
1698
|
+ HEATER_1_MAX6675_TMAX
|
|
1699
|
+ #else
|
|
1700
|
+ HEATER_0_MAX6675_TMAX
|
|
1701
|
+ #endif
|
|
1702
|
+ );
|
1655
|
1703
|
}
|
1656
|
1704
|
else
|
1657
|
1705
|
max6675_temp >>= MAX6675_DISCARD_BITS;
|
|
@@ -1660,24 +1708,28 @@ void Temperature::disable_all_heaters() {
|
1660
|
1708
|
if (max6675_temp & 0x00002000) max6675_temp |= 0xFFFFC000;
|
1661
|
1709
|
#endif
|
1662
|
1710
|
|
1663
|
|
- return (int)max6675_temp;
|
|
1711
|
+ return int(max6675_temp);
|
1664
|
1712
|
}
|
1665
|
1713
|
|
1666
|
|
-#endif // HEATER_0_USES_MAX6675
|
|
1714
|
+#endif // HAS_MAX6675
|
1667
|
1715
|
|
1668
|
1716
|
/**
|
1669
|
1717
|
* Get raw temperatures
|
1670
|
1718
|
*/
|
1671
|
1719
|
void Temperature::set_current_temp_raw() {
|
|
1720
|
+
|
1672
|
1721
|
#if HAS_TEMP_ADC_0 && DISABLED(HEATER_0_USES_MAX6675)
|
1673
|
1722
|
current_temperature_raw[0] = raw_temp_value[0];
|
1674
|
1723
|
#endif
|
|
1724
|
+
|
1675
|
1725
|
#if HAS_TEMP_ADC_1
|
|
1726
|
+
|
1676
|
1727
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
1677
|
1728
|
redundant_temperature_raw = raw_temp_value[1];
|
1678
|
|
- #else
|
|
1729
|
+ #elif DISABLED(HEATER_1_USES_MAX6675)
|
1679
|
1730
|
current_temperature_raw[1] = raw_temp_value[1];
|
1680
|
1731
|
#endif
|
|
1732
|
+
|
1681
|
1733
|
#if HAS_TEMP_ADC_2
|
1682
|
1734
|
current_temperature_raw[2] = raw_temp_value[2];
|
1683
|
1735
|
#if HAS_TEMP_ADC_3
|
|
@@ -1690,6 +1742,7 @@ void Temperature::set_current_temp_raw() {
|
1690
|
1742
|
#endif // HAS_TEMP_ADC_4
|
1691
|
1743
|
#endif // HAS_TEMP_ADC_3
|
1692
|
1744
|
#endif // HAS_TEMP_ADC_2
|
|
1745
|
+
|
1693
|
1746
|
#endif // HAS_TEMP_ADC_1
|
1694
|
1747
|
|
1695
|
1748
|
#if HAS_HEATED_BED
|
|
@@ -1771,17 +1824,17 @@ void Temperature::readings_ready() {
|
1771
|
1824
|
|
1772
|
1825
|
#if HAS_HEATED_BED
|
1773
|
1826
|
#if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP
|
1774
|
|
- #define GEBED <=
|
|
1827
|
+ #define BEDCMP(A,B) ((A)<=(B))
|
1775
|
1828
|
#else
|
1776
|
|
- #define GEBED >=
|
|
1829
|
+ #define BEDCMP(A,B) ((A)>=(B))
|
1777
|
1830
|
#endif
|
1778
|
1831
|
const bool bed_on = (target_temperature_bed > 0)
|
1779
|
1832
|
#if ENABLED(PIDTEMPBED)
|
1780
|
1833
|
|| (soft_pwm_amount_bed > 0)
|
1781
|
1834
|
#endif
|
1782
|
1835
|
;
|
1783
|
|
- if (current_temperature_bed_raw GEBED bed_maxttemp_raw) max_temp_error(-1);
|
1784
|
|
- if (bed_minttemp_raw GEBED current_temperature_bed_raw && bed_on) min_temp_error(-1);
|
|
1836
|
+ if (BEDCMP(current_temperature_bed_raw, bed_maxttemp_raw)) max_temp_error(-1);
|
|
1837
|
+ if (BEDCMP(bed_minttemp_raw, current_temperature_bed_raw) && bed_on) min_temp_error(-1);
|
1785
|
1838
|
#endif
|
1786
|
1839
|
}
|
1787
|
1840
|
|