Browse Source

Added MAX6675 support. (Thanks to gregfrost)

Needs some work to remove the blocking in read max6675.
Erik van der Zalm 12 years ago
parent
commit
9f139d6e0e
3 changed files with 97 additions and 6 deletions
  1. 2
    0
      Marlin/Configuration.h
  2. 5
    4
      Marlin/pins.h
  3. 90
    2
      Marlin/temperature.cpp

+ 2
- 0
Marlin/Configuration.h View File

55
 #define HEATER_0_USES_AD595
55
 #define HEATER_0_USES_AD595
56
 //#define HEATER_1_USES_AD595
56
 //#define HEATER_1_USES_AD595
57
 //#define HEATER_2_USES_AD595
57
 //#define HEATER_2_USES_AD595
58
+//#define HEATER_0_USES_MAX6675
59
+ 
58
 
60
 
59
 // Select one of these only to define how the bed temp is read.
61
 // Select one of these only to define how the bed temp is read.
60
 //#define THERMISTORBED 1
62
 //#define THERMISTORBED 1

+ 5
- 4
Marlin/pins.h View File

331
 // SPI for Max6675 Thermocouple 
331
 // SPI for Max6675 Thermocouple 
332
 
332
 
333
 #ifndef SDSUPPORT
333
 #ifndef SDSUPPORT
334
-// these pins are defined in the SD library if building with SD support  #define SCK_PIN          52
335
-  #define MISO_PIN         50
336
-  #define MOSI_PIN         51
334
+// these pins are defined in the SD library if building with SD support  
335
+  #define MAX_SCK_PIN          52
336
+  #define MAX_MISO_PIN         50
337
+  #define MAX_MOSI_PIN         51
337
   #define MAX6675_SS       53
338
   #define MAX6675_SS       53
338
 #else
339
 #else
339
   #define MAX6675_SS       49
340
   #define MAX6675_SS       49
340
 #endif
341
 #endif
341
 
342
 
342
-
343
 #endif
343
 #endif
344
+
344
 /****************************************************************************************
345
 /****************************************************************************************
345
 * Duemilanove w/ ATMega328P pin assignment
346
 * Duemilanove w/ ATMega328P pin assignment
346
 *
347
 *

+ 90
- 2
Marlin/temperature.cpp View File

283
       SERIAL_ERRORLNPGM(" - Invalid extruder number!");
283
       SERIAL_ERRORLNPGM(" - Invalid extruder number!");
284
       kill();
284
       kill();
285
   }
285
   }
286
+  #ifdef HEATER_0_USES_MAX6675
287
+    if (e == 0)
288
+    {
289
+      return celsius * 4;
290
+    }
291
+  #endif
286
   if(heater_ttbl_map[e] != 0)
292
   if(heater_ttbl_map[e] != 0)
287
   {
293
   {
288
     int raw = 0;
294
     int raw = 0;
352
       SERIAL_ERROR((int)e);
358
       SERIAL_ERROR((int)e);
353
       SERIAL_ERRORLNPGM(" - Invalid extruder number !");
359
       SERIAL_ERRORLNPGM(" - Invalid extruder number !");
354
       kill();
360
       kill();
355
-  }
361
+  } 
362
+  #ifdef HEATER_0_USES_MAX6675
363
+    if (e == 0)
364
+    {
365
+      return 0.25 * raw;
366
+    }
367
+  #endif
368
+
356
   if(heater_ttbl_map[e] != 0)
369
   if(heater_ttbl_map[e] != 0)
357
   {
370
   {
358
     float celsius = 0;
371
     float celsius = 0;
446
     SET_OUTPUT(FAN_PIN);
459
     SET_OUTPUT(FAN_PIN);
447
   #endif  
460
   #endif  
448
 
461
 
462
+  #ifdef HEATER_0_USES_MAX6675
463
+    #ifndef SDSUPPORT
464
+      SET_OUTPUT(MAX_SCK_PIN);
465
+      WRITE(MAX_SCK_PIN,0);
466
+    
467
+      SET_OUTPUT(MAX_MOSI_PIN);
468
+      WRITE(MAX_MOSI_PIN,1);
469
+    
470
+      SET_INPUT(MAX_MISO_PIN);
471
+      WRITE(MAX_MISO_PIN,1);
472
+    #endif
473
+    
474
+    SET_OUTPUT(MAX6675_SS);
475
+    WRITE(MAX6675_SS,1);
476
+  #endif
477
+
449
   // Set analog inputs
478
   // Set analog inputs
450
   ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
479
   ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
451
   DIDR0 = 0;
480
   DIDR0 = 0;
595
   SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
624
   SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
596
 }
625
 }
597
 
626
 
627
+#define HEAT_INTERVAL 250
628
+#ifdef HEATER_0_USES_MAX6675
629
+long max6675_previous_millis = -HEAT_INTERVAL;
630
+int max6675_temp = 2000;
631
+
632
+int read_max6675()
633
+{
634
+  if (millis() - max6675_previous_millis < HEAT_INTERVAL) 
635
+    return max6675_temp;
636
+  
637
+  max6675_previous_millis = millis();
638
+  max6675_temp = 0;
639
+    
640
+  #ifdef	PRR
641
+    PRR &= ~(1<<PRSPI);
642
+  #elif defined PRR0
643
+    PRR0 &= ~(1<<PRSPI);
644
+  #endif
645
+  
646
+  SPCR = (1<<MSTR) | (1<<SPE) | (1<<SPR0);
647
+  
648
+  // enable TT_MAX6675
649
+  WRITE(MAX6675_SS, 0);
650
+  
651
+  // ensure 100ns delay - a bit extra is fine
652
+  delay(1);
653
+  
654
+  // read MSB
655
+  SPDR = 0;
656
+  for (;(SPSR & (1<<SPIF)) == 0;);
657
+  max6675_temp = SPDR;
658
+  max6675_temp <<= 8;
659
+  
660
+  // read LSB
661
+  SPDR = 0;
662
+  for (;(SPSR & (1<<SPIF)) == 0;);
663
+  max6675_temp |= SPDR;
664
+  
665
+  // disable TT_MAX6675
666
+  WRITE(MAX6675_SS, 1);
667
+
668
+  if (max6675_temp & 4) 
669
+  {
670
+    // thermocouple open
671
+    max6675_temp = 2000;
672
+  }
673
+  else 
674
+  {
675
+    max6675_temp = max6675_temp >> 3;
676
+  }
677
+
678
+  return max6675_temp;
679
+}
680
+#endif
681
+
682
+
598
 // Timer 0 is shared with millies
683
 // Timer 0 is shared with millies
599
 ISR(TIMER0_COMPB_vect)
684
 ISR(TIMER0_COMPB_vect)
600
 {
685
 {
653
       #if (TEMP_0_PIN > -1)
738
       #if (TEMP_0_PIN > -1)
654
         raw_temp_0_value += ADC;
739
         raw_temp_0_value += ADC;
655
       #endif
740
       #endif
741
+      #ifdef HEATER_0_USES_MAX6675 // TODO remove the blocking
742
+        raw_temp_0_value = read_max6675();
743
+      #endif
656
       temp_state = 2;
744
       temp_state = 2;
657
       break;
745
       break;
658
     case 2: // Prepare TEMP_BED
746
     case 2: // Prepare TEMP_BED
732
     #endif
820
     #endif
733
 
821
 
734
 #if EXTRUDERS > 1    
822
 #if EXTRUDERS > 1    
735
-    #ifdef HEATER_1_USES_AD595
823
+    #ifdef HEATER_1_USES_AD595 || defined HEATER_0_USES_MAX6675
736
       current_raw[1] = raw_temp_1_value;
824
       current_raw[1] = raw_temp_1_value;
737
     #else
825
     #else
738
       current_raw[1] = 16383 - raw_temp_1_value;
826
       current_raw[1] = 16383 - raw_temp_1_value;

Loading…
Cancel
Save