Ver código fonte

Merge pull request #1402 from thinkyhead/issue_1227_max6675_spi

Borrow from Ultimaker to fix MAX6675 SPI conflict
Scott Lahteine 9 anos atrás
pai
commit
9552e59306
2 arquivos alterados com 40 adições e 18 exclusões
  1. 1
    1
      Marlin/pins.h
  2. 39
    17
      Marlin/temperature.cpp

+ 1
- 1
Marlin/pins.h Ver arquivo

@@ -904,7 +904,7 @@
904 904
   #define SCK_PIN          52
905 905
   #define MISO_PIN         50
906 906
   #define MOSI_PIN         51
907
-  #define MAX6675_SS       66// Do not use pin 53 if there is even the remote possibility of using Dsplay/SD card
907
+  #define MAX6675_SS       66// Do not use pin 53 if there is even the remote possibility of using Display/SD card
908 908
 #else
909 909
   #define MAX6675_SS       66// Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
910 910
 #endif

+ 39
- 17
Marlin/temperature.cpp Ver arquivo

@@ -177,6 +177,11 @@ unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0);
177 177
 #ifdef FILAMENT_SENSOR
178 178
   static int meas_shift_index;  //used to point to a delayed sample in buffer for filament width sensor
179 179
 #endif
180
+
181
+#ifdef HEATER_0_USES_MAX6675
182
+  static int read_max6675();
183
+#endif
184
+
180 185
 //===========================================================================
181 186
 //=============================   functions      ============================
182 187
 //===========================================================================
@@ -448,6 +453,15 @@ void manage_heater()
448 453
 
449 454
   updateTemperaturesFromRawValues();
450 455
 
456
+  #ifdef HEATER_0_USES_MAX6675
457
+    if (current_temperature[0] > 1023 || current_temperature[0] > HEATER_0_MAXTEMP) {
458
+      max_temp_error(0);
459
+    }
460
+    if (current_temperature[0] == 0  || current_temperature[0] < HEATER_0_MINTEMP) {
461
+      min_temp_error(0);
462
+    }
463
+  #endif //HEATER_0_USES_MAX6675
464
+
451 465
   for(int e = 0; e < EXTRUDERS; e++) 
452 466
   {
453 467
 
@@ -757,6 +771,9 @@ static float analog2tempBed(int raw) {
757 771
     and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
758 772
 static void updateTemperaturesFromRawValues()
759 773
 {
774
+    #ifdef HEATER_0_USES_MAX6675
775
+        current_temperature_raw[0] = read_max6675();
776
+    #endif
760 777
     for(uint8_t e=0;e<EXTRUDERS;e++)
761 778
     {
762 779
         current_temperature[e] = analog2temp(current_temperature_raw[e], e);
@@ -833,7 +850,7 @@ void tp_init()
833 850
   #endif  
834 851
   #if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1) 
835 852
     SET_OUTPUT(HEATER_1_PIN);
836
-  #endif  
853
+  #endif
837 854
   #if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1) 
838 855
     SET_OUTPUT(HEATER_2_PIN);
839 856
   #endif  
@@ -851,6 +868,7 @@ void tp_init()
851 868
   #endif  
852 869
 
853 870
   #ifdef HEATER_0_USES_MAX6675
871
+
854 872
     #ifndef SDSUPPORT
855 873
       SET_OUTPUT(SCK_PIN);
856 874
       WRITE(SCK_PIN,0);
@@ -860,15 +878,15 @@ void tp_init()
860 878
     
861 879
       SET_INPUT(MISO_PIN);
862 880
       WRITE(MISO_PIN,1);
881
+    #else
882
+      pinMode(SS_PIN, OUTPUT);
883
+      digitalWrite(SS_PIN, HIGH);
863 884
     #endif
864
-    /* Using pinMode and digitalWrite, as that was the only way I could get it to compile */
865 885
     
866
-    //Have to toggle SD card CS pin to low first, to enable firmware to talk with SD card
867
-	pinMode(SS_PIN, OUTPUT);
868
-	digitalWrite(SS_PIN,0);  
869
-	pinMode(MAX6675_SS, OUTPUT);
870
-	digitalWrite(MAX6675_SS,1);
871
-  #endif
886
+    SET_OUTPUT(MAX6675_SS);
887
+    WRITE(MAX6675_SS,1);
888
+
889
+  #endif //HEATER_0_USES_MAX6675
872 890
 
873 891
   // Set analog inputs
874 892
   ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
@@ -1167,7 +1185,7 @@ void bed_max_temp_error(void) {
1167 1185
 long max6675_previous_millis = MAX6675_HEAT_INTERVAL;
1168 1186
 int max6675_temp = 2000;
1169 1187
 
1170
-int read_max6675()
1188
+static int read_max6675()
1171 1189
 {
1172 1190
   if (millis() - max6675_previous_millis < MAX6675_HEAT_INTERVAL) 
1173 1191
     return max6675_temp;
@@ -1175,9 +1193,9 @@ int read_max6675()
1175 1193
   max6675_previous_millis = millis();
1176 1194
   max6675_temp = 0;
1177 1195
     
1178
-  #ifdef	PRR
1196
+  #ifdef PRR
1179 1197
     PRR &= ~(1<<PRSPI);
1180
-  #elif defined PRR0
1198
+  #elif defined(PRR0)
1181 1199
     PRR0 &= ~(1<<PRSPI);
1182 1200
   #endif
1183 1201
   
@@ -1204,10 +1222,10 @@ int read_max6675()
1204 1222
   // disable TT_MAX6675
1205 1223
   WRITE(MAX6675_SS, 1);
1206 1224
 
1207
-  if (max6675_temp & 4) 
1225
+  if (max6675_temp & 4)
1208 1226
   {
1209 1227
     // thermocouple open
1210
-    max6675_temp = 2000;
1228
+    max6675_temp = 4000;
1211 1229
   }
1212 1230
   else 
1213 1231
   {
@@ -1216,7 +1234,8 @@ int read_max6675()
1216 1234
 
1217 1235
   return max6675_temp;
1218 1236
 }
1219
-#endif
1237
+
1238
+#endif //HEATER_0_USES_MAX6675
1220 1239
 
1221 1240
 
1222 1241
 // Timer 0 is shared with millies
@@ -1554,9 +1573,6 @@ ISR(TIMER0_COMPB_vect)
1554 1573
       #if defined(TEMP_0_PIN) && (TEMP_0_PIN > -1)
1555 1574
         raw_temp_0_value += ADC;
1556 1575
       #endif
1557
-      #ifdef HEATER_0_USES_MAX6675 // TODO remove the blocking
1558
-        raw_temp_0_value = read_max6675();
1559
-      #endif
1560 1576
       temp_state = 2;
1561 1577
       break;
1562 1578
     case 2: // Prepare TEMP_BED
@@ -1659,7 +1675,9 @@ ISR(TIMER0_COMPB_vect)
1659 1675
   {
1660 1676
     if (!temp_meas_ready) //Only update the raw values if they have been read. Else we could be updating them during reading.
1661 1677
     {
1678
+#ifndef HEATER_0_USES_MAX6675
1662 1679
       current_temperature_raw[0] = raw_temp_0_value;
1680
+#endif
1663 1681
 #if EXTRUDERS > 1
1664 1682
       current_temperature_raw[1] = raw_temp_1_value;
1665 1683
 #endif
@@ -1690,14 +1708,18 @@ ISR(TIMER0_COMPB_vect)
1690 1708
 #else
1691 1709
     if(current_temperature_raw[0] >= maxttemp_raw[0]) {
1692 1710
 #endif
1711
+#ifndef HEATER_0_USES_MAX6675
1693 1712
         max_temp_error(0);
1713
+#endif
1694 1714
     }
1695 1715
 #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
1696 1716
     if(current_temperature_raw[0] >= minttemp_raw[0]) {
1697 1717
 #else
1698 1718
     if(current_temperature_raw[0] <= minttemp_raw[0]) {
1699 1719
 #endif
1720
+#ifndef HEATER_0_USES_MAX6675
1700 1721
         min_temp_error(0);
1722
+#endif
1701 1723
     }
1702 1724
 #if EXTRUDERS > 1
1703 1725
 #if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP

Carregando…
Cancelar
Salvar