1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-23 12:04:19 +00:00

Added MAX6675 support. (Thanks to gregfrost)

Needs some work to remove the blocking in read max6675.
This commit is contained in:
Erik van der Zalm 2012-02-05 13:05:07 +01:00
parent e45e5c68bb
commit 9f139d6e0e
3 changed files with 97 additions and 6 deletions

View File

@ -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

View File

@ -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
*

View File

@ -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<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
DIDR0 = 0;
@ -595,6 +624,62 @@ void bed_max_temp_error(void) {
SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
}
#define HEAT_INTERVAL 250
#ifdef HEATER_0_USES_MAX6675
long max6675_previous_millis = -HEAT_INTERVAL;
int max6675_temp = 2000;
int read_max6675()
{
if (millis() - max6675_previous_millis < HEAT_INTERVAL)
return max6675_temp;
max6675_previous_millis = millis();
max6675_temp = 0;
#ifdef PRR
PRR &= ~(1<<PRSPI);
#elif defined PRR0
PRR0 &= ~(1<<PRSPI);
#endif
SPCR = (1<<MSTR) | (1<<SPE) | (1<<SPR0);
// enable TT_MAX6675
WRITE(MAX6675_SS, 0);
// ensure 100ns delay - a bit extra is fine
delay(1);
// read MSB
SPDR = 0;
for (;(SPSR & (1<<SPIF)) == 0;);
max6675_temp = SPDR;
max6675_temp <<= 8;
// read LSB
SPDR = 0;
for (;(SPSR & (1<<SPIF)) == 0;);
max6675_temp |= SPDR;
// disable TT_MAX6675
WRITE(MAX6675_SS, 1);
if (max6675_temp & 4)
{
// thermocouple open
max6675_temp = 2000;
}
else
{
max6675_temp = max6675_temp >> 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;