Browse Source

Fix temperature min/max test

- Base tests on all thermistors/thermocouples, not just heater 0
Scott Lahteine 9 years ago
parent
commit
3703694e30
1 changed files with 67 additions and 34 deletions
  1. 67
    34
      Marlin/temperature.cpp

+ 67
- 34
Marlin/temperature.cpp View File

145
   static float temp_iState_min_bed;
145
   static float temp_iState_min_bed;
146
   static float temp_iState_max_bed;
146
   static float temp_iState_max_bed;
147
 #else //PIDTEMPBED
147
 #else //PIDTEMPBED
148
-	static unsigned long  previous_millis_bed_heater;
148
+  static unsigned long  previous_millis_bed_heater;
149
 #endif //PIDTEMPBED
149
 #endif //PIDTEMPBED
150
   static unsigned char soft_pwm[EXTRUDERS];
150
   static unsigned char soft_pwm[EXTRUDERS];
151
 
151
 
243
     SERIAL_ECHOLN(MSG_PID_BAD_EXTRUDER_NUM);
243
     SERIAL_ECHOLN(MSG_PID_BAD_EXTRUDER_NUM);
244
     return;
244
     return;
245
   }
245
   }
246
-	
246
+  
247
   SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START);
247
   SERIAL_ECHOLN(MSG_PID_AUTOTUNE_START);
248
 
248
 
249
   disable_heater(); // switch off all heaters.
249
   disable_heater(); // switch off all heaters.
755
   #ifdef FILAMENT_SENSOR
755
   #ifdef FILAMENT_SENSOR
756
     if (filament_sensor) {
756
     if (filament_sensor) {
757
       meas_shift_index = delay_index1 - meas_delay_cm;
757
       meas_shift_index = delay_index1 - meas_delay_cm;
758
-		  if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
759
-		  
758
+      if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
759
+      
760
       // Get the delayed info and add 100 to reconstitute to a percent of
760
       // Get the delayed info and add 100 to reconstitute to a percent of
761
       // the nominal filament diameter then square it to get an area
761
       // the nominal filament diameter then square it to get an area
762
       meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
762
       meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
1259
 ISR(TIMER0_COMPB_vect) {
1259
 ISR(TIMER0_COMPB_vect) {
1260
   //these variables are only accesible from the ISR, but static, so they don't lose their value
1260
   //these variables are only accesible from the ISR, but static, so they don't lose their value
1261
   static unsigned char temp_count = 0;
1261
   static unsigned char temp_count = 0;
1262
-  static unsigned long raw_temp_0_value = 0;
1263
-  static unsigned long raw_temp_1_value = 0;
1264
-  static unsigned long raw_temp_2_value = 0;
1265
-  static unsigned long raw_temp_3_value = 0;
1262
+  static unsigned long raw_temp_value[EXTRUDERS] = { 0 };
1266
   static unsigned long raw_temp_bed_value = 0;
1263
   static unsigned long raw_temp_bed_value = 0;
1267
   static TempState temp_state = StartupDelay;
1264
   static TempState temp_state = StartupDelay;
1268
   static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
1265
   static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
1474
       break;
1471
       break;
1475
     case MeasureTemp_0:
1472
     case MeasureTemp_0:
1476
       #if HAS_TEMP_0
1473
       #if HAS_TEMP_0
1477
-        raw_temp_0_value += ADC;
1474
+        raw_temp_value[0] += ADC;
1478
       #endif
1475
       #endif
1479
       temp_state = PrepareTemp_BED;
1476
       temp_state = PrepareTemp_BED;
1480
       break;
1477
       break;
1500
       break;
1497
       break;
1501
     case MeasureTemp_1:
1498
     case MeasureTemp_1:
1502
       #if HAS_TEMP_1
1499
       #if HAS_TEMP_1
1503
-        raw_temp_1_value += ADC;
1500
+        raw_temp_value[1] += ADC;
1504
       #endif
1501
       #endif
1505
       temp_state = PrepareTemp_2;
1502
       temp_state = PrepareTemp_2;
1506
       break;
1503
       break;
1513
       break;
1510
       break;
1514
     case MeasureTemp_2:
1511
     case MeasureTemp_2:
1515
       #if HAS_TEMP_2
1512
       #if HAS_TEMP_2
1516
-        raw_temp_2_value += ADC;
1513
+        raw_temp_value[2] += ADC;
1517
       #endif
1514
       #endif
1518
       temp_state = PrepareTemp_3;
1515
       temp_state = PrepareTemp_3;
1519
       break;
1516
       break;
1526
       break;
1523
       break;
1527
     case MeasureTemp_3:
1524
     case MeasureTemp_3:
1528
       #if HAS_TEMP_3
1525
       #if HAS_TEMP_3
1529
-        raw_temp_3_value += ADC;
1526
+        raw_temp_value[3] += ADC;
1530
       #endif
1527
       #endif
1531
       temp_state = Prepare_FILWIDTH;
1528
       temp_state = Prepare_FILWIDTH;
1532
       break;
1529
       break;
1561
   if (temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256)  = 164ms.
1558
   if (temp_count >= OVERSAMPLENR) { // 10 * 16 * 1/(16000000/64/256)  = 164ms.
1562
     if (!temp_meas_ready) { //Only update the raw values if they have been read. Else we could be updating them during reading.
1559
     if (!temp_meas_ready) { //Only update the raw values if they have been read. Else we could be updating them during reading.
1563
       #ifndef HEATER_0_USES_MAX6675
1560
       #ifndef HEATER_0_USES_MAX6675
1564
-        current_temperature_raw[0] = raw_temp_0_value;
1561
+        current_temperature_raw[0] = raw_temp_value[0];
1565
       #endif
1562
       #endif
1566
       #if EXTRUDERS > 1
1563
       #if EXTRUDERS > 1
1567
-        current_temperature_raw[1] = raw_temp_1_value;
1564
+        current_temperature_raw[1] = raw_temp_value[1];
1568
         #if EXTRUDERS > 2
1565
         #if EXTRUDERS > 2
1569
-          current_temperature_raw[2] = raw_temp_2_value;
1566
+          current_temperature_raw[2] = raw_temp_value[2];
1570
           #if EXTRUDERS > 3
1567
           #if EXTRUDERS > 3
1571
-            current_temperature_raw[3] = raw_temp_3_value;
1568
+            current_temperature_raw[3] = raw_temp_value[3];
1572
           #endif
1569
           #endif
1573
         #endif
1570
         #endif
1574
       #endif
1571
       #endif
1575
       #ifdef TEMP_SENSOR_1_AS_REDUNDANT
1572
       #ifdef TEMP_SENSOR_1_AS_REDUNDANT
1576
-        redundant_temperature_raw = raw_temp_1_value;
1573
+        redundant_temperature_raw = raw_temp_value[1];
1577
       #endif
1574
       #endif
1578
       current_temperature_bed_raw = raw_temp_bed_value;
1575
       current_temperature_bed_raw = raw_temp_bed_value;
1579
     } //!temp_meas_ready
1576
     } //!temp_meas_ready
1585
     
1582
     
1586
     temp_meas_ready = true;
1583
     temp_meas_ready = true;
1587
     temp_count = 0;
1584
     temp_count = 0;
1588
-    raw_temp_0_value = 0;
1589
-    raw_temp_1_value = 0;
1590
-    raw_temp_2_value = 0;
1591
-    raw_temp_3_value = 0;
1585
+    for (int i = 0; i < EXTRUDERS; i++) raw_temp_value[i] = 0;
1592
     raw_temp_bed_value = 0;
1586
     raw_temp_bed_value = 0;
1593
 
1587
 
1594
     #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1588
     #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1595
-      #define MAXTEST <=
1596
-      #define MINTEST >=
1589
+      #define GE0 <=
1590
+      #define LE0 >=
1597
     #else
1591
     #else
1598
-      #define MAXTEST >=
1599
-      #define MINTEST <=
1592
+      #define GE0 >=
1593
+      #define LE0 <=
1600
     #endif
1594
     #endif
1595
+    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);
1597
+
1598
+    #if EXTRUDERS > 1
1599
+      #if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
1600
+        #define GE1 <=
1601
+        #define LE1 >=
1602
+      #else
1603
+        #define GE1 >=
1604
+        #define LE1 <=
1605
+      #endif
1606
+      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);
1608
+      #if EXTRUDERS > 2
1609
+        #if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
1610
+          #define GE2 <=
1611
+          #define LE2 >=
1612
+        #else
1613
+          #define GE2 >=
1614
+          #define LE2 <=
1615
+        #endif
1616
+        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);
1618
+        #if EXTRUDERS > 3
1619
+          #if HEATER_3_RAW_LO_TEMP > HEATER_3_RAW_HI_TEMP
1620
+            #define GE3 <=
1621
+            #define LE3 >=
1622
+          #else
1623
+            #define GE3 >=
1624
+            #define LE3 <=
1625
+          #endif
1626
+          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);
1628
+        #endif // EXTRUDERS > 3
1629
+      #endif // EXTRUDERS > 2
1630
+    #endif // EXTRUDERS > 1
1601
 
1631
 
1602
-    for (int i=0; i<EXTRUDERS; i++) {
1603
-      if (current_temperature_raw[i] MAXTEST maxttemp_raw[i]) max_temp_error(i);
1604
-      else if (current_temperature_raw[i] MINTEST minttemp_raw[i]) min_temp_error(i);
1605
-    }
1606
-    /* No bed MINTEMP error? */
1607
     #if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0)
1632
     #if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0)
1608
-      if (current_temperature_bed_raw MAXTEST bed_maxttemp_raw) {
1609
-          target_temperature_bed = 0;
1610
-          bed_max_temp_error();
1611
-        }
1633
+      #if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP
1634
+        #define GEBED <=
1635
+        #define LEBED >=
1636
+      #else
1637
+        #define GEBED >=
1638
+        #define LEBED <=
1639
+      #endif
1640
+      if (current_temperature_bed_raw GEBED bed_maxttemp_raw) {
1641
+        target_temperature_bed = 0;
1642
+        bed_max_temp_error();
1643
+      }
1612
     #endif
1644
     #endif
1645
+
1613
   } // temp_count >= OVERSAMPLENR
1646
   } // temp_count >= OVERSAMPLENR
1614
 
1647
 
1615
   #ifdef BABYSTEPPING
1648
   #ifdef BABYSTEPPING

Loading…
Cancel
Save