Explorar el Código

Added MAX6675 support. (Thanks to gregfrost)

Needs some work to remove the blocking in read max6675.
Erik van der Zalm hace 12 años
padre
commit
9f139d6e0e
Se han modificado 3 ficheros con 97 adiciones y 6 borrados
  1. 2
    0
      Marlin/Configuration.h
  2. 5
    4
      Marlin/pins.h
  3. 90
    2
      Marlin/temperature.cpp

+ 2
- 0
Marlin/Configuration.h Ver fichero

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

+ 5
- 4
Marlin/pins.h Ver fichero

@@ -331,16 +331,17 @@
331 331
 // SPI for Max6675 Thermocouple 
332 332
 
333 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 338
   #define MAX6675_SS       53
338 339
 #else
339 340
   #define MAX6675_SS       49
340 341
 #endif
341 342
 
342
-
343 343
 #endif
344
+
344 345
 /****************************************************************************************
345 346
 * Duemilanove w/ ATMega328P pin assignment
346 347
 *

+ 90
- 2
Marlin/temperature.cpp Ver fichero

@@ -283,6 +283,12 @@ int temp2analog(int celsius, uint8_t e) {
283 283
       SERIAL_ERRORLNPGM(" - Invalid extruder number!");
284 284
       kill();
285 285
   }
286
+  #ifdef HEATER_0_USES_MAX6675
287
+    if (e == 0)
288
+    {
289
+      return celsius * 4;
290
+    }
291
+  #endif
286 292
   if(heater_ttbl_map[e] != 0)
287 293
   {
288 294
     int raw = 0;
@@ -352,7 +358,14 @@ float analog2temp(int raw, uint8_t e) {
352 358
       SERIAL_ERROR((int)e);
353 359
       SERIAL_ERRORLNPGM(" - Invalid extruder number !");
354 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 369
   if(heater_ttbl_map[e] != 0)
357 370
   {
358 371
     float celsius = 0;
@@ -446,6 +459,22 @@ void tp_init()
446 459
     SET_OUTPUT(FAN_PIN);
447 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 478
   // Set analog inputs
450 479
   ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
451 480
   DIDR0 = 0;
@@ -595,6 +624,62 @@ void bed_max_temp_error(void) {
595 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 683
 // Timer 0 is shared with millies
599 684
 ISR(TIMER0_COMPB_vect)
600 685
 {
@@ -653,6 +738,9 @@ ISR(TIMER0_COMPB_vect)
653 738
       #if (TEMP_0_PIN > -1)
654 739
         raw_temp_0_value += ADC;
655 740
       #endif
741
+      #ifdef HEATER_0_USES_MAX6675 // TODO remove the blocking
742
+        raw_temp_0_value = read_max6675();
743
+      #endif
656 744
       temp_state = 2;
657 745
       break;
658 746
     case 2: // Prepare TEMP_BED
@@ -732,7 +820,7 @@ ISR(TIMER0_COMPB_vect)
732 820
     #endif
733 821
 
734 822
 #if EXTRUDERS > 1    
735
-    #ifdef HEATER_1_USES_AD595
823
+    #ifdef HEATER_1_USES_AD595 || defined HEATER_0_USES_MAX6675
736 824
       current_raw[1] = raw_temp_1_value;
737 825
     #else
738 826
       current_raw[1] = 16383 - raw_temp_1_value;

Loading…
Cancelar
Guardar