From 9f139d6e0e3592c71851535f25fb83245361a5f3 Mon Sep 17 00:00:00 2001 From: Erik van der Zalm Date: Sun, 5 Feb 2012 13:05:07 +0100 Subject: [PATCH] Added MAX6675 support. (Thanks to gregfrost) Needs some work to remove the blocking in read max6675. --- Marlin/Configuration.h | 2 + Marlin/pins.h | 9 +++-- Marlin/temperature.cpp | 92 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 97 insertions(+), 6 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 6b5e19a3d..49721cc19 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -55,6 +55,8 @@ #define HEATER_0_USES_AD595 //#define HEATER_1_USES_AD595 //#define HEATER_2_USES_AD595 +//#define HEATER_0_USES_MAX6675 + // Select one of these only to define how the bed temp is read. //#define THERMISTORBED 1 diff --git a/Marlin/pins.h b/Marlin/pins.h index 02f26150a..9ff7dd94a 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -331,16 +331,17 @@ // SPI for Max6675 Thermocouple #ifndef SDSUPPORT -// these pins are defined in the SD library if building with SD support #define SCK_PIN 52 - #define MISO_PIN 50 - #define MOSI_PIN 51 +// these pins are defined in the SD library if building with SD support + #define MAX_SCK_PIN 52 + #define MAX_MISO_PIN 50 + #define MAX_MOSI_PIN 51 #define MAX6675_SS 53 #else #define MAX6675_SS 49 #endif - #endif + /**************************************************************************************** * Duemilanove w/ ATMega328P pin assignment * diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 371c6e589..0be5f2607 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -283,6 +283,12 @@ int temp2analog(int celsius, uint8_t e) { SERIAL_ERRORLNPGM(" - Invalid extruder number!"); kill(); } + #ifdef HEATER_0_USES_MAX6675 + if (e == 0) + { + return celsius * 4; + } + #endif if(heater_ttbl_map[e] != 0) { int raw = 0; @@ -352,7 +358,14 @@ float analog2temp(int raw, uint8_t e) { SERIAL_ERROR((int)e); SERIAL_ERRORLNPGM(" - Invalid extruder number !"); kill(); - } + } + #ifdef HEATER_0_USES_MAX6675 + if (e == 0) + { + return 0.25 * raw; + } + #endif + if(heater_ttbl_map[e] != 0) { float celsius = 0; @@ -446,6 +459,22 @@ void tp_init() SET_OUTPUT(FAN_PIN); #endif + #ifdef HEATER_0_USES_MAX6675 + #ifndef SDSUPPORT + SET_OUTPUT(MAX_SCK_PIN); + WRITE(MAX_SCK_PIN,0); + + SET_OUTPUT(MAX_MOSI_PIN); + WRITE(MAX_MOSI_PIN,1); + + SET_INPUT(MAX_MISO_PIN); + WRITE(MAX_MISO_PIN,1); + #endif + + SET_OUTPUT(MAX6675_SS); + WRITE(MAX6675_SS,1); + #endif + // Set analog inputs ADCSRA = 1<> 3; + } + + return max6675_temp; +} +#endif + + // Timer 0 is shared with millies ISR(TIMER0_COMPB_vect) { @@ -653,6 +738,9 @@ ISR(TIMER0_COMPB_vect) #if (TEMP_0_PIN > -1) raw_temp_0_value += ADC; #endif + #ifdef HEATER_0_USES_MAX6675 // TODO remove the blocking + raw_temp_0_value = read_max6675(); + #endif temp_state = 2; break; case 2: // Prepare TEMP_BED @@ -732,7 +820,7 @@ ISR(TIMER0_COMPB_vect) #endif #if EXTRUDERS > 1 - #ifdef HEATER_1_USES_AD595 + #ifdef HEATER_1_USES_AD595 || defined HEATER_0_USES_MAX6675 current_raw[1] = raw_temp_1_value; #else current_raw[1] = 16383 - raw_temp_1_value;