Browse Source

Merge pull request #1402 from thinkyhead/issue_1227_max6675_spi

Borrow from Ultimaker to fix MAX6675 SPI conflict
Scott Lahteine 9 years ago
parent
commit
9552e59306
2 changed files with 40 additions and 18 deletions
  1. 1
    1
      Marlin/pins.h
  2. 39
    17
      Marlin/temperature.cpp

+ 1
- 1
Marlin/pins.h View File

904
   #define SCK_PIN          52
904
   #define SCK_PIN          52
905
   #define MISO_PIN         50
905
   #define MISO_PIN         50
906
   #define MOSI_PIN         51
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
 #else
908
 #else
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
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
 #endif
910
 #endif

+ 39
- 17
Marlin/temperature.cpp View File

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

Loading…
Cancel
Save